From: dxy <1731678236qq.com> Date: Fri, 15 Aug 2025 06:10:18 +0000 (+0800) Subject: SOS优化 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=4c409f25026efb6f2f9d2b035b824ab9e66b4c2b;p=mirrors%2FASR1603_G5.git SOS优化 --- 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 cd3f295e..5b746946 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 @@ -623,6 +623,8 @@ class AI_dev(Abstract): print("等待网络 {}...".format(count)) utime.sleep_ms(500) self.KeyAI_timer = osTimer() + self.KeySOS_timer = osTimer() + self.KeySOS_timer_count = 0 if dev_type == "G10" : self.extint_AI = ExtInt(ExtInt.GPIO19,ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.keyAI_extint_cb) self.pwk_key = ExtInt(ExtInt.GPIO26, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_PU, self.pwk_extint_cb) @@ -674,6 +676,7 @@ class AI_dev(Abstract): EventMesh.subscribe("sleep_BT",self.sleep_BT) EventMesh.subscribe("sys_sleep_cb",self.sys_sleep_cb) EventMesh.subscribe("GET_USB_STATE",self.get_usb_state) + EventMesh.subscribe("SET_TTS_VOLUME",self.set_tts_volume) print("AI_dev:2") self.pk = PowerKey() @@ -692,6 +695,7 @@ class AI_dev(Abstract): if self.VC_TTS_volume == None: self.VC_TTS_volume = 100 self.aud.setVolume(self.VC_TTS_volume //10) + EventMesh.publish("set_storage_config",["VC_TTS_volume",self.VC_TTS_volume]) #self.aud.play(1,0,'U:/static/xianyikaiji.mp3')#开机音频 #EventMesh.publish("audio_montage_play",["xianyikaiji.mp3"]) #EventMesh.publish("publish_AI_btnInfo",{"func":self.ntptime_cb}) @@ -750,6 +754,11 @@ class AI_dev(Abstract): #self.aud.play(1,1,'U:/static/R_CHARGE_OUT.mp3') def get_usb_state(self,event,msg): return self.usb_status + def set_tts_volume(self,event,msg): + EventMesh.publish("set_storage_config",["VC_TTS_volume",msg])#音量配置 + self.VC_TTS_volume = msg + self.aud.setVolume(self.VC_TTS_volume //10) + pass def btnInfo_queue_thread(self): while True: data = self.btnInfo_queue.get() @@ -930,11 +939,13 @@ class AI_dev(Abstract): self.KeyAI_status = self.extint_AI.read_level() self.KeyAI_timer_count +=1 if self.KeyAI_timer_count >= 10*1 : #长按1s + self.KeySOS_timer_count = 0 if self.KeyAI_long_press == 0: self.KeyAI_long_press = 1 #EventMesh.publish("AI_key_long_press") EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_key_long_press}) elif self.KeyAI_timer_count >= 10*8:#关机 + self.KeySOS_timer_count=0 if dev_type == 'jswm' or dev_type == 'jswm_BOX': EventMesh.publish("audio_montage_play",["zhengzaiguanji.mp3"]) #self.aud.play(1,0,'U:/static/zhengzaiguanji.mp3')#关机音频 @@ -963,7 +974,13 @@ class AI_dev(Abstract): self.check_rest_timer_count = 0 print("AI_key_press") EventMesh.publish("AI_key_press") - + def KeySos_timer_cb(self,*argc): + if self.KeySOS_timer_count >= 3: + self.KeySOS_timer_count = 0 + get_sos_flag = EventMesh.publish("get_sos_flag") + if get_sos_flag == 0: + EventMesh.publish("set_sos_info_call") + pass def AI_key_long_press(self): self.check_rest_timer_count = 0 print("AI_key_long_press") @@ -972,7 +989,8 @@ class AI_dev(Abstract): def AI_key_release(self): print("AI_key_release") - + self.KeySOS_timer_count +=1 + self.KeySOS_timer.start(500, 0, self.KeySos_timer_cb) EventMesh.publish("AI_key_release") def pwk_key_Long_Press(self,event=None,msg=None): @@ -1523,8 +1541,6 @@ class device_res_author(Abstract): if len(EventMesh.publish("get_dev_token")) != 0: if self.connect_web_flag == 0: EventMesh.publish("post_iccid_user") - EventMesh.publish("connect_iot_websocket_cb") - self.connect_web_flag = 1 print("dev_sign_in end") #ICCID上传 @@ -2677,6 +2693,8 @@ class AI_VC(Abstract): self.Close() EventMesh.publish("start_voice_record",2)#停止静默录音 return + if EventMesh.publish("get_sos_flag") == 1: + return EventMesh.publish("stop_voice_record") #开启静默需要关闭 print("AI_key_press") self.get_config_timer_count = 0 @@ -4674,6 +4692,7 @@ class AI_VC(Abstract): } } } + self.AI_new_voice_url = "" print("AI_client_new_voice!!!!!!!!!!!!!!!!!!!!!!!!!!!!!{}".format(json_data)) self.AI_client_VC_send(ujson.dumps(json_data)) @@ -4866,7 +4885,8 @@ class AI_VC(Abstract): if self.AI_VC_send_data_queue.empty()!=True: self.AI_VC_send_data_queue.clear() - + self.play_new_voice_flag = 0 #语音消息播放状态 + self.AI_new_voice_url ="" #语音播放地址 self.AI_ASR_send_buf_len = 0 #self.AI_WS_connect_Queue.put(self.AI_client_VC) EventMesh.publish("close_led") 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 7029bdb0..23249ae0 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 @@ -441,8 +441,8 @@ class IOTWebLocationManager(Abstract): TYPE = self.location_queue.get() # (5, [('70:2A:D7:63:BD:B4', -38), ('C0:94:AD:80:21:5F', -61), ('D8:38:0D:05:1F:E3', -65), ('08:9E:84:E7:A6:38', -73), ('B0:44:14:BC:13:B0', -73)]) wifi_tmp = [] - print("wifi_num:{}".format(wifi_num)) wifi_num = msg[0][0] + print("wifi_num:{}".format(wifi_num)) if wifi_num == 0: wifi_tmp = [] else: #([], [], [(0, 69483137, 1120, 1, 385, 30504, 100, -75, -8), (3, 111950593, 1120, 1, 58, 30504, 1650, -98, -19), (3, 219097617, 1120, 17, 76, 30504, 2452, -106, -23), (3, 102345712, 1120, 1, 58, 30504, 3740, -96, -18)]) @@ -756,6 +756,7 @@ class IOTSendCmdManager(Abstract): #设备上报状态上报数据格式 def device_report_state_send_data(self): + get_volume = EventMesh.publish("get_storage_config","VC_TTS_volume") device_report_data ={ "cmd":"post_device_state", "ts":self.time_tmp, @@ -763,7 +764,7 @@ class IOTSendCmdManager(Abstract): "mediaTitle":"haha", "mediaState":"stop", "cover":"899", - "volume":45 + "volume":get_volume } } # HR_DATA=EventMesh.publish("GET_IOT_WEB_SEND_CMD",WEB_CMD_ENUM.POST_DEVICE_STATE_S_CMD) @@ -902,7 +903,7 @@ class sosInfoCallManager(Abstract): if EventMesh.publish("get_storage_config","sos_config") != None: self.sos_config= EventMesh.publish("get_storage_config","sos_config") - # sos_list=[{"index":0,"phone":"15521469561"}, {"index":0,"phone":"15692025051"},{"index":0,"phone":"15521469561"}] + self.sos_list=[{"index":0,"phone":"15521469561","name":"dengxueying0"}, {"name":"dengxueying1","index":0,"phone":"15692025051"},{"name":"dengxueying2","index":0,"phone":"15521469561"}] EventMesh.subscribe("call_out_cb", self.call_out_cb) EventMesh.subscribe("get_sos_flag", self.get_sos_flag) @@ -930,9 +931,23 @@ class sosInfoCallManager(Abstract): pass def sos_call_out_phone(self, msg):#电话拨出去 if self.call_state == 0: - voiceCall.callStart(self.sos_phone_num) + ret = voiceCall.callStart(self.sos_phone_num) + if ret == -1: + self.call_state = 0 + self.num=0 #不管有没有拨打sos都清除 + self.num_len = 0 + self.sos_flag = 0 + tts_str = "请确认卡支持语音拨号及余额充足" + EventMesh.publish("stop_voice_record") #电话优先级最高 + EventMesh.publish("stop_AI_record") + EventMesh.publish("play_tts",[tts_str,1]) #播放tts闹钟文本内容 + + return + def phone110112_cb(self,*argc): if self.call_state == 0: + EventMesh.publish("stop_voice_record") #电话优先级最高 + EventMesh.publish("stop_AI_record") voiceCall.callStart(self.phone110112) self.phone110112 = "" # if ("btStateSwitch".equals(testType)) { @@ -958,9 +973,10 @@ class sosInfoCallManager(Abstract): if self.call_state == 0: self.sos_phone_num = phonenumber - EventMesh.publish(constants.EVENT.START_LOCATION,WEB_CMD_ENUM.POST_SOS_S_CMD) #开始AL定位 - self.sos_timer1.start(2000, 0, self.sos_call_out_phone) + self.sos_timer1.start(4000, 0, self.sos_call_out_phone) self.sos_timer2.start(30000, 0, self.sos_time_out_phone) + EventMesh.publish(constants.EVENT.START_LOCATION,WEB_CMD_ENUM.POST_SOS_S_CMD) #开始AL定位 + def sos_time_out_phone(self, msg):#30s超时未打通或者信号不好则重新拨打 if self.sos_flag == 1: @@ -973,9 +989,19 @@ class sosInfoCallManager(Abstract): if sim.getStatus() != 1:#网络正常 self.sos_flag = 0 self.num = 0 + self.call_state = 0 + self.num=0 #不管有没有拨打sos都清除 + self.num_len = 0 + self.sos_flag = 0 + tts_str = "无SIM卡" + EventMesh.publish("stop_voice_record") #电话优先级最高 + EventMesh.publish("stop_AI_record") + EventMesh.publish("play_tts",[tts_str,1]) #播放tts闹钟文本内容 return if self.call_state != 0: return + EventMesh.publish("stop_voice_record") #电话优先级最高 + EventMesh.publish("stop_AI_record") if self.sos_flag == 0: self.sos_flag = 1 sos_flag = self.sos_flag @@ -1048,6 +1074,7 @@ class sosInfoCallManager(Abstract): self.num_len = 0 self.sos_flag = 0 #未设置号码 + def voice_callback(self,args): EventMesh.debug_log('111test voicecall iinfo:{}'.format(args)) @@ -1105,7 +1132,7 @@ try: except Exception as e: usys.print_exception(e) import ai_alarm as _schedule -DEFIEN_HR_REPORT_TIME = 3*60 +DEFIEN_HR_REPORT_TIME = 5*60 DEFIEN_LOCATION_REPORT_TIME = 60 WEB_CONNECT_MAX_COUNT = 10 #默认重连次数 class SockMangager(Abstract): @@ -1132,6 +1159,8 @@ class SockMangager(Abstract): self.schedule = _schedule.schedule() self._1S_timer = osTimer() self.timer_id = 0 + self.start_voice_flag = 0 + self.init_send_default=0 EventMesh.subscribe("REPORT_ALARM_TO_IOT",self.report_alarm_to_iot) def report_alarm_to_iot(self,event,msg): @@ -1174,65 +1203,13 @@ class SockMangager(Abstract): self.connect_web_timer.start(5*1000,0,self.iot_web_connect_timerCb) self.timerHr = 0 self.reconnect_count = 0 - self.voice_id = "" + self.voice_id = "0" self.deviceReadState = "" self.reconnect_count = 0 self.test_id = 0 self.bt_connect_list = [] - self.new_voice_list = [ - { - "id":"1", - "url": "http://qipaiai-oss1.tos-cn-beijing.volces.com/qi_pai_ringtone/2025_08_11/742659759219544064test.mp3", - "size": 0, - "from": "user/dev", - "duration": 12, - "deviceId": "设备ID", - "userId": "用户ID", - "userReadState": "1", - "deviceReadState": "1", - "md5": "md5", - "fileName": "文件名" - }, - { - "id":"2", - "url": "http://qipaiai-oss1.tos-cn-beijing.volces.com/qi_pai_ringtone/2025_08_11/742659759219544064test.mp3", - "size": 0, - "from": "user/dev", - "duration": 12, - "deviceId": "设备ID", - "userId": "用户ID", - "userReadState": "1", - "deviceReadState": "1", - "md5": "md5", - "fileName": "文件名" - }, - { - "id":"3", - "url": "http://qipaiai-oss1.tos-cn-beijing.volces.com/qi_pai_ringtone/2025_08_11/742659759219544064test.mp3", - "size": 0, - "from": "user/dev", - "duration": 12, - "deviceId": "设备ID", - "userId": "用户ID", - "userReadState": "1", - "deviceReadState": "1", - "md5": "md5", - "fileName": "文件名" - }, - { - "id":"4", - "url": "http://qipaiai-oss1.tos-cn-beijing.volces.com/qi_pai_ringtone/2025_08_11/742659759219544064test.mp3", - "size": 0, - "from": "user/dev", - "duration": 12, - "deviceId": "设备ID", - "userId": "用户ID", - "userReadState": "1", - "deviceReadState": "1", - "md5": "md5", - "fileName": "文件名" - } - ] + self.new_voice_list = [] + def save_bt_connect_list(self,event,msg): print("msg:{}".format(msg)) # msg = {"event":"bt_connect_single","data":{"name":"yeiwyei","mac":"89:89:78:78:98:89","state":"connected"}} @@ -1281,19 +1258,6 @@ class SockMangager(Abstract): pass def play_new_voice_list(self,event,msg): - # { - # "id":"语音ID" - # "url": "音频地址", - # "size": 0大小,kb, - # "from": "user/dev", - # "duration": 12 秒, - # "deviceId": "设备ID", - # "userId": "用户ID", - # "userReadState": "0/1阅读状态", - # "deviceReadState": "0/1阅读状态", - # "md5": "md5", - # "fileName": "文件名" - # } print("play_new_voice_list:{}".format(len(self.new_voice_list))) if len(self.new_voice_list) != 0: @@ -1302,7 +1266,6 @@ class SockMangager(Abstract): self.voice_index = i self.voice_id = data["id"] url = data["url"] - # url = "http://qipaiai-oss1.tos-cn-beijing.volces.com/qi_pai_ringtone/2025_08_11/742659759219544064test.mp3" EventMesh.publish("play_new_voice",[url,1]) @@ -1459,7 +1422,7 @@ class SockMangager(Abstract): # self.alarm_test() EventMesh.publish("set_curr_battery_level",bat_total_value) # EventMesh.publish("publish_AI_btnInfo",{"func":self.hr_report_publish_event,"data":0}) - self.timerHr+=1 + self.timerHr+=10 if self.timerHr >= DEFIEN_HR_REPORT_TIME: self.timerHr= 0 self.reconnect_count = 0 @@ -1470,7 +1433,7 @@ class SockMangager(Abstract): self.timerLocation = 0 else: if locate_duration_c != 0: - self.timerLocation+=1 + self.timerLocation+=10 if self.timerLocation >= locate_duration_c: self.timerLocation= 0 print("timerLocation") @@ -1524,7 +1487,6 @@ class SockMangager(Abstract): if sim.getStatus() != 1 or self.start_voice_flag == 1:#网络正常 return - if self.reconnect_count >= WEB_CONNECT_MAX_COUNT: #重连次数大于10次不在进重连只有下发心跳才重新连接 return @@ -1545,6 +1507,7 @@ class SockMangager(Abstract): 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.socket_send_queue_id = _thread.start_new_thread(self.socket_send_queue_thread, ()) _thread.stack_size(8*1024) @@ -1552,8 +1515,7 @@ class SockMangager(Abstract): _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) - - EventMesh.publish("publish_AI_btnInfo",{"func":self.hr_report_publish_event,"data":0}) + else: print("self.iot_protocol_client init!!!!!!!!!") self.reconnect_count+=1 @@ -1569,7 +1531,11 @@ class SockMangager(Abstract): 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(1000, 1, self.hr_report_event_cb) + self.hr_report_timer.start(10000, 1, self.hr_report_event_cb) + EventMesh.publish("publish_AI_btnInfo",{"func":self.hr_report_publish_event,"data":0}) + 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) #上报设备状态 self.timer_id=1 except Exception as e: @@ -1697,6 +1663,7 @@ class SockMangager(Abstract): if self.start_voice_flag == 0: #如果关闭了就需要重新再 self.reconnect_count+=1 EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket}) + return self.iot_web_send_queue.put(data) EventMesh.debug_log("self.socket_send_queue.put:success:{}".format(len(data))) @@ -1837,7 +1804,6 @@ class IOTWeb_fence_sosProtoCol(ProtoCol): if len(sos_list) > 0: get_sos_flag = EventMesh.publish("get_sos_flag") if get_sos_flag == 0: - EventMesh.publish("set_sos_info_call") pass print("recv fence_sos{}".format(msg)) @@ -2269,9 +2235,7 @@ class IOTWeb_volumeProtoCol(ProtoCol): if "data" in msg: r_volume = msg["data"] print("recv volume{} type:{}".format(r_volume,type(msg))) - EventMesh.publish("set_storage_config",["volume",int(r_volume)]) - vloum = EventMesh.publish("get_storage_config","volume") - print(vloum) + EventMesh.publish("SET_TTS_VOLUME",int(r_volume)) EventMesh.publish(WEB_CMD_ENUM.VOLUME_S_CMD,None) #下发SOS配置 class IOTWeb_sos_configProtoCol(ProtoCol): @@ -2420,27 +2384,30 @@ class IOTWeb_voice_recordProtoCol(ProtoCol): s_rest = "0" if data == "0": s_rest = "0" - EventMesh.publish(WEB_CMD_ENUM.VOICE_RECORD_S_CMD,s_rest) + record_mode = EventMesh.publish("get_voice_record_mode") if record_mode == None: record_mode = 0 - if record_mode == 2:#语音留言不允许打断 - pass - else: - EventMesh.publish("stop_voice_record",1) + if record_mode != 2:#语音留言不允许打断 + EventMesh.publish("stop_voice_record") print("停止录音") + EventMesh.publish(WEB_CMD_ENUM.VOICE_RECORD_S_CMD,s_rest) elif data == "1": - s_rest = "1" - EventMesh.publish(WEB_CMD_ENUM.VOICE_RECORD_S_CMD,s_rest) + + record_mode = EventMesh.publish("get_voice_record_mode") if record_mode == None: record_mode = 0 - if record_mode == 2:#语音留言不允许打断 - pass - else: + if record_mode != 2:#语音留言不允许打断 + s_rest = "1" + EventMesh.publish(WEB_CMD_ENUM.VOICE_RECORD_S_CMD,s_rest) EventMesh.publish("start_voice_record",1) - + + else: + s_rest = "0" + EventMesh.publish(WEB_CMD_ENUM.VOICE_RECORD_S_CMD,s_rest) + print("开始录音") @@ -2663,26 +2630,26 @@ class IOTWeb_new_voice_msg_listProtoCol(ProtoCol): @param event:new_voice_msg_list @param msg: 接收到的下行数据 """ - new_voice_msg_list = { - "cmd":"new_voice_msg_list", - "ts":1738283829, - "msg":"请求未读的语音消息列表", - "data":[ - { - "id":"语音ID", - "url": "音频地址", - "size": 0, - "from": "user/dev", - "duration": 12, - "deviceId": "设备ID", - "userId": "用户ID", - "userReadState": "1", - "deviceReadState": "1", - "md5": "md5", - "fileName": "文件名" - } - ] - } + # new_voice_msg_list = { + # "cmd":"new_voice_msg_list", + # "ts":1738283829, + # "msg":"请求未读的语音消息列表", + # "data":[ + # { + # "id":"语音ID", + # "url": "音频地址", + # "size": 0, + # "from": "user/dev", + # "duration": 12, + # "deviceId": "设备ID", + # "userId": "用户ID", + # "userReadState": "1", + # "deviceReadState": "1", + # "md5": "md5", + # "fileName": "文件名" + # } + # ] + # } new_voice_list = [] if "data" in msg: data = msg["data"] diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/voice_record.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/voice_record.py index cc7df050..08363162 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/voice_record.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/voice_record.py @@ -63,17 +63,22 @@ class VOICE_RECORD(Abstract): #静默录音 def get_voice_record_mode(self,event,msg): return self.voice_mode def start_voice_record(self,event,msg): + if EventMesh.publish("get_sos_flag") == 1: + return get_VC_satrt_flag = EventMesh.publish("get_VC_satrt_flag") if get_VC_satrt_flag == None: get_VC_satrt_flag = 0 - if get_VC_satrt_flag == 1: #在AI对话不允许静默录音 - return -1 + if msg == 1: #静默录音 + if get_VC_satrt_flag == 1: #在AI对话不允许静默录音 + return -1 + if self.voice_mode == 1 and self.start_voice_record_flag == 1: #如果上一个是静默录音并且正在录音 需要语音留言 关闭触再发语音留言 + EventMesh.publish("stop_voice_record") if self.start_voice_record_flag == 1: return -1 #开启线程 #开启录音 EventMesh.publish("stop_voice_record") - self.voice_mode = msg #录音模式 1静默录音 2 语音留言 + self.voice_mode = msg #录音模式 1静默录音 2 语音留言 0没有录音模式 self.start_voice_record_flag = 1 self.connect_web_count = 0 if self.voice_record_thread_id == 0: