Repository: akolar/ogn-lib

Issue:
Implement parser for LiveTrack24 messages (OGLT24)

Discussion:

Patch:
diff --git a/ogn_lib/parser.py b/ogn_lib/parser.py
index 4df961f..e50eb80 100644
--- a/ogn_lib/parser.py
+++ b/ogn_lib/parser.py
@@ -714,3 +714,32 @@ class Skylines(Parser):
             'id': fields[0],
             'vertical_speed': int(fields[1][:3]) * FEET_TO_METERS
         }
+
+
+class LiveTrack24(Parser):
+    """
+    Parser for LiveTrack24-formatted APRS messages.
+    """
+
+    __destto__ = ['OGLT24', 'OGLT24-1']
+
+    @staticmethod
+    def _parse_protocol_specific(comment):
+        """
+        Parses the comment string from LiveTrack24's APRS messages.
+        :param str comment: comment string
+        :return: parsed comment
+        :rtype: dict
+        """
+
+        fields = comment.split(' ', maxsplit=2)
+
+        if len(fields) < 3:
+            raise exceptions.ParseError('LT24 comment incorrectly formatted:'
+                                        ' received {}'.format(comment))
+
+        return {
+            'id': fields[0],
+            'vertical_speed': int(fields[1][:3]) * FEET_TO_METERS,
+            'source': fields[2]
+        }


Test patch:
diff --git a/tests/test_parser.py b/tests/test_parser.py
index fa7c7cd..fb5ec8d 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -481,6 +481,23 @@ class TestSkylines:
             parser.Skylines._parse_protocol_specific('id1111')
 
 
+class TestLT24:
+    def test_parse_protocol_specific(self):
+        data = parser.LiveTrack24._parse_protocol_specific('id25387 +000fpm GPS')
+        assert data['id'] == 'id25387'
+        assert data['vertical_speed'] == 0
+        assert data['source'] == 'GPS'
+
+        data = parser.LiveTrack24._parse_protocol_specific('id25387 +159fpm GPS')
+        assert data['id'] == 'id25387'
+        assert abs(data['vertical_speed'] - 4.57) < 0.1
+        assert data['source'] == 'GPS'
+
+    def test_parse_protocol_specific_fail(self):
+        with pytest.raises(exceptions.ParseError):
+            parser.LiveTrack24._parse_protocol_specific('id11111 GPS')
+
+
 class TestServerParser:
 
     def test_parse_message_beacon(self, mocker):