From d0da38575fdb1c67188c3bfc9cbdf5f03ba58b69 Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Fri, 18 Mar 2022 00:51:00 +0100 Subject: [PATCH] define more protocol units --- gps303.conf | 2 +- gps303/GT06mod.py | 53 ++++++++++++++++++++++++++++++++++++++++------ gps303/__main__.py | 1 + 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/gps303.conf b/gps303.conf index ab4befa..97c9959 100644 --- a/gps303.conf +++ b/gps303.conf @@ -1,6 +1,6 @@ [daemon] port = 4303 -dbfn = /tmp/gps303.sqlite +dbfn = gps303.sqlite [device] uploadIntervalSeconds = 0x0300 diff --git a/gps303/GT06mod.py b/gps303/GT06mod.py index c3918c7..86cc8aa 100755 --- a/gps303/GT06mod.py +++ b/gps303/GT06mod.py @@ -99,9 +99,15 @@ class LOGIN(_GT06pkt): return super().response(b"") -class SUPERVISION(_GT06pkt): +class SUPERVISION(_GT06pkt): # Server sends supervision number status PROTO = 0x05 + def response(self, supnum=0): + # 1: The device automatically answers Pickup effect + # 2: Automatically Answering Two-way Calls + # 3: Ring manually answer the two-way call + return super().response(b"") + class HEARTBEAT(_GT06pkt): PROTO = 0x08 @@ -150,26 +156,41 @@ class STATUS(_GT06pkt): def from_packet(cls, length, proto, payload): self = super().from_packet(length, proto, payload) if len(payload) == 5: - self.batt, self.ver, self.intvl, self.signal, _ = unpack( - "BBBBB", payload - ) + ( + self.batt, + self.ver, + self.timezone, + self.intvl, + self.signal, + ) = unpack("BBBBB", payload) elif len(payload) == 4: - self.batt, self.ver, self.intvl, _ = unpack("BBBB", payload) + self.batt, self.ver, self.timezone, self.intvl = unpack( + "BBBB", payload + ) self.signal = None return self + def response(self, upload_interval=25): # Set interval in minutes + return super().response(pack("B", upload_interval)) + class HIBERNATION(_GT06pkt): PROTO = 0x14 -class RESET(_GT06pkt): +class RESET(_GT06pkt): # Device sends when it got reset SMS PROTO = 0x15 + def response(self): # Server can send to initiate factory reset + return super().response(b"") + -class WHITELIST_TOTAL(_GT06pkt): +class WHITELIST_TOTAL(_GT06pkt): # Server sends to initiage sync (0x58) PROTO = 0x16 + def response(self, number=3): # Number of whitelist entries + return super().response(pack("B", number)) + class _WIFI_POSITIONING(_GT06pkt): @classmethod @@ -215,10 +236,24 @@ class TIME(_GT06pkt): return super().response(payload) +class PROHIBIT_LBS(_GT06pkt): + PROTO = 0x33 + + def response(self, status=1): # Server sent, 0-off, 1-on + return super().response(pack("B", status)) + + class MOM_PHONE(_GT06pkt): PROTO = 0x43 +class STOP_UPLOAD(_GT06pkt): # Server response to LOGIN to thwart the device + PROTO = 0x44 + + def response(self): + return super().response(b"") + + class STOP_ALARM(_GT06pkt): PROTO = 0x56 @@ -310,6 +345,10 @@ class POSITION_UPLOAD_INTERVAL(_GT06pkt): return super().response(pack("!H", self.interval)) +class SOS_ALARM(_GT06pkt): + PROTO = 0x99 + + # Build a dict protocol number -> class CLASSES = {} if True: # just to indent the code, sorry! diff --git a/gps303/__main__.py b/gps303/__main__.py index 665615d..ddad2b7 100755 --- a/gps303/__main__.py +++ b/gps303/__main__.py @@ -89,6 +89,7 @@ if __name__.endswith("__main__"): except OSError as e: log.debug("sending to fd %d error %s", fd, e) else: + # TODO: Also disconnect on HIBERNATION log.info("disconnect fd %d imei %s", fd, imei) pollset.unregister(fd) clntsock.close() -- 2.43.0