add descriptor module and docu

This commit is contained in:
Bastian Schroll 2019-10-27 21:08:23 +01:00
parent 42209615ab
commit 157f6b5c10
No known key found for this signature in database
GPG key ID: 0AE96912A20E9F5F
3 changed files with 83 additions and 14 deletions

View file

@ -0,0 +1,65 @@
# <center>Descriptor</center>
---
## Beschreibung
Mit diesem Modul können einem Alarmpaket beliebige Beschreibung in Abhänigkeit der enthaltenen Informationen im Paket hinzugefügt werden.
## Resource
`descriptor`
## Konfiguration
Informationen zum Aufbau eines [BOSWatch Pakets](../develop/packet.md)
|Feld|Beschreibung|Default|
|----|------------|-------|
|scanField|Feld des BW Pakets welches geprüft werden soll||
|descrField|Name des Feldes im BW Paket in welchem die Beschreibung gespeichert werden soll||
|wildcard|Optional: Es kann für das angelegte `descrField` automatisch ein Wildcard registriert werden|None|
|descriptions|Liste der Beschreibungen||
#### `descriptions:`
|Feld|Beschreibung|Default|
|----|------------|-------|
|for|Inhalt im `scanField` auf welchem geprüft werden soll||
|add|Beschreibungstext welcher im `descrField` hinterlegt werden soll||
**Beispiel:**
```yaml
- type: module
res: descriptor
config:
- scanField: zvei
descrField: description
wildcard: "{DESCR}"
descriptions:
- for: 12345
add: FF DescriptorTest
- for: 45678
add: FF TestDescription
- scanField: status
descrField: fmsStatDescr
wildcard: "{STATUSTEXT}"
descriptions:
- for: 1
add: Frei (Funk)
- for: 2
add: Frei (Wache)
- ...
```
---
## Abhängigkeiten
- keine
---
## Paket Modifikationen
- Wenn im Paket das Feld `scanField` vorhanden ist, wird das Feld `descrField` dem Paket hinzugefügt
---
## Zusätzliche Wildcards
- Von der Konfiguration abhängig

View file

@ -20,6 +20,7 @@ nav:
- Module:
- Mode Filter: modul/mode_filter.md
- Regex Filter: modul/regex_filter.md
- Descriptor: modul/descriptor.md
- Plugins: tbd.md
- Entwickler:
- Eigenes Modul/Plugin schreiben: develop/ModulPlugin.md

View file

@ -9,10 +9,10 @@
German BOS Information Script
by Bastian Schroll
@file: template_module.py
@date: 01.03.2019
@file: descriptor.py
@date: 27.10.2019
@author: Bastian Schroll
@description: Template Module File
@description: Module to add descriptions to bwPackets
"""
import logging
from module.module import Module
@ -26,28 +26,31 @@ logging.debug("- %s loaded", __name__)
class BoswatchModule(Module):
"""!Description of the Module"""
"""!Adds descriptions to bwPackets"""
def __init__(self, config):
"""!Do not change anything here!"""
super().__init__(__name__, config) # you can access the config class on 'self.config'
def onLoad(self):
"""!Called by import of the plugin"""
pass
for descriptor in self.config:
if descriptor.get("wildcard"):
self.registerWildcard(descriptor.get("wildcard"), descriptor.get("descrField"))
def doWork(self, bwPacket):
"""!start an run of the module.
@param bwPacket: A BOSWatch packet instance"""
if bwPacket.get("mode") == "fms":
pass
elif bwPacket.get("mode") == "zvei":
pass
elif bwPacket.get("mode") == "pocsag":
pass
elif bwPacket.get("mode") == "msg":
pass
for descriptor in self.config:
for description in descriptor.get("descriptions"):
if not bwPacket.get(descriptor.get("scanField")):
break # scanField is not available in this packet
bwPacket.set(descriptor.get("descrField"), description.get("for"))
if str(description.get("for")) == str(bwPacket.get(descriptor.get("scanField"))):
logging.debug("Description '%s' added in packet field '%s'", description.get("add"),
descriptor.get("descrField"))
bwPacket.set(descriptor.get("descrField"), description.get("add"))
break # this descriptor has found a description - run next descriptor
return bwPacket
def onUnload(self):