From 4915de585df61792c71dddfbaaf7ef0cec245ab5 Mon Sep 17 00:00:00 2001 From: JHCD Date: Fri, 22 May 2015 21:48:16 +0200 Subject: [PATCH] restructure decoder - fms --- includes/decoder.py | 36 ++---------------------------------- includes/decoders/fms.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 34 deletions(-) diff --git a/includes/decoder.py b/includes/decoder.py index ecd5632..b693120 100644 --- a/includes/decoder.py +++ b/includes/decoder.py @@ -2,47 +2,15 @@ # -*- coding: cp1252 -*- import logging -import time #timestamp for doublealarm -import re #Regex for validation - -from includes import globals # Global variables - def decode(freq, decoded): - timestamp = int(time.time())#Get Timestamp #FMS Decoder Section #check FMS: -> check CRC -> validate -> check double alarm -> log if "FMS:" in decoded: logging.debug("recieved FMS") - - fms_service = decoded[19] #Organisation - fms_country = decoded[36] #Bundesland - fms_location = decoded[65:67] #Ort - fms_vehicle = decoded[72:76] #Fahrzeug - fms_status = decoded[84] #Status - fms_direction = decoded[101] #Richtung - fms_tsi = decoded[114:117] #Taktische Kruzinformation - - if "CRC correct" in decoded: #check CRC is correct - fms_id = fms_service+fms_country+fms_location+fms_vehicle+fms_status+fms_direction #build FMS id - if re.search("[0-9a-f]{8}[0-9a-f]{1}[01]{1}", fms_id): #if FMS is valid - if fms_id == globals.fms_id_old and timestamp < globals.fms_time_old + globals.config.getint("BOSWatch", "fms_double_ignore_time"): #check for double alarm - logging.info("FMS double alarm: %s within %s second(s)", globals.fms_id_old, timestamp-globals.fms_time_old) - globals.fms_time_old = timestamp #in case of double alarm, fms_double_ignore_time set new - else: - logging.info("FMS:%s Status:%s Richtung:%s TKI:%s", fms_id[0:8], fms_status, fms_direction, fms_tsi) - data = {"fms":fms_id[0:8], "status":fms_status, "direction":fms_direction, "tsi":fms_tsi} - from includes import pluginHandler - pluginHandler.throwAlarm("FMS",freq,data) - - globals.fms_id_old = fms_id #save last id - globals.fms_time_old = timestamp #save last time - else: - logging.warning("No valid FMS: %s", fms_id) - else: - logging.warning("FMS CRC incorrect") - + from includes.decoders import fms + fms.decode(freq, decoded) #ZVEI Decoder Section #check ZVEI: -> validate -> check double alarm -> log diff --git a/includes/decoders/fms.py b/includes/decoders/fms.py index e69de29..da4eed3 100644 --- a/includes/decoders/fms.py +++ b/includes/decoders/fms.py @@ -0,0 +1,40 @@ +#!/usr/bin/python +# -*- coding: cp1252 -*- + +import logging +import time #timestamp for doublealarm +import re #Regex for validation + +from includes import globals # Global variables + +#FMS Decoder Function +#validate -> check double alarm -> log +def decode(freq, decoded): + timestamp = int(time.time())#Get Timestamp + + fms_service = decoded[19] #Organisation + fms_country = decoded[36] #Bundesland + fms_location = decoded[65:67] #Ort + fms_vehicle = decoded[72:76] #Fahrzeug + fms_status = decoded[84] #Status + fms_direction = decoded[101] #Richtung + fms_tsi = decoded[114:117] #Taktische Kruzinformation + + if "CRC correct" in decoded: #check CRC is correct + fms_id = fms_service+fms_country+fms_location+fms_vehicle+fms_status+fms_direction #build FMS id + if re.search("[0-9a-f]{8}[0-9a-f]{1}[01]{1}", fms_id): #if FMS is valid + if fms_id == globals.fms_id_old and timestamp < globals.fms_time_old + globals.config.getint("BOSWatch", "fms_double_ignore_time"): #check for double alarm + logging.info("FMS double alarm: %s within %s second(s)", globals.fms_id_old, timestamp-globals.fms_time_old) + globals.fms_time_old = timestamp #in case of double alarm, fms_double_ignore_time set new + else: + logging.info("FMS:%s Status:%s Richtung:%s TKI:%s", fms_id[0:8], fms_status, fms_direction, fms_tsi) + data = {"fms":fms_id[0:8], "status":fms_status, "direction":fms_direction, "tsi":fms_tsi} + from includes import pluginHandler + pluginHandler.throwAlarm("FMS",freq,data) + + globals.fms_id_old = fms_id #save last id + globals.fms_time_old = timestamp #save last time + else: + logging.warning("No valid FMS: %s", fms_id) + else: + logging.warning("FMS CRC incorrect") \ No newline at end of file