]> www.average.org Git - loctrkd.git/blobdiff - gps303/zmsg.py
Partly revert "Broadcast location, gps and approximated"
[loctrkd.git] / gps303 / zmsg.py
index 80cf0003cbb97eee3baf55684a9085cb010d2c3f..211011392a296f200cc6cbce99188ceda20c1f44 100644 (file)
@@ -1,10 +1,9 @@
 """ Zeromq messages """
 
-from datetime import datetime, timezone
 import ipaddress as ip
 from struct import pack, unpack
 
-__all__ = "Bcast", "LocEvt", "Resp"
+__all__ = "Bcast", "Resp"
 
 
 def pack_peer(peeraddr):
@@ -59,15 +58,20 @@ class _Zmsg:
             ),
         )
 
+    def __eq__(self, other):
+        return all(
+            [getattr(self, k) == getattr(other, k) for k, _ in self.KWARGS]
+        )
+
     def decode(self, buffer):
-        raise RuntimeError(
-            self.__class__.__name__ + "must implement `encode()` method"
+        raise NotImplementedError(
+            self.__class__.__name__ + "must implement `decode()` method"
         )
 
     @property
     def packed(self):
-        raise RuntimeError(
-            self.__class__.__name__ + "must implement `encode()` method"
+        raise NotImplementedError(
+            self.__class__.__name__ + "must implement `packed()` property"
         )
 
 
@@ -120,31 +124,3 @@ class Resp(_Zmsg):
     def decode(self, buffer):
         self.imei = buffer[:16].decode()
         self.packet = buffer[16:]
-
-
-class LocEvt(_Zmsg):
-    """Zmq message with original or approximated location from lookaside"""
-
-    KWARGS = (
-        ("imei", "0000000000000000"),
-        ("devtime", datetime(1970, 1, 1, tzinfo=timezone.utc)),
-        ("lat", 0.0),
-        ("lon", 0.0),
-        ("is_gps", True),
-    )
-
-    @property
-    def packed(self):
-        return self.imei.encode() + pack(
-            "!dddB",
-            self.devtime.replace(tzinfo=timezone.utc).timestamp(),
-            self.lat,
-            self.lon,
-            int(self.is_gps),
-        )
-
-    def decode(self, buffer):
-        self.imei = buffer[:16].decode()
-        when, self.lat, self.lon, is_gps = unpack("!dddB", buffer[16:])
-        self.devtime = datetime.fromtimestamp(when).astimezone(tz=timezone.utc)
-        self.is_gps = bool(is_gps)