修改定位周期协议格式和人家报错问题
authordxy <1731678236qq.com>
Mon, 25 Aug 2025 03:04:37 +0000 (11:04 +0800)
committerdxy <1731678236qq.com>
Mon, 25 Aug 2025 03:04:37 +0000 (11:04 +0800)
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/protocol.py

index 148f403..6a0b088 100644 (file)
@@ -1242,10 +1242,20 @@ class SockMangager(Abstract):
         self.voice_id = "0"
         self.bt_connect_list = []
         self.new_voice_list = []
-        self.locate_duration_c = 0
-        self.locate_duration_c = EventMesh.publish("get_storage_config","locate_duration_time") #获取定位频率
-        if self.locate_duration_c == None:
-            self.locate_duration_c=0
+        self.location_info= {}
+        self.locate_duration = 0
+        self.locate_duration_state = 0
+        self.location_info = EventMesh.publish("get_storage_config","locate_duration_time") #获取定位频率
+        if self.location_info == None:
+            self.location_info = {}
+        else:
+            # location_time["duration"]=locate_duration_time
+            # location_time["state"]=locate_duration_state
+            if "duration" in self.location_info:
+                self.locate_duration = self.location_info["duration"]
+            if "state" in self.location_info:
+                self.locate_duration_state = self.location_info["state"]
+            pass
         EventMesh.subscribe("REPORT_ALARM_TO_IOT",self.report_alarm_to_iot)
 
     def report_alarm_to_iot(self,event,msg):
@@ -1305,7 +1315,11 @@ class SockMangager(Abstract):
         print("device_state{}".format(device_state))
         EventMesh.publish(WEB_CMD_ENUM.POST_DEVICE_STATE_S_CMD,device_state) #上报设备状态
     def set_location_timer(self,event,msg):
-        self.locate_duration_c=msg
+        if "duration" in msg:
+            self.locate_duration=msg["duration"]
+        if "state" in msg:
+            self.locate_duration_state=msg["state"]
+
 
     def save_bt_connect_list(self,event,msg):
         print("msg:{}".format(msg))
@@ -1567,19 +1581,21 @@ class SockMangager(Abstract):
             self.timerHr= 0
             self.reconnect_count = 0
             EventMesh.publish("publish_AI_btnInfo",{"func":self.hr_report_publish_event,"data":0}) 
-
-        
-        if self.locate_duration_c == None:
-            self.timerLocation = 0
-        else:
-            if self.locate_duration_c != 0:
-                self.timerLocation+=DEFINE_TIME_COUNT
-                if self.timerLocation >= self.locate_duration_c:
-                    self.timerLocation= 0
-                    print("timerLocation")
-                    EventMesh.publish(constants.EVENT.START_LOCATION,WEB_CMD_ENUM.POST_LOCATION_S_CMD) #定位上报
+        # print("self.locate_duration_state:{} self.locate_duration:{}".format(self.locate_duration_state,self.locate_duration))
+        if self.locate_duration_state == 1:
+            if self.locate_duration == None:
+                self.timerLocation = 0
             else:
-                self.timerLocation= 0
+                if self.locate_duration != 0:
+                    self.timerLocation+=DEFINE_TIME_COUNT
+                    if self.timerLocation >= self.locate_duration:
+                        self.timerLocation= 0
+                        
+                        EventMesh.publish(constants.EVENT.START_LOCATION,WEB_CMD_ENUM.POST_LOCATION_S_CMD) #定位上报
+                else:
+                    self.timerLocation= 0
+        else:
+            self.timerLocation= 0
 
        
         if self.send_device_time < DEFIEN_LOCATION_REPORT_TIME :
@@ -2046,10 +2062,19 @@ class IOTWeb_locatedurationProtoCol(ProtoCol):
         #     "msg":"下发定位周期",
         #     "data":300,0表示关
         # }
+        # {"cmd":"locate_duration","msg":"下发定位周期","data":{"duration":300,"state":"1"},"ts":1756089226052,"targetDeviceId":"860132064633266"}
+        #location_time
+        location_time = {}
         if "data" in msg:
-            locate_duration_time = int(msg["data"])
-            EventMesh.publish("set_storage_config",["locate_duration_time",locate_duration_time])
-            EventMesh.publish("set_location_timer",locate_duration_time)
+            data = msg["data"]
+            if "duration" in data:
+                locate_duration_time = int(data["duration"])
+                locate_duration_state = int(data["state"])
+                location_time["duration"]=locate_duration_time
+                location_time["state"]=locate_duration_state
+
+                EventMesh.publish("set_storage_config",["locate_duration_time",location_time])
+                EventMesh.publish("set_location_timer",location_time)
             locate_duration_c = EventMesh.publish("get_storage_config","locate_duration_time")
             print("locate_duration_c:{}".format(locate_duration_c))