M36_K01:
authordxy15521469561 <1731678236@qq.com>
Tue, 30 Jul 2024 07:16:58 +0000 (15:16 +0800)
committerdxy15521469561 <1731678236@qq.com>
Tue, 30 Jul 2024 07:16:58 +0000 (15:16 +0800)
增加AL指令协议

2.sdk-ZY/project/K01/sdk/services/microPython/ports/quectel/core/constants.py
2.sdk-ZY/project/K01/sdk/services/microPython/ports/quectel/core/main_init.py
2.sdk-ZY/project/K01/sdk/services/microPython/ports/quectel/core/mgr.py
2.sdk-ZY/project/K01/sdk/services/microPython/ports/quectel/core/protocol.py
2.sdk-ZY/project/W9/sdk/services/microPython/ports/quectel/core/mgr.py
2.sdk/project/W8/sdk/services/microPython/ports/quectel/core/mgr.py

index 657aa31..bd9745a 100644 (file)
@@ -14,6 +14,9 @@ class PROTOCOL:
     CR_SEND = "CR_SEND"
     CR_RECV = "CR_RECV"
 
+    AL_SEND = "AL_SEND"
+    AL_RECV = "AL_RECV"
+
     FIND_SEND = "FIND_SEND"
     FIND_RECV = "FIND_RECV"
 
index 0d50661..5b84457 100644 (file)
@@ -204,7 +204,7 @@ def main_init():
     
     from protocol import RTALK_ProtoCol,TKS_ProtoCol,RCALLING_ProtoCol,AGTALK_ProtoCol,CALLING_ProtoCol,MEMBERS_ProtoCol,JPREG_ProtoCol,ppsrvvoicemsg_ProtoCol,ppdevvoicemsg_ProtoCol,srvtextmsg_ProtoCol,TK_ProtoCol,MESSAGE_ProtoCol,APPVOICEMSG_ProtoCol,restart_ProtoCol,factory_ProtoCol,SILENCETIMEFS_ProtoCol,WLKEY_ProtoCol,SILENCETIME2_ProtoCol,KEYBRD_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,\
-        pp_ProtoCol,ppfriends_ProtoCol,revpp_ProtoCol,reqpp_ProtoCol,delpp_ProtoCol,ProtoColResolver,PHL_ProtoCol,MONITOR_ProtoCol,bootoff_ProtoCol,WDSTART_ProtoCol,LOWBAT_ProtoCol,sosHome_dial_ProtoCol,SockManager,NetManager
+        pp_ProtoCol,ppfriends_ProtoCol,revpp_ProtoCol,AL_ProtoCol,reqpp_ProtoCol,delpp_ProtoCol,ProtoColResolver,PHL_ProtoCol,MONITOR_ProtoCol,bootoff_ProtoCol,WDSTART_ProtoCol,LOWBAT_ProtoCol,sosHome_dial_ProtoCol,SockManager,NetManager
     
     from protocol import CALLCANCEL_ProtoCol,HANGUP_ProtoCol,JMEMBERS_ProtoCol
 
@@ -318,6 +318,7 @@ def main_init():
     pcr.add_support(CALLING_ProtoCol())
     pcr.add_support(RCALLING_ProtoCol())
     pcr.add_support(RTALK_ProtoCol())
+    pcr.add_support(AL_ProtoCol())
     # pcr.add_support(HANGUP_ProtoCol())
     EventMesh.publish("load_screen", {"screen": "poweron"})
     sm = SockManager()
index 886efa9..6a8cc4b 100644 (file)
@@ -563,8 +563,12 @@ def voice_callback(args):
             voiceCall.callEnd()
             return
         EventMesh.publish("set_call_state",4)##设置通话状态
-        EventMesh.publish("set_interrup_incall",0)
-        EventMesh.publish("set_UI_high_priority",0)
+        
+        screen_NAME = EventMesh.publish("get_screen_NAME")
+        if screen_NAME != None:
+            if screen_NAME != "dialing_noplay_popup":
+                EventMesh.publish("set_interrup_incall",0)
+                EventMesh.publish("set_UI_high_priority",0)
         EventMesh.publish("load_screen", {"screen": "dialing_noplay_popup"})
         
     elif args[0] == 15:
@@ -661,6 +665,8 @@ class DeviceInfoManager(Abstract):
         self.normal_oldtotalmin = 0
         self.normal_flag = 0
         self.normal_count = 0
+
+        self.dev_state = 0
         # #print("hsensor.open_heart:%d\r\n"%(self.hsensor.open_heart()))
         print("DeviceInfoManager:3")
         self.i2c0 = I2C(I2C.I2C0, I2C.FAST_MODE)
@@ -713,6 +719,9 @@ class DeviceInfoManager(Abstract):
         EventMesh.subscribe(constants.EVENT.STOP_TEMP, self.stop_temp)
         EventMesh.subscribe(constants.EVENT.GET_TEMP, self.get_temp)
 
+        EventMesh.subscribe("get_dev_state",self.get_dev_state)
+        EventMesh.subscribe("set_dev_state",self.set_dev_state)
+
         print("post_processor_after_instantiation:2")
         self.timer_push_schedule.start(10000, 1, self.publish_event_cb)
         # self.timer_pusht_test.start(2000, 1, self.publish_test)
@@ -756,6 +765,11 @@ class DeviceInfoManager(Abstract):
             # if flip_sw == 1:
             #     EventMesh.publish(constants.EVENT.SYSTEM_SLEEP)
 
+    def get_dev_state(self, event, msg):
+        return self.dev_state
+    def set_dev_state(self, event, msg):
+        self.dev_state = msg
+
     def publish_event_cb(self, *args, **kwargs):
         EventMesh.publish("publish_message_event_DeviceInfo",{"func":self.publish_event,"data":0})  
     def publish_event(self,data):
@@ -1951,139 +1965,146 @@ class LocationManager(Abstract):
           #print("Location_send1")
         if self.location_queue.empty() == True:
             return
