BW3-Core/boswatch/inputSource/inputBase.py

90 lines
3.5 KiB
Python
Raw Normal View History

2019-10-28 21:20:27 +01:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
r"""!
2019-10-28 21:20:27 +01:00
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
German BOS Information Script
by Bastian Schroll
@file: inoutSource.py
@date: 28.10.2018
@author: Bastian Schroll
@description: Base class for boswatch input sources
"""
import time
import logging
import threading
2019-10-30 11:08:26 +01:00
from abc import ABC, abstractmethod
2020-07-08 11:55:46 +02:00
from boswatch.utils import paths
2020-07-06 12:01:41 +02:00
from boswatch.processManager import ProcessManager
from boswatch.decoder.decoder import Decoder
2019-10-28 21:20:27 +01:00
logging.debug("- %s loaded", __name__)
2019-10-30 11:08:26 +01:00
class InputBase(ABC):
r"""!Base class for handling inout sources"""
2019-10-28 21:20:27 +01:00
def __init__(self, inputQueue, inputConfig, decoderConfig):
r"""!Build a new InputSource class
2019-10-28 21:20:27 +01:00
@param inputQueue: Python queue object to store input data
@param inputConfig: ConfigYaml object with the inoutSource config
@param decoderConfig: ConfigYaml object with the decoder config"""
self._inputThread = None
self._isRunning = False
self._inputQueue = inputQueue
self._inputConfig = inputConfig
self._decoderConfig = decoderConfig
def start(self):
r"""!Start the input source thread"""
2019-10-28 21:20:27 +01:00
logging.debug("starting input thread")
self._isRunning = True
self._inputThread = threading.Thread(target=self._runThread, name="inputThread",
args=(self._inputQueue, self._inputConfig, self._decoderConfig))
self._inputThread.daemon = True
self._inputThread.start()
2019-10-30 11:08:26 +01:00
@abstractmethod
2019-10-28 21:20:27 +01:00
def _runThread(self, dataQueue, sdrConfig, decoderConfig):
r"""!Thread routine of the input source has to be inherit"""
2019-10-28 21:20:27 +01:00
def shutdown(self):
r"""!Stop the input source thread"""
2019-10-28 21:20:27 +01:00
if self._isRunning:
logging.debug("wait for stopping the input thread")
self._isRunning = False
self._inputThread.join()
logging.debug("input thread stopped")
def addToQueue(self, data):
r"""!Decode and add alarm data to the queue for further processing during boswatch client"""
bwPacket = Decoder.decode(data)
if bwPacket is not None:
self._inputQueue.put_nowait((bwPacket, time.time()))
logging.debug("Added received data to queue")
2020-07-06 12:01:41 +02:00
2020-07-08 20:33:58 +02:00
def getDecoderInstance(self, decoderConfig, StdIn):
2020-07-13 20:02:00 +02:00
mmProc = ProcessManager(str(decoderConfig.get("path", default="multimon-ng")), textMode=True)
2020-07-06 12:01:41 +02:00
if decoderConfig.get("fms", default=0):
mmProc.addArgument("-a FMSFSK")
if decoderConfig.get("zvei", default=0):
mmProc.addArgument("-a ZVEI1")
if decoderConfig.get("poc512", default=0):
mmProc.addArgument("-a POCSAG512")
if decoderConfig.get("poc1200", default=0):
mmProc.addArgument("-a POCSAG1200")
if decoderConfig.get("poc2400", default=0):
mmProc.addArgument("-a POCSAG2400")
2020-07-13 20:02:00 +02:00
if decoderConfig.get("char", default=0):
mmProc.addArgument("-C " + str(decoderConfig.get("char")))
2020-07-06 12:01:41 +02:00
mmProc.addArgument("-f alpha")
mmProc.addArgument("-t raw -")
2020-07-08 11:55:46 +02:00
mmProc.setStdin(StdIn)
mmProc.setStderr(open(paths.LOG_PATH + "multimon-ng.log", "a"))
2020-07-06 12:01:41 +02:00
return mmProc