Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented multicast alarms #88

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 44 additions & 30 deletions config/server.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
# -*- coding: utf-8 -*-
# ____ ____ ______ __ __ __ _____
# / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
# / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
# / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
#/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
# German BOS Information Script
# by Bastian Schroll

server:
port: 8080
name: BW3 Server # name of the BW3 Server instance
useBroadcast: no # serve server ip on broadcast request

alarmRouter:
- Router 1

router:
- name: Router 1
route:
- type: module
res: filter.modeFilter
name: Filter Fms/Zvei
config:
allowed:
- fms
- zvei
- type: plugin
name: test plugin
res: template_plugin
# -*- coding: utf-8 -*-
# ____ ____ ______ __ __ __ _____
# / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
# / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
# / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
#/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
# German BOS Information Script
# by Bastian Schroll

server:
port: 8080
name: BW3 Server # name of the BW3 Server instance
useBroadcast: no # serve server ip on broadcast request

alarmRouter:
- Alarm_multicast

router:
- name: Alarm_multicast
route:
- type: module
res: filter.regexFilter
config:
- name: "valid multicast rics"
checks:
- field: ric
regex: 210000|210002|210003
- type: module
res: filter.doubleFilter
name: Filter double
config:
ignoreTime: 10
maxEntry: 10
pocsagFields:
- ric
- subric
- type: module
res: multicast
name: Find the multicast message infos
config:
multicastAlarm_textRics: 2100002,210001
multicastAlarm_ignore_time: 10
multicastAlarm_delimiterRic: 2100003
multicastAlarm_delimiterSubric: 0
133 changes: 133 additions & 0 deletions module/multicast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
German BOS Information Script
by Bastian Schroll

@file: multicast.py
@date: 02.05.2021
@author: Thierry Fredrich
@description: Implements multicast alarms

structure of a multicast alarm
# 1 ) network delimiter without text
# 2 ) alarm ric without text
# 3 ) text ric with message
# 4 ) network delimiter ric message <BS>
"""
import logging
from module.moduleBase import ModuleBase


logging.debug("- %s loaded", __name__)


class BoswatchModule(ModuleBase):
"""!Description of the Module"""
# initializing with empty list

textRics = []
delimiterRic = 42
delimiterSubric = 42
ignoreTime = 42
### to be cleared
receivedAlarmRic = 42
receivedAlarmSubric = 42
bufferListFormingAMulticastAlarm = []
initialDelimiterReceived = False
alarmReceived = False
textRicReceived = False
textRicMessage = ''
def initStorage(self):
self.receivedAlarmRic = 42
self.receivedAlarmSubric = 42
self.bufferListFormingAMulticastAlarm = []
self.initialDelimiterReceived = False
self.alarmReceived = False
self.textRicReceived = False
self.textRicMessage = ''

def __init__(self, config):
"""!Do not change anything here!"""
super().__init__(__name__, config) # you can access the config class on 'self.config'
logging.debug("starting multicast module")
logging.debug("multicastAlarm_delimiterRic is: %i" % self.config.get("multicastAlarm_delimiterRic"))
logging.debug("multicastAlarm_delimiterSubric is: %i" % self.config.get("multicastAlarm_delimiterSubric"))
logging.debug("multicastAlarm_ignore_time is: %i" % self.config.get("multicastAlarm_ignore_time"))
logging.debug("multicastAlarm_textRics is: %s" % self.config.get("multicastAlarm_textRics"))
self.delimiterRic = int(self.config.get("multicastAlarm_delimiterRic"))
self.delimiterSubric = int(self.config.get("multicastAlarm_delimiterSubric"))
self.ignoreTime = int(self.config.get("multicastAlarm_ignore_time"))
for aTextRic in self.config.get("multicastAlarm_textRics").split(','):
self.textRics.append(int(aTextRic))
self.initStorage()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be done in the onLoad() method below.
The Init must not be changed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I will change that accordingly.


def onLoad(self):
"""!Called by import of the plugin
Remove if not implemented"""
pass

def doWork(self, bwPacket):
"""!start an run of the module.

@param bwPacket: A BOSWatch packet instance"""
thisRic = int(bwPacket.get("ric"))
thisSubric = int(bwPacket.get("subric"))-1
thisMessage = bwPacket.get("message")
if bwPacket.get("mode") == "pocsag":
pass
else:
logging.error("multicast module only works with pocsag")
raise NameError('multicast module only works with pocsag')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please respect the defined return values for the modules.
See "Rückgabewert bei Modulen".
https://docs.boswatch.de/develop/ModulPlugin.html#arbeiten-mit-dem-bwpacket

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A module should return either of these: bwPacket, False, None

According to the manual, "False" simply stops the Router. In the above situation, everything should stop because the user demands something impossible? Is raising an error a problem for the rest of the logic?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently not sure where this exception will be caught, but I think it will kill the entire server application.
The idea behind this router concept is that you can also have multiple types of messages in a single pipeline.

So it is possible that I want to send ZVEI and POCSAG via a single pipeline (e.g. send by Telegram), but only the POCSAG files should be modified by this module.
For me this is not a error as nothing will break if you return False


'''delimiter received'''
if self.delimiterRic == thisRic and self.delimiterSubric == thisSubric:
''' is it the initial delimiter?'''
if not self.initialDelimiterReceived and \
not self.alarmReceived and \
not self.textRicReceived:
self.bufferListFormingAMulticastAlarm.append(bwPacket)
self.initialDelimiterReceived = True
return False
''' is it the closeing delimiter?'''
if self.initialDelimiterReceived and \
self.alarmReceived and self.textRicReceived:
self.bufferListFormingAMulticastAlarm.append(bwPacket) # deliting list here?
logging.debug("modify bwPacket" )
bwPacket.set('message',self.textRicMessage)
#bwPacket.update({'message':'bla'})
logging.debug("multicast completed... clearing storage")
self.initStorage()
return bwPacket

'''alarm ric recceived'''
if thisRic != self.delimiterRic and thisRic not in self.textRics:
if self.initialDelimiterReceived:
self.bufferListFormingAMulticastAlarm.append(bwPacket)
self.receivedAlarmRic = thisRic
self.receivedAlarmSubric = thisSubric
logging.debug("hoping %i is a valid alarm ric" % thisRic)
logging.debug("with subric %i " % thisSubric)
self.alarmReceived = True
return False

'''text ric received'''
if thisRic in self.textRics:
if self.initialDelimiterReceived and self.alarmReceived:
self.bufferListFormingAMulticastAlarm.append(bwPacket)
self.textRicReceived = True
self.textRicMessage = thisMessage
logging.debug("multicast text is: %s" % thisMessage )
return False
return False

def onUnload(self):
"""!Called by destruction of the plugin
Remove if not implemented"""
pass

Loading