From 0c05cd6fce7a6671b4d279d6963fb398cf72e05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Schotth=C3=B6fer?= Date: Mon, 25 Jan 2021 13:53:41 +0100 Subject: [PATCH 1/8] Regex evaluation for POC message text --- config/config.template.ini | 3 +++ includes/decoders/poc.py | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/config/config.template.ini b/config/config.template.ini index e20a7eb..8f22956 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -127,6 +127,9 @@ geo_enable = 0 geo_format = #C(\d{2})(\d{5}),(\d{2})(\d{5})# geo_order = LON, lon, LAT, lat +# Analyze message and associate data to named fields +schemaRegex = ^(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?)$ + [multicastAlarm] # Configure multicastAlarm if your POCSAG network uses an optimized transmission scheme for alarms with more than one RIC (often found in Swissphone networks). diff --git a/includes/decoders/poc.py b/includes/decoders/poc.py index bf906fd..1a0bc45 100644 --- a/includes/decoders/poc.py +++ b/includes/decoders/poc.py @@ -157,7 +157,20 @@ def decode(freq, decoded): # check for double alarm if doubleFilter.checkID("POC", poc_id+poc_sub, poc_text): - data = {"ric":poc_id, "function":poc_sub, "msg":poc_text, "bitrate":bitrate, "description":poc_id, "has_geo":has_geo} + data = {"ric":poc_id, "function":poc_sub, "msg":poc_text, "bitrate":bitrate, "description":poc_id, "has_geo":has_geo, "has_schema_fields":False} + + # if a schema is defined, analyze and associate + if globalVars.config.has_option("POC", "schemaRegex"): + logging.info("schemaRegex found") + m = re.match(globalVars.config.get("POC", "schemaRegex"), poc_text) + if m: + logging.info("POC Schema match") + # enrich data structure by regex groups + data.update(m.groupdict()) + data["has_schema_fields"] = True + else: + logging.info("No POC Schema match") + if has_geo == True: data["lon"] = lon data["lat"] = lat @@ -177,7 +190,7 @@ def decode(freq, decoded): logging.debug(" - multicastAlarm without msg") from includes import multicastAlarm multicastAlarm.newEntrymultiList(data) - + # multicastAlarm processing if enabled and alarm message has been received elif globalVars.config.getint("multicastAlarm", "multicastAlarm") and data["msg"] != "" and data["ric"] in globalVars.config.get("multicastAlarm", "multicastAlarm_ric"): logging.debug(" - multicastAlarm with message") From c0b5e896929447b3ace8fa9905b6ca3cc99ec498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Schotth=C3=B6fer?= Date: Tue, 26 Jan 2021 11:24:49 +0100 Subject: [PATCH 2/8] Added changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3107002..a53f25d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### __[v2.5.3]__ - unreleased ##### Added +- Extending POC data-structure by Regex named groups matching. ##### Changed ##### Deprecated ##### Removed From 7e4a271a3c67f6bc309b93f10fd88dc5387ec603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Schotth=C3=B6fer?= Date: Tue, 26 Jan 2021 11:50:25 +0100 Subject: [PATCH 3/8] Add pull request link to changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a53f25d..dbd9df5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ### __[v2.5.3]__ - unreleased ##### Added -- Extending POC data-structure by Regex named groups matching. +- Extending POC data-structure by Regex named groups matching. [#508](https://github.com/Schrolli91/BOSWatch/pull/508) ##### Changed ##### Deprecated ##### Removed From 88bfb4fb76969e404f8b0b78e4cb0ea3c98a4484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Schotth=C3=B6fer?= Date: Tue, 26 Jan 2021 12:25:42 +0100 Subject: [PATCH 4/8] Commented out optional configuration option --- config/config.template.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.template.ini b/config/config.template.ini index 8f22956..c70e8f9 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -128,7 +128,7 @@ geo_format = #C(\d{2})(\d{5}),(\d{2})(\d{5})# geo_order = LON, lon, LAT, lat # Analyze message and associate data to named fields -schemaRegex = ^(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?)$ +#schemaRegex = ^(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?)$ [multicastAlarm] From d9b142c59fe83c00ec09c37d322187d4ac4251f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Schotth=C3=B6fer?= Date: Tue, 26 Jan 2021 14:40:40 +0100 Subject: [PATCH 5/8] Added some more description --- config/config.template.ini | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/config/config.template.ini b/config/config.template.ini index c70e8f9..533d840 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -128,6 +128,19 @@ geo_format = #C(\d{2})(\d{5}),(\d{2})(\d{5})# geo_order = LON, lon, LAT, lat # Analyze message and associate data to named fields +# If the regular expression matches the POC message, the "named groups" defined in schemaRegex will be added to the data structure. +# You can check this by looking at the value in data["has_schema_fields"]. If it is True, then the regular expression has been hit and the additional fields are available. +# E.g. POC message is "TESTALARM Person in Zwangslage;H2.04;Neustadt;Königsbach;Weinstraße 1;VS Winzerheim;;Dortige Baustelle..Treppensturz" +# +# Without the schemaRegex, data will look like this (RIC, SubRIC and Bitrate are random): +# {'function': '1', 'has_geo': False, 'description': '1234567', 'has_schema_fields': False, 'msg': 'TESTALARM Person in Zwangslage;H2.04;Neustadt;Königsbach;Weinstraße 1;VS Winzerheim;;Dortige Baustelle..Treppensturz', 'bitrate': 1200, 'ric': '1234567'} +# +# When using the schemaRegex from below, data will look like this: +# {'function': '1', 'has_geo': False, 'description': '1234567', 'has_schema_fields': True, 'msg': 'TESTALARM Person in Zwangslage;H2.04;Neustadt;Königsbach;Weinstraße 1;VS Winzerheim;;Dortige Baustelle..Treppensturz', 'bitrate': 1200, 'ric': '1234567, 'Objekt': 'VS Winzerheim', 'StichwortLang': 'TESTALARM Person in Zwangslage', 'Ort': 'Neustadt', 'Bemerkung1': '', 'Adresse': 'Weinstraße 1', 'Bemerkung2': 'Dortige Baustelle..Treppensturz', 'StichwortKurz': 'H2.04', 'Ortsteil': 'Königsbach' +# +# Attention: If you define named groups with names of fields that that are already present in POC decoder's standard data-structure, the content of the respective fields will be overwritten +# with data evaluated by this regex (if the regex finds a match). E.g. if you define a named group like "...(?P.*)..." and the regex will be hit, +# then data["ric"] will get filled with the content evaluated by the regex. #schemaRegex = ^(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?);(?P.*?)$ From 43697da228698014c0a658aafad52e62e53c3639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Schotth=C3=B6fer?= Date: Tue, 26 Jan 2021 14:43:07 +0100 Subject: [PATCH 6/8] Typo --- config/config.template.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.template.ini b/config/config.template.ini index 533d840..e49cbea 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -136,7 +136,7 @@ geo_order = LON, lon, LAT, lat # {'function': '1', 'has_geo': False, 'description': '1234567', 'has_schema_fields': False, 'msg': 'TESTALARM Person in Zwangslage;H2.04;Neustadt;Königsbach;Weinstraße 1;VS Winzerheim;;Dortige Baustelle..Treppensturz', 'bitrate': 1200, 'ric': '1234567'} # # When using the schemaRegex from below, data will look like this: -# {'function': '1', 'has_geo': False, 'description': '1234567', 'has_schema_fields': True, 'msg': 'TESTALARM Person in Zwangslage;H2.04;Neustadt;Königsbach;Weinstraße 1;VS Winzerheim;;Dortige Baustelle..Treppensturz', 'bitrate': 1200, 'ric': '1234567, 'Objekt': 'VS Winzerheim', 'StichwortLang': 'TESTALARM Person in Zwangslage', 'Ort': 'Neustadt', 'Bemerkung1': '', 'Adresse': 'Weinstraße 1', 'Bemerkung2': 'Dortige Baustelle..Treppensturz', 'StichwortKurz': 'H2.04', 'Ortsteil': 'Königsbach' +# {'function': '1', 'has_geo': False, 'description': '1234567', 'has_schema_fields': True, 'msg': 'TESTALARM Person in Zwangslage;H2.04;Neustadt;Königsbach;Weinstraße 1;VS Winzerheim;;Dortige Baustelle..Treppensturz', 'bitrate': 1200, 'ric': '1234567, 'Objekt': 'VS Winzerheim', 'StichwortLang': 'TESTALARM Person in Zwangslage', 'Ort': 'Neustadt', 'Bemerkung1': '', 'Adresse': 'Weinstraße 1', 'Bemerkung2': 'Dortige Baustelle..Treppensturz', 'StichwortKurz': 'H2.04', 'Ortsteil': 'Königsbach'} # # Attention: If you define named groups with names of fields that that are already present in POC decoder's standard data-structure, the content of the respective fields will be overwritten # with data evaluated by this regex (if the regex finds a match). E.g. if you define a named group like "...(?P.*)..." and the regex will be hit, From 0cdde7808b35fff2c3e643f090e186ca3a2acc2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Schotth=C3=B6fer?= Date: Tue, 26 Jan 2021 17:43:09 +0100 Subject: [PATCH 7/8] reduce loglevel for config option disovery notification --- includes/decoders/poc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/decoders/poc.py b/includes/decoders/poc.py index 1a0bc45..aafe44e 100644 --- a/includes/decoders/poc.py +++ b/includes/decoders/poc.py @@ -161,7 +161,7 @@ def decode(freq, decoded): # if a schema is defined, analyze and associate if globalVars.config.has_option("POC", "schemaRegex"): - logging.info("schemaRegex found") + logging.debug("schemaRegex found") m = re.match(globalVars.config.get("POC", "schemaRegex"), poc_text) if m: logging.info("POC Schema match") From 567303ee9924400b863a04c858cbfc193518a6b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Schotth=C3=B6fer?= Date: Tue, 26 Jan 2021 19:18:18 +0100 Subject: [PATCH 8/8] Decrease two more logging occurrences --- includes/decoders/poc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/decoders/poc.py b/includes/decoders/poc.py index aafe44e..7c5fec5 100644 --- a/includes/decoders/poc.py +++ b/includes/decoders/poc.py @@ -164,12 +164,12 @@ def decode(freq, decoded): logging.debug("schemaRegex found") m = re.match(globalVars.config.get("POC", "schemaRegex"), poc_text) if m: - logging.info("POC Schema match") + logging.debug("POC Schema match") # enrich data structure by regex groups data.update(m.groupdict()) data["has_schema_fields"] = True else: - logging.info("No POC Schema match") + logging.debug("No POC Schema match") if has_geo == True: data["lon"] = lon