From 33a7690f7deb12bbdf0896cc364e0bd501dd3a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Gru=CC=88ndger?= Date: Sat, 30 Sep 2017 11:42:16 +0200 Subject: [PATCH] Added Tracker (OGNTRK) and Receiver (OGNSDR) parser --- ogn/parser/parse.py | 26 +++++++++++++----- ogn/parser/pattern.py | 54 ++++++++++++++++++++++++++++++++++++++ tests/parser/test_parse.py | 2 +- 3 files changed, 74 insertions(+), 8 deletions(-) diff --git a/ogn/parser/parse.py b/ogn/parser/parse.py index 6978668..73757cd 100644 --- a/ogn/parser/parse.py +++ b/ogn/parser/parse.py @@ -11,6 +11,10 @@ from ogn.parser.parse_lt24 import parse as parse_lt24_beacon from ogn.parser.parse_spider import parse as parse_spider_beacon from ogn.parser.parse_spot import parse as parse_spot_beacon from ogn.parser.parse_skylines import parse as parse_skylines_beacon +from ogn.parser.parse_tracker import parse_position as parse_tracker_position +from ogn.parser.parse_tracker import parse_status as parse_tracker_status +from ogn.parser.parse_receiver import parse_position as parse_receiver_position +from ogn.parser.parse_receiver import parse_status as parse_receiver_status def parse_aprs(message, reference_date=None, reference_time=None): @@ -50,7 +54,7 @@ def parse_aprs(message, reference_date=None, reference_time=None): raise AprsParseError(message) -def parse_ogn_beacon(aprs_comment, dstcall="APRS"): +def parse_ogn_beacon(aprs_comment, dstcall="APRS", aprs_type="position"): if dstcall == "APRS": # this can be a receiver or an aircraft if not aprs_comment: return {'beacon_type': 'receiver_beacon'} @@ -71,13 +75,21 @@ def parse_ogn_beacon(aprs_comment, dstcall="APRS"): ac_data.update({'beacon_type': 'aircraft_beacon'}) return ac_data elif dstcall == "OGNTRK": - ac_data = parse_aircraft_beacon(aprs_comment) - ac_data.update({'beacon_type': 'aircraft_beacon'}) - return ac_data + if aprs_type == "position": + data = parse_tracker_position(aprs_comment) + data.update({'beacon_type': 'aircraft_beacon'}) + elif aprs_type == "status": + data = parse_tracker_status(aprs_comment) + data.update({'beacon_type': 'aircraft_beacon'}) + return data elif dstcall == "OGNSDR": - ac_data = parse_receiver_beacon(aprs_comment) - ac_data.update({'beacon_type': 'receiver_beacon'}) - return ac_data + if aprs_type == "position": + data = parse_receiver_position(aprs_comment) + data.update({'beacon_type': 'receiver_beacon'}) + elif aprs_type == "status": + data = parse_receiver_status(aprs_comment) + data.update({'beacon_type': 'receiver_beacon'}) + return data elif dstcall == "OGLT24": ac_data = parse_lt24_beacon(aprs_comment) ac_data.update({'beacon_type': 'lt24_beacon'}) diff --git a/ogn/parser/pattern.py b/ogn/parser/pattern.py index 8a0dce2..dc33363 100644 --- a/ogn/parser/pattern.py +++ b/ogn/parser/pattern.py @@ -10,6 +10,60 @@ PATTERN_NAVITER_BEACON = re.compile(""" (?P[+-][\d.]+)rot """, re.VERBOSE | re.MULTILINE) +PATTERN_TRACKER_BEACON_POSITION = re.compile(""" + id(?P
\w{2})(?P\w{6}?)\s? + (?:(?P[+-]\d+?)fpm\s)? + (?:(?P[+-][\d.]+?)rot\s)? + (?:FL(?P[\d.]+)\s)? + (?:(?P[\d.]+?)dB\s)? + (?:(?P\d+)e\s)? + (?:(?P[+-][\d.]+?)kHz\s?)? + (?:gps(?P\d+x\d+)\s?)? + (?:s(?P[\d.]+)\s?)? + (?:h(?P[\dA-F]{2})\s?)? +""", re.VERBOSE | re.MULTILINE) + +PATTERN_TRACKER_BEACON_STATUS = re.compile(""" + h(?P[\d]{2})\s + v(?P[\d]{2})\s + (?P[\d]+)sat/(?P\d)\s + (?P\d+)m\s + (?P[\d.]+)hPa\s + (?P[+-][\d.]+)degC\s + (?P\d+)%\s + (?P[\d.]+)V\s + (?P\d+)/(?P[+-][\d.]+)dBm\s + (?P\d+)/min +""", re.VERBOSE | re.MULTILINE) + +PATTERN_RECEIVER_POSITION = re.compile(r""" + (?:(?P.+))? +""", re.VERBOSE | re.MULTILINE) + +PATTERN_RECEIVER_STATUS = re.compile(""" + (?: + v(?P\d+\.\d+\.\d+) + (?:\.(?P.+?))? + \s)? + CPU:(?P[\d.]+)\s + RAM:(?P[\d.]+)/(?P[\d.]+)MB\s + NTP:(?P[\d.]+)ms/(?P[+-][\d.]+)ppm\s + (?:(?P[\d.]+)V\s)? + (?:(?P[\d.]+)A\s)? + (?:(?P[+-][\d.]+)C\s*)? + (?:(?P\d+)/(?P\d+)Acfts\[1h\]\s*)? + (?:RF: + (?: + (?P[+-][\d]+) + (?P[+-][\d.]+)ppm/ + )? + (?P[+-][\d.]+)dB + (?:/(?P[+-][\d.]+)dB@10km\[(?P\d+)\])? + (?:/(?P[+-][\d.]+)dB@10km\[(?P\d+)/(?P\d+)\])? + )? +""", re.VERBOSE | re.MULTILINE) + + # The following regexp patterns are part of the ruby ogn-client. # source: https://github.com/svoop/ogn_client-ruby diff --git a/tests/parser/test_parse.py b/tests/parser/test_parse.py index b855baa..3417f73 100644 --- a/tests/parser/test_parse.py +++ b/tests/parser/test_parse.py @@ -17,7 +17,7 @@ class TestStringMethods(unittest.TestCase): aprs = parse_aprs(line, datetime(2015, 4, 10, 17, 0)) self.assertFalse(aprs is None) if aprs['comment']: - message = parse_ogn_beacon(aprs['comment'], dstcall=aprs['dstcall']) + message = parse_ogn_beacon(aprs['comment'], dstcall=aprs['dstcall'], aprs_type=aprs['aprs_type']) self.assertEqual(message['beacon_type'], beacon_type) def test_aprs_aircraft_beacons(self):