From: dxy <1731678236qq.com> Date: Fri, 26 Sep 2025 09:00:36 +0000 (+0800) Subject: 优化 X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=6a6ebd6a3006d1a23eeb13613e6f6b35acb2dff5;p=mirrors%2FASR1603_G5.git 优化 --- diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ai_VC.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ai_VC.py index 129bb40e..01dd8d76 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ai_VC.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ai_VC.py @@ -1401,7 +1401,7 @@ class AI_dev(Abstract): self.KeyAI_long_press = 1 #EventMesh.publish("AI_key_long_press") EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_key_long_press}) - if self.KeyAI_timer_count >= 10*3 : #长按1s + if self.KeyAI_timer_count >= 10*3 : #长按3s 上一次是短按则拨打sos紧急联系人 print("long sos phone:{}".format(self.KeySOS_timer_flag)) if self.KeySOS_timer_flag == 1: @@ -1439,7 +1439,7 @@ class AI_dev(Abstract): if self.KeySOS_timer_flag == 0: self.KeySOS_timer_flag = 1 self.KeySos_long_press = 0 - self.KeySOS_timer.start(5000, 0, self.KeySos_timer_cb) + self.KeySOS_timer.start(5000, 0, self.KeySos_timer_cb) #短按开启5s定时器 5s之内没有长按3s则清除标识 长按3s拨打sos紧急联系人 else: self.KeySOS_timer_flag = 0 self.KeySos_long_press = 0 @@ -1468,7 +1468,7 @@ class AI_dev(Abstract): def KeySos_timer_cb(self,*argc): print("KeySos_timer_cb!!!!!!!!!!{} {}".format(self.KeySos_long_press,self.KeySOS_timer_flag)) - if self.KeySos_long_press == 1 and self.KeySOS_timer_flag == 1: + if self.KeySos_long_press == 1 and self.KeySOS_timer_flag == 1: #清空sos标识 self.KeySos_long_press=0 self.KeySOS_timer_flag=0 diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/protocol.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/protocol.py index b31f7338..67e3a876 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/protocol.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/protocol.py @@ -279,6 +279,7 @@ def wifiScan_cb(args): print("wifi_data:{}".format(args)) EventMesh.publish(constants.EVENT.WIFIINFO, args) wifiScan.control(0) +#定位thered class IOTWebLocationManager(Abstract): def __init__(self): @@ -825,6 +826,7 @@ class IOTSendCmdManager(Abstract): } return alarm_data +#解析收到的数据协议 def playpolad_data(data): if(isinstance(data, bytes) == 0 or len(data) <= PROTOCLO_LEN): return @@ -875,6 +877,7 @@ VERSION = (0x01).to_bytes(1,"big")#"03".encode('utf-8') TYPE = (0x03).to_bytes(1,"big") DATA_LEN = (0x00000000).to_bytes(4,"big") #magic+version+type+playload_len+playload +#普通协议数据格式根据协议指定 def protocol_send_total_data(data): MAGIC = (0xfffe).to_bytes(2,"big") VERSION = (0x01).to_bytes(1,"big")#"03".encode('utf-8') @@ -909,7 +912,8 @@ def protocol_yuyin_voice_playload_data(data,msgid,endflag): heards_infor = b'' heards_infor = MAGIC+VERSION+TYPE+MSGID+ENDFLAG+DATA_LEN+data return heards_infor -class sosInfoCallManager(Abstract): +#sos紧急电话class +class sosInfoCallManager(Abstract): def __init__(self): self.num = 0 self.num=0 @@ -1277,16 +1281,16 @@ class SockMangager(Abstract): self.location_info= {} self.locate_duration = 0 self.locate_duration_state = 0 - self.location_info = EventMesh.publish("get_storage_config","locate_duration_time") #获取定位频率 + self.location_info = EventMesh.publish("get_storage_config","locate_duration_time") #获取定位频率信息 if self.location_info == None: self.location_info = {} else: # location_time["duration"]=locate_duration_time # location_time["state"]=locate_duration_state if "duration" in self.location_info: - self.locate_duration = self.location_info["duration"] + self.locate_duration = self.location_info["duration"] #定位频率 if "state" in self.location_info: - self.locate_duration_state = self.location_info["state"] + self.locate_duration_state = self.location_info["state"] #是否开启频率定位 pass EventMesh.subscribe("REPORT_ALARM_TO_IOT",self.report_alarm_to_iot) @@ -1310,18 +1314,18 @@ class SockMangager(Abstract): EventMesh.subscribe("set_play_new_voice_list",self.set_play_new_voice_list) # import EventMesh # EventMesh.publish("play_new_voice_list") - EventMesh.subscribe("play_new_voice_list",self.play_new_voice_list) - EventMesh.subscribe("update_play_new_voice_info",self.update_play_new_voice_info) - EventMesh.subscribe("send_bt_scan_list",self.send_bt_scan_list) - EventMesh.subscribe("save_bt_connect_list",self.save_bt_connect_list) - EventMesh.subscribe("send_bt_connect_list",self.send_bt_connect_list) - EventMesh.subscribe("set_play_new_voice_state",self.set_play_new_voice_state) - EventMesh.subscribe("get_play_new_voice_state",self.get_play_new_voice_state) - EventMesh.subscribe("send_bt_connect_state_to_iot",self.send_bt_connect_state_to_iot) - EventMesh.subscribe("send_unbind_dev_to_iot",self.send_unbind_dev_to_iot) - EventMesh.subscribe("set_location_timer",self.set_location_timer) - EventMesh.subscribe("post_device_state",self.post_device_state) - EventMesh.subscribe("send_power_init_data",self.send_power_init_data) + EventMesh.subscribe("play_new_voice_list",self.play_new_voice_list) #播放语音未读信息 + EventMesh.subscribe("update_play_new_voice_info",self.update_play_new_voice_info) #更新语音未读信息状态上报IOT + EventMesh.subscribe("send_bt_scan_list",self.send_bt_scan_list) #上报扫描列表 + EventMesh.subscribe("save_bt_connect_list",self.save_bt_connect_list) #保存耳机连接状态列表 + EventMesh.subscribe("send_bt_connect_list",self.send_bt_connect_list) #发送耳机连接状态列表 + EventMesh.subscribe("set_play_new_voice_state",self.set_play_new_voice_state) #设置播放语音未读状态1正在播放语音未读消息 + EventMesh.subscribe("get_play_new_voice_state",self.get_play_new_voice_state) #获取播放语音未读状态1正在播放语音未读消息 + EventMesh.subscribe("send_bt_connect_state_to_iot",self.send_bt_connect_state_to_iot) #发耳机;链接状态->IOT + EventMesh.subscribe("send_unbind_dev_to_iot",self.send_unbind_dev_to_iot) #发送解绑指令到IOT平台 + EventMesh.subscribe("set_location_info",self.set_location_info) #设置定位信息 + EventMesh.subscribe("post_device_state",self.post_device_state) #上报设备状态信息-》IOT + EventMesh.subscribe("send_power_init_data",self.send_power_init_data) #上电初始化上报数据集合 # count = 0 # while True: # count += 1 @@ -1342,12 +1346,79 @@ class SockMangager(Abstract): self.get_voice_new_msginit = 0 self.bt_connect_list = [] self.new_voice_list = [] - self.connect_web_timer.start(2000,0,self.iot_web_connect_timerCb) + self.connect_web_timer.start(2000,0,self.iot_web_connect_timerCb) #开机2s之后连接iot + def connect_iot_websocket(self): + if EventMesh.publish("get_voice_record_flag") == 1: + EventMesh.publish("stop_voice_record") + print("connect_iot_websocket !!!!") + self.iot_close_web_therad() + + if sim.getStatus() != 1 or self.start_voice_flag == 1:#网络正常 + return + + if self.reconnect_count >= WEB_CONNECT_MAX_COUNT: #重连次数大于10次不在进重连只有下发心跳才重新连接 + return + token = EventMesh.publish("get_dev_token") + + print("token:{}".format(token)) + # token = "957119d6b67b89dc1bc533d2e0c058d559" + # token = "951b74498eabe241e8a8c644a4f07531ef" + + try: + if token != None: + self.connect_web_timer_count = 0 + url_t = "ws://220.160.104.34:30800/ws-hub/dev/v1?qp-dt={}".format(token) + try: + self.iot_protocol_client=uwebsocket.Client.connect(url_t, debug=True) + self.reconnect_count=0 + except Exception as e: + print("再次连接") + self.reconnect_count+=1 + EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket}) #self.connect_iot_websocket() + return + + if self.iot_protocol_client != None: + self.reconnect_count = 0 + _thread.stack_size(self.thread_buf_size+8*1024) #_thread.stack_size(16*1024) + self.iot_web_send_queue_id = _thread.start_new_thread(self.websocket_send_queue_thread, ()) + _thread.stack_size(8*1024) + + _thread.stack_size(self.thread_buf_size+8*1024) + self.iot_web_protoclo_recv_id = _thread.start_new_thread(self.websocket_recv_queue_thread, ()) + _thread.stack_size(8*1024) + + else: + print("self.iot_protocol_client init!!!!!!!!!") + self.reconnect_count+=1 + # EventMesh.publish("connect_iot_websocket_cb") + EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket}) #self.connect_iot_websocket() + return + + if self.iot_protocol_client != None: + self.start_voice_flag = 1 + else: + self.start_voice_flag = 0 + + print("self.iot_protocol_client %d self.start_voice_flag:%d",self.iot_protocol_client,self.start_voice_flag) + if self.iot_protocol_client != None: + if self.timer_id == 0: + # self.hr_report_timer.start(DEFINE_TIME_COUNT*1000, 1, self.public_report_event) + self.timer_id=1 + else: + print("没有token!!!!!!!!!!") + self.connect_web_timer_count+=1 + if self.connect_web_timer_count <= 10: + self.connect_web_timer.start(5000,0,self.iot_web_connect_timerCb) #没有token 5s之后再重连 + pass + except Exception as e: + self.iot_protocol_client = None + print("connect_iot_websocket error") + def post_device_state(self,event,msg): #上报设备状态 device_state=EventMesh.publish("GET_IOT_WEB_SEND_CMD",WEB_CMD_ENUM.POST_DEVICE_STATE_S_CMD) print("device_state{}".format(device_state)) EventMesh.publish(WEB_CMD_ENUM.POST_DEVICE_STATE_S_CMD,device_state) #上报设备状态 - def set_location_timer(self,event,msg): + def set_location_info(self,event,msg): if "duration" in msg: self.locate_duration=msg["duration"] if "state" in msg: @@ -1510,65 +1581,65 @@ class SockMangager(Abstract): usys.print_exception(e) pass - def send_jm_audio_to_iot(self,event,msg): + def send_jm_audio_to_iot(self,event,msg): #静默录音音频数据上报到IOT平台 send_data = b'' send_data = protocol_audio_ji_playload_data(msg[0],msg[1],msg[2]) # print("jm:{}".format(msg[2])) EventMesh.publish("CHANNEL_IOT_WEB_SEND",send_data) pass - def send_yuyin_audio_to_iot(self,event,msg): + def send_yuyin_audio_to_iot(self,event,msg): #上报语音留言音频数据到IOT平台 send_data = b'' send_data = protocol_yuyin_voice_playload_data(msg[0],msg[1],msg[2]) # print("yuyin:{}".format(msg[2])) EventMesh.publish("CHANNEL_IOT_WEB_SEND",send_data) pass - + #获取电池电量 def get_battery(self, event=None, msg=None): - """ - 获取电池事件,暂时没支持 - :param event: - :param msg: - :return: - """ + """ + 获取电池事件,暂时没支持 + :param event: + :param msg: + :return: + """ + + charge_state = '0' + usb_state = EventMesh.publish("GET_USB_STATE") + if usb_state == None: + usb_state = 0 + if usb_state == 1: + charge_state = '1' + else: charge_state = '0' - usb_state = EventMesh.publish("GET_USB_STATE") - if usb_state == None: - usb_state = 0 - if usb_state == 1: - charge_state = '1' - else: - charge_state = '0' - - #temp = Power.getVbatt() - temp = EventMesh.publish("get_curr_battery_level") - vbat = EventMesh.publish("get_battery",temp) - if vbat == None: - vbat = 100 - # EventMesh.debug_log("vbat",vbat) - # if temp != None : - # if temp <= 3505: - # vbat = 0 - # elif temp <= 3699: - # vbat = 20 #"E:/vbat_20.jpg" - # elif temp <= 3772: - # vbat = 40 #"E:/vbat_40.jpg" - # elif temp <= 3882: - # vbat = 60 #"E:/vbat_60.jpg" - # elif temp <= 4070: - # vbat = 80 #"E:/vbat_80.jpg" - # elif temp <= 4200: - # vbat = 90 # - # else: - # vbat = 100 #"E:/vbat_100.jpg" - # else: - # vbat = 100 + #temp = Power.getVbatt() + temp = EventMesh.publish("get_curr_battery_level") + vbat = EventMesh.publish("get_battery",temp) + if vbat == None: + vbat = 100 + # EventMesh.debug_log("vbat",vbat) + # if temp != None : + # if temp <= 3505: + # vbat = 0 + # elif temp <= 3699: + # vbat = 20 #"E:/vbat_20.jpg" + # elif temp <= 3772: + # vbat = 40 #"E:/vbat_40.jpg" + # elif temp <= 3882: + # vbat = 60 #"E:/vbat_60.jpg" + # elif temp <= 4070: + # vbat = 80 #"E:/vbat_80.jpg" + # elif temp <= 4200: + # vbat = 90 # + # else: + # vbat = 100 #"E:/vbat_100.jpg" + # else: + # vbat = 100 - result = [charge_state, vbat] + result = [charge_state, vbat] - return result + return result def set_curr_battery_level(self, event=None, msg=None): self.curr_battery_level = msg @@ -1582,12 +1653,12 @@ class SockMangager(Abstract): self.connect_iot_websocket() def add_support_resolver(self, resolver): self.resolver = resolver - def hr_report_event(self, *args, **kwargs): - EventMesh.publish("publish_AI_btnInfo",{"func":self.hr_report_event_cb}) #self.connect_iot_websocket() + def public_report_event(self, *args, **kwargs): + EventMesh.publish("publish_AI_btnInfo",{"func":self.public_report_event_cb}) #self.connect_iot_websocket() def send_power_init_data(self,event=None,msg=None): - self.hr_report_event_cb() - - def hr_report_event_cb(self): + self.public_report_event_cb() + #上报心跳 上报设备状态 检查闹钟 日程 + def public_report_event_cb(self): """电池平均值""" temp = Power.getVbatt() if self.bat_count < 10: @@ -1606,7 +1677,9 @@ class SockMangager(Abstract): # print("AI_schedule_open!!!") if EventMesh.publish("get_sos_flag") != None: if EventMesh.publish("get_sos_flag") == 1: + print("get_sos_flag!!!!!!") EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠 + print("get_sos_flag1!!!!!!") EventMesh.publish("AI_alarm_start") #检查是否有闹钟需要提醒 EventMesh.publish("AI_schedule_open")#检查日程是否需要提醒 @@ -1635,7 +1708,7 @@ class SockMangager(Abstract): self.timerLocation= 0 - if self.send_device_time < DEFIEN_LOCATION_REPORT_TIME : + if self.send_device_time < DEFIEN_LOCATION_REPORT_TIME : #上电初始化上报一次设备状态信息 self.send_device_time+=DEFINE_TIME_COUNT else: if self.get_voice_new_msginit == 0: #开机获取一次语音未读消息 @@ -1645,7 +1718,7 @@ class SockMangager(Abstract): print("device_state{}".format(device_state)) EventMesh.publish(WEB_CMD_ENUM.POST_DEVICE_STATE_S_CMD,device_state) #上报设备状态 - EventMesh.publish(WEB_CMD_ENUM.GET_NEW_VOICE_MSG_S) + EventMesh.publish(WEB_CMD_ENUM.GET_NEW_VOICE_MSG_S)#向IOT获取语音未读消息 # http://220.160.104.34:30800/ws-bus/test/voice-record/876226211472149?state=1, @@ -1660,72 +1733,6 @@ class SockMangager(Abstract): def iot_web_connect_timerCb(self,*argc): self.connect_iot_websocket() - def connect_iot_websocket(self): - if EventMesh.publish("get_voice_record_flag") == 1: - EventMesh.publish("stop_voice_record") - print("connect_iot_websocket !!!!") - self.iot_close_web_therad() - - if sim.getStatus() != 1 or self.start_voice_flag == 1:#网络正常 - return - - if self.reconnect_count >= WEB_CONNECT_MAX_COUNT: #重连次数大于10次不在进重连只有下发心跳才重新连接 - return - token = EventMesh.publish("get_dev_token") - - print("token:{}".format(token)) - # token = "957119d6b67b89dc1bc533d2e0c058d559" - # token = "951b74498eabe241e8a8c644a4f07531ef" - - try: - if token != None: - self.connect_web_timer_count = 0 - url_t = "ws://220.160.104.34:30800/ws-hub/dev/v1?qp-dt={}".format(token) - try: - self.iot_protocol_client=uwebsocket.Client.connect(url_t, debug=True) - self.reconnect_count=0 - except Exception as e: - print("再次连接") - self.reconnect_count+=1 - EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket}) #self.connect_iot_websocket() - return - - if self.iot_protocol_client != None: - self.reconnect_count = 0 - _thread.stack_size(self.thread_buf_size+8*1024) #_thread.stack_size(16*1024) - self.iot_web_send_queue_id = _thread.start_new_thread(self.socket_send_queue_thread, ()) - _thread.stack_size(8*1024) - - _thread.stack_size(self.thread_buf_size+8*1024) - self.iot_web_protoclo_recv_id = _thread.start_new_thread(self.iot_protocol_recv, ()) - _thread.stack_size(8*1024) - - else: - print("self.iot_protocol_client init!!!!!!!!!") - self.reconnect_count+=1 - # EventMesh.publish("connect_iot_websocket_cb") - EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket}) #self.connect_iot_websocket() - return - - if self.iot_protocol_client != None: - self.start_voice_flag = 1 - else: - self.start_voice_flag = 0 - - print("self.iot_protocol_client %d self.start_voice_flag:%d",self.iot_protocol_client,self.start_voice_flag) - if self.iot_protocol_client != None: - if self.timer_id == 0: - # self.hr_report_timer.start(DEFINE_TIME_COUNT*1000, 1, self.hr_report_event) - self.timer_id=1 - else: - print("没有token!!!!!!!!!!") - self.connect_web_timer_count+=1 - if self.connect_web_timer_count <= 10: - self.connect_web_timer.start(5000,0,self.iot_web_connect_timerCb) - pass - except Exception as e: - self.iot_protocol_client = None - print("connect_iot_websocket error") def open_websocket_timer(self,event,msg): self.VC_pingping_timerout = 0 @@ -1736,7 +1743,7 @@ class SockMangager(Abstract): - def socket_send_queue_thread(self): + def websocket_send_queue_thread(self): while True: data = self.iot_web_send_queue.get() @@ -1758,7 +1765,7 @@ class SockMangager(Abstract): break - def iot_protocol_recv(self): + def websocket_recv_queue_thread(self): while True: # 死循环接收数据 try: @@ -2116,7 +2123,7 @@ class IOTWeb_locatedurationProtoCol(ProtoCol): location_time["state"]=locate_duration_state EventMesh.publish("set_storage_config",["locate_duration_time",location_time]) - EventMesh.publish("set_location_timer",location_time) + EventMesh.publish("set_location_info",location_time) locate_duration_c = EventMesh.publish("get_storage_config","locate_duration_time") print("locate_duration_c:{}".format(locate_duration_c)) @@ -3504,8 +3511,9 @@ class IOTWeb_connect_btProtoCol(ProtoCol): ok = 1 if "data" in msg: mac = msg["data"] - # mac = "75:e8:8c:62:9a:df" - # mac = "36:72:cc:e6:dd:e8" + # mac = "36:72:cc:e6:dd:e8"#deep + # mac = "61:E8:6D:CD:7F:17" #Q36 + # mac = "75:E8:8C:62:9A:DF" Fineblue Clip if len(mac) == 17: ok = 1 EventMesh.publish("send_connect_bt_mac",mac) diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ui.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ui.py index 84fa866a..de44198a 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ui.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ui.py @@ -277,7 +277,8 @@ class UI(object): self.__lcd_on() def system_sleep_timer_cb(self, *args): - #EventMesh.debug_log("system_sleep_timer_count:{}".format(self.system_sleep_timer_count)) + EventMesh.publish("publish_message_event_ui",{"func":self.system_sleep_timer_,"data":0}) + def system_sleep_timer_(self,data): time = EventMesh.publish("get_brightness_time") if time == None: time = 20