mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2025-12-06 07:12:04 +01:00
refactor server/client
This commit is contained in:
parent
002c449c1c
commit
87457392ea
93
bw_client.py
93
bw_client.py
|
|
@ -32,6 +32,10 @@ logging.debug("BOSWatch client has started ...")
|
||||||
logging.debug("Import python modules")
|
logging.debug("Import python modules")
|
||||||
import argparse
|
import argparse
|
||||||
logging.debug("- argparse")
|
logging.debug("- argparse")
|
||||||
|
import threading
|
||||||
|
logging.debug("- threading")
|
||||||
|
import queue
|
||||||
|
logging.debug("- queue")
|
||||||
import time
|
import time
|
||||||
logging.debug("- time")
|
logging.debug("- time")
|
||||||
|
|
||||||
|
|
@ -39,6 +43,7 @@ logging.debug("Import BOSWatch modules")
|
||||||
from boswatch.configYaml import ConfigYAML
|
from boswatch.configYaml import ConfigYAML
|
||||||
from boswatch.network.client import TCPClient
|
from boswatch.network.client import TCPClient
|
||||||
from boswatch.network.broadcast import BroadcastClient
|
from boswatch.network.broadcast import BroadcastClient
|
||||||
|
from boswatch.processManager import ProcessManager
|
||||||
from boswatch.decoder.decoder import Decoder
|
from boswatch.decoder.decoder import Decoder
|
||||||
from boswatch.utils import header
|
from boswatch.utils import header
|
||||||
from boswatch.utils import misc
|
from boswatch.utils import misc
|
||||||
|
|
@ -55,6 +60,7 @@ parser = argparse.ArgumentParser(prog="bw_client.py",
|
||||||
epilog="""More options you can find in the extern client.ini
|
epilog="""More options you can find in the extern client.ini
|
||||||
file in the folder /config""")
|
file in the folder /config""")
|
||||||
parser.add_argument("-c", "--config", help="Name to configuration File", required=True)
|
parser.add_argument("-c", "--config", help="Name to configuration File", required=True)
|
||||||
|
parser.add_argument("-t", "--test", help="Start Client with testdata-set")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
bwConfig = ConfigYAML()
|
bwConfig = ConfigYAML()
|
||||||
|
|
@ -62,10 +68,8 @@ if not bwConfig.loadConfigFile(paths.CONFIG_PATH + args.config):
|
||||||
logging.error("cannot load config file")
|
logging.error("cannot load config file")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
# ========== CLIENT CODE ==========
|
||||||
# ############################# begin client system
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
ip = bwConfig.get("server", "ip", default="127.0.0.1")
|
ip = bwConfig.get("server", "ip", default="127.0.0.1")
|
||||||
port = bwConfig.get("server", "port", default="8080")
|
port = bwConfig.get("server", "port", default="8080")
|
||||||
|
|
||||||
|
|
@ -75,41 +79,67 @@ try:
|
||||||
ip = broadcastClient.serverIP
|
ip = broadcastClient.serverIP
|
||||||
port = broadcastClient.serverPort
|
port = broadcastClient.serverPort
|
||||||
|
|
||||||
bwClient = TCPClient()
|
inputQueue = queue.Queue()
|
||||||
if bwClient.connect(ip, port):
|
|
||||||
|
|
||||||
testFile = open(paths.TEST_PATH + "testdata.list", "r")
|
|
||||||
|
|
||||||
|
# ========== INPUT CODE ==========
|
||||||
|
def handleSDRInput(dataQueue, config):
|
||||||
|
mmProc = ProcessManager("/opt/multimon/multimon-ng", textMode=True)
|
||||||
|
mmProc.addArgument("-i")
|
||||||
|
mmProc.addArgument("-a POCSAG1200")
|
||||||
|
mmProc.addArgument("-t raw")
|
||||||
|
mmProc.addArgument("./poc1200.raw")
|
||||||
|
mmProc.start()
|
||||||
|
mmProc.skipLines(5)
|
||||||
while 1:
|
while 1:
|
||||||
|
if not mmProc.isRunning:
|
||||||
|
logging.warning("multimon was down - try to restart")
|
||||||
|
mmProc.start()
|
||||||
|
mmProc.skipLines(5)
|
||||||
|
line = mmProc.readline()
|
||||||
|
if line:
|
||||||
|
dataQueue.put_nowait((line, time.time()))
|
||||||
|
logging.debug("Add data to queue")
|
||||||
|
# ========== INPUT CODE ==========
|
||||||
|
|
||||||
for testData in testFile:
|
mmThread = threading.Thread(target=handleSDRInput, name="mmReader", args=(inputQueue, bwConfig.get("inputSource")))
|
||||||
|
mmThread.daemon = True
|
||||||
|
mmThread.start()
|
||||||
|
|
||||||
if (len(testData.rstrip(' \t\n\r')) == 0) or ("#" in testData[0]):
|
bwClient = TCPClient()
|
||||||
continue
|
bwClient.connect(ip, port)
|
||||||
|
while 1:
|
||||||
|
|
||||||
logging.debug("Test: %s", testData)
|
if not bwClient.isConnected:
|
||||||
bwPacket = Decoder.decode(testData)
|
logging.warning("connection to server lost - sleep %d seconds", bwConfig.get("client", "reconnectDelay", default="3"))
|
||||||
|
time.sleep(bwConfig.get("client", "reconnectDelay", default="3"))
|
||||||
|
bwClient.connect(ip, port)
|
||||||
|
|
||||||
if bwPacket:
|
elif not inputQueue.empty():
|
||||||
bwPacket.printInfo()
|
data = inputQueue.get()
|
||||||
misc.addClientDataToPacket(bwPacket, bwConfig)
|
logging.info("get data from queue (waited %0.3f sec.)", time.time() - data[1])
|
||||||
bwClient.transmit(str(bwPacket))
|
logging.debug("%s packet(s) still waiting in queue", inputQueue.qsize())
|
||||||
|
|
||||||
# todo should we do this in an thread, to not block receiving ??? but then we should use transmit() and receive() with Lock()
|
bwPacket = Decoder.decode(data[0])
|
||||||
failedTransmits = 0
|
inputQueue.task_done()
|
||||||
while not bwClient.receive() == "[ack]": # wait for ack or timeout
|
|
||||||
if failedTransmits >= 3:
|
|
||||||
logging.error("cannot transmit after 3 retires")
|
|
||||||
break
|
|
||||||
failedTransmits += 1
|
|
||||||
logging.warning("attempt %d to resend packet", failedTransmits)
|
|
||||||
bwClient.transmit(str(bwPacket)) # try to resend
|
|
||||||
|
|
||||||
|
if bwPacket is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
bwPacket.printInfo()
|
||||||
|
misc.addClientDataToPacket(bwPacket, bwConfig)
|
||||||
|
|
||||||
|
for sendCnt in range(bwConfig.get("client", "sendTries", default="3")):
|
||||||
|
bwClient.transmit(str(bwPacket))
|
||||||
|
if bwClient.receive() == "[ack-]":
|
||||||
logging.debug("ack ok")
|
logging.debug("ack ok")
|
||||||
|
break
|
||||||
|
logging.warning("cannot send packet - sleep %d seconds", bwConfig.get("client", "sendDelay", default="3"))
|
||||||
|
time.sleep(bwConfig.get("client", "sendDelay", default="3"))
|
||||||
|
|
||||||
|
else:
|
||||||
|
time.sleep(0.1) # reduce cpu load (wait 100ms)
|
||||||
|
# in worst case a packet have to wait 100ms until it will be processed
|
||||||
|
|
||||||
bwClient.disconnect()
|
|
||||||
break
|
|
||||||
# test for server ####################################
|
|
||||||
|
|
||||||
except KeyboardInterrupt: # pragma: no cover
|
except KeyboardInterrupt: # pragma: no cover
|
||||||
logging.warning("Keyboard interrupt")
|
logging.warning("Keyboard interrupt")
|
||||||
|
|
@ -117,5 +147,8 @@ except SystemExit: # pragma: no cover
|
||||||
logging.error("BOSWatch interrupted by an error")
|
logging.error("BOSWatch interrupted by an error")
|
||||||
except: # pragma: no cover
|
except: # pragma: no cover
|
||||||
logging.exception("BOSWatch interrupted by an error")
|
logging.exception("BOSWatch interrupted by an error")
|
||||||
finally: # pragma: no cover
|
finally:
|
||||||
logging.debug("BOSWatch has ended ...")
|
logging.debug("Starting shutdown routine")
|
||||||
|
bwClient.disconnect()
|
||||||
|
logging.debug("BOSWatch client has stopped ...")
|
||||||
|
|
||||||
|
|
|
||||||
22
bw_server.py
22
bw_server.py
|
|
@ -106,23 +106,9 @@ except SystemExit: # pragma: no cover
|
||||||
logging.error("BOSWatch interrupted by an error")
|
logging.error("BOSWatch interrupted by an error")
|
||||||
except: # pragma: no cover
|
except: # pragma: no cover
|
||||||
logging.exception("BOSWatch interrupted by an error")
|
logging.exception("BOSWatch interrupted by an error")
|
||||||
finally: # pragma: no cover
|
finally:
|
||||||
|
|
||||||
logging.debug("Starting shutdown routine")
|
logging.debug("Starting shutdown routine")
|
||||||
del bwRoutMan
|
del bwRoutMan
|
||||||
|
bwServer.stop()
|
||||||
try:
|
bcServer.stop()
|
||||||
bwServer.stop()
|
logging.debug("BOSWatch server has stopped ...")
|
||||||
except NameError:
|
|
||||||
pass
|
|
||||||
except:
|
|
||||||
raise
|
|
||||||
|
|
||||||
try:
|
|
||||||
bcServer.stop()
|
|
||||||
except NameError:
|
|
||||||
pass
|
|
||||||
except:
|
|
||||||
raise
|
|
||||||
|
|
||||||
logging.debug("BOSWatch has ended ...")
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,13 @@
|
||||||
# <center>BOSWatch 3</center>
|
# <center>BOSWatch 3</center>
|
||||||
---
|
---
|
||||||
|
|
||||||
<center></center>
|
<center>
|
||||||
|

|
||||||
|
|
||||||
|
Falls du uns unterstützen möchtest würden wir uns über eine Spende freuen.
|
||||||
|
Server, Hosting, Domain sowie Kaffee kosten leider Geld ;-)
|
||||||
|
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=CLK9VBN2MSLZY&source=url)
|
||||||
|
</center>
|
||||||
|
|
||||||
**Es wird darauf hingewiesen, dass für die Teilnahme am BOS-Funk nur nach den Technischen Richtlinien der BOS zugelassene Funkanlagen verwendet werden dürfen.**
|
**Es wird darauf hingewiesen, dass für die Teilnahme am BOS-Funk nur nach den Technischen Richtlinien der BOS zugelassene Funkanlagen verwendet werden dürfen.**
|
||||||
**Der BOS-Funk ist ein nichtöffentlicher mobiler Landfunk. Privatpersonen gehören nicht zum Kreis der berechtigten Funkteilnehmer.** _(Quelle: TR-BOS)_
|
**Der BOS-Funk ist ein nichtöffentlicher mobiler Landfunk. Privatpersonen gehören nicht zum Kreis der berechtigten Funkteilnehmer.** _(Quelle: TR-BOS)_
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue