优化协议部分功能
authordxy <1731678236qq.com>
Fri, 15 Aug 2025 09:48:53 +0000 (17:48 +0800)
committerdxy <1731678236qq.com>
Fri, 15 Aug 2025 09:48:53 +0000 (17:48 +0800)
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ai_VC.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ai_alarm.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/main_init.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/protocol.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/voice_record.py

index 6332b27..ce77c5b 100644 (file)
@@ -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<self.VBATT_tab["20"]and VC_satrt_flag == 0 and self.Low_power_warning_flag ==0:#低电报警
+        if  self.usb_status == 0 and Vbatt<self.VBATT_tab["20"]and VC_satrt_flag == 0 and self.Low_power_warning_flag ==0 and voice_record_satrt_flag == 0:#低电报警
             self.Low_power_warning_flag  = 1
             EventMesh.publish("flicker_led_red")
             #self.aud.play(1,0,'Low_power_warning.mp3')
@@ -1747,7 +1750,10 @@ class OTA():
             VC_satrt_flag = EventMesh.publish("get_VC_satrt_flag")#获取vc是否在运行
             if VC_satrt_flag == None:
                 VC_satrt_flag = 0
-            if VC_satrt_flag == 0 or count<=0:
+            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 count<=0 or voice_record_satrt_flag == 0:
                 break
             utime.sleep_ms(100)
         
@@ -3605,15 +3611,15 @@ class AI_VC(Abstract):
                             else:
                                 EventMesh.publish("publish_AI_btnInfo",{"func":self.websocket_error,"data":jsload_data["payload"]["message"]}) 
                             pass
-                            if self.play_new_voice_flag == 1:
-                                self.play_new_voice_flag=0
+                            if EventMesh.publish("get_play_new_voice_state")== 1:
+                                EventMesh.publish("set_play_new_voice_state",1)
                                 EventMesh.publish("update_play_new_voice_info")
                                 EventMesh.publish("play_new_voice_list")
                                 pass
 
                         elif jsload_data["event"] == "audio.convert.completed":#接口
-                            if self.play_new_voice_flag == 1:
-                                self.play_new_voice_flag=0
+                            if EventMesh.publish("get_play_new_voice_state")== 1:
+                                EventMesh.publish("set_play_new_voice_state",1)
                                 EventMesh.publish("update_play_new_voice_info")
                                 EventMesh.publish("play_new_voice_list")
                                 
index 44d5cff..87a87ea 100644 (file)
@@ -296,6 +296,7 @@ class AI_alarm():
                     AringTimes  = alarm_TTS_str["ringTimes"]
                     alarmMode = alarm_TTS_str["alarmMode"]
                     shakeType = alarm_TTS_str["shakeType"]
+                    ringUrl = alarm_TTS_str["ringUrl"]
                     print("{} {} {}".format(AringTimes,alarmMode,shakeType))
                     if alarmMode == "ring": #只响铃
                         tts_audio = "chenggong.mp3"
@@ -303,7 +304,12 @@ class AI_alarm():
                             AringTimes = 1
                         tts_str = [tts_audio] * AringTimes
                         print(tts_str)
-                        # EventMesh.publish("audio_montage_play",tts_str) 
+                        if ringUrl == None:
+                            pass
+                            # EventMesh.publish("audio_montage_play",tts_str) 
+                        else:
+                            pass
+                            # EventMesh.publish("play_new_voice",[ringUrl,1])
                         pass
                     elif alarmMode == "shake": #只振动
                         if shakeType == "short":
@@ -317,7 +323,12 @@ class AI_alarm():
                         if AringTimes == 0:
                             AringTimes = 1
                         tts_str = [tts_audio] * AringTimes
-
+                        if ringUrl == None:
+                            pass
+                            # EventMesh.publish("audio_montage_play",tts_str) 
+                        else:
+                            pass
+                            # EventMesh.publish("play_new_voice",[ringUrl,1])
                         # EventMesh.publish("audio_montage_play",tts_str) 
                         if shakeType == "short":
                             EventMesh.publish("set_motor_time",[1,1,5,8,4])#设置马达参数
index f8135d1..1994073 100644 (file)
@@ -242,6 +242,7 @@ def main_init():
             pcr.add_support(pro.IOTWeb_get_bt_connect_record_listProtoCol())
             pcr.add_support(pro.IOTWeb_bt_connect_record_listProtoCol())
             pcr.add_support(pro.IOTWeb_fence_sosProtoCol())
+            pcr.add_support(pro.IOTWeb_player_controlProtoCol())
             sm = pro.SockMangager()
 
             sm.add_support_resolver(pcr)
index 23249ae..56eca3b 100644 (file)
@@ -538,6 +538,7 @@ class IOTWebLocationManager(Abstract):
             except Exception as e:
                 usys.print_exception(e)
                 EventMesh.publish(constants.EVENT.CLOSE_LOCATION)#关闭定位 
+            utime.sleep_ms(1000)
         wifiScan.control(0)
 
                     
@@ -656,6 +657,12 @@ class WEB_CMD_ENUM:
     BT_CONNECT_RECORD_LIST_R="bt_connect_record_list_R"
     BT_CONNECT_RECORD_LIST_S="bt_connect_record_list_S"
 
+    FENCE_SOS_R="fence_sos_R"
+    FENCE_SOS_S="fence_sos_S"
+
+    PLAY_CONTROL_R="player_control_R"
+    PLAY_CONTROL_S="player_control_S"
+
 class IOTSendCmdManager(Abstract):
     #
     def __init__(self):
@@ -903,7 +910,7 @@ class sosInfoCallManager(Abstract):
         if EventMesh.publish("get_storage_config","sos_config") != None:
             self.sos_config= EventMesh.publish("get_storage_config","sos_config")
         
