From e2ca436e5dcab6bd5eeb269537f51ce4ca0a638d Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Wed, 27 Feb 2019 12:08:55 +0100 Subject: [PATCH] make client ready for broadcast function --- boswatch/network/broadcast.py | 6 ++++++ boswatch/packet/packet.py | 2 +- bw_client.py | 24 ++++++++++++++++++++---- bw_server.py | 9 +-------- config/client.yaml | 13 +++++-------- 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/boswatch/network/broadcast.py b/boswatch/network/broadcast.py index cfaf0d4..7f9da4b 100644 --- a/boswatch/network/broadcast.py +++ b/boswatch/network/broadcast.py @@ -101,6 +101,12 @@ class BroadcastServer: self._serverShutdown = False self._servePort = servePort + def __del__(self): + if self.isRunning: + self.stop() + while self.isRunning: + pass + def start(self): """!Start the broadcast server in a new thread diff --git a/boswatch/packet/packet.py b/boswatch/packet/packet.py index 87510ec..600588c 100644 --- a/boswatch/packet/packet.py +++ b/boswatch/packet/packet.py @@ -80,7 +80,7 @@ class Packet: self.set("clientBuildDate", version.date) self.set("clientBranch", version.branch) self.set("inputSource", config["client"]["inputSource"]) - self.set("frequency", config["inputSource"]["stick"]["frequency"]) + self.set("frequency", config["inputSource"]["sdr"]["frequency"]) def addServerData(self): """!Add the server information to the decoded data diff --git a/bw_client.py b/bw_client.py index 20b6c01..67ff76b 100644 --- a/bw_client.py +++ b/bw_client.py @@ -45,6 +45,7 @@ try: logging.debug("Import BOSWatch modules") from boswatch import configYaml from boswatch.network.client import TCPClient + from boswatch.network.broadcast import BroadcastClient from boswatch.decoder.decoder import Decoder from boswatch.utils import header except Exception as e: # pragma: no cover @@ -71,12 +72,27 @@ try: 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 + logging.error("cannot load config file") + +except Exception as e: # pragma: no cover + logging.exception("error occurred") + exit(1) + + +# ############################# begin client system +try: + + if bwConfig["client"]["useBroadcast"]: + broadcastClient = BroadcastClient() + if broadcastClient.getConnInfo(): + ip = broadcastClient.serverIP + port = broadcastClient.serverPort + else: + ip = bwConfig["server"]["ip"] + port = bwConfig["server"]["port"] bwClient = TCPClient() - if bwClient.connect(bwConfig["server"]["ip"], bwConfig["server"]["port"]): + if bwClient.connect(ip, port): while 1: for i in range(0, 5): diff --git a/bw_server.py b/bw_server.py index 7c8982a..c695d16 100644 --- a/bw_server.py +++ b/bw_server.py @@ -61,15 +61,8 @@ except Exception as e: # pragma: no cover # Test for the broadcast connection info function server = BroadcastServer() -client = BroadcastClient() server.start() -print(server.isRunning) -client.getConnInfo() -print(client.serverIP, client.serverPort) -server.stop() -print(server.isRunning) -time.sleep(2) -print(server.isRunning) + # test for the timer class from boswatch.utils.timer import RepeatedTimer diff --git a/config/client.yaml b/config/client.yaml index a099a95..2f9b09a 100644 --- a/config/client.yaml +++ b/config/client.yaml @@ -9,25 +9,22 @@ 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 + inputSource: sdr # atm only 'sdr' is possible + useBroadcast: no # use broadcast to find server automatically -# atm only one server possible -server: # only used if useBroadcast = no - name: Server one +server: # only used if useBroadcast = no ip: 127.0.0.1 port: 8080 inputSource: - stick: + sdr: device: 0 frequency: 85.000M PPMError: 0 Squelch: 0 Gain: 100 - audio: # not implemented yet -decoder: # not implemented yet +decoder: fms: yes zvei: yes poc512: yes