-        server_data = server_init()
-        # print("SockManager:server_data:{}".format(server_data))
-        server_addr = server_data[0]
-        server_port = server_data[1]
-        ip_infor = EventMesh.publish("get_new_ip_com")
-        print("ip_infor1:{} \n\n\n".format(ip_infor))
-        
-        if ip_infor != None: #已经改过服务器
-            server_addr = ip_infor[0]
-            server_port = ip_infor[1]
-        d_server_addr = "device.miwitracker.com"
-        d_server_port = 8505
-        print("server_addr:{} server_port:{}".format(server_addr,server_port))
-        self.date_info = "{:04d}{:02d}{:02d},{:02d}{:02d}{:02d}".format(*utime.localtime()[0:6])
-        self.date_info =  self.date_info[2:]
-        if server_addr == d_server_addr and server_port == d_server_port:
-            
-            data = RTC().datetime()
-            hour = data[4]
-            min = data[5]
-            sec = data[6]
-
-            week = data[3]
-
-            year = data[0]#年
-            month = data[1]#月
-            day = data[2]#日
-            year_date = int(str(year)[2:])
-            # print("year_date",year_date)
-            self.date_info = "%02d"%(day)+"%02d"%(month)+"%02d"%(year_date)+','+"%02d"%(hour)+"%02d"%(min)+"%02d"%(sec)#云米要日月年
-        # self.date_info = "%02d"%(utime.localtime()[1])+"%02d"%(utime.localtime()[2])+"%02d"%(year_date)+','+"%02d"%(utime.localtime()[3])+"%02d"%(utime.localtime()[4])+"%02d"%(utime.localtime()[5])
-        # print("date_info",self.date_info)
-
-        #date = "180916,025723"
-        date = self.date_info
-        #date = "180916,025723"
-        GPS_type = "V"
-        latitude = "0.000000,N"
-        longitude = "0.000000,E"
-        speed = "0.00"
-        direction = "0.0"
-        high = "100.0"
-        number = "0"
-        precision = "24"
-        if msg[0] :#有GPS数据
-            GPS_type = "A"
-            # 纬度
-            latitude = msg[0]["latitude"]
-            # 经度
-            longitude = msg[0]["longitude"]
-            # 速度
-            speed = msg[0]["speed"]
-            # 方向
-            direction = "0"
-            if msg[0]["direction"] :
-                direction = msg[0]["direction"]
-            # 高度
-            high = msg[0]["high"]
-            high_tmp = high.split(".")
-            if len(high_tmp) >= 2 :
-                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"))
-        # 电池电量百分比 
-        bat_tmp = EventMesh.publish("screen_get_battery")
-        battery_caption =  str(bat_tmp[1])
-        #步数
-        old_step = 0
-        step = 0
-        step = EventMesh.publish("get_old_step_value")
-        if step != None:
-            tmp_data  = EventMesh.publish("get_storage_config","old_step_new")
-            if tmp_data != None:
-                old_step = tmp_data
-            if old_step !=  step:
-                EventMesh.publish("set_storage_config",["old_step",step])
-                EventMesh.publish("set_storage_config",["old_step_new",step])
-        else:
-            step = 0  
-        old_step = step
-        # step = str(EventMesh.publish(constants.EVENT.GET_STEP)[0])
-        #翻转次数
-        turn_count = "0"
-        #终端状态
-        state = "00000000"
-        #基站数据
-        CELL_num = len(msg[2])
-        CELL_data = "1," #时延
-        if msg[2] != []:
-            for CELL in msg[2] :
-                if CELL[0] == 0 :
-                    CELL_data += "%X,"%(int(CELL[2])) #MCC
-                    CELL_data += str(CELL[3]) +","#MNC
-                    CELL_data += str(CELL[5]) +","#tac,区域码
-                    CELL_data += str(CELL[1]) +","#基站编号 CID
-                    CELL_data += str(int(CELL[7]+140)) +","#信号强度 rssi
-                else :
-                    CELL_data += str(CELL[5]) +","#tac,区域码
-                    CELL_data += str(CELL[1]) +","#基站编号 CID
-                    CELL_data += str(int(CELL[7]+140)) +","#信号强度 rssi
-            CELL_data = CELL_data[:(len(CELL_data)-1)]
-        #WIFI数据
-        WIFI_num = 0 
-        WIFI_data = ""
-        if msg[1] :
-            WIFI_num = msg[1][0]
-            i = 0
-            for MAC in msg[1][1] :
-                WIFI_data += "wifi%d,%s,%d,"%(i,str(MAC[0]),MAC[1])
-                i += 1
-            WIFI_data = WIFI_data[:(len(WIFI_data)-1)]
-        WIFI_data = WIFI_data.lower()
-        #send_data = "UD ,%s ,%s     ,%s       ,%s       ,%s   ,%s       ,%s  ,%s    ,%s     ,%s             ,%s  ,%s        ,%s   ,%d     ,%s       ,%d      ,%s"\
-        #              %(date,GPS_type,latitude,longitude,speed,direction,high,number,gsm_sig,battery_caption,step,turn_count,state,CELL_num,CELL_data,WIFI_num,WIFI_data)
-        #定位数据
-        send_data = "%s,%s,%s"%(date,GPS_type,latitude)
-        send_data += ",%s,%s,%s"%(longitude,speed,direction)
-        send_data += ",%s,%s,%s"%(high,number,gsm_sig,)
-        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:
                 TYPE = self.location_queue.get()
