only dos2linux on files

This commit is contained in:
JHCD 2015-06-25 21:19:41 +02:00
parent f54debb44e
commit f6e25d77b4
13 changed files with 643 additions and 643 deletions

View file

@ -1,10 +1,10 @@
fms,description fms,description
# #
# BOSWatch CSV file for describing FMS-Addresses # BOSWatch CSV file for describing FMS-Addresses
# #
# For each FMS-Address you could set a description-text # For each FMS-Address you could set a description-text
# Use the structure: fms,"Description-Text" # Use the structure: fms,"Description-Text"
# #
# !!! DO NOT delete the first line !!! # !!! DO NOT delete the first line !!!
# #
93377141,"John Q. Publics car" 93377141,"John Q. Publics car"
Can't render this file because it has a wrong number of fields in line 2.

View file

@ -1,10 +1,10 @@
ric,description ric,description
# #
# BOSWatch CSV file for describing POCSAG-Addresses # BOSWatch CSV file for describing POCSAG-Addresses
# #
# For each RIC-Address you could set a description-text # For each RIC-Address you could set a description-text
# Use the structure: ric,"Description-Text" # Use the structure: ric,"Description-Text"
# #
# !!! DO NOT delete the first line !!! # !!! DO NOT delete the first line !!!
# #
1234567,"John Q. Public" 1234567,"John Q. Public"
Can't render this file because it has a wrong number of fields in line 2.

View file

@ -1,10 +1,10 @@
zvei,description zvei,description
# #
# BOSWatch CSV file for describing ZVEI-Addresses # BOSWatch CSV file for describing ZVEI-Addresses
# #
# For each ZVEI-Address you could set a description-text # For each ZVEI-Address you could set a description-text
# Use the structure: zvei,"Description-Text" # Use the structure: zvei,"Description-Text"
# #
# !!! DO NOT delete the first line !!! # !!! DO NOT delete the first line !!!
# #
25832,"John Q. Public" 25832,"John Q. Public"
Can't render this file because it has a wrong number of fields in line 2.

View file

@ -1,18 +1,18 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: cp1252 -*- # -*- coding: cp1252 -*-
# #
""" """
This Class extended the TimedRotatingFileHandler with the possibility This Class extended the TimedRotatingFileHandler with the possibility
to change the backupCount after initialization. to change the backupCount after initialization.
@author: Jens Herrmann @author: Jens Herrmann
""" """
import logging import logging
class MyTimedRotatingFileHandler(logging.handlers.TimedRotatingFileHandler): class MyTimedRotatingFileHandler(logging.handlers.TimedRotatingFileHandler):
"""Extended Version of TimedRotatingFileHandler""" """Extended Version of TimedRotatingFileHandler"""
def setBackupCount(self, backupCount): def setBackupCount(self, backupCount):
"""Set/Change backupCount""" """Set/Change backupCount"""
self.backupCount = backupCount self.backupCount = backupCount

View file

@ -1,29 +1,29 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: cp1252 -*- # -*- coding: cp1252 -*-
# #
""" """
convert frequency to Hz convert frequency to Hz
@author: Bastian Schroll @author: Bastian Schroll
""" """
import logging import logging
def freqToHz(freq): def freqToHz(freq):
""" """
gets a frequency and resolve it in Hz gets a frequency and resolve it in Hz
@type freq: string @type freq: string
@param freq: frequency of the SDR Stick @param freq: frequency of the SDR Stick
@return: frequency in Hz @return: frequency in Hz
@exception: Exception if Error by recalc @exception: Exception if Error by recalc
""" """
try: try:
freq = freq.replace("k","e3").replace("M","e6") freq = freq.replace("k","e3").replace("M","e6")
# freq has to be interpreted as float first... # freq has to be interpreted as float first...
# otherwise you will get the error: an invalid literal for int() with base 10 # otherwise you will get the error: an invalid literal for int() with base 10
return int(float(freq)) return int(float(freq))
except: except:
logging.exception("Error in freqToHz()") logging.exception("Error in freqToHz()")

View file

@ -1,53 +1,53 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: cp1252 -*- # -*- coding: cp1252 -*-
""" """
Search for decode string and call the right decoder function Search for decode string and call the right decoder function
@author: Jens Herrmann @author: Jens Herrmann
@requires: none @requires: none
""" """
import logging # Global logger import logging # Global logger
def decode(freq, decoded): def decode(freq, decoded):
""" """
Search for decode string and call the right decoder function Search for decode string and call the right decoder function
@type freq: string @type freq: string
@param freq: frequency of the SDR Stick @param freq: frequency of the SDR Stick
@type decoded: string @type decoded: string
@param decoded: RAW Information from Multimon-NG @param decoded: RAW Information from Multimon-NG
@return: nothing @return: nothing
@exception: Exception if decoder file call failed @exception: Exception if decoder file call failed
""" """
try: try:
# FMS Decoder Section # FMS Decoder Section
# check FMS: -> check CRC -> validate -> check double alarm -> log # check FMS: -> check CRC -> validate -> check double alarm -> log
if "FMS:" in decoded: if "FMS:" in decoded:
logging.debug("recieved FMS") logging.debug("recieved FMS")
from includes.decoders import fms from includes.decoders import fms
fms.decode(freq, decoded) fms.decode(freq, decoded)
# ZVEI Decoder Section # ZVEI Decoder Section
# check ZVEI: -> validate -> check double alarm -> log # check ZVEI: -> validate -> check double alarm -> log
elif "ZVEI2:" in decoded: elif "ZVEI2:" in decoded:
logging.debug("recieved ZVEI") logging.debug("recieved ZVEI")
from includes.decoders import zvei from includes.decoders import zvei
zvei.decode(freq, decoded) zvei.decode(freq, decoded)
# For POCSAG we have to ignore the multimon-ng line "Enabled demodulators:" # For POCSAG we have to ignore the multimon-ng line "Enabled demodulators:"
elif "Enabled demodulators:" in decoded: elif "Enabled demodulators:" in decoded:
pass pass
# POCSAG Decoder Section # POCSAG Decoder Section
# check POCSAG -> validate -> check double alarm -> log # check POCSAG -> validate -> check double alarm -> log
elif "POCSAG" in decoded: elif "POCSAG" in decoded:
logging.debug("recieved POCSAG") logging.debug("recieved POCSAG")
from includes.decoders import poc from includes.decoders import poc
poc.decode(freq, decoded) poc.decode(freq, decoded)
except: except:
logging.exception("cannot start decoder") logging.exception("cannot start decoder")

View file

@ -1,78 +1,78 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: cp1252 -*- # -*- coding: cp1252 -*-
""" """
FMS Decoder FMS Decoder
@author: Bastian Schroll @author: Bastian Schroll
@requires: Configuration has to be set in the config.ini @requires: Configuration has to be set in the config.ini
""" """
import logging # Global logger import logging # Global logger
import time # timestamp for doublealarm import time # timestamp for doublealarm
import re # Regex for validation import re # Regex for validation
from includes import globals # Global variables from includes import globals # Global variables
## ##
# #
# FMS decoder function # FMS decoder function
# validate -> check double alarm -> log # validate -> check double alarm -> log
# #
def decode(freq, decoded): def decode(freq, decoded):
""" """
Export FMS Information from Multimon-NG RAW String and call alarmHandler.processAlarm() Export FMS Information from Multimon-NG RAW String and call alarmHandler.processAlarm()
@type freq: string @type freq: string
@param freq: frequency of the SDR Stick @param freq: frequency of the SDR Stick
@type decoded: string @type decoded: string
@param decoded: RAW Information from Multimon-NG @param decoded: RAW Information from Multimon-NG
@requires: Configuration has to be set in the config.ini @requires: Configuration has to be set in the config.ini
@return: nothing @return: nothing
@exception: Exception if FMS decode failed @exception: Exception if FMS decode failed
""" """
timestamp = int(time.time()) # Get Timestamp timestamp = int(time.time()) # Get Timestamp
fms_service = decoded[19] # Organisation fms_service = decoded[19] # Organisation
fms_country = decoded[36] # Bundesland fms_country = decoded[36] # Bundesland
fms_location = decoded[65:67] # Ort fms_location = decoded[65:67] # Ort
fms_vehicle = decoded[72:76] # Fahrzeug fms_vehicle = decoded[72:76] # Fahrzeug
fms_status = decoded[84] # Status fms_status = decoded[84] # Status
fms_direction = decoded[101] # Richtung fms_direction = decoded[101] # Richtung
fms_directionText = decoded[103:110] # Richtung (Text) fms_directionText = decoded[103:110] # Richtung (Text)
fms_tsi = decoded[114:117] # Taktische Kruzinformation fms_tsi = decoded[114:117] # Taktische Kruzinformation
if "CRC correct" in decoded: #check CRC is correct 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 fms_id = fms_service+fms_country+fms_location+fms_vehicle+fms_status+fms_direction # build FMS id
# if FMS is valid # if FMS is valid
if re.search("[0-9a-f]{8}[0-9a-f]{1}[01]{1}", fms_id): if re.search("[0-9a-f]{8}[0-9a-f]{1}[01]{1}", fms_id):
# check for double alarm # check for double alarm
if fms_id == globals.fms_id_old and timestamp < globals.fms_time_old + globals.config.getint("FMS", "double_ignore_time"): if fms_id == globals.fms_id_old and timestamp < globals.fms_time_old + globals.config.getint("FMS", "double_ignore_time"):
logging.info("FMS double alarm: %s within %s second(s)", globals.fms_id_old, timestamp-globals.fms_time_old) logging.info("FMS double alarm: %s within %s second(s)", globals.fms_id_old, timestamp-globals.fms_time_old)
# in case of double alarm, fms_double_ignore_time set new # in case of double alarm, fms_double_ignore_time set new
globals.fms_time_old = timestamp globals.fms_time_old = timestamp
else: else:
logging.info("FMS:%s Status:%s Richtung:%s TSI:%s", fms_id[0:8], fms_status, fms_direction, fms_tsi) logging.info("FMS:%s Status:%s Richtung:%s TSI:%s", fms_id[0:8], fms_status, fms_direction, fms_tsi)
data = {"fms":fms_id[0:8], "status":fms_status, "direction":fms_direction, "directionText":fms_directionText, "tsi":fms_tsi, "description":fms_id[0:8]} data = {"fms":fms_id[0:8], "status":fms_status, "direction":fms_direction, "directionText":fms_directionText, "tsi":fms_tsi, "description":fms_id[0:8]}
# If enabled, look up description # If enabled, look up description
if globals.config.getint("FMS", "idDescribed"): if globals.config.getint("FMS", "idDescribed"):
from includes import descriptionList from includes import descriptionList
data["description"] = descriptionList.getDescription("FMS", fms_id[0:8]) data["description"] = descriptionList.getDescription("FMS", fms_id[0:8])
# processing the alarm # processing the alarm
try: try:
from includes import alarmHandler from includes import alarmHandler
alarmHandler.processAlarm("POC",freq,data) alarmHandler.processAlarm("POC",freq,data)
except: except:
logging.error("processing alarm failed") logging.error("processing alarm failed")
logging.debug("processing alarm failed", exc_info=True) logging.debug("processing alarm failed", exc_info=True)
pass pass
# in every time save old data for double alarm # in every time save old data for double alarm
globals.fms_id_old = fms_id #save last id globals.fms_id_old = fms_id #save last id
globals.fms_time_old = timestamp #save last time globals.fms_time_old = timestamp #save last time
else: else:
logging.warning("No valid FMS: %s", fms_id) logging.warning("No valid FMS: %s", fms_id)
else: else:
logging.warning("FMS CRC incorrect") logging.warning("FMS CRC incorrect")

View file

@ -1,135 +1,135 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: cp1252 -*- # -*- coding: cp1252 -*-
""" """
POCSAG Decoder POCSAG Decoder
@author: Bastian Schroll @author: Bastian Schroll
@author: Jens Herrmann @author: Jens Herrmann
@requires: Configuration has to be set in the config.ini @requires: Configuration has to be set in the config.ini
""" """
import logging # Global logger import logging # Global logger
import time # timestamp for doublealarm import time # timestamp for doublealarm
import re # Regex for validation import re # Regex for validation
from includes import globals # Global variables from includes import globals # Global variables
## ##
# #
# Simple local filter # Simple local filter
# #
def isAllowed(poc_id): def isAllowed(poc_id):
""" """
Simple Filter Functions (Allowed, Denied and Range) Simple Filter Functions (Allowed, Denied and Range)
@type poc_id: string @type poc_id: string
@param poc_id: POCSAG Ric @param poc_id: POCSAG Ric
@requires: Configuration has to be set in the config.ini @requires: Configuration has to be set in the config.ini
@return: True if the Ric is allowed, other False @return: True if the Ric is allowed, other False
@exception: none @exception: none
""" """
# 1.) If allowed RICs is set, only they will path, # 1.) If allowed RICs is set, only they will path,
# If RIC is the right one return True, else False # If RIC is the right one return True, else False
if globals.config.get("POC", "allow_ric"): if globals.config.get("POC", "allow_ric"):
if poc_id in globals.config.get("POC", "allow_ric"): if poc_id in globals.config.get("POC", "allow_ric"):
logging.info("RIC %s is allowed", poc_id) logging.info("RIC %s is allowed", poc_id)
return True return True
else: else:
logging.info("RIC %s is not in the allowed list", poc_id) logging.info("RIC %s is not in the allowed list", poc_id)
return False return False
# 2.) If denied RIC, return False # 2.) If denied RIC, return False
elif poc_id in globals.config.get("POC", "deny_ric"): elif poc_id in globals.config.get("POC", "deny_ric"):
logging.info("RIC %s is denied by config.ini", poc_id) logging.info("RIC %s is denied by config.ini", poc_id)
return False return False
# 3.) Check Range, return False if outside def. range # 3.) Check Range, return False if outside def. range
elif int(poc_id) < globals.config.getint("POC", "filter_range_start"): elif int(poc_id) < globals.config.getint("POC", "filter_range_start"):
logging.info("RIC %s out of filter range (start)", poc_id) logging.info("RIC %s out of filter range (start)", poc_id)
return False return False
elif int(poc_id) > globals.config.getint("POC", "filter_range_end"): elif int(poc_id) > globals.config.getint("POC", "filter_range_end"):
logging.info("RIC %s out of filter range (end)", poc_id) logging.info("RIC %s out of filter range (end)", poc_id)
return False return False
return True return True
## ##
# #
# POCSAG decoder function # POCSAG decoder function
# validate -> check double alarm -> log # validate -> check double alarm -> log
# #
def decode(freq, decoded): def decode(freq, decoded):
""" """
Export POCSAG Information from Multimon-NG RAW String and call alarmHandler.processAlarm() Export POCSAG Information from Multimon-NG RAW String and call alarmHandler.processAlarm()
@type freq: string @type freq: string
@param freq: frequency of the SDR Stick @param freq: frequency of the SDR Stick
@type decoded: string @type decoded: string
@param decoded: RAW Information from Multimon-NG @param decoded: RAW Information from Multimon-NG
@requires: Configuration has to be set in the config.ini @requires: Configuration has to be set in the config.ini
@return: nothing @return: nothing
@exception: Exception if POCSAG decode failed @exception: Exception if POCSAG decode failed
""" """
bitrate = 0 bitrate = 0
timestamp = int(time.time())#Get Timestamp timestamp = int(time.time())#Get Timestamp
if "POCSAG512:" in decoded: if "POCSAG512:" in decoded:
bitrate = 512 bitrate = 512
poc_id = decoded[20:27].replace(" ", "").zfill(7) poc_id = decoded[20:27].replace(" ", "").zfill(7)
poc_sub = decoded[39].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1") poc_sub = decoded[39].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1")
elif "POCSAG1200:" in decoded: elif "POCSAG1200:" in decoded:
bitrate = 1200 bitrate = 1200
poc_id = decoded[21:28].replace(" ", "").zfill(7) poc_id = decoded[21:28].replace(" ", "").zfill(7)
poc_sub = decoded[40].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1") poc_sub = decoded[40].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1")
elif "POCSAG2400:" in decoded: elif "POCSAG2400:" in decoded:
bitrate = 2400 bitrate = 2400
poc_id = decoded[21:28].replace(" ", "").zfill(7) poc_id = decoded[21:28].replace(" ", "").zfill(7)
poc_sub = decoded[40].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1") poc_sub = decoded[40].replace("3", "4").replace("2", "3").replace("1", "2").replace("0", "1")
if bitrate is 0: if bitrate is 0:
logging.warning("POCSAG Bitrate not found") logging.warning("POCSAG Bitrate not found")
logging.debug(" - (%s)", decoded) logging.debug(" - (%s)", decoded)
else: else:
logging.debug("POCSAG Bitrate: %s", bitrate) logging.debug("POCSAG Bitrate: %s", bitrate)
if "Alpha:" in decoded: #check if there is a text message if "Alpha:" in decoded: #check if there is a text message
poc_text = decoded.split('Alpha: ')[1].strip().rstrip('<EOT>').strip() poc_text = decoded.split('Alpha: ')[1].strip().rstrip('<EOT>').strip()
else: else:
poc_text = "" poc_text = ""
if re.search("[0-9]{7}", poc_id): #if POC is valid if re.search("[0-9]{7}", poc_id): #if POC is valid
if isAllowed(poc_id): if isAllowed(poc_id):
# check for double alarm # check for double alarm
if poc_id == globals.poc_id_old and timestamp < globals.poc_time_old + globals.config.getint("POC", "double_ignore_time"): if poc_id == globals.poc_id_old and timestamp < globals.poc_time_old + globals.config.getint("POC", "double_ignore_time"):
logging.info("POCSAG%s double alarm: %s within %s second(s)", bitrate, globals.poc_id_old, timestamp-globals.poc_time_old) logging.info("POCSAG%s double alarm: %s within %s second(s)", bitrate, globals.poc_id_old, timestamp-globals.poc_time_old)
# in case of double alarm, poc_double_ignore_time set new # in case of double alarm, poc_double_ignore_time set new
globals.poc_time_old = timestamp globals.poc_time_old = timestamp
else: else:
logging.info("POCSAG%s: %s %s %s ", bitrate, poc_id, poc_sub, poc_text) logging.info("POCSAG%s: %s %s %s ", bitrate, poc_id, poc_sub, poc_text)
data = {"ric":poc_id, "function":poc_sub, "msg":poc_text, "bitrate":bitrate, "description":poc_id} data = {"ric":poc_id, "function":poc_sub, "msg":poc_text, "bitrate":bitrate, "description":poc_id}
# Add function as character a-d to dataset # Add function as character a-d to dataset
data["functionChar"] = data["function"].replace("1", "a").replace("2", "b").replace("3", "c").replace("4", "d") data["functionChar"] = data["function"].replace("1", "a").replace("2", "b").replace("3", "c").replace("4", "d")
# If enabled, look up description # If enabled, look up description
if globals.config.getint("POC", "idDescribed"): if globals.config.getint("POC", "idDescribed"):
from includes import descriptionList from includes import descriptionList
data["description"] = descriptionList.getDescription("POC", poc_id) data["description"] = descriptionList.getDescription("POC", poc_id)
# processing the alarm # processing the alarm
try: try:
from includes import alarmHandler from includes import alarmHandler
alarmHandler.processAlarm("POC",freq,data) alarmHandler.processAlarm("POC",freq,data)
except: except:
logging.error("processing alarm failed") logging.error("processing alarm failed")
logging.debug("processing alarm failed", exc_info=True) logging.debug("processing alarm failed", exc_info=True)
pass pass
# in every time save old data for double alarm # in every time save old data for double alarm
globals.poc_id_old = poc_id #save last id globals.poc_id_old = poc_id #save last id
globals.poc_time_old = timestamp #save last time globals.poc_time_old = timestamp #save last time
else: else:
logging.debug("POCSAG%s: %s is not allowed", bitrate, poc_id) logging.debug("POCSAG%s: %s is not allowed", bitrate, poc_id)
else: else:
logging.warning("No valid POCSAG%s RIC: %s", bitrate, poc_id) logging.warning("No valid POCSAG%s RIC: %s", bitrate, poc_id)

View file

@ -1,88 +1,88 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: cp1252 -*- # -*- coding: cp1252 -*-
""" """
ZVEI Decoder ZVEI Decoder
@author: Bastian Schroll @author: Bastian Schroll
@requires: Configuration has to be set in the config.ini @requires: Configuration has to be set in the config.ini
""" """
import logging # Global logger import logging # Global logger
import time # timestamp for doublealarm import time # timestamp for doublealarm
import re # Regex for validation import re # Regex for validation
from includes import globals # Global variables from includes import globals # Global variables
## ##
# #
# Local function to remove the 'F' # Local function to remove the 'F'
# #
def removeF(zvei): def removeF(zvei):
""" """
Resolve the F from the repeat Tone Resolve the F from the repeat Tone
@type zvei: string @type zvei: string
@param zvei: ZVEI Information @param zvei: ZVEI Information
@return: ZVEI without F @return: ZVEI without F
@exception: none @exception: none
""" """
if "F" in zvei: if "F" in zvei:
zvei_old = zvei zvei_old = zvei
for i in range(1, 5): for i in range(1, 5):
if zvei[i] == "F": if zvei[i] == "F":
zvei = zvei.replace("F",zvei[i-1],1) zvei = zvei.replace("F",zvei[i-1],1)
logging.debug("resolve F: %s -> %s", zvei_old, zvei) logging.debug("resolve F: %s -> %s", zvei_old, zvei)
return zvei return zvei
## ##
# #
# ZVEI decoder function # ZVEI decoder function
# validate -> check double alarm -> log # validate -> check double alarm -> log
# #
def decode(freq, decoded): def decode(freq, decoded):
""" """
Export ZVEI Information from Multimon-NG RAW String and call alarmHandler.processAlarm() Export ZVEI Information from Multimon-NG RAW String and call alarmHandler.processAlarm()
@type freq: string @type freq: string
@param freq: frequency of the SDR Stick @param freq: frequency of the SDR Stick
@type decoded: string @type decoded: string
@param decoded: RAW Information from Multimon-NG @param decoded: RAW Information from Multimon-NG
@requires: Configuration has to be set in the config.ini @requires: Configuration has to be set in the config.ini
@return: nothing @return: nothing
@exception: Exception if ZVEI decode failed @exception: Exception if ZVEI decode failed
""" """
timestamp = int(time.time()) # Get Timestamp timestamp = int(time.time()) # Get Timestamp
zvei_id = decoded[7:12] # ZVEI Code zvei_id = decoded[7:12] # ZVEI Code
zvei_id = removeF(zvei_id) # resolve F zvei_id = removeF(zvei_id) # resolve F
if re.search("[0-9]{5}", zvei_id): # if ZVEI is valid if re.search("[0-9]{5}", zvei_id): # if ZVEI is valid
# check for double alarm # check for double alarm
if zvei_id == globals.zvei_id_old and timestamp < globals.zvei_time_old + globals.config.getint("ZVEI", "double_ignore_time"): if zvei_id == globals.zvei_id_old and timestamp < globals.zvei_time_old + globals.config.getint("ZVEI", "double_ignore_time"):
logging.info("ZVEI double alarm: %s within %s second(s)", globals.zvei_id_old, timestamp-globals.zvei_time_old) logging.info("ZVEI double alarm: %s within %s second(s)", globals.zvei_id_old, timestamp-globals.zvei_time_old)
# in case of double alarm, zvei_double_ignore_time set new # in case of double alarm, zvei_double_ignore_time set new
globals.zvei_time_old = timestamp globals.zvei_time_old = timestamp
else: else:
logging.info("5-Ton: %s", zvei_id) logging.info("5-Ton: %s", zvei_id)
data = {"zvei":zvei_id, "description":zvei_id} data = {"zvei":zvei_id, "description":zvei_id}
# If enabled, look up description # If enabled, look up description
if globals.config.getint("ZVEI", "idDescribed"): if globals.config.getint("ZVEI", "idDescribed"):
from includes import descriptionList from includes import descriptionList
data["description"] = descriptionList.getDescription("ZVEI", zvei_id) data["description"] = descriptionList.getDescription("ZVEI", zvei_id)
# processing the alarm # processing the alarm
try: try:
from includes import alarmHandler from includes import alarmHandler
alarmHandler.processAlarm("POC",freq,data) alarmHandler.processAlarm("POC",freq,data)
except: except:
logging.error("processing alarm failed") logging.error("processing alarm failed")
logging.debug("processing alarm failed", exc_info=True) logging.debug("processing alarm failed", exc_info=True)
pass pass
# in every time save old data for double alarm # in every time save old data for double alarm
globals.zvei_id_old = zvei_id # save last id globals.zvei_id_old = zvei_id # save last id
globals.zvei_time_old = timestamp # save last time globals.zvei_time_old = timestamp # save last time
else: else:
logging.warning("No valid ZVEI: %s", zvei_id) logging.warning("No valid ZVEI: %s", zvei_id)

