修复bug
authordxy15521469561 <1731678236@qq.com>
Tue, 19 Sep 2023 07:15:20 +0000 (15:15 +0800)
committerdxy15521469561 <1731678236@qq.com>
Tue, 19 Sep 2023 07:15:20 +0000 (15:15 +0800)
2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/constants.py
2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/main_init.py
2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/mgr.py
2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/protocol.py
2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/ui.py
2.sdk/project/K5/sdk/services/microPython/ports/quectel/core/ui_setting.py

index 329e698..ff4d2d2 100644 (file)
@@ -87,6 +87,17 @@ class PROTOCOL:
     KEYBRD_SEND = "KEYBRD_SEND"
     KEYBRD_RECV = "KEYBRD_RECV"
 
+    SILENCETIMEFS_SEND = "SILENCETIMEFS_SEND"
+    SILENCETIMEFS_RECV = "SILENCETIMEFS_RECV"
+
+    BODYTEMP_SEND ="bodytemp_SEND"
+    BODYTEMP_RECV ="bodytemp_RECV"
+
+    BODYTEMP2_SEND ="bodytemp2_SEND"
+    BODYTEMP2_RECV ="bodytemp2_RECV"
+
+    BTEMP2_SEND ="btemp2_SEND"
+    BTEMP2_RECV ="btemp2_RECV"
 
 class EVENT:
     CHANNEL_SOCKET_SEND = "CHANNEL_SOCKET_SEND"
index 14867b8..f5c0110 100644 (file)
@@ -66,7 +66,7 @@ def main_init():
     # from ui_WatchFaceScreen import WatchFaceScreen
     
     from appFactoryMode import  FactoryModeLocationScreen,FactoryModeScreen ,FactoryModeBatTestScreen,FactoryModeHsensorTestScreen,FactoryModeLogScreen
-    from mgr import setSmsIndexManager,ConfigStoreManager,testSmsSetIPManager,playPowerAudioManager,sosInfoCallManager,getBootOffManager,getSosFlagManager,CountdownManager, LocationManager, getVolumSizeManager,gethistoryDataManager,getUpLoadDataManager, getplayAudiodStateManager,\
+    from mgr import setclassTimeManager,setSmsIndexManager,ConfigStoreManager,testSmsSetIPManager,playPowerAudioManager,sosInfoCallManager,getBootOffManager,getSosFlagManager,CountdownManager, LocationManager, getVolumSizeManager,gethistoryDataManager,getUpLoadDataManager, getplayAudiodStateManager,\
     AddrBookManager,MsgdetailManager,PhoneCallingManager,getOldTimeManager,getStorageDataManager,getBrightnessManager,getHrTimeManager,getTempTimeManager,getLowBatManager
 
     import ui as _ui
@@ -195,13 +195,14 @@ def main_init():
 
         ui.add_screen(NewWechatPopupScreen())
         ui.add_screen(HealthScreen())
+        ui.add_screen(_ui.classMgrPopupScreen())
         # ui.add_screen(_ui.Setting3Screen())  
     except Exception as e:
         usys.print_exception(e)
     #print("init6:{}".format(utime.localtime()))
     
     try:
-        from protocol import KEYBRD_ProtoCol,SILENCETIME2_ProtoCol,WLKEY_ProtoCol,LK_ProtoCol,PING_ProtoCol,HEART_ProtoCol,OXYGEN_ProtoCol,OXYGEN_One_ProtoCol,HRSTART_ProtoCol,CENTER_ProtoCol,UPLOAD_ProtoCol,\
+        from protocol import btemp2_ProtoCol,bodytemp2_ProtoCol,TEMP_Hour_ProtoCol,SILENCETIMEFS_ProtoCol,KEYBRD_ProtoCol,SILENCETIME2_ProtoCol,WLKEY_ProtoCol,LK_ProtoCol,PING_ProtoCol,HEART_ProtoCol,OXYGEN_ProtoCol,OXYGEN_One_ProtoCol,HRSTART_ProtoCol,CENTER_ProtoCol,UPLOAD_ProtoCol,\
             TEMP_ProtoCol,DLT_ProtoCol,WT_ProtoCol,UD_ProtoCol,REMIND_ProtoCol, CR_ProtoCol,KA_ProtoCol,FIND_ProtoCol,POWEROFF_ProtoCol,Time_ProtoCol,\
                 ProtoColResolver,PHL_ProtoCol,MONITOR_ProtoCol,bootoff_ProtoCol,WDSTART_ProtoCol,LOWBAT_ProtoCol,sosHome_dial_ProtoCol,SockManager,NetManager
         import mgr as mgr
@@ -260,6 +261,7 @@ def main_init():
         app.append_manager(sosInfoCallManager())
         app.append_manager(testSmsSetIPManager())
         app.append_manager(setSmsIndexManager())
+        app.append_manager(setclassTimeManager())
     except Exception as e:
         usys.print_exception(e)
     #print("init21:{}".format(utime.localtime()))    
@@ -297,6 +299,10 @@ def main_init():
         pcr.add_support(WLKEY_ProtoCol())
         pcr.add_support(KEYBRD_ProtoCol())
         pcr.add_support(SILENCETIME2_ProtoCol())
+        pcr.add_support(SILENCETIMEFS_ProtoCol())
+        pcr.add_support(TEMP_Hour_ProtoCol())
+        pcr.add_support(bodytemp2_ProtoCol())
+        pcr.add_support(btemp2_ProtoCol())
     except Exception as e:
         usys.print_exception(e)
     try:    
index ba13357..c8b5981 100644 (file)
@@ -22,7 +22,6 @@ import usys
 import audio
 from machine import I2C
 from Gsensor import SC7A20
-import pm
 try :
     from Hsensor import GH3018
 except Exception as e:
@@ -517,6 +516,22 @@ class sosInfoCallManager(Abstract):
                         num_len = len(number)+2  
                     # print("number:{} number_len :{} num:{} num_len:{}".format(number,len(number),num,num_len))
                     if num > num_len :
+                        if len(number) == 1:
+                            number1 = str(number[0])
+                            sms.sendPduMsg(number1, '我需要你的帮助', 'UCS2')
+                        elif len(number) == 2:
+                            number1 = str(number[0])
+                            sms.sendPduMsg(number1, '我需要你的帮助', 'UCS2')
+
+                            number2 = str(number[1])
+                            sms.sendPduMsg(number2, '我需要你的帮助', 'UCS2')
+                        elif len(number) == 3:
+                            number1 = str(number[0])
+                            sms.sendPduMsg(number1, '我需要你的帮助', 'UCS2')
+                            number2 = str(number[1])
+                            sms.sendPduMsg(number2, '我需要你的帮助', 'UCS2')
+                            number3 = str(number[2])
+                            sms.sendPduMsg(number3, '我需要你的帮助', 'UCS2')
                         EventMesh.publish("set_sos_flag",0)
                         EventMesh.publish("set_sos_num",0)
                     else:
@@ -634,7 +649,7 @@ class DeviceInfoManager(Abstract):
         
         #self.battery_push_schedule = osTimer()
         self.check_battery_list = []
-
+        
         self.step = [0,0,0,0]
         self.timer_push=0
         self.timer_push_tmp=60
@@ -832,13 +847,11 @@ class DeviceInfoManager(Abstract):
 
         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)
-        #     if(get_location_flag == 0):
-        #         EventMesh.publish(constants.EVENT.START_LOCATION,constants.PROTOCOL.UD_SEND) #开始UD定位
+        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分钟一次心跳
@@ -846,25 +859,18 @@ class DeviceInfoManager(Abstract):
             EventMesh.publish(constants.PROTOCOL.KA_SEND)
 
         """定时定位"""
-        #EventMesh.publish("set_upload_data",3*60)
         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  math.fabs(time_tmp - self.UD_time) > self.upload_time: #30分钟一次定位
                 self.UD_time = time_tmp
                 status_tmp = self.gsensor.get_status()#获取运动次数
-                #status_tmp = 4
                 #EventMesh.txt_log("status_count:{}".format(status_tmp))
                 if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1 and status_tmp > 3 :
                     EventMesh.publish(constants.EVENT.START_LOCATION,constants.PROTOCOL.UD_SEND) #开始UD定位
                     self.gsensor.clean_status()#清除运动次数
-                else : #关闭定位
-                    #EventMesh.txt_log("NO status")
-                    print("NO status")
-                    EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位 
         EventMesh.publish(constants.EVENT.PUSH_STEP, self.get_step_count())
 
-
         """电池平均值"""
         temp = Power.getVbatt()
         if self.bat_count < 10:
@@ -1464,7 +1470,7 @@ class DeviceInfoManager(Abstract):
             self.old_time = 0    
             self.set_hsenor_crt = 0
 
-        
+        EventMesh.publish("get_class_in_time_page")
         #quecgnss.gnssEnable(0)  
     
       
@@ -1763,7 +1769,7 @@ class DeviceInfoManager(Abstract):
 
     def usb_event_cb(self, state):
         status = state
-        if status == 1:#拔出
+        if status == 1:#
             screen_NAME = EventMesh.publish("get_screen_NAME")
             if screen_NAME != None:
                 if screen_NAME == "poweron" or screen_NAME == "system_init":
@@ -1773,7 +1779,7 @@ class DeviceInfoManager(Abstract):
                 if bat_tmp[0] == "1":
                     EventMesh.publish("load_screen", {"screen": "charge_in"})
             pass
-        elif status == 0:#插入usb
+        elif status == 0:#
             screen_NAME = EventMesh.publish("get_screen_NAME")
             if screen_NAME != None:
                 if screen_NAME == "poweron" or screen_NAME == "system_init":
@@ -1793,7 +1799,6 @@ class DeviceInfoManager(Abstract):
 
 def wifiScan_cb(args):
         EventMesh.publish(constants.EVENT.WIFIINFO, args)
-        wifiScan.control(0)
 
 class LocationManager(Abstract):
 
@@ -1802,18 +1807,16 @@ class LocationManager(Abstract):
         self.match = GPSMatch()
         self.timer_read_GPS_info = osTimer()
         self.wifi_data = []
-        self.gps_data  = {}
+        self.gps_data = []
         self.cell_data = []
         self.location_timer_count = 0
         self.location_check_data_timer_count = 0
-        self.GGA_count = 0
-        self.RMC_A_count = 0
         self.location_type = 0 #定位类型,0:正常定位,有gps数据或60秒关闭;1:测试模式,只有发CLOSE_LOCATION消息才关闭
         self.location_flag = 0
         self.start_location_flag = 0
-        self.location_thread_id  = 0
+        self.location_thread_id = 0
+        self.location_thread_id  = _thread.start_new_thread(self.location_thread, ())
         self.location_queue = Queue(100)
-        self.lpm_fd = None
         #quecgnss.init()
         #quecgnss.gnssEnable(0)
     @staticmethod
@@ -1853,37 +1856,34 @@ class LocationManager(Abstract):
         return self.location_flag
     def start_location(self, event, msg):
         self.location_queue.put(msg)#测试类型入队
-        self.gps_data = {}
-        self.wifi_data = []
-        self.cell_data = []
-        self.location_timer_count = 0
-        self.GSV_sig_ok_count = 0
         print("start_location:{}".format(msg))
+        self.timer_read_GPS_info.start(1000, 1, self.location_timer)
         if( self.location_flag == 1):
             return
-        self.location_thread_id  = _thread.start_new_thread(self.location_thread, ())
+        self.location_timer_count = 0
         self.location_flag = 1
         #self.gps_open(event, msg)
 
+        self.start_location_flag = 1
 
     def start_location_test(self, event, msg):
         print("start_location_test")
-        
-        self.location_type = 1
+        self.timer_read_GPS_info.start(1000, 1, self.location_timer)
         if( self.location_flag == 1):
             return
-        self.location_thread_id  = _thread.start_new_thread(self.location_thread, ())
         self.location_timer_count = 0
         self.location_flag = 1
         #self.gps_open(event, msg)
         self.location_type = 1
- 
+        self.start_location_flag = 1   
 
     def close_location(self, event, msg):
         self.location_flag = 0
         self.location_type = 0
+        self.gps.power_switch(0)
+        wifiScan.control(0)
+        self.timer_read_GPS_info.stop()
 
-        
 
     def WIFI_INFO(self, event, msg):
         self.wifi_data = msg
@@ -1892,12 +1892,11 @@ class LocationManager(Abstract):
 
     def WIFI_scan_open(self, event, msg):
         #print("WIFI_scan_open")
-        
-
-        if wifiScan.getState() == False :
-            self.wifi_data = []
-            wifiScan.control(1)
-            wifiScan.setCfgParam(6, 2, 5,  0)  #设置WiFi参数,10秒上层,两轮,最多6个,6秒底层,PS优先
+        self.wifi_data = []
+        if wifiScan.support():
+            if wifiScan.getState() == False :
+                wifiScan.control(1)
+            wifiScan.setConfig(4, 2, 5, 6, 0)  #设置WiFi参数,10秒上层,两轮,最多6个,6秒底层,PS优先
             wifiScan.setCallback(wifiScan_cb) #注册回调函数
             wifiScan.asyncStart()
             #print("wifiScan.asyncStart")
@@ -1917,11 +1916,8 @@ class LocationManager(Abstract):
 
     def Location_send(self, msg) :
         #print("Location_send1")
-        if self.location_queue.empty() == True:
-            return
         date = "{:04d}{:02d}{:02d},{:02d}{:02d}{:02d}".format(*utime.localtime()[0:6])
         date = date[2:]
-        #date = "180916,025723"
         GPS_type = "V"
         latitude = "0.000000,N"
         longitude = "0.000000,E"
@@ -1929,8 +1925,7 @@ class LocationManager(Abstract):
         direction = "0.0"
         high = "100.0"
         number = "0"
-        precision = "24"
-        if msg[0] :#有GPS数据
+        if msg[0] != [] :#有GPS数据
             GPS_type = "A"
             # 纬度
             latitude = msg[0]["latitude"]
@@ -1949,9 +1944,6 @@ class LocationManager(Abstract):
                 high = "%s"%(high_tmp[0])
             # 讯号质量:搜索到的卫星数目
             number = msg[0]["number"]
-            precision = msg[0]["precision"]
-            #date = msg[0]["date"]
-        
         #gsm 信号强度
         gsm_sig =  str((100//31)*EventMesh.publish("screen_get_sig"))
         # 电池电量百分比 
@@ -2011,7 +2003,6 @@ class LocationManager(Abstract):
         send_data += ",%s,%s,%s"%(battery_caption,step,turn_count)
         send_data += ",%s,%d,%s"%(state,CELL_num,CELL_data)
         send_data += ",%d,%s"%(WIFI_num,WIFI_data)
-        send_data+=",%s"%(precision)
         #print("Location_send2:{} q_size:{}".format(send_data,self.location_queue.size()))
         while True:
             if self.location_queue.empty() == False:
@@ -2024,231 +2015,134 @@ class LocationManager(Abstract):
 
     def location_thread(self):
         
-        self.wifi_data = []
-        self.gps_data = {}
-        self.cell_data = []
-        gnss_r_data = []
-        self.GSV_sig_ok_count = 0
-        self.GGA_count = 0
-        self.RMC_A_count = 0
-        if self.lpm_fd == None:
-            self.lpm_fd = pm.create_wakelock("test_lock", len("test_lock"))
-        pm.wakelock_lock(self.lpm_fd)
-        print("location_thread:1")
-        EventMesh.publish(constants.EVENT.GPSOPEN)
-        print("location_thread:2")
-        self.timer_read_GPS_info.start(1000, 1, self.location_timer)
-        
-        #utime.sleep_ms(1000)
-        self.location_timer_count = 0
-        #quecgnss.read(4096)#去掉第一次错误数据
-        #EventMesh.txt_log("START_LOCATION")
-        # pm.autosleep(0)#唤醒
-        # pm.sclkEx_set(0, 1, 5)
-        while self.location_flag == 1:
+        gnss_r_data = ""
+        while True:
             try :   
-                
-                match_gga_data = []
-                #match_gsv_data = []
-                gnss_r_data = []
-                # if self.location_check_data_timer_count >= 3:
-                #     pm.autosleep(0)#唤醒
-                #     pm.sclkEx_set(0, 1, 5)
-                if self.location_check_data_timer_count >= 5 :#5秒查一次基站数据和wifi数据
-                    self.location_check_data_timer_count = 0
-                    #print(self.location_timer_count)
-                    #GSV_dict= {}
+                if self.location_flag == 1 :
                     
-                    #检查GNSS数据
-                    if ( self.gps_data == {} or self.location_type == 1) and quecgnss.get_state() == 2:
+                    if self.start_location_flag == 1 :
+                        self.start_location_flag = 0
+                        self.wifi_data = []
+                        self.gps_data = []
+                        self.cell_data = []
+                        gnss_r_data = []
+                        print("location_thread:1")
+                        EventMesh.publish(constants.EVENT.GPSOPEN)
+                        print("location_thread:2")
+                        EventMesh.publish(constants.EVENT.WIFISCANOPEN)
+                        print("location_thread:3")
+                        utime.sleep_ms(1000)
+                        self.location_timer_count
+                        #quecgnss.read(4096)#去掉第一次错误数据
+                    match_gga_data = []
+                    #match_gsv_data = []
+                    gnss_r_data = []
+                    if self.location_check_data_timer_count > 3 :#5秒查一次基站数据和wifi数据
+                        self.location_check_data_timer_count = 0
+                        #print(self.location_timer_count)
+                        GSV_dict= {}
+                        GSV_sig_ok_count = 0
+                        #检查GNSS数据
+                        if (self.gps_data == [] or self.location_type == 1) and quecgnss.get_state() == 2:
+                            self.gps.__gps_nmea_data_clean()
+                            #gnss_r_data = [0,1]
+                            gnss_r_data = quecgnss.read(4096)
+                            #print("location gnss_r_data:{}".format(gnss_r_data[1].decode()))
+                            print("gnss_r_data len:{}".format(gnss_r_data[0]))
+                            if gnss_r_data[0] > 0 : #有数据
+                                gsv_data = gnss_r_data[1].split("GSV")           
+                                if len(gsv_data) >= 2 :  
+                                    gsv_data = gsv_data[1:]
+                                    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]
+                                                try:
+                                                    #print("gsv_tmp[i+3]:{}".format(gsv_tmp[i+3]))
+                                                    if gsv_tmp[i+3] != "" :
+                                                        if int(gsv_tmp[i+3])>=24:
+                                                            GSV_sig_ok_count+=1
+                                                except Exception as e:
+                                                    usys.print_exception(e)
+                                                #print("GSV_dict:{}:[{}]".format(gsv_tmp[i],gsv_tmp[i+3]))
+                                            if len(gsv_tmp)-i < 4:
+                                                break 
+                                #match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
+                                #match_gsv_data = self.match.GxGSV(gnss_r_data[1]).split(",")
+                                if self.gps.__check_gps_valid(gnss_r_data[1].decode()): #数据齐全
+                                    match_gmc_data = self.match.GxRMC(gnss_r_data[1]).split(",")
+                                    match_vtg_data = self.match.GxVTG(gnss_r_data[1]).split(",")
+                                    match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
+                                    gps_data_tmp = self.gps.read_coordinates(gnss_r_data[1])
+                                    latitude_tmp = str(gps_data_tmp[1]).split(".")
+                                    if len(latitude_tmp) >= 2 and len(latitude_tmp[1])>=5:
+                                        latitude = "%s.%s"%(latitude_tmp[0],latitude_tmp[1][:6])
+                                    latitude = "%s,%s"%(latitude,match_gmc_data[4] )
+                                    longitude_tmp = str(gps_data_tmp[0]).split(".")
+                                    if len(longitude_tmp) >= 2 and len(longitude_tmp[1])>=5:
+                                        longitude = "%s.%s"%(longitude_tmp[0],longitude_tmp[1][:6])
+                                    longitude = "%s,%s"%(longitude,match_gmc_data[6] ) #match_gmc_data[6] + str(gnss_r_data[1])
+                                    high = str(gps_data_tmp[2])
+                                    self.gps_data = {
+                                        "latitude": latitude,
+                                        "longitude": longitude,
+                                        "high": high,
+                                        "direction": match_vtg_data[1],
+                                        "speed": match_vtg_data[5],
+                                        "number": match_gga_data[7],   
+                                    }
+                            #检查wifi数据
+                            if self.wifi_data == [] or (self.wifi_data != [] and self.wifi_data[0] == 0):#and self.wifi_data[0] <= 0:
+                                EventMesh.publish(constants.EVENT.WIFISCANOPEN)
                         
-                        self.gps.__gps_nmea_data_clean()
-                        #gnss_r_data = [0,1]
-                        gnss_r_data = quecgnss.read(4096)
-                        #EventMesh.txt_log("gps Datalen:{}".format(gnss_r_data[0]))
-                        print("location gnss_r_data:len{}\n{}".format(gnss_r_data[0],gnss_r_data[1].decode()))
-                        #print("gnss_r_data len:{}".format(gnss_r_data[0]))
-                        if gnss_r_data[0] > 0 : #有数据
-                            tmp_ok_count = 0
-                            gsv_data = gnss_r_data[1].split("GSV")
-                                      
-                            if len(gsv_data) >= 2 :  
-                                gsv_data = gsv_data[1:]
-                                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 :
+                            #检查基站数据
+                            if self.cell_data == []:   
+                                data_tmp = net.getCellInfo()
+                                for cell in data_tmp:
+                                    if cell and cell[0][0] == 0 and len(cell[0]) > 1:
+                                        self.cell_data = cell
                                         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]
-                                            try:
-                                                #print("gsv_tmp[i+3]:{}".format(gsv_tmp[i+3]))
-                                                if gsv_tmp[i+3] != "" :
-                                                    if int(gsv_tmp[i+3])>=20:
-                                                        tmp_ok_count +=1    
-                                            except Exception as e:
-                                                usys.print_exception(e)
-                                            #print("GSV_dict:{}:[{}]".format(gsv_tmp[i],gsv_tmp[i+3]))
-                                        if len(gsv_tmp)-i < 4:
-                                            break 
-                                
-                                if(tmp_ok_count > self.GSV_sig_ok_count ):
-                                    self.GSV_sig_ok_count = tmp_ok_count
-                            
-
-                            # if len(match_gga_data) > 8:
-                            #     #print(match_gga_data)
-                            #     if(match_gga_data[7] ):
-                            #         gga_count_tmp = int(match_gga_data[7]) #可用卫星
-                            #         if(gga_count_tmp > self.GGA_count):
-                            #             self.GGA_count = gga_count_tmp
-                            print("GGA_count:{} GSV_sig_ok_coun:{} ".format(self.GGA_count,self.GSV_sig_ok_count))
-                            
-                            match_rmc_data = self.match.GxRMC(gnss_r_data[1]).split(",")
-                             
-                            #print("match_rmc_data:\n{}".format(match_rmc_data))
-                            if len (match_rmc_data)>3: #有rmc数据
-                                if match_rmc_data[2] == 'A':
-                                    
-                                    if  self.gps.__check_gps_valid(gnss_r_data[1].decode()): #数据齐全 :
-                                        
-                                        #print("hhhhhh:{}\n\n".format(self.gps.__gsv_data))
-                                        match_vtg_data = self.gps.__vtg_data.split(",")#self.match.GxVTG(gnss_r_data[1]).split(",")
-                                        match_gga_data = self.gps.__gga_data.split(",")#self.match.GxGGA(gnss_r_data[1]).split(",")
-                                        #match_gga_data = self.match.GxGGA(gnss_r_data[1]).split(",")
-                                        
-                                        EventMesh.txt_log("GGA:{}".format(match_gga_data))
-                                        # EventMesh.txt_log("VTG:{}".format(match_vtg_data))
-                                        # EventMesh.txt_log("RMC:{}".format(match_rmc_data)) 
-                                        # EventMesh.txt_log("timer:{} ok_count:{} count:{}\n".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))   
-                                        print("LOCATION_ok :time:{}!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n".format(self.location_timer_count))
-                                        gps_date = "%s,%s"%(match_rmc_data[9],match_rmc_data[1][:6])#日期
-                                        gps_data_tmp = self.gps.read_coordinates(gnss_r_data[1])
-                                        latitude = "0,N" #纬度
-                                        latitude_tmp = str(gps_data_tmp[1]).split(".")
-                                        if len(latitude_tmp) >= 2 and len(latitude_tmp[1])>=5:
-                                            latitude = "%s.%s"%(latitude_tmp[0],latitude_tmp[1][:6])
-                                            latitude = "%s,%s"%(latitude,match_rmc_data[4] )
-
-                                        longitude = "0,E"#经度
-                                        longitude_tmp = str(gps_data_tmp[0]).split(".")
-                                        if len(longitude_tmp) >= 2 and len(longitude_tmp[1])>=5:
-                                            longitude = "%s.%s"%(longitude_tmp[0],longitude_tmp[1][:6])
-                                            longitude = "%s,%s"%(longitude,match_rmc_data[6] ) #match_rmc_data[6] + str(gnss_r_data[1])
-                                        
-                                        high = "0"#高度
-                                        high = str(gps_data_tmp[2])
-                                        number = "0"#可用卫星
-                                        precision = "5.8"#精度
-                                        if len(match_gga_data)>5 :
-                                            if match_gga_data[7]:
-                                                number = match_gga_data[7]
-                                            if match_gga_data[8]:
-                                                precision = match_gga_data[8]
-                                        direction = "249.5" #方向
-                                        speed = '0.00'    #速度    
-                                        if(len(match_vtg_data)>5 ):
-                                            if match_vtg_data[1]:
-                                                direction =  match_vtg_data[1]
-                                            if match_vtg_data[7]:    
-                                                speed =  match_vtg_data[7]
-                                        self.gps_data = {
-                                            "latitude": latitude,
-                                            "longitude": longitude,
-                                            "high": high,
-                                            "direction": direction,
-                                            "speed": speed,
-                                            "number": number, 
-                                            "date":  gps_date,
-                                            "precision":  precision
-                                        }
-                                    else :
-                                        EventMesh.txt_log("gps数据不全")
-                        else :
-                            EventMesh.txt_log("gps 无数据")
-
-
-
-                #检查wifi数据
-                if self.wifi_data == [] or (self.wifi_data != [] and self.wifi_data[0] == 0):#and self.wifi_data[0] <= 0:
-                    EventMesh.publish(constants.EVENT.WIFISCANOPEN)
-            
-                #检查基站数据
-                if self.cell_data == []:   
-                    data_tmp = net.getCellInfo()
-                    if(len(data_tmp)>=2):
-                        for cell in data_tmp:
-                            if cell and cell[0][0] == 0 and len(cell[0]) > 1:
-                                self.cell_data = cell
-                                break
-
-                if self.location_type == 1: #测试模式
-                    self.location_timer_count = 0
-                    if len(gnss_r_data) >= 1:
-                        if gnss_r_data[0] > 0:
-                            EventMesh.publish("PUSH_LOCATION_DATA", [gnss_r_data,self.wifi_data,self.cell_data]) 
-                    if self.gps_data  != {} : #发送数据 
+                    if self.location_timer_count >= 60*7 : #4分钟关闭
                         EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
-                        self.location_queue.put(constants.PROTOCOL.UD_SEND)
-                        self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
-                        
-
-                elif self.location_type == 0: #正常模式     
-                    if self.gps_data  != {} or self.location_timer_count > 100: #or( self.wifi_data != [] and self.cell_data != []): 
-                        if self.location_queue.empty() == False:#有定位队列
-                            EventMesh.txt_log("LOCATION:timer:{} ok_count:{} ".format(self.location_timer_count,self.GSV_sig_ok_count))
-                        upload_time = EventMesh.publish("get_upload_data")
-                        
-                            
-                        self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
-                        #if upload_time > 200  : 
-                        EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
-                        # else:   #定位间隔小于3分钟不关闭gps,不影响无信号判断
-                        #     self.location_timer_count = 0
-                        #     self.GSV_sig_ok_count = 0
-                            
-                        
-                    # if  (self.GGA_count < 3 and self.GSV_sig_ok_count < 2) and self.wifi_data  and self.cell_data  and self.location_timer_count > 30 and self.location_timer_count < 40: #超过20秒且有效卫星个数少于3
-                    #     EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位    
-                    #     EventMesh.txt_log("GGA_count<3:timer:{} ok_count:{} count:{}".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
-                    #     self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
-                        
-                    if self.GSV_sig_ok_count <= 1 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 20: #超过40秒且信号大于30的不足3个
-                        EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位   
-                        EventMesh.txt_log("GSV_sig_ok_count<3:timer:{} ok_count:{} count:{}".format(self.location_timer_count,self.GSV_sig_ok_count,self.GGA_count))
-                        self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
                         #break
-                # if self.location_type != 1 and self.location_timer_count >= 60*4 : #4分钟关闭
-                #     EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位
-                    #break
-                #EventMesh.txt_log("self.GSV_sig_ok_count :{}".format(self.GSV_sig_ok_count))
-                #EventMesh.publish("set_old_step_value",self.location_timer_count)
-                
-                #print("location_timer_count:{}".format(self.location_timer_count))
-                
+                    #EventMesh.txt_log("GSV_sig_ok_count :{}".format(GSV_sig_ok_count))
+                    if self.location_type == 1: #测试模式
+                        if len(gnss_r_data) >= 1:
+                            if gnss_r_data[0] > 0:
+                                EventMesh.publish("PUSH_LOCATION_DATA", [gnss_r_data,self.wifi_data,self.cell_data]) 
+                    elif self.location_type == 0: #正常模式     
+                        if self.gps_data  != [] or self.location_timer_count > 180: #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)#关闭定位
+                            EventMesh.txt_log("CLOSE_LOCATION:location_timer_count:{}".format(self.location_timer_count))
+                            #break
+ 
+                        if len(GSV_dict) < 2 and GSV_sig_ok_count < 1 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 20: #超过20秒且卫星个数少于3
+                            self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+                            EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位    
+                            EventMesh.txt_log("len(GSV_dict) < 2")
+                        if GSV_sig_ok_count < 3 and self.wifi_data != [] and self.cell_data != [] and self.location_timer_count > 40: #超过40秒且信号大于30的不足3个
+                            self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+                            EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位   
+                            EventMesh.txt_log("GSV_sig_ok_count < 3")
+                            #break
+                    utime.sleep_ms(1000)
+                    #print("location_timer_count:{}".format(self.location_timer_count))
+                else :
+                    utime.sleep_ms(2000)
             except Exception as e:
                 usys.print_exception(e)
-                EventMesh.txt_log("location_thread:ERROR:".format(e))
-                #print("location_thread:ERROR:{}".format(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))
-                #self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
+                self.Location_send([self.gps_data,self.wifi_data,self.cell_data])
                 EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位 
-            utime.sleep_ms(500)
-        self.timer_read_GPS_info.stop()
-        self.gps.power_switch(0)
-        wifiScan.control(0)
-        # if EventMesh.publish("get_lcd_state" ) == 0:#休眠的时候,恢复休眠
-        #     pm.autosleep(1)
-        #     pm.sclkEx_set(1, 1, 5)
-        if self.lpm_fd != None:
-            pm.wakelock_unlock(self.lpm_fd)
-        #pm.delete_wakelock(lpm_fd)
-        print("CLOSE_LOCATION")
-        #EventMesh.txt_log("CLOSE_LOCATION")
 
                 
 
@@ -2351,7 +2245,7 @@ class CallLogManager(Abstract):
     def set(self, event, msg):
         self.check_json = msg[0]
         self.read_call_log = msg[1]
-        with open("/usr/static/storage_file/Call_log.json","w+",encoding="utf-8") as fd:
+        with open("/ext/static/storage_file/Call_log.json","w+",encoding="utf-8") as fd:
             ujson.dump(self.read_call_log,fd)
     # def call_usr(self,event,msg):
     #     content = self.log[msg]
@@ -2903,10 +2797,11 @@ class getSosFlagManager(Abstract):#设置sos
         self.call_timer.start(10000, 0, self.call_timer_cb)#延迟10S 继续拨打
 
     def call_timer_cb(self, *args, **kwargs):
-        # print("call_timer_cb:{}".format(self.callnumer))
-        EventMesh.publish("save_phonename",str(self.callnumer))
-        EventMesh.publish("save_phonenum",str(self.callnumer))
-        EventMesh.publish("load_screen", {"screen": "dialing_noplay_popup"})  
+        if self.sos_flag == 1:
+            # print("call_timer_cb:{}".format(self.callnumer))
+            EventMesh.publish("save_phonename",str(self.callnumer))
+            EventMesh.publish("save_phonenum",str(self.callnumer))
+            EventMesh.publish("load_screen", {"screen": "dialing_noplay_popup"})  
 
     def get_sos_flag(self, event, msg): 
         return self.sos_flag
@@ -3063,5 +2958,160 @@ class testSmsSetIPManager(Abstract):#
         if(tmp_data != None):
             return [self.newip,self.newcom]
 
+class setclassTimeManager(Abstract):#设置上课禁用时间
+    def __init__(self):
+        self.class_buf = {}
+        self.class_state = 0
+        check_json = ql_fs.path_exists("/ext/static/storage_file/class_msg.json")
+
+        if check_json == True:
+            with open("/ext/static/storage_file/class_msg.json","r",encoding="utf-8") as fd:
+                self.class_buf = ujson.load(fd)
+                print("读取上课禁用时间段")
+                # print("self.class_buf:",self.class_buf)
+        
+
+
+    def post_processor_after_instantiation(self):
+        EventMesh.subscribe("set_class_time", self.set_class_time)#设置上课禁用时间段
+        EventMesh.subscribe("get_class_time", self.get_class_time)
+        EventMesh.subscribe("get_cur_class_time_state", self.get_cur_class_time_state)
+        EventMesh.subscribe("get_class_in_time_page",self.get_class_in_time_page)
+
+    def set_class_time(self, event, msg): 
+        self.class_buf = msg
+        # print("self.class_buf",self.class_buf)
+        
+
+    def get_class_time(self, event, msg):
+        
+        return self.class_buf
+    
+    def get_cur_class_time_state(self, event, msg):
+        data = RTC().datetime()
+        hour = data[4]#当前小时
+        min = data[5]#当前分钟
+
+        cur_week = data[3]#星期几
+
+
+
+        cur_hour = hour
+        cur_min = min
+        cur_total_min = cur_hour*60+cur_min
+        #print("cur_total_min",cur_total_min)
+
+        start_time1 = 0
+        end_time1 = 0
+        week1 = []
+        enable1 = 0
+
+        start_time2 = 0
+        end_time2 = 0
+        week2 = []
+        enable2 = 0
+
+        start_time3 = 0
+        end_time3 = 0
+        week3 = []
+        enable3 = 0
+
+        start_time4 = 0
+        end_time4 = 0
+        week4 = []
+        enable4 = 0
+
+        self.class_state = 0
+        # {'1': {'enabled': 1, 'end_hour': '17:00', 'start_hour': '10:00', 'week': [1, 2, 3, 4, 5]}, 
+        #  '0': {'enabled': 1, 'end_hour': '17:00', 'start_hour': '08:00', 'week': [1, 2, 3, 4, 5]}, 
+        #  '3': {'enabled': 1, 'end_hour': '17:00', 'start_hour': '08:00', 'week': [1, 2, 3, 4, 5]}, 
+        #  '2': {'enabled': 1, 'end_hour': '17:00', 'start_hour': '08:00', 'week': [1, 2, 3, 4, 5]}}
+        # print("self.class_buf time:",self.class_buf)
+        if len(self.class_buf) != 0:
+            #19:56; 9:16
+            data1 = self.class_buf["0"]
+            start_time1 = int(data1["start_time"].split(":")[0])*60+int(data1["start_time"].split(":")[1])
+            end_time1 = int(data1["end_time"].split(":")[0])*60 + int(data1["end_time"].split(":")[1])
+
+            week1 = data1["week"]
+            enable1 = data1["enable"]
+
+            data2 = self.class_buf["1"]
+            start_time2 = int(data2["start_time"].split(":")[0])*60 + int(data2["start_time"].split(":")[1])
+            end_time2 = int(data2["end_time"].split(":")[0])*60 + int(data2["end_time"].split(":")[1])
+
+            week2 = data2["week"]
+            enable2 = data2["enable"]
+
+            data3 = self.class_buf["2"]
+            start_time3 = int(data3["start_time"].split(":")[0])*60 + int(data3["start_time"].split(":")[1])
+            end_time3= int(data3["end_time"].split(":")[0])*60 + int(data3["end_time"].split(":")[1])
+
+            week3 = data3["week"]
+            enable3 = data3["enable"]
+
+            data4 = self.class_buf["3"]
+            start_time4= int(data4["start_time"].split(":")[0])*60 + int(data4["start_time"].split(":")[1])
+            end_time4 = int(data4["end_time"].split(":")[0])*60 + int(data4["end_time"].split(":")[1])
+
+            week4 = data4["week"]
+            enable4 = data4["enable"]
+            week1_state = 0
+            week2_state = 0
+            week3_state = 0
+            week4_state = 0
+            # print("end_time1 ",start_time1,end_time1,start_time2,end_time2,start_time3,end_time3,start_time4,end_time4)
+            for i in range(0,7):
+                if ((cur_week in week1) and enable1 == 1):
+                    week1_state = 1
+                if ((cur_week in week2) and enable2 == 1):
+                    week2_state = 1
+                
+                if ((cur_week in week3) and enable3 == 1):
+                    week3_state = 1
+                
+                if ((cur_week in week4) and enable4 == 1):
+                    week4_state = 1
+
+                if ((cur_week in week1) and enable1 == 1) or ((cur_week in week2) and enable2 == 1) or\
+                    ((cur_week in week3) and enable3 == 1) or ((cur_week in week4) and enable4 == 1):
+                    if  enable1 == 1 or enable2 == 1 or enable3 == 1 or enable4 == 1:
+                        if week1 != [] or week2 != [] or week3 != [] or week4 != []:
+                            if (end_time1 > start_time1  and  enable1 == 1 and week1_state == 1) or (end_time2 > start_time2 and  enable2 == 1 and week2_state == 1) or\
+                            (end_time3 > start_time3 and  enable3 == 1 and week3_state == 1) or (end_time4 > start_time4 and  enable4 == 1 and week4_state == 1):
+                                if (cur_total_min <= end_time1 and cur_total_min >= start_time1 and enable1 == 1) or (cur_total_min <= end_time2 and cur_total_min >= start_time2 and enable2 == 1) or\
+                                    (cur_total_min <= end_time3 and cur_total_min >= start_time3 and enable3 == 1) or (cur_total_min <= end_time4 and cur_total_min >= start_time4 and enable3 == 1):
+                                    self.class_state = 1
+                                    print("class_in1")
+                                    break
+                            else:#开始时间小于结束时间属于垮天 9:00 -7:00 7*60 6:00
+
+                                # print("end_time1!!!!!!!!!",start_time1,end_time1,start_time2,end_time2,start_time3,end_time3,start_time4,end_time4)
+                                if (((end_time1 >= cur_total_min or cur_total_min >= start_time1) and enable1 == 1 and week1_state == 1)or \
+                                    ((end_time2 >= cur_total_min or cur_total_min >= start_time2) and enable2 == 1 and week2_state == 1) or\
+                                    ((end_time3 >= cur_total_min or cur_total_min >= start_time3) and enable3 == 1 and week3_state == 1) or \
+                                    ((end_time4 >= cur_total_min or cur_total_min >= start_time4) and enable4 == 1 and week4_state == 1)):
+                                        self.class_state = 1
+                                        print("class_in2")
+                                        break
+
 
+        return self.class_state
+    
+    def get_class_in_time_page(self, event, msg):
+        EventMesh.publish("get_cur_class_time_state")
+        phone_call = EventMesh.publish("get_UI_high_priority")
+
+        screen_NAME = EventMesh.publish("get_screen_NAME")
+        if self.class_state == 1:
+            if screen_NAME != None:
+                if screen_NAME != "system_init" or screen_NAME != "poweron":
+                    if screen_NAME != "class_time" and phone_call == 0:
+                        EventMesh.publish("load_screen", {"screen": "class_time"}) 
+        else:
+            if screen_NAME != None:
+                if screen_NAME == "class_time":
+                   EventMesh.publish("load_screen", {"screen": "main_menu"})
+            
+        pass
     
\ No newline at end of file
index 79b173f..2beca40 100644 (file)
@@ -25,7 +25,7 @@ import usys
 def server_init(server_type = None):
     #服务器选择1,防走丢,2大锤,3三基同创,4童信,5云米,6荣为
     if server_type == None:
-        server_type = 4
+        server_type = 5
     #print("server_init:server_type:{}".format(server_type))
     d_server_addr = "api.xcloudtech.com"
     d_server_port = 9000
@@ -779,40 +779,68 @@ class REMIND_ProtoCol(ProtoCol):
         msg_tmp = msg_tmp[1]
 
         alarm_new  = EventMesh.publish("read_alarminjson")
-        # print("alarm_list:{} msg_tmp:{}",alarm_new,msg_tmp)
+        print("alarm_list:{} msg_tmp:{}",alarm_new,msg_tmp)
 
-        k=0
+        
+        k=1
+        count = 0
+        
+        for i in range(len(str(msg_tmp))):#寻找有多少个,号
+            if msg_tmp[i] == ',':
+                k+=1
         if len(alarm_new) < 5 :
             alarm_new = []
             for i in range(5):
-                alarm_new.append({'hour': 16, 'repeart': 1, 'idx': i, 'enabled': 0, 'days': [], 'minute': 39}) 
-        for j in range(2,5):#0 1是开关机,234是闹钟
+                alarm_new.append({'hour': 8, 'repeart': 10, 'idx': i, 'enabled': 0, 'days': [], 'minute': 39}) 
+        for j in range(2,2+k):#0 1是开关机,234是闹钟
             alarm_day = []
             alarm_week = []
             alarm_total_data = []
-            alarm_total_data = msg_tmp.split(',')[k]
-            k+=1
-            b = alarm_total_data.find('-')
-            if b != -1:
-                alarm_data = alarm_total_data.split('-')#-作为分隔符
-                alarm_switch = int(alarm_data[1])#开关
-                alarm_day_num = int(alarm_data[2])#天
-                alarm_time = alarm_data[0]#时间
-                alarm_time_tmp = alarm_time.split(':')#冒号分隔时间 时 分
-                alarm_time_hour = int(alarm_time_tmp[0])
-                alarm_time_min = int(alarm_time_tmp[1])
-                if alarm_day_num == 3:
-                    alarm_week = alarm_data[3]#星期
-
-                if alarm_day_num == 2:#每一天
-                    alarm_day = [1,2,3,4,5,6,0]
-                elif alarm_day_num == 3:#自定义
-                    for i in range(0,7):
-                        if alarm_week[i] != '0':
-                           alarm_day.append(i)
-                alarm_new[j] = {"idx": j, "hour": alarm_time_hour, "minute": alarm_time_min, "days":alarm_day, "enabled": alarm_switch,"repeart":alarm_day_num}
-                
-        # print("self.alarm_list: {}".format(alarm_new))
+            if k == 1:
+                if len(msg_tmp) != 0:
+                    alarm_data = msg_tmp.split('-')#-作为分隔符
+                    alarm_switch = int(alarm_data[1])#开关
+                    alarm_day_num = int(alarm_data[2])#天
+                    alarm_time = alarm_data[0]#时间
+                    alarm_time_tmp = alarm_time.split(':')#冒号分隔时间 时 分
+                    alarm_time_hour = int(alarm_time_tmp[0])
+                    alarm_time_min = int(alarm_time_tmp[1])
+                    if alarm_day_num == 3:
+                        alarm_week = alarm_data[3]#星期
+
+                    if alarm_day_num == 2:#每一天
+                        alarm_day = [1,2,3,4,5,6,0]
+                    elif alarm_day_num == 3:#自定义
+                        for i in range(0,7):
+                            if alarm_week[i] != '0':
+                                alarm_day.append(i)
+                    alarm_new[j] = {"idx": j, "hour": alarm_time_hour, "minute": alarm_time_min, "days":alarm_day, "enabled": alarm_switch,"repeart":alarm_day_num}
+            else:
+                if len(msg_tmp) != 0:
+                    alarm_total_data = msg_tmp.split(',')[count]
+                    count+=1
+                    b = alarm_total_data.find('-')
+                    if b != -1:
+                        alarm_data = alarm_total_data.split('-')#-作为分隔符
+                        alarm_switch = int(alarm_data[1])#开关
+                        alarm_day_num = int(alarm_data[2])#天
+                        alarm_time = alarm_data[0]#时间
+                        alarm_time_tmp = alarm_time.split(':')#冒号分隔时间 时 分
+                        alarm_time_hour = int(alarm_time_tmp[0])
+                        alarm_time_min = int(alarm_time_tmp[1])
+                        if alarm_day_num == 3:
+                            alarm_week = alarm_data[3]#星期
+
+                        if alarm_day_num == 2:#每一天
+                            alarm_day = [1,2,3,4,5,6,0]
+                        elif alarm_day_num == 3:#自定义
+                            for i in range(0,7):
+                                if alarm_week[i] != '0':
+                                    alarm_day.append(i)
+                        alarm_new[j] = {"idx": j, "hour": alarm_time_hour, "minute": alarm_time_min, "days":alarm_day, "enabled": alarm_switch,"repeart":alarm_day_num}
+                        
+        # print("k",k,alarm_new)
+        
         with open("/ext/static/storage_file/alarm_msg.json", 'w',encoding='utf-8') as fd:
             ujson.dump(alarm_new,fd)
         EventMesh.publish("push_update_alarm_show")
@@ -960,8 +988,6 @@ class TEMP_ProtoCol(ProtoCol):
     """上传体温测试数据"""
     TYPE = "temp"
     def send(self, event, msg):
-        # [SZKW*334588000000156*len*heart,x]
-        # print("temp:send:{}".format(msg))
         len_size = len(str(msg[0]))+len("temp,")+1+len(str(msg[1]))
         print("temp:send:{} len:{}".format(msg,len_size))
         #  实例:[XT*334588000000156*0009*temp,36.2]
@@ -976,6 +1002,10 @@ class TEMP_ProtoCol(ProtoCol):
         # 通过socket发送到服务器端
         EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND,data)
 
+        str_data = str(msg[0])+'.'+str(msg[1])
+        num = eval(str_data)#将字符串数据转换成十进制数据
+        EventMesh.publish(constants.PROTOCOL.BTEMP2_SEND,[1,num])
+
     def recv(self, event, msg):
         """
         @param event: 
@@ -984,6 +1014,99 @@ class TEMP_ProtoCol(ProtoCol):
         # print("HRSTART_ProtoCol RECV msg:")
         #EventMesh.publish(constants.PROTOCOL.TEMP_SEND)
 
+
+class TEMP_Hour_ProtoCol(ProtoCol): #云米服务独立指令体温
+    """上传体温频率 小时单位"""
+    TYPE = "bodytemp"
+    def send(self, event, msg):
+        #[XT*334588000000156*len*wdstart,300]
+        send_data = self.PID+"*%s*0008*bodytemp"%(self.imei)
+        MD5_SIGN = self.pack_MD5_head(send_data)
+        data = "[%s%s]"%(str(MD5_SIGN),send_data)
+        # print("temp:data:%s"%(data))
+        # 通过socket发送到服务器端
+        EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND,data)
+
+    def recv(self, event, msg):
+        """
+        @param event: 体温下发频率数据
+        @param msg: 接收到的下行数据
+        """
+        # print("WDSTART_ProtoCol RECV msg:")
+        #TCP recv: data:b'[3G*860132060126844*000C*bodytemp,1,2]'
+        print("bodytemp:{}".format(msg))
+        msg = msg[1:-1]
+        msg_tmp = msg.decode('ascii')
+        msg_tmp = msg_tmp.split('bodytemp,')
+        msg_tmp = msg_tmp[1]
+
+        body_time = 0
+        body_on = 0
+        body_on = msg_tmp.split(',')[0]#开关
+        body_time = msg_tmp.split(',')[1]
+
+        if int(body_on) == 0:
+            body_time = 0
+        else:
+            body_time = int(body_time)*3600
+
+        tempTotal = int(body_time)
+        
+
+        EventMesh.publish("set_temp_time",tempTotal)
+        EventMesh.publish(constants.PROTOCOL.BODYTEMP_SEND)
+
+class bodytemp2_ProtoCol(ProtoCol):
+    """立即测量"""
+    TYPE = "bodytemp2"
+    def send(self, event, msg):
+        #[XT*334588000000156*len*bodytemp2,300]
+        send_data = self.PID+"*%s*0009*bodytemp2"%(self.imei)
+        MD5_SIGN = self.pack_MD5_head(send_data)
+        data = "[%s%s]"%(str(MD5_SIGN),send_data)
+        # print("temp:data:%s"%(data))
+        # 通过socket发送到服务器端
+        EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND,data)
+
+    def recv(self, event, msg):
+        """
+        @param event: 体温下发频率数据
+        @param msg: 接收到的下行数据
+        """
+        # print("bodytemp2_ProtoCol RECV msg:")
+        print("bodytemp2:{}".format(msg))
+        get_temp_state = EventMesh.publish("get_temp_state")
+        print("get_temp_state:{}".format(get_temp_state))
+        if get_temp_state == 0:#只要两个不在测量 单次优先级最低
+            EventMesh.publish("set_temp_state",3)#3代表单次测量
+        EventMesh.publish(constants.PROTOCOL.BODYTEMP2_SEND)
+class btemp2_ProtoCol(ProtoCol):#上传体温数据
+    """立即测量"""
+    TYPE = "btemp2"
+    def send(self, event, msg):
+        # [3G*YYYYYYYYYY*LEN*btemp2,type,temp] Type :测量模式:0:额头模式 1: 手腕模式Temp :体温,
+        len_size = len(str(msg[0]))+len("btemp2,")+1+len(str(msg[1]))
+        print("btemp2:send:{} len:{}".format(msg,len_size))
+        #  实例:[XT*334588000000156*0009*btemp2,1,36.2]
+        # 代表终端的温度为:36.2
+        # 平台回复:
+        # [XT*334588000000156*0004*btemp2]
+        send_data = self.PID+"*%s*%04X*btemp2"%(self.imei,len_size)
+        MD5_head_data = self.PID+"*%s*%04X*%s"%(self.imei,len_size,"btemp2")
+        MD5_SIGN = self.pack_MD5_head(MD5_head_data)
+        data = "[%s%s,%d,%f]"%(str(MD5_SIGN),send_data,1,msg[1])
+        # print("btemp2:data:%s"%(data))
+        # 通过socket发送到服务器端
+        EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND,data)
+
+    def recv(self, event, msg):
+        """
+        @param event: 体温下发频率数据
+        @param msg: 接收到的下行数据
+        """
+        # print("btemp2_ProtoCol RECV msg:")
+       
+
 class WDSTART_ProtoCol(ProtoCol):
     """上传体温频率"""
     TYPE = "wdstart"
@@ -1014,7 +1137,6 @@ class WDSTART_ProtoCol(ProtoCol):
             get_temp_state = EventMesh.publish("get_temp_state")
             print("get_temp_state:{}".format(get_temp_state))
             if get_temp_state == 0:#只要两个不在测量 单次优先级最低
-
                 EventMesh.publish("set_temp_state",3)#3代表单次测量
         else:
             if tempTotal > 0 and tempTotal <= 300:
@@ -1023,9 +1145,6 @@ class WDSTART_ProtoCol(ProtoCol):
                 tempTotal = 65536
             
             EventMesh.publish("set_temp_time",tempTotal)
-
-            
-        
         EventMesh.publish(constants.PROTOCOL.WDSTART_SEND)
 #解绑
 # [XT*334588000000156*0003*DLT]
@@ -1036,11 +1155,11 @@ class DLT_ProtoCol(ProtoCol):
     """解绑数据"""
     TYPE = "DLT"
     def send(self, event, msg):
-        # [XT*334588000000156*0004*temp]
+        # [XT*334588000000156*0004*DLT]
         send_data = self.PID+"*%s*0003*DLT"%(self.imei)
         MD5_SIGN = self.pack_MD5_head(send_data)
         data = "[%s%s]"%(str(MD5_SIGN),send_data)
-        print("temp:data:%s"%(data))
+        print("DLT:data:%s"%(data))
         # 通过socket发送到服务器端
         EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND,data)
 
@@ -1057,7 +1176,7 @@ class UPLOAD_ProtoCol(ProtoCol):
     """定位频率数据"""
     TYPE = "UPLOAD"
     def send(self, event, msg):
-        # [XT*334588000000156*0004*temp]
+        # [XT*334588000000156*0004*UPLOAD]
         send_data = self.PID+"*%s*0006*UPLOAD"%(self.imei)
         MD5_SIGN = self.pack_MD5_head(send_data)
         data = "[%s%s]"%(str(MD5_SIGN),send_data)
@@ -1087,7 +1206,7 @@ class CENTER_ProtoCol(ProtoCol):
     """设置快捷号码"""
     TYPE = "CENTER"
     def send(self, event, msg):
-        # [XT*334588000000156*0004*temp]
+        # [XT*334588000000156*0004*CENTER]
         send_data = self.PID+"*%s*0006*CENTER"%(self.imei)
         MD5_SIGN = self.pack_MD5_head(send_data)
         data = "[%s%s]"%(str(MD5_SIGN),send_data)
@@ -1130,16 +1249,26 @@ class MONITOR_ProtoCol(ProtoCol):
         @param event:
         @param msg: 接收到的下行数据
         """
-        # b'[SZKW*867387060319166*000A*MONITOR]'
-        read_data = EventMesh.publish("get_storage_config","center_dial")
-
-        if read_data != None: 
-            contact = read_data
-            if len(contact) > 0:
-                print("MONITOR RECV msg:{} {}".format(contact,type(contact)))
-                EventMesh.publish("save_phonename", contact)  
-                EventMesh.publish("save_phonenum", contact)  
-                voiceCall.callStart(contact)
+        msg = msg[1:-1]
+        msg_tmp = msg.decode('ascii')
+        msg_tmp = msg_tmp.split('MONITOR')
+        msg_tmp = msg_tmp[1]
+        print("MONITOR_ProtoCol RECV msg:{} msg_:{}".format(msg,len(msg_tmp)))
+        if len(msg_tmp) != 0:
+            EventMesh.publish("save_phonename", contact)  
+            EventMesh.publish("save_phonenum", contact)  
+            EventMesh.publish("load_screen", {"screen": "dialing_noplay_popup"})
+            # voiceCall.callStart(contact)
+        else:
+            read_data = EventMesh.publish("get_storage_config","center_dial")
+
+            if read_data != None: 
+                contact = read_data
+                if len(contact) > 0:
+                    print("MONITOR RECV msg:{} {}".format(contact,type(contact)))
+                    EventMesh.publish("save_phonename", contact)  
+                    EventMesh.publish("save_phonenum", contact)  
+                    EventMesh.publish("load_screen", {"screen": "dialing_noplay_popup"})
         EventMesh.publish(constants.PROTOCOL.MONITOR_SEND)  
 
 #定时开关机
@@ -1304,6 +1433,98 @@ class WLKEY_ProtoCol(ProtoCol):
         # print("WLKEY!!!!!!!!!!!!!",msg)
         EventMesh.publish(constants.PROTOCOL.WLKEY_SEND)  
 
+#免打扰
+class SILENCETIMEFS_ProtoCol(ProtoCol):#云米
+    """上课禁用"""
+    TYPE = "SILENCETIMEFS"
+    def send(self, event, msg):
+        # [XT*334588000000156*0006*SILENCETIME2] a b c d
+        send_data = self.PID+"*%s*000D*SILENCETIMEFS"%(self.imei)
+        MD5_SIGN = self.pack_MD5_head(send_data)
+        data = "[%s%s]"%(str(MD5_SIGN),send_data)
+        # print("KEYBRD:data:%s"%(data))
+        # print("SILENCETIME2!!!!!!!!!!!!!",msg)
+        # 通过socket发送到服务器端
+        EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND,data)
+
+    def recv(self, event, msg):
+        """
+        @param event:
+        @param msg: 接收到的下行数据
+        """
+        class_in_buf = {"1": {'enable': 0, 'end_time': '00:00', 'start_time': '00:00', 'week': []},\
+        "0": {'enable': 0, 'end_time': '00:00', 'start_time': '00:00', 'week': []}, \
+        "3": {'enable': 0, 'end_time': '00:00', 'start_time': '00:00', 'week': []}, \
+        "2": {'enable': 0, 'end_time': '00:00', 'start_time': '00:00', 'week': []}}
+
+        # class_in_buf.append({'start_hour': "16:54", 'week': [], 'idx': 0, 'enabled': 0, 'end_hour': "18:39"}) 
+        msg = msg[1:-1]
+        msg_tmp = msg.decode('ascii')
+        msg_tmp_d = str(msg_tmp.split('SILENCETIMEFS,')[1])
+        
+        count = 1
+        k = 0
+
+        for i in range(len(str(msg_tmp_d))):
+            if msg_tmp_d[i] == ',':
+                count+=1
+
+        for x in range(count):#21:10-7:30@0111110,21:10-7:30@0111110,21:10-7:30@0111110,21:10-7:30@0111110
+            week = []
+            if x >= 4:
+                break
+            if count > 1:
+
+                msg_data = msg_tmp_d.split(',')[x]
+                print("SILENCETIMEFS count",msg_data)
+                b = msg_data.find('-')
+                if b != -1:
+                    data = msg_data.split('-')#-作为分隔符
+                    time = data[1].split('@')#@作为分隔符
+                    print("data",data,time,data[0],time[0])
+                    start_time = data[0]#开始时间
+                    end_time = time[0]#结束时间
+                    enable = 1
+                    week_day = time[1]
+                    for i in range(0,7):
+                        if week_day[i] != '0':
+                            week.append(i)
+                    tmp={}
+                    tmp["start_time"] = start_time
+                    tmp["end_time"] = end_time
+                    tmp["week"] = week
+                    tmp["enable"] = enable
+                    class_in_buf["{}".format(x)] = tmp
+            else:
+                if len(msg_tmp_d) != 0:
+                    b = msg_tmp_d.find('-')
+                    if b != -1:
+                        
+                        data = msg_tmp_d.split('-')#-作为分隔符
+                        time = data[1].split('@')#@作为分隔符
+                        print("data",data,time,data[0],time[0])
+                        start_time = data[0]#开始时间
+                        end_time = time[0]#结束时间
+                        enable = 1
+                        week_day = time[1]
+                        for i in range(0,7):
+                            if week_day[i] != '0':
+                                week.append(i)
+                        tmp={}
+                        tmp["start_time"] = start_time
+                        tmp["end_time"] = end_time
+                        tmp["week"] = week
+                        tmp["enable"] = enable
+                        class_in_buf["{}".format(x)] = tmp
+
+        with open("/ext/static/storage_file/class_msg.json", 'w+',encoding='utf-8') as fd:
+            ujson.dump(class_in_buf,fd)
+
+
+        EventMesh.publish("set_class_time", class_in_buf)
+        EventMesh.publish(constants.PROTOCOL.SILENCETIMEFS_SEND)  
+        EventMesh.publish("get_class_in_time_page")
+
 #免打扰
 class SILENCETIME2_ProtoCol(ProtoCol):
     """免打扰"""
