X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=gps303%2Fgps303proto.py;h=83ac19cd4d68a67ba06091c8b3e0c9274f027110;hb=c772f9219b7a90be63174ef8e66c2f1249200c85;hp=1280fe15ebb6106b8890f6139077e7c4879d8485;hpb=2c60838ac44f02802480eeca626040231014caaa;p=loctrkd.git diff --git a/gps303/gps303proto.py b/gps303/gps303proto.py index 1280fe1..83ac19c 100755 --- a/gps303/gps303proto.py +++ b/gps303/gps303proto.py @@ -25,7 +25,6 @@ __all__ = ( "make_response", "parse_message", "proto_by_name", - "set_config", "GPS303Pkt", "UNKNOWN", "LOGIN", @@ -58,7 +57,6 @@ log = getLogger("gps303") class GPS303Pkt: PROTO: int - CONFIG = None def __init__(self, *args, **kwargs): assert len(args) == 0 @@ -87,7 +85,8 @@ class GPS303Pkt: def to_packet(self): return pack("BB", self.length, self.PROTO) + self.payload - def response(self, *args): + @classmethod + def response(cls, *args): if len(args) == 0: return None assert len(args) == 1 and isinstance(args[0], bytes) @@ -95,7 +94,7 @@ class GPS303Pkt: length = len(payload) + 1 if length > 6: length -= 6 - return pack("BB", length, self.PROTO) + payload + return pack("BB", length, cls.PROTO) + payload class UNKNOWN(GPS303Pkt): @@ -112,14 +111,16 @@ class LOGIN(GPS303Pkt): self.ver = unpack("B", payload[-1:])[0] return self - def response(self): + @classmethod + def response(cls): return super().response(b"") class SUPERVISION(GPS303Pkt): # Server sends supervision number status PROTO = 0x05 - def response(self, supnum=0): + @classmethod + def response(cls, supnum=0): # 1: The device automatically answers Pickup effect # 2: Automatically Answering Two-way Calls # 3: Ring manually answer the two-way call @@ -145,9 +146,9 @@ class _GPS_POSITIONING(GPS303Pkt): self.gps_nb_sat = payload[6] & 0x0F lat, lon, speed, flags = unpack("!IIBH", payload[7:18]) self.gps_is_valid = bool(flags & 0b0001000000000000) # bit 3 - flip_lon = bool(flags & 0b0000100000000000) # bit 4 - flip_lat = not bool(flags & 0b0000010000000000) # bit 5 - self.heading = flags & 0b0000001111111111 # bits 6 - last + flip_lon = bool(flags & 0b0000100000000000) # bit 4 + flip_lat = not bool(flags & 0b0000010000000000) # bit 5 + self.heading = flags & 0b0000001111111111 # bits 6 - last self.latitude = lat / (30000 * 60) * (-1 if flip_lat else 1) self.longitude = lon / (30000 * 60) * (-2 if flip_lon else 1) self.speed = speed @@ -392,7 +393,7 @@ def proto_by_name(name): def proto_of_message(packet): - return unpack("B", packet[1:2]) + return unpack("B", packet[1:2])[0] def make_object(length, proto, payload): @@ -434,6 +435,3 @@ def make_response(msg, **kwargs): # DEPRECATED inframe = msg.response(**kwargs) return None if inframe is None else b"xx" + inframe + b"\r\n" - -def set_config(config): # Note that we are setting _class_ attribute - GPS303Pkt.CONFIG = config