View file

@ -1,113 +1,113 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: cp1252 -*- # -*- coding: cp1252 -*-
""" """
Function to expand the dataset with a description. Function to expand the dataset with a description.
@author: Jens Herrmann @author: Jens Herrmann
@requires: Configuration has to be set in the config.ini @requires: Configuration has to be set in the config.ini
""" """
import logging # Global logger import logging # Global logger
import csv # for loading the description files import csv # for loading the description files
from includes import globals # Global variables from includes import globals # Global variables
## ##
# #
# Local function will load the csv-file # Local function will load the csv-file
# #
def loadCSV(typ, idField): def loadCSV(typ, idField):
""" """
Local function for loading csv-file into python list Local function for loading csv-file into python list
Structure: [id] = description Structure: [id] = description
@return: Python list of descriptions @return: Python list of descriptions
""" """
resultList = {} resultList = {}
try: try:
logging.debug("-- loading %s.csv", typ) logging.debug("-- loading %s.csv", typ)
with open(globals.script_path+'/csv/'+typ+'.csv') as csvfile: with open(globals.script_path+'/csv/'+typ+'.csv') as csvfile:
# DictReader expected structure described in first line of csv-file # DictReader expected structure described in first line of csv-file
reader = csv.DictReader(csvfile) reader = csv.DictReader(csvfile)
for row in reader: for row in reader:
logging.debug(row) logging.debug(row)
# only import rows with an integer as id # only import rows with an integer as id
if row[idField].isdigit() == True: if row[idField].isdigit() == True:
resultList[row[idField]] = row['description'] resultList[row[idField]] = row['description']
logging.debug("-- loading csv finished") logging.debug("-- loading csv finished")
except: except:
logging.error("loading csvList for typ: %s failed", typ) logging.error("loading csvList for typ: %s failed", typ)
logging.debug("loading csvList for typ: %s failed", typ, exc_info=True) logging.debug("loading csvList for typ: %s failed", typ, exc_info=True)
raise raise
return resultList; return resultList;
## ##
# #
# call this for loading the description lists # call this for loading the description lists
# #
def loadDescriptionLists(): def loadDescriptionLists():
""" """
Load data from the csv-files in global description list for FMS, ZVEI and POCSAG Load data from the csv-files in global description list for FMS, ZVEI and POCSAG
@return: nothing @return: nothing
@exception: Exception if loading failed @exception: Exception if loading failed
""" """
try: try:
logging.debug("loading description lists") logging.debug("loading description lists")
if globals.config.getint("FMS", "idDescribed"): if globals.config.getint("FMS", "idDescribed"):
logging.debug("- load FMS description list") logging.debug("- load FMS description list")
globals.fmsDescribtionList = loadCSV("fms", "fms") globals.fmsDescribtionList = loadCSV("fms", "fms")
if globals.config.getint("ZVEI", "idDescribed"): if globals.config.getint("ZVEI", "idDescribed"):
logging.debug("- load ZVEI description list") logging.debug("- load ZVEI description list")
globals.zveiDescribtionList = loadCSV("zvei", "zvei") globals.zveiDescribtionList = loadCSV("zvei", "zvei")
if globals.config.getint("POC", "idDescribed"): if globals.config.getint("POC", "idDescribed"):
logging.debug("- load pocsag description list") logging.debug("- load pocsag description list")
globals.ricDescribtionList = loadCSV("poc", "ric") globals.ricDescribtionList = loadCSV("poc", "ric")
except: except:
logging.error("cannot load description lists") logging.error("cannot load description lists")
logging.debug("cannot load description lists", exc_info=True) logging.debug("cannot load description lists", exc_info=True)
pass pass
## ##
# #
# public function for getting a description # public function for getting a description
# #
def getDescription(typ, id): def getDescription(typ, id):
""" """
Get description for id. Get description for id.
Will return id if no description will be found. Will return id if no description will be found.
@return: description as string @return: description as string
""" """
resultStr = id; resultStr = id;
logging.debug("look up description lists") logging.debug("look up description lists")
try: try:
if typ == "FMS": if typ == "FMS":
resultStr = globals.fmsDescribtionList[id] resultStr = globals.fmsDescribtionList[id]
elif typ == "ZVEI": elif typ == "ZVEI":
resultStr = globals.zveiDescribtionList[id] resultStr = globals.zveiDescribtionList[id]
elif typ == "POC": elif typ == "POC":
resultStr = globals.ricDescribtionList[id] resultStr = globals.ricDescribtionList[id]
else: else:
logging.warning("Invalid Typ: %s", typ) logging.warning("Invalid Typ: %s", typ)
except KeyError: except KeyError:
# will be thrown when there is no description for the id # will be thrown when there is no description for the id
# -> nothing to do... # -> nothing to do...
pass pass
except: except:
logging.debug("Error during look up description lists", exc_info=True) logging.debug("Error during look up description lists", exc_info=True)
pass pass
logging.debug(" - result for %s: %s", id, resultStr) logging.debug(" - result for %s: %s", id, resultStr)
return resultStr return resultStr

