BOSWatch/includes/decoders/zvei.py

78 lines
2.3 KiB
Python
Raw Normal View History

2015-05-22 21:40:38 +02:00
#!/usr/bin/python
# -*- coding: cp1252 -*-
2015-05-27 07:48:24 +02:00
"""
ZVEI Decoder
@author: Bastian Schroll
@requires: Configuration has to be set in the config.ini
"""
2015-05-22 21:40:38 +02:00
import logging
import time #timestamp for doublealarm
import re #Regex for validation
from includes import globals # Global variables
2015-05-31 12:40:43 +02:00
##
#
# ZVEI Decoder Function
# validate -> check double alarm -> log
#
2015-05-22 21:40:38 +02:00
def decode(freq, decoded):
2015-05-27 07:48:24 +02:00
"""
Export ZVEI 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 ZVEI decode failed
"""
2015-05-22 21:40:38 +02:00
timestamp = int(time.time())#Get Timestamp
zvei_id = decoded[7:12] #ZVEI Code
2015-05-25 10:25:31 +02:00
zvei_id = removeF(zvei_id) #resolve F
2015-05-25 00:40:41 +02:00
if re.search("[0-9]{5}", zvei_id): #if ZVEI is valid
if zvei_id == globals.zvei_id_old and timestamp < globals.zvei_time_old + globals.config.getint("ZVEI", "double_ignore_time"): #check for double alarm
2015-05-22 21:40:38 +02:00
logging.info("ZVEI double alarm: %s within %s second(s)", globals.zvei_id_old, timestamp-globals.zvei_time_old)
globals.zvei_time_old = timestamp #in case of double alarm, zvei_double_ignore_time set new
else:
logging.info("5-Ton: %s", zvei_id)
data = {"zvei":zvei_id, "description":zvei_id}
# If enabled, look up description
if globals.config.getint("ZVEI", "idDescribed"):
from includes import descriptionList
data["description"] = descriptionList.getDescription("ZVEI", zvei_id)
# processing the alarm
2015-05-22 22:22:50 +02:00
from includes import alarmHandler
2015-05-22 22:27:41 +02:00
alarmHandler.processAlarm("ZVEI",freq,data)
2015-05-22 21:40:38 +02:00
globals.zvei_id_old = zvei_id #save last id
globals.zvei_time_old = timestamp #save last time
else:
2015-05-25 00:40:41 +02:00
logging.warning("No valid ZVEI: %s", zvei_id)
2015-05-25 10:25:31 +02:00
def removeF(zvei):
2015-05-27 07:48:24 +02:00
"""
Resolve the F from the repeat Tone
@type zvei: string
@param zvei: ZVEI Information
@return: ZVEI without F
@exception: none
"""
2015-05-25 10:25:31 +02:00
if "F" in zvei:
zvei_old = zvei
for i in range(1, 5):
if zvei[i] == "F":
zvei = zvei.replace("F",zvei[i-1],1)
logging.debug("resolve F: %s -> %s", zvei_old, zvei)
2015-05-25 00:40:41 +02:00
return zvei