+                server_data = server_init()
+                # print("SockManager:server_data:{}".format(server_data))
+                server_addr = server_data[0]
+                server_port = server_data[1]
+                ip_infor = EventMesh.publish("get_new_ip_com")
+                print("ip_infor1:{} \n\n\n".format(ip_infor))
+                
+                if ip_infor != None: #已经改过服务器
+                    server_addr = ip_infor[0]
+                    server_port = ip_infor[1]
+                d_server_addr = "device.miwitracker.com"
+                d_server_port = 8505
+                print("server_addr:{} server_port:{}".format(server_addr,server_port))
+                self.date_info = "{:04d}{:02d}{:02d},{:02d}{:02d}{:02d}".format(*utime.localtime()[0:6])
+                self.date_info =  self.date_info[2:]
+                if server_addr == d_server_addr and server_port == d_server_port:
+                    
+                    data = RTC().datetime()
+                    hour = data[4]
+                    min = data[5]
+                    sec = data[6]
+
+                    week = data[3]
+
+                    year = data[0]#年
+                    month = data[1]#月
+                    day = data[2]#日
+                    year_date = int(str(year)[2:])
+                    # print("year_date",year_date)
+                    self.date_info = "%02d"%(day)+"%02d"%(month)+"%02d"%(year_date)+','+"%02d"%(hour)+"%02d"%(min)+"%02d"%(sec)#云米要日月年
+                # self.date_info = "%02d"%(utime.localtime()[1])+"%02d"%(utime.localtime()[2])+"%02d"%(year_date)+','+"%02d"%(utime.localtime()[3])+"%02d"%(utime.localtime()[4])+"%02d"%(utime.localtime()[5])
+                # print("date_info",self.date_info)
+
+                #date = "180916,025723"
+                date = self.date_info
+                #date = "180916,025723"
+                GPS_type = "V"
+                latitude = "0.000000,N"
+                longitude = "0.000000,E"
+                speed = "0.00"
+                direction = "0.0"
+                high = "100.0"
+                number = "0"
+                precision = "24"
+                if msg[0] :#有GPS数据
+                    GPS_type = "A"
+                    # 纬度
+                    latitude = msg[0]["latitude"]
+                    # 经度
+                    longitude = msg[0]["longitude"]
+                    # 速度
+                    speed = msg[0]["speed"]
+                    # 方向
+                    direction = "0"
+                    if msg[0]["direction"] :
+                        direction = msg[0]["direction"]
+                    # 高度
+                    high = msg[0]["high"]
+                    high_tmp = high.split(".")
+                    if len(high_tmp) >= 2 :
+                        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"))
+                # 电池电量百分比 
+                bat_tmp = EventMesh.publish("screen_get_battery")
+                battery_caption =  str(bat_tmp[1])
+                #步数
+                old_step = 0
+                step = 0
+                step = EventMesh.publish("get_old_step_value")
+                if step != None:
+                    tmp_data  = EventMesh.publish("get_storage_config","old_step_new")
+                    if tmp_data != None:
+                        old_step = tmp_data
+                    if old_step !=  step:
+                        EventMesh.publish("set_storage_config",["old_step",step])
+                        EventMesh.publish("set_storage_config",["old_step_new",step])
+                else:
+                    step = 0  
+                old_step = step
+                # step = str(EventMesh.publish(constants.EVENT.GET_STEP)[0])
+                #翻转次数
+                turn_count = "0"
+                #终端状态
+                # state = "00000000"
+                state = "%08X"%(EventMesh.publish("get_dev_state"))
+                #基站数据
+                if type(TYPE) == list:#队列里的数据有终端状态,则用队里的终端状态
+                    if len(TYPE)>= 2 :
+                        state = "%08X"%(TYPE[1])
+                CELL_num = len(msg[2])
+                CELL_data = "1," #时延
+                if msg[2] != []:
+                    for CELL in msg[2] :
+                        if CELL[0] == 0 :
+                            CELL_data += "%X,"%(int(CELL[2])) #MCC
+                            CELL_data += str(CELL[3]) +","#MNC
+                            CELL_data += str(CELL[5]) +","#tac,区域码
+                            CELL_data += str(CELL[1]) +","#基站编号 CID
+                            CELL_data += str(int(CELL[7]+140)) +","#信号强度 rssi
+                        else :
+                            CELL_data += str(CELL[5]) +","#tac,区域码
+                            CELL_data += str(CELL[1]) +","#基站编号 CID
+                            CELL_data += str(int(CELL[7]+140)) +","#信号强度 rssi
+                    CELL_data = CELL_data[:(len(CELL_data)-1)]
+                #WIFI数据
+                WIFI_num = 0 
+                WIFI_data = ""
+                if msg[1] :
+                    WIFI_num = msg[1][0]
+                    i = 0
+                    for MAC in msg[1][1] :
+                        WIFI_data += "wifi%d,%s,%d,"%(i,str(MAC[0]),MAC[1])
+                        i += 1
+                    WIFI_data = WIFI_data[:(len(WIFI_data)-1)]
+                WIFI_data = WIFI_data.lower()
+                #send_data = "UD ,%s ,%s     ,%s       ,%s       ,%s   ,%s       ,%s  ,%s    ,%s     ,%s             ,%s  ,%s        ,%s   ,%d     ,%s       ,%d      ,%s"\
+                #              %(date,GPS_type,latitude,longitude,speed,direction,high,number,gsm_sig,battery_caption,step,turn_count,state,CELL_num,CELL_data,WIFI_num,WIFI_data)
+                #定位数据
+                send_data = "%s,%s,%s"%(date,GPS_type,latitude)
+                send_data += ",%s,%s,%s"%(longitude,speed,direction)
+                send_data += ",%s,%s,%s"%(high,number,gsm_sig,)
+                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()))
                 print("Location_send3:{}-{}".format(TYPE,send_data))