View file

@ -1,52 +1,52 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: cp1252 -*- # -*- coding: cp1252 -*-
""" """
Shows the header in shell if quiet mode is not active Shows the header in shell if quiet mode is not active
@author: Bastian Schroll @author: Bastian Schroll
@author: Jens Herrmann @author: Jens Herrmann
@requires: none @requires: none
""" """
def printHeader(args): def printHeader(args):
""" """
Prints the header to the shell Prints the header to the shell
@type args: Array @type args: Array
@param args: All given arguments from argsparser @param args: All given arguments from argsparser
@return: nothing @return: nothing
""" """
try: try:
print " ____ ____ ______ __ __ __ " print " ____ ____ ______ __ __ __ "
print " / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ b" print " / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ b"
print " / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ e" print " / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ e"
print " / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / t" print " / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / t"
print " /_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ a" print " /_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ a"
print " German BOS Information Script " print " German BOS Information Script "
print " by Bastian Schroll " print " by Bastian Schroll "
print "" print ""
print "Frequency: "+args.freq print "Frequency: "+args.freq
print "Device-ID: "+str(args.device) print "Device-ID: "+str(args.device)
print "Error in PPM: "+str(args.error) print "Error in PPM: "+str(args.error)
print "Active Demods: "+str(len(args.demod)) print "Active Demods: "+str(len(args.demod))
if "FMS" in args.demod: if "FMS" in args.demod:
print "- FMS" print "- FMS"
if "ZVEI" in args.demod: if "ZVEI" in args.demod:
print "- ZVEI" print "- ZVEI"
if "POC512" in args.demod: if "POC512" in args.demod:
print "- POC512" print "- POC512"
if "POC1200" in args.demod: if "POC1200" in args.demod:
print "- POC1200" print "- POC1200"
if "POC2400" in args.demod: if "POC2400" in args.demod:
print "- POC2400" print "- POC2400"
print "Squelch: "+str(args.squelch) print "Squelch: "+str(args.squelch)
if args.verbose: if args.verbose:
print "Verbose Mode!" print "Verbose Mode!"
print "" print ""
except: except:
logging.error("cannot display shell header") logging.error("cannot display shell header")
logging.debug("cannot display shell header", exc_info=True) logging.debug("cannot display shell header", exc_info=True)