-        self.sos_list=[{"index":0,"phone":"15521469561","name":"dengxueying0"}, {"name":"dengxueying1","index":0,"phone":"15692025051"},{"name":"dengxueying2","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) 
 
@@ -933,16 +940,20 @@ class sosInfoCallManager(Abstract):
         if self.call_state == 0:
             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
+                self.call_state = 0
+                self.num=0 #不管有没有拨打sos都清除
+                self.num_len = 0
+                self.sos_flag = 0
+                return -1
+            else:
+                EventMesh.publish(constants.EVENT.START_LOCATION,WEB_CMD_ENUM.POST_SOS_S_CMD) #开始AL定位
+                self.sos_timer2.start(30000, 0, self.sos_time_out_phone)
+        return 1
             
     def phone110112_cb(self,*argc):
         if self.call_state == 0:
@@ -973,30 +984,30 @@ class sosInfoCallManager(Abstract):
         
         if self.call_state == 0:
             self.sos_phone_num = phonenumber
-            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定位
+            self.sos_timer1.start(2000, 0, self.sos_call_out_phone)
+            
+            
       
     def sos_time_out_phone(self, msg):#30s超时未打通或者信号不好则重新拨打
         
         if self.sos_flag == 1:
             if self.call_state == 0 or self.call_state == 3 or self.call_state == 4:
                 voiceCall.callEnd() #挂断
-                self.set_sos_info_call(1,1)
+                EventMesh.publish("set_sos_info_call") #电话优先级最高
             pass #再次拨打
 
     def set_sos_info_call(self,event,msg):
         if sim.getStatus() != 1:#网络正常
+            tts_str = "无SIM卡"
+            EventMesh.publish("stop_voice_record") #电话优先级最高
+            EventMesh.publish("stop_AI_record")
+            EventMesh.publish("play_tts",[tts_str,1])  #播放tts闹钟文本内容
             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
@@ -1133,7 +1144,7 @@ except Exception as e:
     usys.print_exception(e)
     import ai_alarm as _schedule
 DEFIEN_HR_REPORT_TIME = 5*60
-DEFIEN_LOCATION_REPORT_TIME = 60
+DEFIEN_LOCATION_REPORT_TIME = 30
 WEB_CONNECT_MAX_COUNT = 10 #默认重连次数
 class SockMangager(Abstract):
     def __init__(self):
@@ -1161,6 +1172,7 @@ class SockMangager(Abstract):
         self.timer_id = 0
         self.start_voice_flag = 0
         self.init_send_default=0
+        self.play_new_voice_state = 0
         EventMesh.subscribe("REPORT_ALARM_TO_IOT",self.report_alarm_to_iot)
 
     def report_alarm_to_iot(self,event,msg):
@@ -1188,6 +1200,8 @@ class SockMangager(Abstract):
         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)
         # count = 0
         # while True:
         #     count += 1
@@ -1199,16 +1213,17 @@ class SockMangager(Abstract):
         #         self.network_state = 1
         #         break
         #     print("web等待网络 {}...".format(count))
+
         #     utime.sleep_ms(500)
-        self.connect_web_timer.start(5*1000,0,self.iot_web_connect_timerCb)
         self.timerHr = 0
         self.reconnect_count = 0
         self.voice_id = "0"
         self.deviceReadState = ""
-        self.reconnect_count = 0
-        self.test_id = 0
+        self.get_voice_new_msginit = 0
         self.bt_connect_list = []
         self.new_voice_list = []
+        self.connect_web_timer.start(5*1000,0,self.iot_web_connect_timerCb)
+        
 
     def save_bt_connect_list(self,event,msg):
         print("msg:{}".format(msg))
@@ -1257,6 +1272,13 @@ class SockMangager(Abstract):
         self.new_voice_list = msg
         pass
 
+    def set_play_new_voice_state(self,event,msg):
+        self.play_new_voice_state = msg
+        pass
+
+    def get_play_new_voice_state(self,event,msg):
+        return self.play_new_voice_state
+
     def play_new_voice_list(self,event,msg):
         print("play_new_voice_list:{}".format(len(self.new_voice_list)))
         if len(self.new_voice_list) != 0:
@@ -1267,6 +1289,7 @@ class SockMangager(Abstract):
                 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"
+                self.play_new_voice_state = 1
                 EventMesh.publish("play_new_voice",[url,1])
                 
                 break
@@ -1305,14 +1328,14 @@ class SockMangager(Abstract):
     def send_jm_audio_to_iot(self,event,msg):
         send_data = b''
         send_data = protocol_audio_ji_playload_data(msg[0],msg[1],msg[2])
-        print("jm:{}".format(send_data[9]))
+        # print("jm:{}".format(msg[2]))
         EventMesh.publish("CHANNEL_IOT_WEB_SEND",send_data)
         pass
 
     def send_yuyin_audio_to_iot(self,event,msg):
         send_data = b''
         send_data = protocol_yuyin_voice_playload_data(msg[0],msg[1],msg[2])
-        print("yuyin:{}".format(msg[2]))
+        # print("yuyin:{}".format(msg[2]))
         EventMesh.publish("CHANNEL_IOT_WEB_SEND",send_data)
         pass
     
@@ -1438,35 +1461,18 @@ class SockMangager(Abstract):
                     self.timerLocation= 0
                     print("timerLocation")
                     EventMesh.publish(constants.EVENT.START_LOCATION,WEB_CMD_ENUM.POST_LOCATION_S_CMD) #定位上报
+            else:
+                self.timerLocation= 0
 
-        self.timerSOS+=1
-        if self.timerSOS >= 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"
index 0836316..df074b3 100644 (file)
@@ -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)