diff --git a/ogn/parser/aprs_comment/microtrak_parser.py b/ogn/parser/aprs_comment/microtrak_parser.py new file mode 100644 index 0000000..702a218 --- /dev/null +++ b/ogn/parser/aprs_comment/microtrak_parser.py @@ -0,0 +1,23 @@ +from ogn.parser.pattern import PATTERN_MICROTRAK_POSITION_COMMENT + +from .base import BaseParser + + +class MicrotrakParser(BaseParser): + def __init__(self): + self.beacon_type = 'microtrak' + self.position_pattern = PATTERN_MICROTRAK_POSITION_COMMENT + + def parse_position(self, aprs_comment): + match = self.position_pattern.match(aprs_comment) + + result = {} + if match.group('details'): + result.update({ + 'address_type': int(match.group('details'), 16) & 0b00000011, + 'aircraft_type': (int(match.group('details'), 16) & 0b00111100) >> 2, + 'no-tracking': (int(match.group('details'), 16) & 0b01000000) >> 6 == 1, + 'stealth': (int(match.group('details'), 16) & 0b10000000) >> 7 == 1, + 'address': match.group('address'), + }) + return result diff --git a/tests/parser/test_parse_microtrak.py b/tests/parser/test_parse_microtrak.py new file mode 100644 index 0000000..4c43c36 --- /dev/null +++ b/tests/parser/test_parse_microtrak.py @@ -0,0 +1,25 @@ +import unittest + +from ogn.parser.aprs_comment.microtrak_parser import MicrotrakParser + + +class TestStringMethods(unittest.TestCase): + def test_position_comment(self): + message = MicrotrakParser().parse_position("id21A8CBA8") + + self.assertEqual(message['address_type'], 1) + self.assertEqual(message['aircraft_type'], 8) + self.assertFalse(message['stealth']) + self.assertFalse(message['no-tracking']) + self.assertEqual(message['address'], "A8CBA8") + + def test_position_comment_relevant_keys_only(self): + # return only keys where we got informations + message = MicrotrakParser().parse_position("id21A8CBA8") + + self.assertIsNotNone(message) + self.assertEqual(sorted(message.keys()), sorted(['address_type', 'aircraft_type', 'stealth', 'address', 'no-tracking'])) + + +if __name__ == '__main__': + unittest.main() diff --git a/tests/parser/valid_beacon_data/microtrak.txt b/tests/parser/valid_beacon_data/microtrak.txt new file mode 100644 index 0000000..5bad4b3 --- /dev/null +++ b/tests/parser/valid_beacon_data/microtrak.txt @@ -0,0 +1,6 @@ +# The following beacons are example for Microtrak's APRS format +# source: https://github.com/glidernet/ogn-aprs-protocol +# +MTK895B2D>OGNMTK,qAS,Microtrak:/195300h4849.11N/00216.49E'000/000/A=000472 !W72! id07895B2D +MTK895B2D>OGNMTK,qAS,Microtrak:/195300h4849.11N/00216.49E'000/000/A=000472 !W72! id07895B2D +MTK6FC895>OGNMTK,qAS,Microtrak:/195346h4849.09N/00216.52E'000/000/A=000295 !W18! id076FC895