X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=loctrkd%2Fzx303proto.py;h=bd19e108c770221e3a0132dfc7c863e23181622f;hb=1f1c34f9f42911958be5b282bd9092c1ed3de2a5;hp=2c44a1382b1058b7b0a9e2f0325fde57c3b107a5;hpb=ba4cb894d37f24ac333b316cf9487dfc913eaf74;p=loctrkd.git diff --git a/loctrkd/zx303proto.py b/loctrkd/zx303proto.py index 2c44a13..bd19e10 100755 --- a/loctrkd/zx303proto.py +++ b/loctrkd/zx303proto.py @@ -34,11 +34,12 @@ from typing import ( __all__ = ( "Stream", "class_by_prefix", + "enframe", + "exposed_protos", "inline_response", "proto_handled", "parse_message", "probe_buffer", - "proto_by_name", "proto_name", "DecodeError", "Respond", @@ -864,14 +865,18 @@ if True: # just to indent the code, sorry! def class_by_prefix( prefix: str, -) -> Union[Type[GPS303Pkt], List[Tuple[str, int]]]: +) -> Union[Type[GPS303Pkt], List[str]]: + if prefix.startswith(PROTO_PREFIX): + pname = prefix[len(PROTO_PREFIX) :] + else: + raise KeyError(pname) lst = [ (name, proto) for name, proto in PROTOS.items() if name.upper().startswith(prefix.upper()) ] if len(lst) != 1: - return lst + return [name for name, _ in lst] _, proto = lst[0] return CLASSES[proto] @@ -886,10 +891,6 @@ def proto_name(obj: Union[MetaPkt, GPS303Pkt]) -> str: ) -def proto_by_name(name: str) -> int: - return PROTOS.get(name, -1) - - def proto_of_message(packet: bytes) -> str: return proto_name(CLASSES.get(packet[1], UNKNOWN)) @@ -947,3 +948,11 @@ def parse_message(packet: bytes, is_incoming: bool = True) -> GPS303Pkt: retobj.PROTO = proto # Override class attr with object attr retobj.cause = cause return retobj + + +def exposed_protos() -> List[Tuple[str, bool]]: + return [ + (proto_name(GPS_POSITIONING), True), + (proto_name(WIFI_POSITIONING), False), + (proto_name(STATUS), True), + ]