def decode(data): """!Decodes ZVEI @param data: ZVEI for decoding @return BOSWatch ZVEI packet or None""" if re.search("[0-9E]{5}", data[7:12]): logging.debug("found valid ZVEI") bwPacket = Packet() bwPacket.set("mode", "zvei") bwPacket.set("zvei", ZveiDecoder._solveDoubleTone(data[7:12])) return bwPacket logging.warning("no valid ZVEI") return None
def decode(data): """!Decodes FMS @param data: FMS for decoding @return BOSWatch FMS packet or None""" if "CRC correct" in data: service = data[19] country = data[36] location = data[61:63] vehicle = data[72:76] status = data[84] direction = data[101] directionText = data[103:110] tacticalInfo = data[114:117] fms_id = service + country + location + vehicle + status + direction if re.search("[0-9a-f]{8}[0-9a-f][01]", fms_id): logging.debug("found valid FMS") bwPacket = Packet() bwPacket.set("mode", "fms") bwPacket.set("fms", fms_id) bwPacket.set("service", service) bwPacket.set("country", country) bwPacket.set("location", location) bwPacket.set("vehicle", vehicle) bwPacket.set("status", status) bwPacket.set("direction", direction) bwPacket.set("directionText", directionText) bwPacket.set("tacticalInfo", tacticalInfo) return bwPacket logging.warning("no valid FMS") return None logging.warning("CRC Error") return None
def test_copyPacket(buildPacket): """!Copy a packet to an new instance""" bwCopyPacket = Packet(buildPacket.__str__()) assert bwCopyPacket != ""
def buildPacket(): """!Build a BOSWatch packet and serve it to each test""" return Packet()
if bwServer.start(): while 1: if incomingQueue.empty(): # pause only when no data time.sleep(0.1) # reduce cpu load (wait 100ms) # in worst case a packet have to wait 100ms until it will be processed else: data = incomingQueue.get() logging.info("get data from %s (waited in queue %0.3f sec.)", data[0], time.time() - data[2]) logging.debug("%s packet(s) still waiting in queue", incomingQueue.qsize()) bwPacket = Packet((data[1])) bwPacket.set("clientIP", data[0]) misc.addServerDataToPacket(bwPacket, bwConfig) logging.debug("[ --- ALARM --- ]") bwRoutMan.runRouters(bwConfig.get("alarmRouter"), bwPacket) logging.debug("[ --- END ALARM --- ]") incomingQueue.task_done() except KeyboardInterrupt: # pragma: no cover logging.warning("Keyboard interrupt") except SystemExit: # pragma: no cover logging.error("BOSWatch interrupted by an error") except: # pragma: no cover
def decode(data): """!Decodes POCSAG @param data: POCSAG for decoding @return BOSWatch POCSAG packet or None""" bitrate, ric, subric = PocsagDecoder._getBitrateRicSubric(data) if re.search("[0-9]{7}", ric) and re.search("[1-4]", subric): if "Alpha:" in data: message = data.split('Alpha: ')[1].strip() message = message.replace('<NUL>', '').replace( '<NUL', '').replace('< NUL>', '').replace('<EOT>', '').strip() else: message = "" subricText = subric.replace("1", "a").replace("2", "b").replace( "3", "c").replace("4", "d") logging.debug("found valid POCSAG") bwPacket = Packet() bwPacket.set("mode", "pocsag") bwPacket.set("bitrate", bitrate) bwPacket.set("ric", ric) bwPacket.set("subric", subric) bwPacket.set("subricText", subricText) bwPacket.set("message", message) return bwPacket logging.warning("no valid POCSAG") return None
def makePacket(): """!Build a BW Packet object""" packet = Packet() return packet