]> www.average.org Git - loctrkd.git/blobdiff - gps303/gps303proto.py
Initial multiprotocol support
[loctrkd.git] / gps303 / gps303proto.py
index e597b2bbc564da0e24e37f39aa69b5e725b68e2b..e3776c3a529276fd333d619ea1946a8264f8337b 100755 (executable)
@@ -32,10 +32,11 @@ from typing import (
 )
 
 __all__ = (
-    "GPS303Conn",
+    "Stream",
     "class_by_prefix",
     "inline_response",
     "parse_message",
+    "probe_buffer",
     "proto_by_name",
     "DecodeError",
     "Respond",
@@ -84,7 +85,7 @@ __all__ = (
 MAXBUFFER: int = 4096
 
 
-class GPS303Conn:
+class Stream:
     def __init__(self) -> None:
         self.buffer = b""
 
@@ -900,6 +901,15 @@ def inline_response(packet: bytes) -> Optional[bytes]:
     return None
 
 
+def probe_buffer(buffer: bytes) -> bool:
+    framestart = buffer.find(b"xx")
+    if framestart < 0:
+        return False
+    if len(buffer) - framestart < 6:
+        return False
+    return True
+
+
 def parse_message(packet: bytes, is_incoming: bool = True) -> GPS303Pkt:
     """From a packet (without framing bytes) derive the XXX.In object"""
     length, proto = unpack("BB", packet[:2])