-                EventMesh.publish(TYPE,send_data)
+                if type(TYPE) == list:
+                    EventMesh.publish(TYPE[0],send_data)
+                else:
+                    EventMesh.publish(TYPE,send_data)
             else :
                 break
 
@@ -3035,6 +3056,12 @@ class getSosFlagManager(Abstract):#设置sos
            
             if number != None:
                 if len(number) > 0:
+                    sos_state =  EventMesh.publish("get_dev_state")
+                    tmp = 1 << 16
+                    sos_state = sos_state|tmp #第16位=1
+                    EventMesh.publish("set_dev_state",sos_state)
+
+                    EventMesh.publish(constants.EVENT.START_LOCATION,[constants.PROTOCOL.AL_SEND,sos_state]) #开始AL定位
                     EventMesh.publish("save_phonename",number[0])
                     EventMesh.publish("save_phonenum",number[0])
                     EventMesh.publish("set_sos_num",0)
@@ -3049,6 +3076,11 @@ class getSosFlagManager(Abstract):#设置sos
         # print("call_timer_cb:{}".format(self.callnumer))
         EventMesh.publish("save_phonename",str(self.callnumer))
         EventMesh.publish("save_phonenum",str(self.callnumer))
+        sos_state =  EventMesh.publish("get_dev_state")
+        tmp = 1 << 16
+        sos_state = sos_state|tmp #第16位=1
+        EventMesh.publish("set_dev_state",sos_state)
+        EventMesh.publish(constants.EVENT.START_LOCATION,[constants.PROTOCOL.AL_SEND,sos_state]) #开始AL定位
         EventMesh.publish("load_screen", {"screen": "dialing_noplay_popup"})  
 
     def close_sos_timer(self,event,msg):
index 7e028c9..3768403 100644 (file)
@@ -2798,7 +2798,55 @@ class CALLCANCEL_ProtoCol(ProtoCol):#app拒接视频通话
         
         EventMesh.publish(constants.PROTOCOL.CALLCANCEL_SEND)
 
+class AL_ProtoCol(ProtoCol):
+    """报警数据上报"""
+    TYPE = "AL"
+    timer_repetition_send = None
+    repetition_queue = None
 
+    def send(self, event, msg):
+        if self.timer_repetition_send == None:
+            self.timer_repetition_send = osTimer()
+        if self.repetition_queue == None:
+            self.repetition_queue = Queue(100)
+        
+
+        send_data ="AL,"+msg
+        send_len = len(send_data)
+        #wt_data = "%s"%(send_data)
+        send_data = EventMesh.publish("get_new_pid")+"*%s*%04X*%s"%(self.imei,send_len,send_data)
+        MD5_head_data = EventMesh.publish("get_new_pid")+"*%s*%04X*%s"%(self.imei,send_len,"AL")
+        
+        MD5_SIGN = self.pack_MD5_head(MD5_head_data)
+        data = "[%s%s]"%(str(MD5_SIGN),send_data)
+        #EventMesh.debug_log("AL_ProtoCol:send:%s"%(data))
+        # 通过socket发送到服务器端
+        EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data)
+        self.repetition_queue.put(data)#发送入队
+        self.timer_repetition_send.start(10000, 1, self.repetition_timer_cb)
+        EventMesh.publish("set_dev_state",0)
+    def recv(self, event, msg):
+        """
+
+        @param event: PING
+        @param msg: 接收到的下行数据
+        """
+        #EventMesh.publish(constants.PROTOCOL.CR_SEND)
+        #EventMesh.publish(constants.EVENT.START_LOCATION,constants.PROTOCOL.UD_SEND) #开始ud定位
+        # EventMesh.debug_log("报警数据上报:recv:%s"%(msg))   
+        #        
+        if self.repetition_queue.empty() == False:
+            self.repetition_queue.get()#出队
+        else:
+            self.timer_repetition_send.stop()
+
+    def repetition_timer_cb(self, *args, **kwargs):#每隔10秒发送一次
+        if self.repetition_queue.empty() == False:
+            data = self.repetition_queue.get()#出队
+            self.repetition_queue.put(data)#发送入队
+            EventMesh.publish(constants.EVENT.CHANNEL_SOCKET_SEND, data)
+        else:
+            self.timer_repetition_send.stop()
 
 class ProtoColResolver(object):
     def __init__(self):
index 37b8825..6233e13 100644 (file)
@@ -672,8 +672,11 @@ def voice_callback(args):
             voiceCall.callEnd()
             return
         EventMesh.publish("set_call_state",4)##设置通话状态
-        EventMesh.publish("set_interrup_incall",0)
-        EventMesh.publish("set_UI_high_priority",0)
+        screen_NAME = EventMesh.publish("get_screen_NAME")
+        if screen_NAME != None:
+            if screen_NAME != "dialing_noplay_popup":
+                EventMesh.publish("set_interrup_incall",0)
+                EventMesh.publish("set_UI_high_priority",0)
         EventMesh.publish("load_screen", {"screen": "dialing_noplay_popup"})
         
    elif args[0] == 15:
index 94e5b1a..9a87633 100644 (file)
@@ -669,8 +669,12 @@ def voice_callback(args):
             return
         EventMesh.publish("set_call_state",4)##设置通话状态
         print('voicecall dialing, PhoneNO.: ', args[6])
-        EventMesh.publish("set_interrup_incall",0)
-        EventMesh.publish("set_UI_high_priority",0)
+
+        screen_NAME = EventMesh.publish("get_screen_NAME")
+        if screen_NAME != None:
+            if screen_NAME != "dialing_noplay_popup":
+                EventMesh.publish("set_interrup_incall",0)
+                EventMesh.publish("set_UI_high_priority",0)
         EventMesh.publish("load_screen", {"screen": "dialing_noplay_popup"})
         
    elif args[0] == 15: