2015-05-22 21:48:16 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
# -*- coding: cp1252 -*-
|
|
|
|
|
|
2015-05-27 07:48:24 +02:00
|
|
|
"""
|
|
|
|
|
FMS Decoder
|
|
|
|
|
|
|
|
|
|
@author: Bastian Schroll
|
|
|
|
|
|
|
|
|
|
@requires: Configuration has to be set in the config.ini
|
|
|
|
|
"""
|
|
|
|
|
|
2015-05-22 21:48:16 +02:00
|
|
|
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):
|
2015-05-27 07:48:24 +02:00
|
|
|
"""
|
|
|
|
|
Export FMS Information from Multimon-NG RAW String and call alarmHandler.processAlarm()
|
|
|
|
|
|
|
|
|
|
@type freq: string
|
|
|
|
|
@param freq: frequency of the SDR Stick
|
|
|
|
|
@type decoded: string
|
|
|
|
|
@param decoded: RAW Information from Multimon-NG
|
|
|
|
|
|
|
|
|
|
@requires: Configuration has to be set in the config.ini
|
|
|
|
|
|
|
|
|
|
@return: nothing
|
|
|
|
|
@exception: Exception if FMS decode failed
|
|
|
|
|
"""
|
2015-05-22 21:48:16 +02:00
|
|
|
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
|
2015-05-24 21:24:26 +02:00
|
|
|
if fms_id == globals.fms_id_old and timestamp < globals.fms_time_old + globals.config.getint("FMS", "double_ignore_time"): #check for double alarm
|
2015-05-22 21:48:16 +02:00
|
|
|
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:
|
2015-05-24 23:09:38 +02:00
|
|
|
logging.info("FMS:%s Status:%s Richtung:%s TSI:%s", fms_id[0:8], fms_status, fms_direction, fms_tsi)
|
2015-05-22 21:48:16 +02:00
|
|
|
data = {"fms":fms_id[0:8], "status":fms_status, "direction":fms_direction, "tsi":fms_tsi}
|
2015-05-22 22:22:50 +02:00
|
|
|
from includes import alarmHandler
|
2015-05-22 22:27:41 +02:00
|
|
|
alarmHandler.processAlarm("FMS",freq,data)
|
2015-05-22 21:48:16 +02:00
|
|
|
|
|
|
|
|
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")
|