k5工厂模式gps测试调整
authorp15692025051 <846603105@qq.com>
Tue, 22 Aug 2023 01:11:07 +0000 (09:11 +0800)
committerp15692025051 <846603105@qq.com>
Tue, 22 Aug 2023 01:11:07 +0000 (09:11 +0800)
线程报错加日志

2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/appFactoryMode.py
2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/mgr.py
2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/ui.py

index c5a7a40..e74be1c 100644 (file)
@@ -323,24 +323,25 @@ FactoryModeLocation_screen.center()
 FactoryModeLocation_screen.set_size(240, 320)
 FactoryModeLocation_screen.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT)
 
-FactoryModeLocation_WIFI_label = lv.label(FactoryModeLocation_screen)
-FactoryModeLocation_WIFI_label.set_text("WIFI:")
-FactoryModeLocation_WIFI_label.set_size(240, 120)
-FactoryModeLocation_WIFI_label.set_pos(0, 0)
-FactoryModeLocation_WIFI_label.set_style_text_color(lv.color_make(0xff, 0xff, 0xff), lv.STATE.DEFAULT)
-FactoryModeLocation_WIFI_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
-
-FactoryModeLocation_CALL_label = lv.label(FactoryModeLocation_screen)
-FactoryModeLocation_CALL_label.set_text("CALL:")
-FactoryModeLocation_CALL_label.set_size(240, 100)
-FactoryModeLocation_CALL_label.set_pos(0, 120)
-FactoryModeLocation_CALL_label.set_style_text_color(lv.color_make(0xff, 0xff, 0xff), lv.STATE.DEFAULT)
-FactoryModeLocation_CALL_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
+# FactoryModeLocation_WIFI_label = lv.label(FactoryModeLocation_screen)
+# FactoryModeLocation_WIFI_label.set_text("WIFI:")
+# FactoryModeLocation_WIFI_label.set_size(240, 120)
+# FactoryModeLocation_WIFI_label.set_pos(0, 0)
+# FactoryModeLocation_WIFI_label.set_style_text_color(lv.color_make(0xff, 0xff, 0xff), lv.STATE.DEFAULT)
+# FactoryModeLocation_WIFI_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
+
+# FactoryModeLocation_CALL_label = lv.label(FactoryModeLocation_screen)
+# FactoryModeLocation_CALL_label.set_text("CALL:")
+# FactoryModeLocation_CALL_label.set_size(240, 100)
+# FactoryModeLocation_CALL_label.set_pos(0, 120)
+# FactoryModeLocation_CALL_label.set_style_text_color(lv.color_make(0xff, 0xff, 0xff), lv.STATE.DEFAULT)
+# FactoryModeLocation_CALL_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
 
 FactoryModeLocation_GNSS_label = lv.label(FactoryModeLocation_screen)
 FactoryModeLocation_GNSS_label.set_text("GNSS:\n")
-FactoryModeLocation_GNSS_label.set_size(240, 200)
-FactoryModeLocation_GNSS_label.set_pos(0, 220)
+FactoryModeLocation_GNSS_label.set_size(240, lv.SIZE.CONTENT)
+FactoryModeLocation_GNSS_label.set_pos(0, 0)
+FactoryModeLocation_GNSS_label.set_long_mode(lv.label.LONG.WRAP)
 FactoryModeLocation_GNSS_label.set_style_text_color(lv.color_make(0xff, 0xff, 0xff), lv.STATE.DEFAULT)
 FactoryModeLocation_GNSS_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
 
@@ -351,13 +352,18 @@ class FactoryModeLocationScreen(Screen):
         self.meta = FactoryModeLocation_screen
         EventMesh.subscribe("PUSH_LOCATION_DATA",self.GET_LOCATION_DATA)
         self.timer_FactoryModeLocation = osTimer()
+        self.time_count = 0
+        self.time_GNSS = 0
+        self.GNSS_status = 0
 
     def initialization(self):
         FactoryModeLocation_GNSS_label.set_text("GNSS:\n") 
-        FactoryModeLocation_WIFI_label.set_text("WIFI:")
-        FactoryModeLocation_CALL_label.set_text("CALL:")
+        # FactoryModeLocation_WIFI_label.set_text("WIFI:")
+        # FactoryModeLocation_CALL_label.set_text("CALL:")
         self.timer_FactoryModeLocation.start(1000, 1, self.timer_FactoryModeLocation_cb)
-
+        self.time_count = utime.mktime(utime.localtime())
+        self.time_GNSS = 0
+        self.GNSS_status = 0
     def post_processor_after_initialization(self):
         #utime.sleep_ms(1000)
         EventMesh.publish(constants.EVENT.START_LOCATION_TEST) #测试模式
@@ -370,53 +376,67 @@ class FactoryModeLocationScreen(Screen):
         print("WIFI:{}".format(msg[1]))
         print("CALL:{}".format(msg[2]))
         EventMesh.publish("system_sleep_rest")#防止黑屏
+        _DATA = ""
+        time_tmp = utime.mktime(utime.localtime())
+         
+        
+        if len(msg[0]) > 1 : #GPS
+            GNSS_DATA = "GNSS:------\n"
+            
+            _DATA += "定位时间:{} {}秒\n".format(self.time_GNSS,time_tmp-self.time_count)   
+            rmc_data = msg[0][1].split("RMC")
+            gsv_data = msg[0][1].split("GSV")
+            if len(rmc_data) >= 2 :
+                rmc_data = rmc_data[1:]
+                rmc_tmp = rmc_data[0].split(",")
+                if len(rmc_tmp) >= 2:
+                    GNSS_DATA = GNSS_DATA + "{},{},{}\n".format(rmc_tmp[2],rmc_tmp[3],rmc_tmp[5])
+                    if rmc_tmp[2] == 'A':
+                        if self.GNSS_status == 0:
+                            self.time_GNSS =  time_tmp-self.time_count
+                        self.GNSS_status = 1
+                        
+            if len(gsv_data) >= 2 :  
+                gsv_data = gsv_data[1:]
+                GSV_dict= {}
+                for i in range(len(gsv_data)) :
+                    gsv_data[i] = gsv_data[i].split("\r\n")[0]
+                    gsv_tmp = gsv_data[i].split(",")
+                    if len(gsv_tmp) < 7 :
+                        break
+                    gsv_tmp = gsv_tmp[4:]
+                    #print("gsv_tmp:{}".format(gsv_tmp))
+                    for i in range(len(gsv_tmp)) :
+                        if i % 4 == 0:
+                            GSV_dict[gsv_tmp[i]] = gsv_tmp[i+3]
+                            print("GSV_dict:{}:[{}]".format(gsv_tmp[i],gsv_tmp[i+3]))
+                        if len(gsv_tmp)-i < 4:
+                            break 
+                count = 0
+                for key in GSV_dict :
+                    #print("GSV_dict[key]:len:{}".format(len(GSV_dict[key])))
+                    if len(GSV_dict[key]) >= 1 :
+                        GNSS_DATA+=" {:<3}:[{:<3}] \n".format(key,GSV_dict[key])#:<3 宽度为3左对齐
+                        count+=1
+                    if count > 14:
+                        break
+            print("GxGSV:{}".format(GNSS_DATA))
+            _DATA += GNSS_DATA
+            #FactoryModeLocation_GNSS_label.set_text(GNSS_DATA) 
         if msg[1] != [] : #WIFI
             WIFI_len = len(msg[1][1])
-            WIFI_DATA = "WIFI:"
+            _DATA += "WIFI:------\n"
             if WIFI_len > 3:
                 WIFI_len = 3
             for i in range(WIFI_len) :
-                WIFI_DATA += "{}".format(msg[1][1][i])
-            FactoryModeLocation_WIFI_label.set_text(WIFI_DATA)
-        
-        if len(msg[0]) > 1 : #GPS
-            GNSS_DATA = "GNSS:\n"
-
-            gsv_data = msg[0][1].split("GSV")
-            if len(gsv_data) < 2 :
-                return
-            gsv_data = gsv_data[1:]
-            
-            GSV_dict= {}
-            for i in range(len(gsv_data)) :
-                gsv_data[i] = gsv_data[i].split("\r\n")[0]
-                gsv_tmp = gsv_data[i].split(",")
-                if len(gsv_tmp) < 7 :
-                    break
-                gsv_tmp = gsv_tmp[4:]
-                #print("gsv_tmp:{}".format(gsv_tmp))
-                for i in range(len(gsv_tmp)) :
-                    if i % 4 == 0:
-                        GSV_dict[gsv_tmp[i]] = gsv_tmp[i+3]
-                        #print("GSV_dict:{}:[{}]".format(gsv_tmp[i],gsv_tmp[i+3]))
-                    if len(gsv_tmp)-i < 4:
-                        break 
-            count = 0
-            for key in GSV_dict :
-                print("GSV_dict[key]:len".format(len(GSV_dict[key])))
-                if len(GSV_dict[key]) >= 1 :
-                    GNSS_DATA+=" {:<3}:[{:<3}] ".format(key,GSV_dict[key])#:<3 宽度为3左对齐
-                    count+=1
-                if count%2 == 0:
-                    GNSS_DATA+="\n"
-                if count > 14:
-                    break
-            print("GxGSV:{}".format(GNSS_DATA))
-            FactoryModeLocation_GNSS_label.set_text(GNSS_DATA)  
+                _DATA += "{}".format(msg[1][1][i]) 
         if msg[2] != [] :#基站
             #print("CALL data:".format(msg[2][0]))
             if len(msg[2]) >= 2 :
-                FactoryModeLocation_CALL_label.set_text("CALL:{}".format(msg[2][0]))      
+                _DATA += "CALL:------\n{}".format(msg[2][0])
+                #FactoryModeLocation_CALL_label.set_text("CALL:{}".format(msg[2][0]))
+        print("GET_LOCATION_DATA:data:{}".format(_DATA))  
+        FactoryModeLocation_GNSS_label.set_text(_DATA)    
     def Close(self):
         EventMesh.publish(constants.EVENT.CLOSE_LOCATION) 
         self.timer_FactoryModeLocation.stop()
index 106381f..bda833d 100644 (file)
@@ -18,6 +18,7 @@ from location import GPS, GPSMatch,CellLocator
 from misc import USB, Power, ADC
 from machine import ExtInt, Pin,Timer,RTC,UART
 import EventMesh
+import usys
 import audio
 from machine import I2C
 from Gsensor import SC7A20
@@ -676,7 +677,7 @@ class DeviceInfoManager(Abstract):
         self.no_smi_state = 0
 
         self.charge_full_count = 0
-
+        self.GPS_step_t = 0#记录步数
         self.usb = USB()
         self.usb.setCallback(self.usb_event_cb)
         self.log = LogAdapter(self.__class__.__name__)
@@ -711,11 +712,13 @@ class DeviceInfoManager(Abstract):
     def post_processor_after_instantiation(self):
         print("post_processor_after_instantiation:1")
         """订阅此类所有的事件到 EventMesh中"""
+        voiceCall.setCallback(voice_callback)
         EventMesh.subscribe("screen_get_ope", self.get_device_ope)
         EventMesh.subscribe("screen_get_sig", self.get_signal)
         EventMesh.subscribe("screen_get_time", self.get_time)
         EventMesh.subscribe("about_get_imei", self.get_imei)
         EventMesh.subscribe("about_get_iccid", self.get_ic_cid)
+        EventMesh.subscribe("get_sim_Status", self.get_sim_Status)
         EventMesh.subscribe("about_get_phonenum", self.get_phone_num)
         EventMesh.subscribe("screen_get_battery", self.get_battery)
         EventMesh.subscribe("set_curr_battery_level", self.set_curr_battery_level)
@@ -761,6 +764,7 @@ class DeviceInfoManager(Abstract):
         #EventMesh.publish(constants.EVENT.START_HEART)
         # 设备开机立刻更新一次参数
         self.publish_event_cb()
+        
         print("post_processor_after_instantiation:3")
 
     def publish_message_event_DeviceInfo(self,event,msg):
@@ -776,6 +780,7 @@ class DeviceInfoManager(Abstract):
                     data["func"](data["data"])
                 except Exception as e:
                     print("DeviceInfo_queue_thread:ERROR:{}".format(e))
+                    usys.print_exception(e)
 
 
     def gsensor_cb(self, para):
@@ -799,7 +804,7 @@ class DeviceInfoManager(Abstract):
         EventMesh.publish("publish_message_event_DeviceInfo",{"func":self.publish_event,"data":0})  
     def publish_event(self,data):
         """
-        主动推送事件
+        定时事件处理
         :param args:
         :param kwargs:
         :return:
@@ -812,32 +817,40 @@ class DeviceInfoManager(Abstract):
         # EventMesh.publish("time", self.get_time())
         # EventMesh.publish("battery", self.get_battery())
         # EventMesh.publish("signal", self.get_signal())
-
+        
         self.timer_push = 0
         date_tmp = utime.localtime()
         time_tmp = utime.mktime(date_tmp)
         # print("date_tmp......01....{} time_tmp:{}\r\n".format(date_tmp,time_tmp))
+        
+
         EventMesh.publish("countdown_end_cb")
+        """定时检查是否关闭gps失败"""
         gnss_state = quecgnss.get_state()
         get_location_flag = EventMesh.publish("get_location_flag")
         if get_location_flag != None:
             if gnss_state == 2 and get_location_flag == 0:
                 EventMesh.publish(constants.EVENT.GPSCLOSE)
 
+        """7分钟一次心跳"""
         if  math.fabs(time_tmp - self.KA_time) > 7*60: #7分钟一次心跳
             self.KA_time = time_tmp
             EventMesh.publish(constants.PROTOCOL.KA_SEND)
+
+        """定时定位"""
         self.upload_time = EventMesh.publish("get_upload_data")
         #print("self.upload_time:{} math.fabs(time_tmp - self.UD_time):{}".format(self.upload_time,math.fabs(time_tmp - self.UD_time)))
-        if self.upload_time != None:
+        if self.upload_time != None :
             if  math.fabs(time_tmp - self.UD_time) > self.upload_time: #30分钟一次定位
                 self.UD_time = time_tmp
-                if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1:
+                step_tmp = self.gsensor.get_step()
+                if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1 and step_tmp - self.GPS_step_t > 3:
                     EventMesh.publish(constants.EVENT.START_LOCATION,constants.PROTOCOL.UD_SEND) #开始UD定位
+                    self.GPS_step_t = step_tmp#记录步数
         EventMesh.publish(constants.EVENT.PUSH_STEP, self.get_step_count())
 
+        """电池平均值"""
         temp = Power.getVbatt()
-        
         if self.bat_count < 10:
             self.vbat_buf.append(temp)
             self.bat_count += 1
@@ -845,18 +858,13 @@ class DeviceInfoManager(Abstract):
             for i in range(9):
                 self.vbat_buf[i] = self.vbat_buf[i+1]
             self.vbat_buf[9] = temp
-
         curr_count = len(self.vbat_buf)
         bat_total_value = 0
         for i in range(curr_count):
             bat_total_value += self.vbat_buf[i]
-
         bat_total_value = bat_total_value//curr_count#一分钟更新一次电量 10个平均值
-
         EventMesh.publish("set_curr_battery_level",bat_total_value)
         # print("self.vbat_buf:{} curr_count :{} bat_total_value:{} temp:{}".format(self.vbat_buf,curr_count,bat_total_value,temp))
-       
-        
         bat_tmp = EventMesh.publish("screen_get_battery")
         self.vbat_count+=10
         if self.vbat_count >= 60:
@@ -866,14 +874,12 @@ class DeviceInfoManager(Abstract):
                 if bat_value <= 0:
                     EventMesh.publish("load_screen", {"screen": "LOW_ONE_POWER"})
         
-        self.get_hr_state = EventMesh.publish("get_hr_state")
-        self.get_spo2_state = EventMesh.publish("get_spo2_state")
         
+        """"隔天清步数"""
         hour = 0
         min = 0
         hour = date_tmp[3]
         min = date_tmp[4]
-
         old_Timesec = EventMesh.publish("get_old_time_data")
         if old_Timesec != None:
             data = RTC().datetime()
@@ -897,7 +903,6 @@ class DeviceInfoManager(Abstract):
                 if spo2 != 0:
                     EventMesh.publish("set_old_spo2_data", 0)
                 EventMesh.publish("set_old_time_data",time_tmp)
-
         if hour == 0:#清步数
             if min <= 1:
                 if self.clear_step == 0:
@@ -921,7 +926,7 @@ class DeviceInfoManager(Abstract):
             if self.clear_step == 1:
                 self.clear_step = 0
         
-        #电量小于20% 5分钟提醒一次
+        """电量小于20% 5分钟提醒一次"""
         get_low_btn = EventMesh.publish("get_low_bat_btn")#
         battery = EventMesh.publish("screen_get_battery")
         # print("get_low_btn:{} self.bat_time:{}".format(get_low_btn,self.bat_time))
@@ -937,7 +942,29 @@ class DeviceInfoManager(Abstract):
             else:
                 self.bat_time = 0
         
-        #消息已满
+        """未联网提示关机"""
+        if EventMesh.publish(constants.EVENT.GET_CONNECT) == 0:#未联网提示关机
+            if battery[0] == "0":
+                self.no_smi_count+=10
+                if self.no_smi_count > (15*60) and self.no_smi_state == 0:
+                    self.no_smi_count = 0
+                    self.no_smi_state = 1
+                    EventMesh.publish("load_screen", {"screen": "no_sim_auto_screen"})  
+            else:
+                self.no_smi_count = 0
+                self.no_smi_state = 0
+        else:
+            self.no_smi_count = 0
+            self.no_smi_state = 0
+        if battery[0] == "1":
+            if battery[1] >= 100:
+                if self.charge_full_count > 60 and self.charge_full_count % (60*10) == 0:#每十分钟提醒一次
+                    EventMesh.publish("load_screen", {"screen": "charge_full"})  
+                self.charge_full_count+=10
+        else:
+            self.charge_full_count = 0
+
+        """检测短信已满,提示是否清掉"""
         msg_nums = sms.getMsgNums() #获取短信条数
         if(msg_nums != -1):
             sms_data = sms.getSaveLoc()
@@ -950,7 +977,10 @@ class DeviceInfoManager(Abstract):
             else:
                 self.sms_full_flag = 0
 
+        """定时测量心率,血氧,体温"""
         WEAR = EventMesh.publish(constants.EVENT.GET_WEAR)#佩戴数据
+        self.get_hr_state = EventMesh.publish("get_hr_state")
+        self.get_spo2_state = EventMesh.publish("get_spo2_state")
         get_temp_time  = EventMesh.publish("get_temp_time")
         get_temp_state  = EventMesh.publish("get_temp_state")
         hr_time = {}
@@ -1418,32 +1448,12 @@ class DeviceInfoManager(Abstract):
             self.old_time = 0    
             self.set_hsenor_crt = 0
 
-        voiceCall.setCallback(voice_callback)
-        if EventMesh.publish(constants.EVENT.GET_CONNECT) == 0:#未插卡提示关机
-            if battery[0] == "0":
-                self.no_smi_count+=10
-                if self.no_smi_count > (15*60) and self.no_smi_state == 0:
-                    self.no_smi_count = 0
-                    self.no_smi_state = 1
-                    EventMesh.publish("load_screen", {"screen": "no_sim_auto_screen"})  
-            else:
-                self.no_smi_count = 0
-                self.no_smi_state = 0
-        else:
-            self.no_smi_count = 0
-            self.no_smi_state = 0
-        if battery[0] == "1":
-            if battery[1] >= 100:
-                if self.charge_full_count > 60 and self.charge_full_count % (60*10) == 0:#每十分钟提醒一次
-                    EventMesh.publish("load_screen", {"screen": "charge_full"})  
-                self.charge_full_count+=10
-        else:
-            self.charge_full_count = 0
+        
         #quecgnss.gnssEnable(0)  
     
       
-    
-
+    def get_sim_Status(self, event, msg):
+        return sim.getStatus()
     def get_device_ope(self, event, msg):
         """
         获取设备运营商信息
@@ -1990,7 +2000,7 @@ class LocationManager(Abstract):
                         if (self.gps_data == [] or self.location_type == 1) and quecgnss.get_state() == 2:
                             self.gps.__gps_nmea_data_clean()
                             data = quecgnss.read(4096)
-                            #print(data[1].decode())
+                            #print("location data:{}".format(data[1].decode()))
                             if data[0] > 0 : #有数据
                                 match_gga_data = self.match.GxGGA(data[1]).split(",")
                                 match_gsv_data = self.match.GxGSV(data[1]).split(",")
@@ -2029,7 +2039,7 @@ class LocationManager(Abstract):
                     if self.location_type == 1: #测试模式
                         EventMesh.publish("PUSH_LOCATION_DATA", [data,self.wifi_data,self.cell_data]) 
                     elif self.location_type == 0: #正常模式     
-                        if self.gps_data  != [] or self.location_timer_count > 60: #or( self.wifi_data != [] and self.cell_data != []): 
+                        if self.gps_data  != [] or self.location_timer_count > 70: #or( self.wifi_data != [] and self.cell_data != []): 
                             self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
                             EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
                             #break
@@ -2046,6 +2056,7 @@ class LocationManager(Abstract):
                 else :
                     utime.sleep_ms(2000)
             except Exception as e:
+                usys.print_exception(e)
                 utime.sleep_ms(1000)
                 print("location_thread:ERROR:{}\r\n{}".format(e,Exception))
                 print("self.gps_data{},self.wifi_data{},self.cell_data{}".format(self.gps_data,self.wifi_data,self.cell_data))
@@ -2119,9 +2130,11 @@ class MsgdetailManager(Abstract):
 
     def save_msg_name(self, event, msg): 
         self.msg_name = str(msg)
+        print("save_msg_name:msg".format(msg))
     
     def save_msg_content(self, event, msg):
         self.msg_content = str(msg)
+        print("save_msg_content:msg".format(msg))
     
     def get_msg_content(self, event, msg):
         return self.msg_content
index d0e0d09..862f6c7 100644 (file)
@@ -21,7 +21,7 @@ import gc
 import _thread
 from queue import Queue
 from machine import RTC
-
+import usys
 def audio_cb(event):
     if event == 0:
         EventMesh.publish("set_audio_state", 1)
@@ -1875,6 +1875,7 @@ def msg_cb(args):
     if index != -1:
         tmp = sms.searchTextMsg(index)
         detail = tmp[1]#内容
+        print("msg_cb:detail {}".format,detail)
         if  detail.find("SETIP:") != -1:#寻找是否有这个字符串
             tmp_test = detail.split("SETIP:")[1]
             if  tmp_test.find(":") != -1:
@@ -6362,6 +6363,7 @@ class UI(object):
                 try:
                     data["func"](data["data"])
                 except Exception as e:
+                    usys.print_exception(e)
                     print("ui_queue_thread:ERROR:{}".format(e))
             # for scr in self.screen_list:
             #     if scr.handle_message_event(data) == 1 :