X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=loctrkd%2Fzx303proto.py;h=aff3405691baa596ca36ca90e00f7067880cef3f;hb=ca67cd29fc86054f08bcbf4995d484bab77a4e60;hp=2a0ede6991c89b9c46ef56fe3ad344d5c7b506a3;hpb=b965fecb08f4149f6f91770e9d6bb6d79f53f11e;p=loctrkd.git diff --git a/loctrkd/zx303proto.py b/loctrkd/zx303proto.py index 2a0ede6..aff3405 100755 --- a/loctrkd/zx303proto.py +++ b/loctrkd/zx303proto.py @@ -44,12 +44,11 @@ __all__ = ( "proto_handled", "parse_message", "probe_buffer", - "proto_name", "DecodeError", "Respond", ) -PROTO_PREFIX = "ZX:" +PROTO_PREFIX: str = "ZX:" ### Deframer ### @@ -293,6 +292,11 @@ class GPS303Pkt(ProtoClass): # Overridden in subclasses, otherwise make empty payload return b"" + @classmethod + def proto_name(cls) -> str: + """Name of the command as used externally""" + return (PROTO_PREFIX + cls.__name__)[:16] + @property def packed(self) -> bytes: payload = self.encode() @@ -368,9 +372,9 @@ class _GPS_POSITIONING(GPS303Pkt): def rectified(self) -> CoordReport: # JSON-able dict return CoordReport( devtime=str(self.devtime), - battery_percentage=-1, - accuracy=-1.0, - altitude=-1.0, + battery_percentage=None, + accuracy=None, + altitude=None, speed=self.speed, direction=self.heading, latitude=self.latitude, @@ -499,7 +503,7 @@ class _WIFI_POSITIONING(GPS303Pkt): def rectified(self) -> HintReport: return HintReport( devtime=str(self.devtime), - battery_percentage=-1, + battery_percentage=None, mcc=self.mcc, mnc=self.mnc, gsm_cells=self.gsm_cells, @@ -826,14 +830,8 @@ def proto_handled(proto: str) -> bool: return proto.startswith(PROTO_PREFIX) -def proto_name(obj: Union[Type[GPS303Pkt], GPS303Pkt]) -> str: - return PROTO_PREFIX + ( - obj.__class__.__name__ if isinstance(obj, GPS303Pkt) else obj.__name__ - ) - - def proto_of_message(packet: bytes) -> str: - return proto_name(CLASSES.get(packet[1], UNKNOWN)) + return CLASSES.get(packet[1], UNKNOWN).proto_name() def imei_from_packet(packet: bytes) -> Optional[str]: @@ -893,7 +891,7 @@ def parse_message(packet: bytes, is_incoming: bool = True) -> GPS303Pkt: def exposed_protos() -> List[Tuple[str, bool]]: return [ - (proto_name(cls)[:16], cls.RESPOND is Respond.EXT) + (cls.proto_name(), cls.RESPOND is Respond.EXT) for cls in CLASSES.values() if hasattr(cls, "rectified") ]