From: dxy <1731678236qq.com> Date: Fri, 15 Aug 2025 09:48:53 +0000 (+0800) Subject: 优化协议部分功能 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=933c94a89ab00dd40760c23dd8b9eeacb7c4f4b2;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 6332b27f..ce77c5b7 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 @@ -753,7 +753,7 @@ class AI_dev(Abstract): voice_record_satrt_flag = EventMesh.publish("get_voice_record_flag")#获取静默或者语音留言是否在运行 if voice_record_satrt_flag == None: voice_record_satrt_flag = 0 - if VC_satrt_flag == 0 or voice_record_satrt_flag == 0: + if VC_satrt_flag == 0 and voice_record_satrt_flag == 0: self.aud.stop() #EventMesh.publish("flicker_led_red")#充电闪灯 #self.aud.play(1,1,'U:/static/R_CHARGE_IN.mp3') @@ -769,7 +769,7 @@ class AI_dev(Abstract): voice_record_satrt_flag = EventMesh.publish("get_voice_record_flag")#获取静默或者语音留言是否在运行 if voice_record_satrt_flag == None: voice_record_satrt_flag = 0 - if VC_satrt_flag == 0 or voice_record_satrt_flag == 0: + if VC_satrt_flag == 0 and voice_record_satrt_flag == 0: self.aud.stop() EventMesh.publish("close_led") EventMesh.publish("audio_montage_play",["R_CHARGE_OUT.mp3"]) @@ -1052,16 +1052,19 @@ class AI_dev(Abstract): VC_satrt_flag = EventMesh.publish("get_VC_satrt_flag")#获取vc是否在运行 if VC_satrt_flag == None: VC_satrt_flag = 0 + voice_record_satrt_flag = EventMesh.publish("get_voice_record_flag")#获取静默或者语音留言是否在运行 + if voice_record_satrt_flag == None: + voice_record_satrt_flag = 0 Vbatt = Power.getVbatt() - if self.usb_status == 1 and VC_satrt_flag == 0: + if self.usb_status == 1 and VC_satrt_flag == 0 and voice_record_satrt_flag == 0: EventMesh.publish("open_led_red")#充电红灯常亮 - if self.usb_status == 1 and Vbatt>=self.VBATT_tab["charge_full"]and VC_satrt_flag == 0:#充电充满 + if self.usb_status == 1 and Vbatt>=self.VBATT_tab["charge_full"]and VC_satrt_flag == 0 and voice_record_satrt_flag == 0:#充电充满 EventMesh.publish("open_led_green") if self.usb_charge_flag == 0 : EventMesh.publish("audio_montage_play",["R_CHARGE_FULL.mp3"]) #self.aud.play(1,0,'U:/static/R_CHARGE_FULL.mp3')#充电已满 self.usb_charge_flag = 1 - if self.usb_status == 0 and Vbatt= DEFIEN_LOCATION_REPORT_TIME: - self.timerSOS= 0 - print("timerSOS") - date_tmp = utime.localtime() - time_tmp = utime.mktime(date_tmp) - get_new_voice_msg = { - "cmd":"get_new_voice_msg", - "ts":time_tmp, - "msg":"请求未读的语音消息列表", - "data":None - } - - send_data = b'' - send_data = protocol_send_total_data(get_new_voice_msg) - print("send send_data{}".format(send_data)) - EventMesh.publish(WEB_CMD_ENUM.GET_NEW_VOICE_MSG_S,send_data) + + if self.timerSOS <= DEFIEN_LOCATION_REPORT_TIME : + self.timerSOS+=10 + else: + if self.get_voice_new_msginit == 0: #开机获取一次语音未读消息 + self.get_voice_new_msginit=1 + EventMesh.publish(WEB_CMD_ENUM.GET_NEW_VOICE_MSG_S,None) - # alarm_config=EventMesh.publish("GET_IOT_WEB_SEND_CMD",WEB_CMD_ENUM.POST_ALARM_S_CMD) - # print("alarm_config{}".format(alarm_config)) - # EventMesh.publish(WEB_CMD_ENUM.POST_ALARM_S_CMD,alarm_config) - - # HR_DATA=EventMesh.publish("GET_IOT_WEB_SEND_CMD",WEB_CMD_ENUM.POST_DEVICE_STATE_S_CMD) - # print("HR_DATA{}".format(HR_DATA)) - # EventMesh.publish(WEB_CMD_ENUM.POST_DEVICE_STATE_S_CMD,HR_DATA) #上报设备状态 - - # EventMesh.publish(constants.EVENT.START_LOCATION,WEB_CMD_ENUM.POST_SOS_S_CMD) #sos上报 - + # http://220.160.104.34:30800/ws-bus/test/voice-record/876226211472149?state=1, # http://220.160.104.34:30800/ws-bus/test/876226211472149?testType=alarmList def hr_report_publish_event(self,data): @@ -1487,7 +1493,7 @@ class SockMangager(Abstract): 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") @@ -1558,25 +1564,23 @@ class SockMangager(Abstract): def socket_send_queue_thread(self): while True: data = self.iot_web_send_queue.get() - EventMesh.debug_log("websocket:send data1 len:{}".format(len(data))) + if data != None: + # EventMesh.debug_log("websocket:send data1 len:{}".format(len(data))) try: - EventMesh.debug_log("websocket:send data1 len:{} {}".format(len(data),self.iot_protocol_client)) + # EventMesh.debug_log("websocket:send data1 len:{} {}".format(len(data),self.iot_protocol_client)) if self.iot_protocol_client != None: self.iot_protocol_client.send(data) self.reconnect_count = 0 else: - self.reconnect_count+=1 # EventMesh.publish("connect_iot_websocket_cb") EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket}) - EventMesh.debug_log("websocket:send data2 len:{}".format(len(data))) + EventMesh.debug_log("websocket:send data2 len:{}".format(len(data),self.iot_protocol_client)) except Exception as e: EventMesh.debug_log("websocket:send error") - self.reconnect_count+=1 # EventMesh.publish("connect_iot_websocket_cb") EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket}) break - utime.sleep_ms(10) def iot_protocol_recv(self): @@ -1588,7 +1592,6 @@ class SockMangager(Abstract): if recv_data == "websocket close": # 服务器关闭连接或客户端关闭连接 print("对端 服务器强制关闭 cli close") - self.reconnect_count+=1 # EventMesh.publish("connect_iot_websocket_cb") EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket}) break @@ -1599,11 +1602,9 @@ class SockMangager(Abstract): except Exception as e: print("cli break") - self.reconnect_count+=1 # EventMesh.publish("connect_iot_websocket_cb") EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket}) break - utime.sleep_ms(10) self.iot_web_protoclo_recv_id =None def iot_web_send_queue_close(self): @@ -1637,13 +1638,11 @@ class SockMangager(Abstract): def iot_close_web_therad(self): try: self.iot_web_send_queue_close() - print("iot_web_send_queue_close sucess!!!!!!!!") except Exception as e: print("iot_web_send_queue_close error!!!!!!!!") try: self.iot_web_protoclo_recv_close_therad() - print("iot_web_protoclo_recv_close_therad sucess!!!!!!!!") except Exception as e: print("iot_web_protoclo_recv_close_therad error!!!!!!!!") self.start_voice_flag = 0 @@ -1661,12 +1660,12 @@ class SockMangager(Abstract): else : try: 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))) + if data != None: + if len(data) != 0: + self.iot_web_send_queue.put(data) + # EventMesh.debug_log("self.socket_send_queue.put:success:{}".format(len(data))) except Exception as e: EventMesh.debug_log("self.socket_send_queue.put:ERROR:") usys.print_exception(e) @@ -1781,16 +1780,29 @@ class ProtoCol(Abstract): def recv(self, event, msg): pass -#上报心跳 +#电子围栏触发SOS警告 class IOTWeb_fence_sosProtoCol(ProtoCol): """fence_sos""" TYPE = "fence_sos" def send(self, event, msg): print("send fence_sos{}".format(msg)) + date_tmp = utime.localtime() + time_tmp = utime.mktime(date_tmp) # 通过websocket发送到服务器端 + fence_sos = { + "cmd":"dispatch_rest", + "ts":time_tmp, + "msg":"消息收到响应", + "data":{ + "cmd":"fence_sos", + "rest":"success", + "msg":"收到紧急呼叫指令" + } + } send_data = b'' - send_data = protocol_send_total_data(msg) + send_data = protocol_send_total_data(fence_sos) + print("send fence_sos{}".format(send_data)) EventMesh.publish("CHANNEL_IOT_WEB_SEND", send_data) def recv(self, event, msg): @@ -1799,6 +1811,7 @@ class IOTWeb_fence_sosProtoCol(ProtoCol): @param event: 心跳成功 @param msg: 接收到的下行数据 """ + EventMesh.publish(WEB_CMD_ENUM.FENCE_SOS_S,None) sos_list = EventMesh.publish("get_storage_config","sos_list") if sos_list != None: if len(sos_list) > 0: @@ -1806,6 +1819,7 @@ class IOTWeb_fence_sosProtoCol(ProtoCol): if get_sos_flag == 0: EventMesh.publish("set_sos_info_call") pass + print("recv fence_sos{}".format(msg)) #上报心跳 class IOTWeb_HRProtoCol(ProtoCol): @@ -2580,7 +2594,7 @@ class IOTWeb_get_new_voice_msgProtoCol(ProtoCol): send_data = b'' send_data = protocol_send_total_data(get_new_voice_msg) print("send get_new_voice_msg{}".format(send_data)) - EventMesh.publish("CHANNEL_IOT_WEB_SEND",msg) + EventMesh.publish("CHANNEL_IOT_WEB_SEND",send_data) def recv(self, event, msg): """ @@ -2598,8 +2612,81 @@ class IOTWeb_get_new_voice_msgProtoCol(ProtoCol): # "msg":"收到请求新语音列表." # } # } - print("recv send_data{}".format(msg)) + print("recv get_new_voice_msg{}".format(msg)) +# 1播放 0暂停 2上一首 3下一首 +class IOTWeb_player_controlProtoCol(ProtoCol): + """player_control""" + TYPE = "player_control" + def send(self, event, msg): + # 通过websocket发送到服务器端 + date_tmp = utime.localtime() + time_tmp = utime.mktime(date_tmp) + paly_str = "停止" + paly_data = "stop" + if msg == 1: + paly_str = "播放" + paly_data = "play" + pass + elif msg == 0: + paly_str = "停止" + paly_data = "stop" + pass + elif msg == 2: + paly_str = "上一首" + paly_data = "pre" + pass + elif msg == 3: + paly_str = "下一首" + paly_data = "next" + pass + player_control = { + "cmd":"player_control", + "ts":time_tmp, + "msg":paly_str, + "data":paly_data + } + + send_data = b'' + send_data = protocol_send_total_data(player_control) + print("send player_control{}".format(send_data)) + EventMesh.publish("CHANNEL_IOT_WEB_SEND",msg) + + def recv(self, event, msg): + """ + + @param event:get_new_voice_msg + @param msg: 接收到的下行数据 + """ + # { + # "cmd":"post_rest", + # "ts":1738283829, + # "msg":"消息收到响应", + # "data":{ + # "cmd":"player_control", + # "rest":"success|error", + # "msg":"收到播放/停止/暂停指令/下一首/上一首" + # } + # } + paly_state = 0 + if "data" in msg: + data = msg["data"] + msg_str = data["msg"] + if msg_str.find("播放") != -1: + paly_state=1 + pass + elif msg_str.find("停止") != -1: + paly_state=0 + pass + elif msg_str.find("下一首") != -1: + paly_state = 3 + pass + elif msg_str.find("上一首") != -1: + paly_state = 2 + pass + + EventMesh.publish(WEB_CMD_ENUM.PLAY_CONTROL_S,paly_state) + print("recv send_data{}".format(msg)) class IOTWeb_new_voice_msg_listProtoCol(ProtoCol): """new_voice_msg_list""" TYPE = "new_voice_msg_list" 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 08363162..df074b3e 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 @@ -46,6 +46,7 @@ class VOICE_RECORD(Abstract): #静默录音 self.start_voice_record_flag = 0 self.connect_web_count = 0 self.iot_protocol_client = None + self.VC_record_samplerate = 16000 self.msgid_int = 0 self.open_start = 0 #是否需要超时关闭静默录音 self.voice_timer_out = osTimer() @@ -153,12 +154,13 @@ class VOICE_RECORD(Abstract): #静默录音 EventMesh.publish("SEND_JINMOAUDIO_TO_IOT",[read_buf,self.msgid_int,self.start_voice_record_flag]) elif self.voice_mode == 2: #语音留言开始 + EventMesh.publish("SEND_YUYINAUDIO_TO_IOT",[read_buf,self.msgid_int,self.start_voice_record_flag]) if self.start_voice_record_flag == 0: break except Exception as e: usys.print_exception(e) - print("voice Record_len:{}".format(Record_len)) + # print("voice Record_len:{}".format(Record_len)) except Exception as e: usys.print_exception(e) utime.sleep_ms(100)