mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2025-12-06 07:12:04 +01:00
some refactorings
This commit is contained in:
parent
45062bd888
commit
4f389723c0
|
|
@ -34,6 +34,7 @@ class ConfigYAML:
|
|||
yield item
|
||||
|
||||
def __str__(self):
|
||||
"""!Returns the string representation of the internal config dict"""
|
||||
return str(self._config)
|
||||
|
||||
def loadConfigFile(self, configPath):
|
||||
|
|
@ -54,6 +55,12 @@ class ConfigYAML:
|
|||
return False
|
||||
|
||||
def get(self, *args, default=None):
|
||||
"""!Get a single value from the config
|
||||
or a value set in a new configYAML class instance
|
||||
|
||||
@param *args: Config section (one ore more strings)
|
||||
@param default: Default value if section not found (None)
|
||||
@return: A single value, a value set in an configYAML instance, the default value"""
|
||||
tmp = self._config
|
||||
try:
|
||||
for arg in args:
|
||||
|
|
|
|||
|
|
@ -58,38 +58,6 @@ class Packet:
|
|||
logging.warning("field not found: %s", fieldName)
|
||||
return None
|
||||
|
||||
def addClientData(self, config):
|
||||
"""!Add the client information to the decoded data
|
||||
|
||||
This function adds the following data to the bwPacket:
|
||||
- clientName
|
||||
- clientVersion
|
||||
- clientBuildDate
|
||||
- clientBranch
|
||||
- inputSource
|
||||
- frequency"""
|
||||
logging.debug("add client data to bwPacket")
|
||||
self.set("clientName", config.get("client", "name"))
|
||||
self.set("clientVersion", version.client)
|
||||
self.set("clientBuildDate", version.date)
|
||||
self.set("clientBranch", version.branch)
|
||||
self.set("inputSource", config.get("client", "inoutSource"))
|
||||
self.set("frequency", config.get("inputSource", "sdr", "frequency"))
|
||||
|
||||
def addServerData(self, config):
|
||||
"""!Add the server information to the decoded data
|
||||
|
||||
This function adds the following data to the bwPacket:
|
||||
- serverName
|
||||
- serverVersion
|
||||
- serverBuildDate
|
||||
- serverBranch"""
|
||||
logging.debug("add server data to bwPacket")
|
||||
self.set("serverName", config.get("server", "name"))
|
||||
self.set("serverVersion", version.server)
|
||||
self.set("serverBuildDate", version.date)
|
||||
self.set("serverBranch", version.branch)
|
||||
|
||||
def printInfo(self):
|
||||
"""!Print a info message to the log on INFO level.
|
||||
Contains the most useful info about this packet.
|
||||
|
|
|
|||
54
boswatch/utils/misc.py
Normal file
54
boswatch/utils/misc.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""!
|
||||
____ ____ ______ __ __ __ _____
|
||||
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
|
||||
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
|
||||
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
|
||||
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
|
||||
German BOS Information Script
|
||||
by Bastian Schroll
|
||||
|
||||
@file: misc.py
|
||||
@date: 11.03.2019
|
||||
@author: Bastian Schroll
|
||||
@description: Some misc functions
|
||||
"""
|
||||
import logging
|
||||
from boswatch import version
|
||||
|
||||
logging.debug("- %s loaded", __name__)
|
||||
|
||||
|
||||
def addClientDataToPacket(bwPacket, config):
|
||||
"""!Add the client information to the decoded data
|
||||
|
||||
This function adds the following data to the bwPacket:
|
||||
- clientName
|
||||
- clientVersion
|
||||
- clientBuildDate
|
||||
- clientBranch
|
||||
- inputSource
|
||||
- frequency"""
|
||||
logging.debug("add client data to bwPacket")
|
||||
bwPacket.set("clientName", config.get("client", "name"))
|
||||
bwPacket.set("clientVersion", version.client)
|
||||
bwPacket.set("clientBuildDate", version.date)
|
||||
bwPacket.set("clientBranch", version.branch)
|
||||
bwPacket.set("inputSource", config.get("client", "inoutSource"))
|
||||
bwPacket.set("frequency", config.get("inputSource", "sdr", "frequency"))
|
||||
|
||||
|
||||
def addServerDataToPacket(bwPacket, config):
|
||||
"""!Add the server information to the decoded data
|
||||
|
||||
This function adds the following data to the bwPacket:
|
||||
- serverName
|
||||
- serverVersion
|
||||
- serverBuildDate
|
||||
- serverBranch"""
|
||||
logging.debug("add server data to bwPacket")
|
||||
bwPacket.set("serverName", config.get("server", "name"))
|
||||
bwPacket.set("serverVersion", version.server)
|
||||
bwPacket.set("serverBuildDate", version.date)
|
||||
bwPacket.set("serverBranch", version.branch)
|
||||
52
bw_client.py
52
bw_client.py
|
|
@ -41,60 +41,12 @@ from boswatch.network.client import TCPClient
|
|||
from boswatch.network.broadcast import BroadcastClient
|
||||
from boswatch.decoder.decoder import Decoder
|
||||
from boswatch.utils import header
|
||||
from boswatch.processManager import ProcessManager
|
||||
from boswatch.utils import misc
|
||||
|
||||
|
||||
header.logoToLog()
|
||||
header.infoToLog()
|
||||
|
||||
# sox = ProcessManager("_bin/win/sox/sox.exe")
|
||||
# rtl = ProcessManager("_bin/win/rtl_fm/rtl_fm.exe")
|
||||
# multimon = ProcessManager("_bin/win/multimon/multimon-ng.exe", True)
|
||||
#
|
||||
#
|
||||
# try:
|
||||
# rtl.addArgument("-f 85.235MHz")
|
||||
# rtl.addArgument("-d 1")
|
||||
# rtl.addArgument("-M fm -s 22050 -g 100")
|
||||
# rtl.setStderr(None)
|
||||
# #rtl.start()
|
||||
#
|
||||
# sox.addArgument("-t ogg 88022.ogg -esigned-integer -b16 -r 22050 -t raw -")
|
||||
# sox.setStderr(None)
|
||||
# sox.start()
|
||||
#
|
||||
#
|
||||
# #.\_bin\win\sox\sox.exe -t ogg -esigned-integer -b16 -r 22050 88022.ogg -
|
||||
#
|
||||
# multimon.addArgument("-a ZVEI1 -a FMSFSK")
|
||||
# multimon.addArgument("-t raw")
|
||||
# #multimon.addArgument("-v 3")
|
||||
# multimon.addArgument("-")
|
||||
# multimon.setStdin(sox.stdout)
|
||||
# multimon.setStderr(None)
|
||||
#
|
||||
# multimon.start()
|
||||
#
|
||||
# logging.debug("go")
|
||||
#
|
||||
# while multimon.isRunning:
|
||||
# data = multimon.readline()
|
||||
# if data is not None:
|
||||
# print(data)
|
||||
#
|
||||
# logging.debug("end")
|
||||
#
|
||||
# except:
|
||||
# logging.exception("batsch")
|
||||
#
|
||||
# finally:
|
||||
#
|
||||
# sox.stop()
|
||||
# multimon.stop()
|
||||
# rtl.stop()
|
||||
#
|
||||
# exit()
|
||||
|
||||
logging.debug("parse args")
|
||||
# With -h or --help you get the Args help
|
||||
parser = argparse.ArgumentParser(prog="bw_client.py",
|
||||
|
|
@ -140,7 +92,7 @@ try:
|
|||
|
||||
if bwPacket:
|
||||
bwPacket.printInfo()
|
||||
bwPacket.addClientData(bwConfig)
|
||||
misc.addClientDataToPacket(bwPacket, bwConfig)
|
||||
bwClient.transmit(str(bwPacket))
|
||||
|
||||
# todo should we do this in an thread, to not block receiving ??? but then we should use transmit() and receive() with Lock()
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ from boswatch.packet import Packet
|
|||
from boswatch.utils import header
|
||||
from boswatch.network.broadcast import BroadcastServer
|
||||
from boswatch.router.routerManager import RouterManager
|
||||
from boswatch.utils import misc
|
||||
|
||||
|
||||
header.logoToLog()
|
||||
|
|
@ -93,7 +94,7 @@ try:
|
|||
bwPacket = Packet((data[1]))
|
||||
|
||||
bwPacket.set("clientIP", data[0])
|
||||
bwPacket.addServerData(bwConfig)
|
||||
misc.addServerDataToPacket(bwPacket, bwConfig)
|
||||
|
||||
bwRoutMan.runRouter(bwConfig.get("alarmRouter"), bwPacket)
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
import logging
|
||||
import time
|
||||
|
||||
from boswatch.utils import wildcard
|
||||
from boswatch import wildcard
|
||||
|
||||
logging.debug("- %s loaded", __name__)
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import logging
|
|||
import time
|
||||
import pytest
|
||||
|
||||
from boswatch.utils.timer import RepeatedTimer
|
||||
from boswatch.timer import RepeatedTimer
|
||||
|
||||
|
||||
def setup_method(method):
|
||||
|
|
|
|||
Loading…
Reference in a new issue