View file

@ -1,32 +1,32 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: cp1252 -*- # -*- coding: cp1252 -*-
# #
""" """
TERM-Handler for use script as a daemon TERM-Handler for use script as a daemon
In order for the Python program to exit gracefully when the TERM signal is received, In order for the Python program to exit gracefully when the TERM signal is received,
it must have a function that exits the program when signal.SIGTERM is received. it must have a function that exits the program when signal.SIGTERM is received.
@author: Jens Herrmann @author: Jens Herrmann
""" """
import logging import logging
import signal # for use as daemon import signal # for use as daemon
import sys # throw SystemExitException when daemon is terminated import sys # throw SystemExitException when daemon is terminated
def sigterm_handler(_signo, _stack_frame): def sigterm_handler(_signo, _stack_frame):
""" """
TERM-Handler for use script as a daemon TERM-Handler for use script as a daemon
@type _signo: signalnum @type _signo: signalnum
@param _signo: signal number @param _signo: signal number
@type _stack_frame: frame object @type _stack_frame: frame object
@param _stack_frame: current stack frame @param _stack_frame: current stack frame
@exception: SystemExitException when daemon is terminated @exception: SystemExitException when daemon is terminated
""" """
logging.warning("TERM signal received") logging.warning("TERM signal received")
sys.exit(0) sys.exit(0)
# Set the handler for signal to the function handler. # Set the handler for signal to the function handler.
signal.signal(signal.SIGTERM, sigterm_handler) signal.signal(signal.SIGTERM, sigterm_handler)

