mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2025-12-06 07:12:04 +01:00
change decoder strategy
This commit is contained in:
parent
e97b97640b
commit
a1e1be6275
|
|
@ -16,42 +16,25 @@
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from boswatch.decoder.fms import Fms
|
from boswatch.decoder.fmsdecoder import FmsDecoder
|
||||||
from boswatch.decoder.pocsag import Pocsag
|
from boswatch.decoder.pocsagdecoder import PocsagDecoder
|
||||||
from boswatch.decoder.zvei import Zvei
|
from boswatch.decoder.zveidecoder import ZveiDecoder
|
||||||
|
|
||||||
logging.debug("- %s loaded", __name__)
|
logging.debug("- %s loaded", __name__)
|
||||||
|
|
||||||
|
|
||||||
def getDecoder(data):
|
def decode(data):
|
||||||
"""!Choose the right decoder and return the new decoder object
|
"""!Choose the right decoder and return a bwPacket instance
|
||||||
|
|
||||||
@param data: data to decode
|
@param data: data to decode
|
||||||
@return Decoder object"""
|
@return bwPacket instance"""
|
||||||
logging.debug("search decoder")
|
logging.debug("search decoder")
|
||||||
if "FMS" in data:
|
if "FMS" in data:
|
||||||
return Fms()
|
return FmsDecoder.decode(data)
|
||||||
elif "POCSAG" in data:
|
elif "POCSAG" in data:
|
||||||
return Pocsag()
|
return PocsagDecoder.decode(data)
|
||||||
elif "ZVEI" in data:
|
elif "ZVEI" in data:
|
||||||
return Zvei()
|
return ZveiDecoder.decode(data)
|
||||||
else:
|
else:
|
||||||
logging.debug("no decoder found for: %s", data)
|
logging.error("no decoder found for: %s", data)
|
||||||
return DummyDecoder()
|
return False
|
||||||
|
|
||||||
|
|
||||||
class DummyDecoder:
|
|
||||||
"""!This dummy decoder class is needed because in case of
|
|
||||||
an getDecoder() with false data, we must return a decoder
|
|
||||||
object with an decode() method to prevent an error"""
|
|
||||||
def __init__(self):
|
|
||||||
"""!Do nothing"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def decode(data):
|
|
||||||
"""!Dummy decode() method
|
|
||||||
|
|
||||||
@param data: data to decode
|
|
||||||
@return ALWAYS None"""
|
|
||||||
return None
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ from boswatch.packet import packet
|
||||||
logging.debug("- %s loaded", __name__)
|
logging.debug("- %s loaded", __name__)
|
||||||
|
|
||||||
|
|
||||||
class Fms:
|
class FmsDecoder:
|
||||||
"""!FMS decoder class
|
"""!FMS decoder class
|
||||||
|
|
||||||
This class decodes FMS data.
|
This class decodes FMS data.
|
||||||
|
|
@ -23,7 +23,7 @@ from boswatch.packet import packet
|
||||||
logging.debug("- %s loaded", __name__)
|
logging.debug("- %s loaded", __name__)
|
||||||
|
|
||||||
|
|
||||||
class Pocsag:
|
class PocsagDecoder:
|
||||||
"""!POCSAG decoder class
|
"""!POCSAG decoder class
|
||||||
|
|
||||||
This class decodes POCSAG data.
|
This class decodes POCSAG data.
|
||||||
|
|
@ -40,7 +40,7 @@ class Pocsag:
|
||||||
|
|
||||||
@param data: POCSAG for decoding
|
@param data: POCSAG for decoding
|
||||||
@return BOSWatch POCSAG packet or None"""
|
@return BOSWatch POCSAG packet or None"""
|
||||||
bitrate, ric, subric = Pocsag._getBitrateRicSubric(data)
|
bitrate, ric, subric = PocsagDecoder._getBitrateRicSubric(data)
|
||||||
|
|
||||||
if re.search("[0-9]{7}", ric) and re.search("[1-4]", subric):
|
if re.search("[0-9]{7}", ric) and re.search("[1-4]", subric):
|
||||||
if "Alpha:" in data:
|
if "Alpha:" in data:
|
||||||
|
|
@ -23,7 +23,7 @@ from boswatch.packet import packet
|
||||||
logging.debug("- %s loaded", __name__)
|
logging.debug("- %s loaded", __name__)
|
||||||
|
|
||||||
|
|
||||||
class Zvei:
|
class ZveiDecoder:
|
||||||
"""!ZVEI decoder class
|
"""!ZVEI decoder class
|
||||||
|
|
||||||
This class decodes ZVEI data.
|
This class decodes ZVEI data.
|
||||||
|
|
@ -46,7 +46,7 @@ class Zvei:
|
||||||
|
|
||||||
bwPacket = packet.Packet()
|
bwPacket = packet.Packet()
|
||||||
bwPacket.set("mode", "zvei")
|
bwPacket.set("mode", "zvei")
|
||||||
bwPacket.set("zvei", Zvei._solveDoubleTone(data[7:12]))
|
bwPacket.set("zvei", ZveiDecoder._solveDoubleTone(data[7:12]))
|
||||||
|
|
||||||
logging.debug(bwPacket)
|
logging.debug(bwPacket)
|
||||||
return bwPacket
|
return bwPacket
|
||||||
|
|
@ -84,7 +84,7 @@ try:
|
||||||
print("Alarm Nr #" + str(i))
|
print("Alarm Nr #" + str(i))
|
||||||
|
|
||||||
data = "ZVEI1: 12345"
|
data = "ZVEI1: 12345"
|
||||||
bwPacket = decoder.getDecoder(data).decode(data)
|
bwPacket = decoder.decode(data)
|
||||||
|
|
||||||
if bwPacket:
|
if bwPacket:
|
||||||
bwPacket.printInfo()
|
bwPacket.printInfo()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue