mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2025-12-06 07:12:04 +01:00
make decoder classes <<static>>
This commit is contained in:
parent
a6542f0b63
commit
f1bf468c2a
|
|
@ -23,18 +23,21 @@ from boswatch.decoder.zveidecoder import ZveiDecoder
|
|||
logging.debug("- %s loaded", __name__)
|
||||
|
||||
|
||||
def decode(data):
|
||||
"""!Choose the right decoder and return a bwPacket instance
|
||||
class Decoder:
|
||||
|
||||
@param data: data to decode
|
||||
@return bwPacket instance"""
|
||||
logging.debug("search decoder")
|
||||
if "FMS" in data:
|
||||
return FmsDecoder.decode(data)
|
||||
elif "POCSAG" in data:
|
||||
return PocsagDecoder.decode(data)
|
||||
elif "ZVEI" in data:
|
||||
return ZveiDecoder.decode(data)
|
||||
else:
|
||||
logging.error("no decoder found for: %s", data)
|
||||
return None
|
||||
@staticmethod
|
||||
def decode(data):
|
||||
"""!Choose the right decoder and return a bwPacket instance
|
||||
|
||||
@param data: data to decode
|
||||
@return bwPacket instance"""
|
||||
logging.debug("search decoder")
|
||||
if "FMS" in data:
|
||||
return FmsDecoder.decode(data)
|
||||
elif "POCSAG" in data:
|
||||
return PocsagDecoder.decode(data)
|
||||
elif "ZVEI" in data:
|
||||
return ZveiDecoder.decode(data)
|
||||
else:
|
||||
logging.error("no decoder found for: %s", data)
|
||||
return None
|
||||
|
|
|
|||
|
|
@ -30,10 +30,6 @@ class FmsDecoder:
|
|||
First step is to validate the data and _check if the format is correct.
|
||||
In the last step a valid BOSWatch packet is created and returned"""
|
||||
|
||||
def __init__(self):
|
||||
"""!Create a new instance"""
|
||||
logging.debug("FMS decoder started")
|
||||
|
||||
@staticmethod
|
||||
def decode(data):
|
||||
"""!Decodes FMS
|
||||
|
|
|
|||
|
|
@ -30,10 +30,6 @@ class PocsagDecoder:
|
|||
First step is to validate the data and _check if the format is correct.
|
||||
In the last step a valid BOSWatch packet is created and returned"""
|
||||
|
||||
def __init__(self):
|
||||
"""!Create a new instance"""
|
||||
logging.debug("POCSAG decoder started")
|
||||
|
||||
@staticmethod
|
||||
def decode(data):
|
||||
"""!Decodes POCSAG
|
||||
|
|
|
|||
|
|
@ -31,10 +31,6 @@ class ZveiDecoder:
|
|||
After that the double-tone-sign 'E' is replaced.
|
||||
In the last step a valid BOSWatch packet is created and returned"""
|
||||
|
||||
def __init__(self):
|
||||
"""!Create a new instance"""
|
||||
logging.debug("ZVEI decoder started")
|
||||
|
||||
@staticmethod
|
||||
def decode(data):
|
||||
"""!Decodes ZVEI
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ try:
|
|||
logging.debug("Import BOSWatch modules")
|
||||
from boswatch.config import Config
|
||||
from boswatch.network.client import TCPClient
|
||||
from boswatch.decoder import decoder
|
||||
from boswatch.decoder.decoder import Decoder
|
||||
from boswatch.utils import header
|
||||
except Exception as e: # pragma: no cover
|
||||
logging.exception("cannot import modules")
|
||||
|
|
@ -84,7 +84,7 @@ try:
|
|||
print("Alarm Nr #" + str(i))
|
||||
|
||||
data = "ZVEI1: 12345"
|
||||
bwPacket = decoder.decode(data)
|
||||
bwPacket = Decoder.decode(data)
|
||||
|
||||
if bwPacket:
|
||||
bwPacket.printInfo()
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@
|
|||
German BOS Information Script
|
||||
by Bastian Schroll
|
||||
|
||||
@file: test_decoder.py
|
||||
@file: test_Decoder.py
|
||||
@date: 15.12.2017
|
||||
@author: Bastian Schroll
|
||||
@description: Unittests for BOSWatch. File must be _run as "pytest" unittest
|
||||
"""
|
||||
import logging
|
||||
|
||||
from boswatch.decoder import decoder
|
||||
from boswatch.decoder.decoder import Decoder
|
||||
|
||||
|
||||
class Test_Decoder:
|
||||
|
|
@ -27,69 +27,69 @@ class Test_Decoder:
|
|||
|
||||
def test_decoderNoData(self):
|
||||
"""!Test a empty string"""
|
||||
assert decoder.decode("") is None
|
||||
assert Decoder.decode("") is None
|
||||
|
||||
def test_decoderZveiValid(self):
|
||||
"""!Test valid ZVEI"""
|
||||
assert not decoder.decode("ZVEI1: 12345") is None
|
||||
assert not decoder.decode("ZVEI1: 12838") is None
|
||||
assert not decoder.decode("ZVEI1: 34675") is None
|
||||
assert not Decoder.decode("ZVEI1: 12345") is None
|
||||
assert not Decoder.decode("ZVEI1: 12838") is None
|
||||
assert not Decoder.decode("ZVEI1: 34675") is None
|
||||
|
||||
def test_decoderZveiDoubleTone(self):
|
||||
"""!Test doubleTone included ZVEI"""
|
||||
assert not decoder.decode("ZVEI1: 6E789") is None
|
||||
assert not decoder.decode("ZVEI1: 975E7") is None
|
||||
assert not decoder.decode("ZVEI1: 2E87E") is None
|
||||
assert not Decoder.decode("ZVEI1: 6E789") is None
|
||||
assert not Decoder.decode("ZVEI1: 975E7") is None
|
||||
assert not Decoder.decode("ZVEI1: 2E87E") is None
|
||||
|
||||
def test_decoderZveiInvalid(self):
|
||||
"""Test invalid ZVEI"""
|
||||
assert decoder.decode("ZVEI1: 1245A") is None
|
||||
assert decoder.decode("ZVEI1: 1245") is None
|
||||
assert decoder.decode("ZVEI1: 135") is None
|
||||
assert decoder.decode("ZVEI1: 54") is None
|
||||
assert decoder.decode("ZVEI1: 54") is None
|
||||
assert Decoder.decode("ZVEI1: 1245A") is None
|
||||
assert Decoder.decode("ZVEI1: 1245") is None
|
||||
assert Decoder.decode("ZVEI1: 135") is None
|
||||
assert Decoder.decode("ZVEI1: 54") is None
|
||||
assert Decoder.decode("ZVEI1: 54") is None
|
||||
|
||||
def test_decoderPocsagValid(self):
|
||||
"""!Test valid POCSAG"""
|
||||
assert not decoder.decode("POCSAG512: Address: 1000000 Function: 0") is None
|
||||
assert not decoder.decode("POCSAG512: Address: 1000001 Function: 1") is None
|
||||
assert not decoder.decode("POCSAG1200: Address: 1000002 Function: 2") is None
|
||||
assert not decoder.decode("POCSAG2400: Address: 1000003 Function: 3") is None
|
||||
assert not Decoder.decode("POCSAG512: Address: 1000000 Function: 0") is None
|
||||
assert not Decoder.decode("POCSAG512: Address: 1000001 Function: 1") is None
|
||||
assert not Decoder.decode("POCSAG1200: Address: 1000002 Function: 2") is None
|
||||
assert not Decoder.decode("POCSAG2400: Address: 1000003 Function: 3") is None
|
||||
|
||||
def test_decoderPocsagText(self):
|
||||
"""!Test POCSAG with text"""
|
||||
assert not decoder.decode("POCSAG512: Address: 1000000 Function: 0 Alpha: test") is None
|
||||
assert not decoder.decode("POCSAG512: Address: 1000001 Function: 1 Alpha: test") is None
|
||||
assert not decoder.decode("POCSAG1200: Address: 1000002 Function: 2 Alpha: test") is None
|
||||
assert not decoder.decode("POCSAG2400: Address: 1000003 Function: 3 Alpha: test") is None
|
||||
assert not Decoder.decode("POCSAG512: Address: 1000000 Function: 0 Alpha: test") is None
|
||||
assert not Decoder.decode("POCSAG512: Address: 1000001 Function: 1 Alpha: test") is None
|
||||
assert not Decoder.decode("POCSAG1200: Address: 1000002 Function: 2 Alpha: test") is None
|
||||
assert not Decoder.decode("POCSAG2400: Address: 1000003 Function: 3 Alpha: test") is None
|
||||
|
||||
def test_decoderPocsagShortRic(self):
|
||||
"""!Test short POCSAG"""
|
||||
assert not decoder.decode("POCSAG512: Address: 3 Function: 0 Alpha: test") is None
|
||||
assert not decoder.decode("POCSAG512: Address: 33 Function: 0 Alpha: test") is None
|
||||
assert not decoder.decode("POCSAG1200: Address: 333 Function: 0 Alpha: test") is None
|
||||
assert not decoder.decode("POCSAG1200: Address: 3333 Function: 0 Alpha: test") is None
|
||||
assert not decoder.decode("POCSAG2400: Address: 33333 Function: 0 Alpha: test") is None
|
||||
assert not decoder.decode("POCSAG2400: Address: 333333 Function: 0 Alpha: test") is None
|
||||
assert not decoder.decode("POCSAG2400: Address: 3333333 Function: 0 Alpha: test") is None
|
||||
assert not Decoder.decode("POCSAG512: Address: 3 Function: 0 Alpha: test") is None
|
||||
assert not Decoder.decode("POCSAG512: Address: 33 Function: 0 Alpha: test") is None
|
||||
assert not Decoder.decode("POCSAG1200: Address: 333 Function: 0 Alpha: test") is None
|
||||
assert not Decoder.decode("POCSAG1200: Address: 3333 Function: 0 Alpha: test") is None
|
||||
assert not Decoder.decode("POCSAG2400: Address: 33333 Function: 0 Alpha: test") is None
|
||||
assert not Decoder.decode("POCSAG2400: Address: 333333 Function: 0 Alpha: test") is None
|
||||
assert not Decoder.decode("POCSAG2400: Address: 3333333 Function: 0 Alpha: test") is None
|
||||
|
||||
def test_decoderPocsagInvalid(self):
|
||||
"""!Test invalid POCSAG"""
|
||||
assert decoder.decode("POCSAG512: Address: 333333F Function: 0 Alpha: invalid") is None
|
||||
assert decoder.decode("POCSAG512: Address: 333333F Function: 1 Alpha: invalid") is None
|
||||
assert decoder.decode("POCSAG512: Address: 3333333 Function: 4 Alpha: invalid") is None
|
||||
assert Decoder.decode("POCSAG512: Address: 333333F Function: 0 Alpha: invalid") is None
|
||||
assert Decoder.decode("POCSAG512: Address: 333333F Function: 1 Alpha: invalid") is None
|
||||
assert Decoder.decode("POCSAG512: Address: 3333333 Function: 4 Alpha: invalid") is None
|
||||
|
||||
def test_decoderFmsValid(self):
|
||||
"""!Test valid FMS"""
|
||||
assert not decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST 2=I (ohneNA,ohneSIGNAL)) CRC correct""") is None
|
||||
assert not decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=I (ohneNA,ohneSIGNAL)) CRC correct""") is None
|
||||
assert not decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST 2=II (ohneNA,mit SIGNAL)) CRC correct""") is None
|
||||
assert not decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=III(mit NA,ohneSIGNAL)) CRC correct""") is None
|
||||
assert not decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST 2=IV (mit NA,mit SIGNAL)) CRC correct""") is None
|
||||
assert not Decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST 2=I (ohneNA,ohneSIGNAL)) CRC correct""") is None
|
||||
assert not Decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=I (ohneNA,ohneSIGNAL)) CRC correct""") is None
|
||||
assert not Decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST 2=II (ohneNA,mit SIGNAL)) CRC correct""") is None
|
||||
assert not Decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=III(mit NA,ohneSIGNAL)) CRC correct""") is None
|
||||
assert not Decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 0=FZG->LST 2=IV (mit NA,mit SIGNAL)) CRC correct""") is None
|
||||
|
||||
def test_decoderFmsInvalid(self):
|
||||
"""!Test invalid FMS"""
|
||||
assert decoder.decode("""FMS: 14170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=III(mit NA,ohneSIGNAL)) CRC correct""") is None
|
||||
assert decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Sta 3=Einsatz Ab 0=FZG->LST 2=IV (mit NA,mit SIGNAL)) CRC correct""") is None
|
||||
assert decoder.decode("""FMS: 14170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=III(mit NA,ohneSIGNAL)) CRC incorrect""") is None
|
||||
assert decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Sta 3=Einsatz Ab 0=FZG->LST 2=IV (mit NA,mit SIGNAL)) CRC incorrect""") is None
|
||||
assert Decoder.decode("""FMS: 14170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=III(mit NA,ohneSIGNAL)) CRC correct""") is None
|
||||
assert Decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Sta 3=Einsatz Ab 0=FZG->LST 2=IV (mit NA,mit SIGNAL)) CRC correct""") is None
|
||||
assert Decoder.decode("""FMS: 14170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Status 3=Einsatz Ab 1=LST->FZG 2=III(mit NA,ohneSIGNAL)) CRC incorrect""") is None
|
||||
assert Decoder.decode("""FMS: 43f314170000 (9=Rotkreuz 3=Bayern 1 Ort 0x25=037FZG 7141Sta 3=Einsatz Ab 0=FZG->LST 2=IV (mit NA,mit SIGNAL)) CRC incorrect""") is None
|
||||
|
|
|
|||
Loading…
Reference in a new issue