View file

@ -1,28 +1,28 @@
### Start BOSWatch as a daemon ### Start BOSWatch as a daemon
##### Changing the init script ##### Changing the init script
Lines 14 and 15 define where to find the Python script. Lines 14 and 15 define where to find the Python script.
In this case the script expects that there is a folder `/usr/local/bin/BOSWatch` and that the script is inside there. In this case the script expects that there is a folder `/usr/local/bin/BOSWatch` and that the script is inside there.
Line 23 sets what user to run the script as. Using a root-user is necessary for BOSWatch. Line 23 sets what user to run the script as. Using a root-user is necessary for BOSWatch.
Line 19 sets the parameters for BOSWatch, use the same as starting BOSWatch from the shell. Line 19 sets the parameters for BOSWatch, use the same as starting BOSWatch from the shell.
We recommend to use "-u" and "-q" when you want to run BOSWatch as a daemon. We recommend to use "-u" and "-q" when you want to run BOSWatch as a daemon.
- "-u": You will find the logfiles in `/var/log/BOSWatch` - "-u": You will find the logfiles in `/var/log/BOSWatch`
- "-q": Shows no information. Only logfiles - "-q": Shows no information. Only logfiles
##### Using the init script ##### Using the init script
To actually use this script, put BOSWatch where you want (recommend `/usr/local/bin/BOSWatch`) To actually use this script, put BOSWatch where you want (recommend `/usr/local/bin/BOSWatch`)
and make sure it is executable (e.g. `sudo chmod 755 boswatch.py`). and make sure it is executable (e.g. `sudo chmod 755 boswatch.py`).
Edit the init script accordingly. Copy it into /etc/init.d using e.g. `sudo cp boswatch.sh /etc/init.d`. Edit the init script accordingly. Copy it into /etc/init.d using e.g. `sudo cp boswatch.sh /etc/init.d`.
Make sure the script is executable (chmod again) and make sure that it has UNIX line-endings. Make sure the script is executable (chmod again) and make sure that it has UNIX line-endings.
At this point you should be able to start BOSWatchcd ~/srt using the command `sudo /etc/init.d/boswatch.sh start`, At this point you should be able to start BOSWatchcd ~/srt using the command `sudo /etc/init.d/boswatch.sh start`,
check its status with the `sudo /etc/init.d/boswatch.sh status` argument and stop it with `sudo /etc/init.d/boswatch.sh stop`. check its status with the `sudo /etc/init.d/boswatch.sh status` argument and stop it with `sudo /etc/init.d/boswatch.sh stop`.
To make the Raspberry Pi use your init script at the right time, one more step is required: To make the Raspberry Pi use your init script at the right time, one more step is required:
Running the command `sudo update-rc.d boswatch.sh defaults`. Running the command `sudo update-rc.d boswatch.sh defaults`.
This command adds in symbolic links to the /etc/rc.x directories so that the init script is run at the default times. This command adds in symbolic links to the /etc/rc.x directories so that the init script is run at the default times.
You can see these links if you do `ls -l /etc/rc?.d/*boswatch.sh` You can see these links if you do `ls -l /etc/rc?.d/*boswatch.sh`