mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2026-01-04 07:39:56 +01:00
simplify server and and client
This commit is contained in:
parent
031f19063b
commit
cc680b578f
14
bw_client.py
14
bw_client.py
|
|
@ -48,10 +48,9 @@ try:
|
|||
from boswatch.network.broadcast import BroadcastClient
|
||||
from boswatch.decoder.decoder import Decoder
|
||||
from boswatch.utils import header
|
||||
except Exception as e: # pragma: no cover
|
||||
|
||||
except: # pragma: no cover
|
||||
logging.exception("cannot import modules")
|
||||
print("cannot import modules")
|
||||
print(e)
|
||||
exit(1)
|
||||
|
||||
try:
|
||||
|
|
@ -67,14 +66,13 @@ try:
|
|||
epilog="""More options you can find in the extern client.ini
|
||||
file in the folder /config""")
|
||||
parser.add_argument("-c", "--config", help="Name to configuration File", required=True)
|
||||
parser.add_argument("-t", "--test", help="Client will send some testdata", action="store_true") # todo implement testmode
|
||||
args = parser.parse_args()
|
||||
|
||||
bwConfig = configYaml.loadConfigFile(paths.CONFIG_PATH + args.config, "clientConfig")
|
||||
if bwConfig is None:
|
||||
logging.error("cannot load config file")
|
||||
|
||||
except Exception as e: # pragma: no cover
|
||||
except: # pragma: no cover
|
||||
logging.exception("error occurred")
|
||||
exit(1)
|
||||
|
||||
|
|
@ -95,12 +93,12 @@ try:
|
|||
if bwClient.connect(ip, port):
|
||||
|
||||
while 1:
|
||||
for i in range(0, 5):
|
||||
|
||||
for i in range(0, 5): # todo implement real data receive
|
||||
time.sleep(1)
|
||||
print("Alarm Nr #" + str(i))
|
||||
|
||||
data = "ZVEI1: 12345"
|
||||
bwPacket = Decoder.decode(data)
|
||||
bwPacket = Decoder.decode("ZVEI1: 12345")
|
||||
|
||||
if bwPacket:
|
||||
bwPacket.printInfo()
|
||||
|
|
|
|||
96
bw_server.py
96
bw_server.py
|
|
@ -15,6 +15,7 @@
|
|||
@description: BOSWatch server application
|
||||
"""
|
||||
from boswatch.utils import paths
|
||||
|
||||
if not paths.makeDirIfNotExist(paths.LOG_PATH):
|
||||
print("cannot find/create log directory: %s", paths.LOG_PATH)
|
||||
exit(1)
|
||||
|
|
@ -53,27 +54,10 @@ try:
|
|||
from boswatch.utils import header
|
||||
from boswatch.network.broadcast import BroadcastClient
|
||||
from boswatch.network.broadcast import BroadcastServer
|
||||
except Exception as e: # pragma: no cover
|
||||
except: # pragma: no cover
|
||||
logging.exception("cannot import modules")
|
||||
print("cannot import modules")
|
||||
print(e)
|
||||
exit(1)
|
||||
|
||||
# Test for the broadcast connection info function
|
||||
server = BroadcastServer()
|
||||
server.start()
|
||||
|
||||
|
||||
# test for the timer class
|
||||
from boswatch.utils.timer import RepeatedTimer
|
||||
from boswatch.network.netCheck import NetCheck
|
||||
net = NetCheck()
|
||||
test = RepeatedTimer(3, net.checkConn)
|
||||
test.start()
|
||||
time.sleep(10)
|
||||
print(net.connectionState)
|
||||
test.stop()
|
||||
|
||||
try:
|
||||
header.logoToLog()
|
||||
header.infoToLog()
|
||||
|
|
@ -91,78 +75,40 @@ try:
|
|||
|
||||
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
|
||||
logging.error("cannot load config file")
|
||||
|
||||
bwPluginManager = PluginManager()
|
||||
bwPluginManager.searchPluginDir()
|
||||
bwPluginManager.importAllPlugins()
|
||||
bwPluginManager.loadAllPlugins()
|
||||
except: # pragma: no cover
|
||||
logging.exception("error occurred")
|
||||
exit(1)
|
||||
|
||||
bwDoubleFilter = DoubleFilter()
|
||||
|
||||
serverPaused = False # flag to pause alarming of server
|
||||
serverStop = False # flag to stop the whole server application
|
||||
# ############################# begin server system
|
||||
try:
|
||||
|
||||
# server flags test code
|
||||
# ----------------------
|
||||
# import threading
|
||||
# def eins():
|
||||
# global serverPaused
|
||||
# serverPaused = True
|
||||
# def zwei():
|
||||
# global serverPaused
|
||||
# serverPaused = False
|
||||
def drei():
|
||||
global serverStop
|
||||
serverStop = True
|
||||
#
|
||||
# t1 = threading.Timer(1, eins)
|
||||
# t2 = threading.Timer(5, zwei)
|
||||
# t3 = threading.Timer(600, drei)
|
||||
# t1.start()
|
||||
# t2.start()
|
||||
# t3.start()
|
||||
if bwConfig["server"]["useBroadcast"]:
|
||||
bcServer = BroadcastServer()
|
||||
bcServer.start()
|
||||
|
||||
incomingQueue = queue.Queue()
|
||||
bwServer = TCPServer(incomingQueue)
|
||||
if bwServer.start():
|
||||
|
||||
while 1:
|
||||
if serverPaused:
|
||||
logging.warning("Server pause flag received ...")
|
||||
logging.debug("But all received packages will be cached!")
|
||||
packetsOld = 0
|
||||
while serverPaused is True:
|
||||
time.sleep(0.2) # reduce cpu load (run all 200ms)
|
||||
packetsNew = incomingQueue.qsize()
|
||||
if packetsNew is not packetsOld:
|
||||
logging.debug("%s packet(s) waiting in queue", packetsNew)
|
||||
packetsOld = packetsNew
|
||||
logging.warning("Server resumed ...")
|
||||
|
||||
if serverStop:
|
||||
logging.warning("Server stop flag received ...")
|
||||
break
|
||||
|
||||
if incomingQueue.empty(): # pause only when no data
|
||||
time.sleep(0.1) # reduce cpu load (run all 100ms)
|
||||
time.sleep(0.1) # reduce cpu load (wait 100ms)
|
||||
|
||||
else:
|
||||
data = incomingQueue.get()
|
||||
|
||||
data = incomingQueue.get()
|
||||
if data is not None:
|
||||
logging.info("get data from %s (waited in queue %0.3f sec.)", data[0], time.time() - data[2])
|
||||
logging.debug("%s packet(s) waiting in queue", incomingQueue.qsize())
|
||||
logging.debug("%s packet(s) still waiting in queue", incomingQueue.qsize())
|
||||
bwPacket = Packet((data[1]))
|
||||
|
||||
if not bwDoubleFilter.filter(bwPacket):
|
||||
continue
|
||||
|
||||
bwPacket.set("clientIP", data[0])
|
||||
bwPacket.addServerData()
|
||||
|
||||
bwPluginManager.runAllPlugins(bwPacket)
|
||||
# print(bwPacket.get("clientVersion")["major"])
|
||||
# todo implement routing
|
||||
|
||||
incomingQueue.task_done()
|
||||
|
||||
except KeyboardInterrupt: # pragma: no cover
|
||||
|
|
@ -176,10 +122,8 @@ finally: # pragma: no cover
|
|||
# bwServer or bwPluginManager are not defined in case of an early error
|
||||
try:
|
||||
bwServer.stop()
|
||||
except: # pragma: no cover
|
||||
pass
|
||||
try:
|
||||
bwPluginManager.unloadAllPlugins()
|
||||
if "bcServer" in locals():
|
||||
bcServer.stop()
|
||||
except: # pragma: no cover
|
||||
pass
|
||||
logging.debug("BOSWatch has ended ...")
|
||||
|
|
|
|||
|
|
@ -8,8 +8,16 @@
|
|||
# by Bastian Schroll
|
||||
|
||||
server:
|
||||
port: 8080
|
||||
name: BW3 Server # name of the BW3 Server instance
|
||||
useBroadcast: no # serve server ip on broadcast request
|
||||
|
||||
|
||||
## 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
|
||||
plugins:
|
||||
template: 1
|
||||
|
||||
|
|
@ -45,56 +53,3 @@ router:
|
|||
|
||||
- name: Router 2
|
||||
route:
|
||||
|
||||
#[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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue