first tests with yaml config

This commit is contained in:
Bastian Schroll 2019-02-27 08:39:54 +01:00
parent 90ccbf9d0d
commit 60912ce705
8 changed files with 94 additions and 89 deletions

View file

@ -9,7 +9,7 @@
German BOS Information Script
by Bastian Schroll
@file: config_yaml.py
@file: configYaml.py
@date: 27.02.2019
@author: Bastian Schroll
@description: Module for the configuration in yaml format

View file

@ -18,7 +18,7 @@
import logging
import time
from boswatch.config import Config
from boswatch import configYaml
logging.debug("- %s loaded", __name__)
@ -28,7 +28,7 @@ class DoubleFilter:
def __init__(self):
"""!init"""
self._config = Config()
self._config = configYaml.loadConfigSharepoint("serverConfig")["filter"]["doubleFilter"]
self._filterLists = {}
def filter(self, bwPacket):
@ -57,14 +57,14 @@ class DoubleFilter:
# delete entries that are to old
counter = 0
for listPacket in self._filterLists[bwPacket.get("mode")][1:]: # [1:] skip first entry, thats the new one
if listPacket.get("timestamp") < (time.time() - self._config.getInt("doubleFilter", "IgnoreTime", "serverConfig")):
if listPacket.get("timestamp") < (time.time() - self._config["ignoreTime"]):
self._filterLists[bwPacket.get("mode")].remove(listPacket)
counter += 1
if counter:
logging.debug("%d old entry(s) removed", counter)
# delete last entry if list is to big
if len(self._filterLists[bwPacket.get("mode")]) > self._config.getInt("doubleFilter", "MaxEntry", "serverConfig"):
if len(self._filterLists[bwPacket.get("mode")]) > self._config["maxEntry"]:
logging.debug("MaxEntry reached - delete oldest")
self._filterLists[bwPacket.get("mode")].pop()

View file

@ -16,7 +16,7 @@
"""
import logging
import time
from boswatch.config import Config
from boswatch import configYaml
from boswatch import version
logging.debug("- %s loaded", __name__)
@ -73,14 +73,14 @@ class Packet:
- clientBranch
- inputSource
- frequency"""
config = Config()
config = configYaml.loadConfigSharepoint("clientConfig")
logging.debug("add client data to bwPacket")
self.set("clientName", config.getStr("Client", "Name", "clientConfig"))
self.set("clientName", config["client"]["name"])
self.set("clientVersion", version.client)
self.set("clientBuildDate", version.date)
self.set("clientBranch", version.branch)
self.set("inputSource", config.getStr("Client", "InputSource", "clientConfig"))
self.set("frequency", config.getStr("Stick", "Frequency", "clientConfig"))
self.set("inputSource", config["client"]["inputSource"])
self.set("frequency", config["inputSource"]["stick"]["frequency"])
def addServerData(self):
"""!Add the server information to the decoded data
@ -90,9 +90,9 @@ class Packet:
- serverVersion
- serverBuildDate
- serverBranch"""
config = Config()
config = configYaml.loadConfigSharepoint("serverConfig")
logging.debug("add server data to bwPacket")
self.set("serverName", config.getStr("Server", "Name", "serverConfig"))
self.set("serverName", config["server"]["name"])
self.set("serverVersion", version.server)
self.set("serverBuildDate", version.date)
self.set("serverBranch", version.branch)

View file

@ -43,7 +43,7 @@ try:
import time
logging.debug("Import BOSWatch modules")
from boswatch import config_yaml
from boswatch import configYaml
from boswatch.network.client import TCPClient
from boswatch.decoder.decoder import Decoder
from boswatch.utils import header
@ -69,14 +69,14 @@ try:
parser.add_argument("-t", "--test", help="Client will send some testdata", action="store_true") # todo implement testmode
args = parser.parse_args()
bwConfig = config_yaml.loadConfigFile(paths.CONFIG_PATH + args.config, "clientConfig")
bwConfig = configYaml.loadConfigFile(paths.CONFIG_PATH + args.config, "clientConfig")
if bwConfig is None:
logging.exception("cannot load config file")
print("cannot load config file")
exit(1) # without config cannot _run
exit(1) # without config cannot run
bwClient = TCPClient()
if bwClient.connect(bwConfig["servers"][0]["ip"], bwConfig["servers"][0]["port"]):
if bwClient.connect(bwConfig["server"]["ip"], bwConfig["server"]["port"]):
while 1:
for i in range(0, 5):

View file

@ -44,7 +44,7 @@ try:
import queue
logging.debug("Import BOSWatch modules")
from boswatch.config import Config
from boswatch import configYaml
from boswatch.network.server import TCPServer
from boswatch.packet.packet import Packet
from boswatch.plugin.pluginManager import PluginManager
@ -96,8 +96,8 @@ try:
parser.add_argument("-c", "--config", help="Name to configuration File", required=True)
args = parser.parse_args()
bwConfig = Config()
if bwConfig.loadConfigFile(paths.CONFIG_PATH + args.config, "serverConfig") is False:
bwConfig = configYaml.loadConfigFile(paths.CONFIG_PATH + args.config, "serverConfig")
if bwConfig is None:
logging.exception("cannot load config file")
print("cannot load config file")
exit(1) # without config cannot run
@ -107,14 +107,6 @@ try:
bwPluginManager.importAllPlugins()
bwPluginManager.loadAllPlugins()
bwDescriptor = Descriptor()
if bwConfig.getBool("Description", "fms"):
bwDescriptor.loadDescription("fms")
if bwConfig.getBool("Description", "pocsag"):
bwDescriptor.loadDescription("pocsag")
if bwConfig.getBool("Description", "zvei"):
bwDescriptor.loadDescription("zvei")
bwDoubleFilter = DoubleFilter()
serverPaused = False # flag to pause alarming of server
@ -176,9 +168,6 @@ try:
bwPacket.set("clientIP", data[0])
bwPacket.addServerData()
if bwConfig.getBool("Description", bwPacket.get("mode")):
bwDescriptor.addDescriptions(bwPacket)
bwPluginManager.runAllPlugins(bwPacket)
# print(bwPacket.get("clientVersion")["major"])
incomingQueue.task_done()

View file

@ -1,49 +0,0 @@
# -*- coding: utf-8 -*-
# ____ ____ ______ __ __ __ _____
# / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
# / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
# / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
#/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
# German BOS Information Script
# by Bastian Schroll
[Server]
# connection params to BOSWatch alarm server
IP = 127.0.0.1
PORT = 8080
# you can set multiple servers (one line for each)
# the alarm data are served to all server simultane
# for each server you can set one backup server that be used if master is not reachable
# {indv. name} = {Master}:{PORT};{Slave}:{PORT}
# Name Master Port|Slave Port
server1 = 127.0.0.1:8080
serverTest = 127.0.0.1:1234;192.168.178.1:1234
[Client]
# information about this BOSWatch client instance
Name = BW3 Client
# choose input source for multimon
# 'stick' or 'audio'
InputSource = stick
[Stick]
# configuration for your DVB-T stick
Device = 0
Frequency = 85.000M
PPMError = 0
Squelch = 0
Gain = 100
[Audio]
# configuration for audio input
[Decoder]
# here you can enable needed decoders
FMS = 0
ZVEI = 0
POC512 = 0
POC1200 = 0
POC2400 = 0

View file

@ -10,16 +10,13 @@
client:
name: BW3 Client # name of the BW3 Client instance
inputSource: stick # possible is 'stick' or 'audio'
useBroadcast: yes # use broadcast function to find server
# useBroadcast: yes # use broadcast function to find server
servers: # only used if useBroadcast = no
- name: Server one
ip: 127.0.0.1
port: 8080
- name: Server two
ip: 11.12.13.14
port: 5000
# atm only one server possible
server: # only used if useBroadcast = no
name: Server one
ip: 127.0.0.1
port: 8080
inputSource:
stick:
@ -30,7 +27,7 @@ inputSource:
Gain: 100
audio: # not implemented yet
decoder:
decoder: # not implemented yet
fms: yes
zvei: yes
poc512: yes

68
config/server.yaml Normal file
View file

@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
# ____ ____ ______ __ __ __ _____
# / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
# / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
# / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
#/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
# German BOS Information Script
# by Bastian Schroll
server:
name: BW3 Server # name of the BW3 Server instance
filter:
doubleFilter:
maxEntry: 30
ignoreTime: 10
checkMsg: no
#[Server]
#PORT = 8080
#Name = BW3 Server
#
#[FMS]
#UseLists =
#Allowed =
#Denied =
#RegEx =
#
#[POCSAG]
#UseLists =
#Allowed =
#Denied =
#Range =
#RegEx =
#
#[ZVEI]
#UseLists =
#Allowed =
#Denied =
#Range =
#RegEx =
#
#[Filter]
#UseDoubleFilter = 0
#UseRegexFilter = 0
#
#[doubleFilter]
## max number of entrys to save for comparison
#MaxEntry = 30
## time to ignore same alarm in seconds
#IgnoreTime = 10
## include pocsag msg in comparison
#CheckMsg = 0
#
#[regexFilter]
#
#[Description]
## load CSV description files with short and lon description
#fms = 0
#pocsag = 0
#zvei = 0
#
#[Plugins]
## here you can enable needed plugins
## 0 is disabled
## all greater than 0 enable the plugin
## the higher the number the earlier the plugin is called on alarm
## we call ist Plugin Prioority
#template = 1