From 96b719a4188aa123e7b46676de83f477f67b33dc Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Tue, 15 Mar 2022 21:56:04 +0100 Subject: [PATCH] add necessary responses --- gps303/GT06mod.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/gps303/GT06mod.py b/gps303/GT06mod.py index d10c9de..31be5d3 100755 --- a/gps303/GT06mod.py +++ b/gps303/GT06mod.py @@ -3,6 +3,7 @@ Implementation of the protocol used by zx303 GPS+GPRS module Description from https://github.com/tobadia/petGPS/tree/master/resources """ +from datetime import datetime from inspect import isclass from logging import getLogger from struct import pack, unpack @@ -81,11 +82,24 @@ class HEARTBEAT(_GT06pkt): PROTO = 0x08 -class GPS_POSITIONING(_GT06pkt): +class _GPS_POSITIONING(_GT06pkt): + + @classmethod + def from_packet(cls, length, proto, payload): + self = super().from_packet(length, proto, payload) + self.dtime = payload[:6] + # TODO parse the rest + return self + + def response(self): + return super().response(self.dtime) + + +class GPS_POSITIONING(_GPS_POSITIONING): PROTO = 0x10 -class GPS_OFFLINE_POSITIONING(_GT06pkt): +class GPS_OFFLINE_POSITIONING(_GPS_POSITIONING): PROTO = 0x11 @@ -124,6 +138,10 @@ class WIFI_OFFLINE_POSITIONING(_GT06pkt): class TIME(_GT06pkt): PROTO = 0x30 + def response(self): + payload = pack("!HBBBBB", *datetime.utcnow().timetuple()[:6]) + return super().response(payload) + class MOM_PHONE(_GT06pkt): PROTO = 0x43 @@ -206,6 +224,15 @@ class VIBRATION_RECEIVED(_GT06pkt): class POSITION_UPLOAD_INTERVAL(_GT06pkt): PROTO = 0x98 + @classmethod + def from_packet(cls, length, proto, payload): + self = super().from_packet(length, proto, payload) + self.interval = unpack("!H", payload[:2]) + return self + + def response(self): + return super().response(pack("!H", self.interval)) + # Build a dict protocol number -> class CLASSES = {} -- 2.43.0