@@ -1323,9 +1544,71 @@ class SILENCETIME2_ProtoCol(ProtoCol):
         @param event:
         @param msg: 接收到的下行数据
         """
-        # b'[SZKW*867387060319166*000A*KEYBRD]'
-        # print("SILENCETIME2!!!!!!!!!!!!!",msg)
+        class_in_buf = {"1": {'enable': 0, 'end_time': '00:00', 'start_time': '00:00', 'week': []},\
+        "0": {'enable': 0, 'end_time': '00:00', 'start_time': '00:00', 'week': []}, \
+        "3": {'enable': 0, 'end_time': '00:00', 'start_time': '00:00', 'week': []}, \
+        "2": {'enable': 0, 'end_time': '00:00', 'start_time': '00:00', 'week': []}}
+
+        # class_in_buf.append({'start_hour': "16:54", 'week': [], 'idx': 0, 'enabled': 0, 'end_hour': "18:39"}) 
+        msg = msg[1:-1]
+        msg_tmp = msg.decode('ascii')
+        msg_tmp_d = str(msg_tmp.split('SILENCETIME2,')[1])
+        
+        count = 1
+        k = 0
+
+        for i in range(len(str(msg_tmp_d))):
+            if msg_tmp_d[i] == ',':
+                count+=1
+
+        for x in range(count):#08:00-17:00-1-0111110,08:00-17:00-1-0111110
+            week = []
+            if count > 1:
+                msg_data = msg_tmp_d.split(',')[k]
+                # print("SILENCETIME count",msg_data)
+                k+= 1
+                b = msg_data.find('-')
+                if b != -1:
+                    data = msg_data.split('-')#-作为分隔符
+                    start_time = data[0]
+                    end_time = data[1]
+                    enable = int(data[2])
+                    week_day = data[3]
+                    for i in range(0,7):
+                        if week_day[i] != '0':
+                            week.append(i)
+                    tmp={}
+                    tmp["start_time"] = start_time
+                    tmp["end_time"] = end_time
+                    tmp["week"] = week
+                    tmp["enable"] = enable
+                    class_in_buf["{}".format(x)] = tmp
+            else:
+                b = msg_tmp_d.find('-')
+                if b != -1:
+                    data = msg_tmp_d.split('-')#-作为分隔符
+                    start_time = data[0]
+                    end_time = data[1]
+                    enable = int(data[2])
+                    week_day = data[3]
+                    for i in range(0,7):
+                        if week_day[i] != '0':
+                            week.append(i)
+                    tmp={}
+                    tmp["start_time"] = start_time
+                    tmp["end_time"] = end_time
+                    tmp["week"] = week
+                    tmp["enable"] = enable
+                    class_in_buf["{}".format(x)] = tmp
+
+        with open("/ext/static/storage_file/class_msg.json", 'w+',encoding='utf-8') as fd:
+            ujson.dump(class_in_buf,fd)
+
+
+        EventMesh.publish("set_class_time", class_in_buf)
         EventMesh.publish(constants.PROTOCOL.SILENCETIME2_SEND)  
+        EventMesh.publish("get_class_in_time_page")
+#键盘开关
 
 #键盘开关
 class KEYBRD_ProtoCol(ProtoCol):
index 98f9a4a..0a901e6 100644 (file)
@@ -6282,7 +6282,95 @@ class restore_confirmScreen(Screen):
     def btn1_release(self):
         pass
 
+style_font_youyuan_70_red = lv.style_t()
+style_font_youyuan_70_red.init()
+style_font_youyuan_70_red.set_text_color(lv.color_make(0xff, 0xff, 0xff))
+style_font_youyuan_70_red.set_text_font(lv.font_70_bold)
+
+class_mgr_popup_screen = None
+class_mgr_popup_label = None
+class_mgr_popup_time1_text = None
+class classMgrPopupScreen(Screen):#上课禁用时间界面
+    #上课禁用
+    NAME = "class_time"
+    
+    def __init__(self):
+        super().__init__()
+        self.meta = None
+        self.timer = osTimer()
+    def initialization(self):
+        global class_mgr_popup_screen ,class_mgr_popup_label ,class_mgr_popup_time1_text
+        if class_mgr_popup_screen == None:
+            class_mgr_popup_screen = lv.obj()
+            print("Lowpower_screen")
+            class_mgr_popup_screen.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT)
+       
+            class_mgr_popup_time1_text = lv.label(class_mgr_popup_screen)
+            class_mgr_popup_time1_text.set_pos(0, 10)
+            class_mgr_popup_time1_text.set_size(240, 80)
+            class_mgr_popup_time1_text.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
+            class_mgr_popup_time1_text.set_text(" ")
+            class_mgr_popup_time1_text.add_style(style_font_youyuan_70_red, lv.PART.MAIN|lv.STATE.DEFAULT)
+
+            class_mgr_popup_label = lv.label(class_mgr_popup_screen)
+            class_mgr_popup_label.set_pos(0, 120)
+            class_mgr_popup_label.set_size(240, 50)
+            class_mgr_popup_label.set_text("现在是上课时间点,禁用手表功能")
+            class_mgr_popup_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT)
+            class_mgr_popup_label.set_long_mode(lv.label.LONG.WRAP)
+            class_mgr_popup_label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
+            self.meta = class_mgr_popup_screen
+
+        sos_flag = EventMesh.publish("get_sos_flag")
+        if sos_flag == 1:
+            EventMesh.publish("set_sos_flag",0)
+            EventMesh.publish("set_sos_num",0)
+            EventMesh.publish("set_hangup_mode",0)
+        data = RTC().datetime()
+        hour = data[4]
+        min = data[5]
+        class_mgr_popup_time1_text.set_text("{}:{}".format("%02d"%(hour),"%02d"%(min)))
+        self.timer.start(1*1000,1,self.fun)
+
+    def lcd_on(self):
+        self.timer.start(1*1000,1,self.fun)
+
+    def lcd_off(self):
+        self.timer.stop()
+    
+    def fun(self,*argc):
+        global class_mgr_popup_time1_text
+        data = RTC().datetime()
+        hour = data[4]
+        min = data[5]
+        class_mgr_popup_time1_text.set_text("{}:{}".format("%02d"%(hour),"%02d"%(min)))
+
+
+    def btn1_release(self):
+        state = EventMesh.publish("get_cur_class_time_state")
+        print("state:{}".format(state))
+        if state != None:
+            if state == 0:
+                EventMesh.publish("load_screen", {"screen": "main_menu"})
+                return
+        flag = EventMesh.publish("get_lcd_state")
+        if flag == 1:
+            EventMesh.publish(constants.EVENT.SYSTEM_SLEEP)
+        else:
+            EventMesh.publish(constants.EVENT.SYSTEM_UP)
 
+    def btn8_press(self):
+        state = EventMesh.publish("get_cur_class_time_state")
+        print("state:{}".format(state))
+        if state != None:
+            if state == 0:
+                EventMesh.publish("load_screen", {"screen": "main_menu"})
+                return
+        flag = EventMesh.publish("get_lcd_state")
+        if flag == 1:
+            EventMesh.publish(constants.EVENT.SYSTEM_SLEEP)
+        else:
+            EventMesh.publish(constants.EVENT.SYSTEM_UP)
 
 #from usr.ui_WatchFaceScreen import WatchFaceScreen
 class UI(object):
@@ -6585,9 +6673,29 @@ class UI(object):
         EventMesh.publish("publish_message_event_ui",{"func":self.load_screen,"data":msg})  
 
     def load_screen(self, msg):
-        print("msg1={}".format(msg))
+        print("msg1={} self.UI_high_priority_flag:{}".format(msg,self.UI_high_priority_flag))
         if self.UI_high_priority_flag == 1:#电话界面屏蔽其他界面
             return
+        state = EventMesh.publish("get_cur_class_time_state")
+        print("state:{}".format(state))
+        if state != None:
+            if state == 1:
+                screen_NAME = EventMesh.publish("get_screen_NAME")
+                if screen_NAME != None:
+                        if msg["screen"] == "charge_out" or  msg["screen"] == "charge_in":
+                                pass
+                        else:
+                            if screen_NAME == "class_time" :#在上课禁用界面打断其他操作界面
+                                print("class_time UI")
+                                if msg["screen"] == "countdown_end":
+                                    # print("countdown_end UI")
+                                    EventMesh.publish("close_count_show_info")
+                                return
+                            else:
+                                if screen_NAME != "dialing_noplay_popup" or  screen_NAME != "dial_no_connect_popup" or \
+                                screen_NAME != "on_call" or screen_NAME != "dialing" or screen_NAME != "incoming_call" or \
+                                screen_NAME != "charge_in" or screen_NAME != "charge_out":
+                                    EventMesh.publish("load_screen", {"screen": "class_time"}) 
         if self.screen :
             if self.screen.NAME == msg["screen"]:
                 return
index dcb24b4..5067645 100644 (file)
@@ -1086,7 +1086,7 @@ class PoweroffConfirmScreen(Screen):
             EventMesh.publish("set_storage_config",["old_step",step])
             
         date_tmp = utime.localtime()
-        EventMesh.publish("set_storage_config",["old_timesecond",date_tmp])#关机保存一个是时间
+        EventMesh.publish("set_storage_config",["old_time",date_tmp])#关机保存一个是时间
 
         #print("self.read_data:{}".format(self.read_data))
         EventMesh.publish("play_poewr_off_event")#