some refactorings

This commit is contained in:
Bastian Schroll 2019-10-28 21:20:05 +01:00
parent e061adab4c
commit 2f5184742f
No known key found for this signature in database
GPG key ID: 0AE96912A20E9F5F
8 changed files with 104 additions and 14 deletions

View file

@ -0,0 +1,90 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
German BOS Information Script
by Bastian Schroll
@file: sdrInput.py
@date: 28.10.2018
@author: Bastian Schroll
@description: Input source for sdr with rtl_fm
"""
import time
import logging
import threading
from boswatch.utils import paths
from boswatch.processManager import ProcessManager
logging.debug("- %s loaded", __name__)
class SdrInput:
"""!Worker class to check internet connection"""
def __init__(self):
self._isRunning = False
self._mmThread = None
def start(self, packetQueue, inputConfig, decoderConfig):
self._isRunning = True
self._mmThread = threading.Thread(target=self._handleSDRInput, name="mmReader",
args=(packetQueue, inputConfig, decoderConfig))
self._mmThread.daemon = True
self._mmThread.start()
def shutdown(self):
self._isRunning = False
self._mmThread.join()
def _handleSDRInput(self, dataQueue, sdrConfig, decoderConfig): # todo exception handling inside
sdrProc = ProcessManager(str(sdrConfig.get("rtlPath", default="rtl_fm")))
sdrProc.addArgument("-d " + str(sdrConfig.get("device", default="0"))) # device id
sdrProc.addArgument("-f " + sdrConfig.get("frequency")) # frequencies
sdrProc.addArgument("-p " + str(sdrConfig.get("error", default="0"))) # frequency error in ppm
sdrProc.addArgument("-l " + str(sdrConfig.get("squelch", default="1"))) # squelch
sdrProc.addArgument("-g " + str(sdrConfig.get("gain", default="100"))) # gain
sdrProc.addArgument("-M fm") # set mode to fm
sdrProc.addArgument("-E DC") # set DC filter
sdrProc.addArgument("-s 22050") # bit rate of audio stream
sdrProc.setStderr(open(paths.LOG_PATH + "rtl_fm.log", "a"))
sdrProc.start()
mmProc = ProcessManager(str(sdrConfig.get("mmPath", default="multimon-ng")), textMode=True)
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")
mmProc.addArgument("-f alpha")
mmProc.addArgument("-t raw -")
mmProc.setStdin(sdrProc.stdout)
mmProc.setStderr(open(paths.LOG_PATH + "multimon-ng.log", "a"))
mmProc.start()
logging.info("start decoding")
while self._isRunning:
if not sdrProc.isRunning:
logging.warning("rtl_fm was down - try to restart")
sdrProc.start()
elif not mmProc.isRunning:
logging.warning("multimon was down - try to restart")
mmProc.start()
elif sdrProc.isRunning and mmProc.isRunning:
line = mmProc.readline()
if line:
dataQueue.put_nowait((line, time.time()))
logging.debug("Add data to queue")
print(line)
logging.debug("stopping thread")
mmProc.stop()
sdrProc.stop()

View file

@ -15,7 +15,7 @@
@description: Module to add descriptions to bwPackets
"""
import logging
from module.module import Module
from module.moduleBase import ModuleBase
# ###################### #
# Custom plugin includes #
@ -25,7 +25,7 @@ from module.module import Module
logging.debug("- %s loaded", __name__)
class BoswatchModule(Module):
class BoswatchModuleBase(ModuleBase):
"""!Adds descriptions to bwPackets"""
def __init__(self, config):
"""!Do not change anything here!"""

View file

@ -15,7 +15,7 @@
@description: Filter module for the packet type
"""
import logging
from module.module import Module
from module.moduleBase import ModuleBase
# ###################### #
# Custom plugin includes #
@ -25,7 +25,7 @@ from module.module import Module
logging.debug("- %s loaded", __name__)
class BoswatchModule(Module):
class BoswatchModuleBase(ModuleBase):
"""!Filter of specific bwPacket mode"""
def __init__(self, config):
"""!Do not change anything here!"""

View file

@ -15,7 +15,7 @@
@description: Regex filter module
"""
import logging
from module.module import Module
from module.moduleBase import ModuleBase
# ###################### #
# Custom plugin includes #
@ -25,7 +25,7 @@ import re
logging.debug("- %s loaded", __name__)
class BoswatchModule(Module):
class BoswatchModuleBase(ModuleBase):
"""!Regex based filter mechanism"""
def __init__(self, config):
"""!Do not change anything here!"""

View file

@ -9,7 +9,7 @@
German BOS Information Script
by Bastian Schroll
@file: module.py
@file: moduleBase.py
@date: 01.03.2019
@author: Bastian Schroll
@description: Module main class to inherit
@ -22,7 +22,7 @@ from boswatch import wildcard
logging.debug("- %s loaded", __name__)
class Module:
class ModuleBase:
"""!Main module class"""
_modulesActive = []

View file

@ -15,7 +15,7 @@
@description: Template Module File
"""
import logging
from module.module import Module
from module.moduleBase import ModuleBase
# ###################### #
# Custom plugin includes #
@ -25,7 +25,7 @@ from module.module import Module
logging.debug("- %s loaded", __name__)
class BoswatchModule(Module):
class BoswatchModuleBase(ModuleBase):
"""!Description of the Module"""
def __init__(self, config):
"""!Do not change anything here!"""

View file

@ -9,7 +9,7 @@
German BOS Information Script
by Bastian Schroll
@file: plugin.py
@file: pluginBase.py
@date: 08.01.2018
@author: Bastian Schroll
@description: Plugin main class to inherit
@ -22,7 +22,7 @@ from boswatch import wildcard
logging.debug("- %s loaded", __name__)
class Plugin:
class PluginBase:
"""!Main plugin class"""
_pluginsActive = []

View file

@ -15,7 +15,7 @@
@description: Template Plugin File
"""
import logging
from plugin.plugin import Plugin
from plugin.pluginBase import PluginBase
# ###################### #
# Custom plugin includes #
@ -25,7 +25,7 @@ from plugin.plugin import Plugin
logging.debug("- %s loaded", __name__)
class BoswatchPlugin(Plugin):
class BoswatchPluginBase(PluginBase):
"""!Description of the Plugin"""
def __init__(self, config):
"""!Do not change anything here!"""