diff --git a/ogn/parser/aprs_comment/inreach_parser.py b/ogn/parser/aprs_comment/inreach_parser.py new file mode 100644 index 0000000..43cba3f --- /dev/null +++ b/ogn/parser/aprs_comment/inreach_parser.py @@ -0,0 +1,18 @@ +import re + +from ogn.parser.pattern import PATTERN_INREACH_POSITION_COMMENT + +from .base import BaseParser + + +class InreachParser(BaseParser): + def __init__(self): + self.beacon_type = 'inreach' + self.position_pattern = re.compile(PATTERN_INREACH_POSITION_COMMENT) + + def parse_position(self, aprs_comment): + ac_match = self.position_pattern.match(aprs_comment) + return {'address': ac_match.group('id'), + 'model': ac_match.group('model') if ac_match.group('model') else None, + 'status': ac_match.group('status') if ac_match.group('status') else None, + 'pilot_name': ac_match.group('pilot_name') if ac_match.group('pilot_name') else None} diff --git a/ogn/parser/parse.py b/ogn/parser/parse.py index cc20c25..75687f1 100644 --- a/ogn/parser/parse.py +++ b/ogn/parser/parse.py @@ -15,6 +15,7 @@ from ogn.parser.aprs_comment.receiver_parser import ReceiverParser from ogn.parser.aprs_comment.skylines_parser import SkylinesParser from ogn.parser.aprs_comment.spider_parser import SpiderParser from ogn.parser.aprs_comment.spot_parser import SpotParser +from ogn.parser.aprs_comment.inreach_parser import InreachParser from ogn.parser.aprs_comment.generic_parser import GenericParser @@ -106,6 +107,7 @@ dstcall_parser_mapping = {'APRS': OgnParser(), 'OGSKYL': SkylinesParser(), 'OGSPID': SpiderParser(), 'OGSPOT': SpotParser(), + 'OGINREACH': InreachParser(), 'GENERIC': GenericParser(), } diff --git a/ogn/parser/pattern.py b/ogn/parser/pattern.py index 47a37ca..293a296 100644 --- a/ogn/parser/pattern.py +++ b/ogn/parser/pattern.py @@ -55,6 +55,13 @@ PATTERN_SPOT_POSITION_COMMENT = re.compile(""" (?P[A-Z]+) """, re.VERBOSE | re.MULTILINE) +PATTERN_INREACH_POSITION_COMMENT = re.compile(""" + id(?P[\d]+)\s + (?PinReac[A-Za-z\d]*)\s + (?P[A-Za-z]+)\s? + (?P.+)? +""", re.VERBOSE | re.MULTILINE) + PATTERN_TRACKER_POSITION_COMMENT = re.compile(""" id(?P
[\dA-F]{2})(?P
[\dA-F]{6}?)\s? (?:(?P[+-]\d+?)fpm\s)? diff --git a/tests/parser/test_parse_inreach.py b/tests/parser/test_parse_inreach.py new file mode 100644 index 0000000..04af6ba --- /dev/null +++ b/tests/parser/test_parse_inreach.py @@ -0,0 +1,21 @@ +import unittest +from ogn.parser.aprs_comment.inreach_parser import InreachParser + + +class TestStringMethods(unittest.TestCase): + def test_position_comment(self): + message = InreachParser().parse_position("id300434060496190 inReac True") + self.assertEqual(message['address'], "300434060496190") + self.assertEqual(message['model'], 'inReac') + self.assertEqual(message['status'], "True") + self.assertEqual(message['pilot_name'], None) + + message = InreachParser().parse_position("id300434060496190 inReac True Jim Bob") + self.assertEqual(message['address'], "300434060496190") + self.assertEqual(message['model'], 'inReac') + self.assertEqual(message['status'], "True") + self.assertEqual(message['pilot_name'], "Jim Bob") + + +if __name__ == '__main__': + unittest.main()