From: azao <821478748@qq.com> Date: Thu, 26 Feb 2026 06:49:32 +0000 (+0800) Subject: 修改柒牌适配金三,并按双按键设计需求修改完成 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=7c949f4fd096a4e53fd792b4c231ac3ed0229558;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 0c40918e..c5ea7e0f 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 @@ -1059,6 +1059,11 @@ class AI_dev(Abstract): self.pwk_key_long_press = 0 self.pwk_key_press = 0 self.pwk_key_timer = osTimer() + self.pwk_is_double_timer = osTimer() + self.double_click_threshold = 1000#双击间隔时间 + self.pwk_press_count = 0#按下次数 + self.last_key_time = 0 # 上一次有效触发时间 + self.key_debounce_interval = 20 # 防抖窗口20ms,标准值 #self.pwk_key = ExtInt(ExtInt.GPIO26, ExtInt.IRQ_RISING_FALLING, ExtInt.PULL_DISABLE, self.pwk_extint_cb) self.pwk_key.enable() @@ -1313,24 +1318,90 @@ class AI_dev(Abstract): def pwk_extint_cb(self,args):#pwk + current_time = 0 + interval = 0 + try: + # 1. 按键电平判断(硬件低电平按下,根据实际调整) + press_level = 0 + current_level = self.pwk_key.read_level() + if current_level != press_level: + return # 非按下状态,直接返回 + + # 2. 消抖处理 + current_time = utime.ticks_ms() + if utime.ticks_diff(current_time, self.last_key_time) < self.key_debounce_interval: + return + self.last_key_time = current_time # 更新最后按键时间 + print("pwk 按键按下") + + # 3. 仅处理"按下瞬间"事件(避免重复触发) + if len(args) < 2: + print("args参数不足,跳过") + return self.pwk_key_status = int(args[1]) - if self.pwk_key_status == 0: - self.pwk_key_status = 1 - else: - self.pwk_key_status = 0 - pass - if self.pwk_key_status == 0:#按下 + if self.pwk_key_status != 1: + return + + # 4. 双击计数逻辑 + self.pwk_press_count += 1 + current_time = utime.ticks_ms() + + #第一次按下(启动长按定时器+双击等待) + if self.pwk_press_count == 1: + self.pwk_first_press_time = current_time # 记录首次按下时间 + self.pwk_key_long_press = 0 # 重置长按标记 + self.pwk_key_timer_count = 0 # 重置定时器计数 + self.pwk_key_press = 1 # 标记按键按下 - if self.pwk_key_press == 0 : - self.pwk_key.disable() - self.pwk_key_press = 1 - self.pwk_key_long_press = 0 - self.pwk_key_timer.start(100, 1, self.pwk_key_timer_cb) + # 停止旧定时器,启动长按/单击判定定时器(100ms单次触发,循环靠回调自启) + self.pwk_key_timer.stop() + self.pwk_key_timer.start(100, 1, self.pwk_key_timer_cb) + print("第一次按下,等待第二次按下") + + #第二次按下(双击判断) + elif self.pwk_press_count == 2: + # 计算两次按下间隔 + interval = utime.ticks_diff(current_time, self.pwk_first_press_time) + + # 2.1 符合双击阈值:执行双击逻辑 + if interval <= self.double_click_threshold: + self.pwk_key_timer.stop() # 停止长按定时器(关键:避免触发长按) + self.pwk_key_double_press() # 执行双击业务 + print("双击生效") + # 重置所有状态 + self.pwk_press_count = 0 + self.pwk_key_press = 0 self.pwk_key_timer_count = 0 - #EventMesh.publish("AI_key_press") - except Exception as e: + + # 2.2 间隔过长:视为新的第一次按下 + else: + self.pwk_first_press_time = current_time # 更新首次按下时间 + self.pwk_press_count = 1 # 重置为第一次按下 + print("间隔过长,视为新的第一次按下") + + #按下次数超过2次(防计数溢出) + else: + self.pwk_press_count = 0 + self.pwk_key_timer.stop() + print("按键次数过多,重置计数") + + except Exception as e: + # 异常时重置所有状态,避免卡死 + self.pwk_press_count = 0 + self.pwk_key_press = 0 + self.pwk_key_timer_count = 0 + self.pwk_key_timer.stop() usys.print_exception(e) + + + def pwk_is_double_judge(self, *args): + # if self.press_count == 1: # 仅一次按下,判定为单击 + + # 重置计数(无论何种情况,超时后清零) + self.pwk_press_count = 0 + + def pwk_key_timer_cb(self, *args, **kwargs): EventMesh.publish("set_wait_first_flag",0) EventMesh.publish("set_history_board_flag",0) @@ -1367,10 +1438,10 @@ class AI_dev(Abstract): #EventMesh.publish("AI_key_release") EventMesh.publish("publish_AI_btnInfo",{"func":self.pwk_key_release}) self.pwk_key.enable() - self.pwk_key_timer.stop() self.pwk_key_timer_count = 0 self.pwk_key_press = 0 - + self.pwk_press_count = 0#按下次数 + self.pwk_key_timer.stop() except Exception as e: usys.print_exception(e) @@ -1398,7 +1469,7 @@ class AI_dev(Abstract): if EventMesh.publish("get_play_new_voice_state") == 1: EventMesh.publish("set_play_new_voice_state",0) - EventMesh.publish("set_VC_stop_play_audio_flag",0)#按键按下不允许播放之前下发的音频数据 + EventMesh.publish("set_VC_stop_play_audio_flag",1)#按键按下不允许播放之前下发的音频数据 self.extint_AI.disable() self.KeyAI_press = 1 self.KeyAI_long_press = 0 @@ -1505,6 +1576,7 @@ class AI_dev(Abstract): EventMesh.publish("set_sos_info_call") self.KeySOS_timer_count = 0 pass + def AI_key_long_press(self): self.check_rest_timer_count = 0 print("AI_key_long_press") @@ -1520,6 +1592,11 @@ class AI_dev(Abstract): # self.KeySOS_timer.start(5000, 0, self.KeySos_timer_cb) EventMesh.publish("AI_key_release") + def pwk_key_double_press(self): + self.check_rest_timer_count = 0 + print("pwk_key_double_press") + EventMesh.publish("pwk_key_double_press") + def pwk_key_Long_Press(self,event=None,msg=None): self.check_rest_timer_count = 0 print("pwk_key_long_press!!!!!!!") @@ -2959,10 +3036,12 @@ class AI_VC(Abstract): self.is_noread_voice = EventMesh.publish("get_storage_config","is_noread_voice") if self.is_noread_voice == None: self.is_noread_voice = 0#是否还有未读留言(开机判断) + self.is_ruppt_tts = 0#是否已经打断tts播放 EventMesh.subscribe("AI_key_press", self.AI_key_press) EventMesh.subscribe("BT_AI_key_press", self.BT_AI_key_press) EventMesh.subscribe("stop_AI_record", self.stop_AI_record) EventMesh.subscribe("AI_key_release", self.AI_key_release) + EventMesh.subscribe("pwk_key_double_press", self.pwk_key_double_press) EventMesh.subscribe("AI_key_long_press", self.AI_key_long_press) EventMesh.subscribe("pwk_key_release", self.pwk_key_release) EventMesh.subscribe("get_AI_audio_queue", self.get_AI_audio_queue) @@ -3347,6 +3426,14 @@ class AI_VC(Abstract): if dev_type == "7PIN": #2代产品要延时播放按键音 为了连接蓝牙后不播放按键音的问题 # print("1111111111播放按键音!!!!!!!!!!") self.aud.aud_tone_play(10,400)#播放按键音 + + # 播放状态判定 + if self.VC_state >= VC_State_TTSStart and self.VC_state <= VC_State_TTSEnd: + print("【打断播放】设备正在说话,仅中断播放,不发起新对话") + self.is_ruppt_tts = 1 + EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_client_VC_RequestToSpeak})#打断 + return + EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠 if EventMesh.publish("get_sos_flag")== 1: return @@ -3387,6 +3474,7 @@ class AI_VC(Abstract): pass # self.aud.aud_tone_play(10,200)#播放按键音 utime.sleep_ms(500) + self.Close() if PRESS_AUDIO_MODE == 0: if dev_type == "7PIN" or dev_type == "7PIN_1_5": @@ -3414,7 +3502,6 @@ class AI_VC(Abstract): self.VC_Speech_End() self.VC_Speech_Start() - self.AI_VC_start() @@ -3535,6 +3622,17 @@ class AI_VC(Abstract): pass #self.VC_Speech_End() + def pwk_key_double_press(self,event,msg):#pwk双击 + print("come 双击") + if self.VC_mode == 0: + self.VC_mode = 1 + tts_str = "已切换到单对话模式" + else: + self.VC_mode = 0 + tts_str = "已切换到长对话模式" + EventMesh.publish("play_tts",[tts_str,1]) + EventMesh.publish("set_storage_config",["VC_mode",self.VC_mode]) + def AI_key_long_press(self, event, msg):#按键长按 print("AI_key_long_press") if dev_type == 'jswm' or dev_type == 'jswm_BOX' : @@ -3795,8 +3893,7 @@ class AI_VC(Abstract): print("检测到VAD=1!!!!!!!!!!!!!") print("检测到VAD=1!!!!!!!!!!!!!") print("检测到VAD=1!!!!!!!!!!!!!") - - EventMesh.publish("publish_AI_btnInfo",{"func":self.VC_Play_Pause,"data":1})#停止音频 + # EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_client_VC_RequestToSpeak})#打断 # RequestToSpeak_flag = 1 @@ -4112,6 +4209,7 @@ class AI_VC(Abstract): print("VC VC: send_data:{}".format(data[1])) else: print("VC: send_data len:{}".format(len(data[1]))) + # print("self.AI_client_VC = {} , self.AI_client_VC_isconnect = {}".format(self.AI_client_VC,self.AI_client_VC_isconnect)) if self.AI_client_VC != None and self.AI_client_VC_isconnect == 1: self.AI_client_VC.send(data[1]) else: @@ -4349,7 +4447,15 @@ class AI_VC(Abstract): pass elif jsload_data["event"] == "canceled" :#打断 + self.is_ruppt_tts = 0#设备上发中断tts,收到服务器返回的cancel后置为0 EventMesh.publish("publish_AI_btnInfo",{"func":self.VC_Speech_Start_now})#开始录音 + if self.AI_audio_queue_thread_id ==0: + _thread.stack_size(24*1024) + self.AI_audio_queue_thread_id = _thread.start_new_thread(self.AI_audio_queue_thread, ()) + _thread.stack_size(8*1024) + print("AI_VC_start :AI_audio_queue_thread_id :{} ".format(self.AI_audio_queue_thread_id)) + else: + print("AI_VC_start :AI_audio_queue_thread_id != 0 ") self.VC_state = VC_State_None elif jsload_data["event"] == "completed" :#会话结束 "event":"audio.convert.completed" #EventMesh.publish("open_led_green")#绿色 @@ -4456,8 +4562,9 @@ class AI_VC(Abstract): if self.VC_stop_play_audio_flag == 0: print("新的AI对话不允许以前的播放数据:") break + print("下发音频数据1:{}".format(len(recv_data))) - + if self.play_data_save_flag == 1: if self.play_fd ==None: try: @@ -4470,22 +4577,25 @@ class AI_VC(Abstract): # print("下发音频数据2:{}".format(len(recv_data))) #if self.VC_state >= VC_State_TTSStart: #self.put_record_data([recv_data,""]) - if self.VC_play_TYPE == VC_play_TYPE_PCM: - if self.play_pcm != None: - try: - #print("play_pcm.stream_write !!!") - buf_len = self.play_pcm.stream_get_buf_len() - count_tmp = 1000 - while buf_len < len(recv_data): - utime.sleep_ms(1) - count_tmp-=1 - if count_tmp<=0 or self.play_pcm == None: - break + if self.is_ruppt_tts == 0:#被设备主动打断打断则不播放,知道收到服务器返回的cancel才修改标志位 + if self.VC_play_TYPE == VC_play_TYPE_PCM: + if self.play_pcm != None: + try: + #print("play_pcm.stream_write !!!") buf_len = self.play_pcm.stream_get_buf_len() - #print("buf已满,等待释放:buf_len:{},count_tmp:{}".format(buf_len,count_tmp)) - except Exception as e: - usys.print_exception(e) - EventMesh.publish("publish_AI_btnInfo",{"func":self.put_record_data,"data":[recv_data,""]}) + count_tmp = 1000 + while buf_len < len(recv_data): + utime.sleep_ms(1) + count_tmp-=1 + if count_tmp<=0 or self.play_pcm == None: + break + buf_len = self.play_pcm.stream_get_buf_len() + #print("buf已满,等待释放:buf_len:{},count_tmp:{}".format(buf_len,count_tmp)) + except Exception as e: + usys.print_exception(e) + EventMesh.publish("publish_AI_btnInfo",{"func":self.put_record_data,"data":[recv_data,""]}) + else: + print("被打断不播放") utime.sleep_ms(1) except Exception as e: usys.print_exception(e) @@ -5014,58 +5124,58 @@ class AI_VC(Abstract): #self.aud.play(1,0,'U:/static/peizhichenggong.mp3')#切换成功 return 0 - # if text.find("音量") != -1: - # if text.find("加") != -1 : - # self.VC_TTS_volume += 10 - # if self.VC_TTS_volume > 100: - # #EventMesh.publish("audio_montage_play",["yinliangyizuida.mp3"]) - # #self.aud.play(1,0,'U:/static/yinliangyizuida.mp3')#音量已最大 - # self.AI_TTS_str = "音量已最大" - # self.VC_TTS_volume = 100 - # else: - # self.aud.setVolume(self.VC_TTS_volume //10) - # EventMesh.publish("set_storage_config",["VC_TTS_volume",self.VC_TTS_volume]) - # EventMesh.publish("post_device_state") - # EventMesh.publish("adjust_volume_toBle",self.VC_TTS_volume) - # #EventMesh.publish("audio_montage_play",["peizhichenggong.mp3"]) - # #self.aud.play(1,0,'U:/static/peizhichenggong.mp3')#配置成功 - # self.AI_TTS_str = "配置成功,当前音量 {}".format(self.VC_TTS_volume) + if text.find("音量") != -1: + if text.find("加") != -1 : + self.VC_TTS_volume += 10 + if self.VC_TTS_volume > 100: + #EventMesh.publish("audio_montage_play",["yinliangyizuida.mp3"]) + #self.aud.play(1,0,'U:/static/yinliangyizuida.mp3')#音量已最大 + self.AI_TTS_str = "音量已最大" + self.VC_TTS_volume = 100 + else: + self.aud.setVolume(self.VC_TTS_volume //10) + EventMesh.publish("set_storage_config",["VC_TTS_volume",self.VC_TTS_volume]) + EventMesh.publish("post_device_state") + EventMesh.publish("adjust_volume_toBle",self.VC_TTS_volume) + #EventMesh.publish("audio_montage_play",["peizhichenggong.mp3"]) + #self.aud.play(1,0,'U:/static/peizhichenggong.mp3')#配置成功 + self.AI_TTS_str = "配置成功,当前音量 {}".format(self.VC_TTS_volume) - # return 0 - # if text.find("减") != -1: - # self.VC_TTS_volume -= 10 - # if self.VC_TTS_volume < 0: - # self.VC_TTS_volume = 0 - # #EventMesh.publish("audio_montage_play",["yinliangyizuixiao.mp3"]) - # #self.aud.play(1,0,'U:/static/yinliangyizuixiao.mp3')#音量已最小 - # self.AI_TTS_str = "音量已最小" - # else: - # self.aud.setVolume(self.VC_TTS_volume //10) - # EventMesh.publish("set_storage_config",["VC_TTS_volume",self.VC_TTS_volume]) - # EventMesh.publish("post_device_state") - # EventMesh.publish("adjust_volume_toBle",self.VC_TTS_volume) - # #EventMesh.publish("audio_montage_play",["peizhichenggong.mp3"]) - # #self.aud.play(1,0,'U:/static/peizhichenggong.mp3')#配置成功 - # self.AI_TTS_str = "配置成功,当前音量 {}".format(self.VC_TTS_volume) - # return 0 + return 0 + if text.find("减") != -1: + self.VC_TTS_volume -= 10 + if self.VC_TTS_volume < 0: + self.VC_TTS_volume = 0 + #EventMesh.publish("audio_montage_play",["yinliangyizuixiao.mp3"]) + #self.aud.play(1,0,'U:/static/yinliangyizuixiao.mp3')#音量已最小 + self.AI_TTS_str = "音量已最小" + else: + self.aud.setVolume(self.VC_TTS_volume //10) + EventMesh.publish("set_storage_config",["VC_TTS_volume",self.VC_TTS_volume]) + EventMesh.publish("post_device_state") + EventMesh.publish("adjust_volume_toBle",self.VC_TTS_volume) + #EventMesh.publish("audio_montage_play",["peizhichenggong.mp3"]) + #self.aud.play(1,0,'U:/static/peizhichenggong.mp3')#配置成功 + self.AI_TTS_str = "配置成功,当前音量 {}".format(self.VC_TTS_volume) + return 0 if text.find("进入工厂模式") != -1 : self.factory_mode() return 1 if text.find("查询") != -1: - # if text.find("信号") != -1 : - # signal = net.csqQueryPoll() + if text.find("信号") != -1 : + signal = net.csqQueryPoll() - # self.AI_TTS_str = "当前信号{}".format(signal) - # return 0 - # if text.find("电量") != -1 : - # battery = EventMesh.publish("get_battery") - # print("电量查询:{}".format(battery)) - # #EventMesh.publish("audio_montage_play",["dianliangshengyu{}.mp3".format(battery)]) - # #self.aud.play(1,0,'U:/static/dianliangshengyu{}.mp3'.format(battery))#电量剩余 - # self.AI_TTS_str = "电量剩余百分之{}".format(battery) - # return 0 + self.AI_TTS_str = "当前信号{}".format(signal) + return 0 + if text.find("电量") != -1 : + battery = EventMesh.publish("get_battery") + print("电量查询:{}".format(battery)) + #EventMesh.publish("audio_montage_play",["dianliangshengyu{}.mp3".format(battery)]) + #self.aud.play(1,0,'U:/static/dianliangshengyu{}.mp3'.format(battery))#电量剩余 + self.AI_TTS_str = "电量剩余百分之{}".format(battery) + return 0 if text.find("电压") != -1 : Vbatt = Power.getVbatt() #EventMesh.publish("audio_montage_play",["dianliangshengyu{}.mp3".format(battery)]) @@ -5102,55 +5212,55 @@ class AI_VC(Abstract): self.AI_TTS_str ="服务器地址"+self.server_ip return 0 - # if text.find("讲话") != -1 or text.find("说话") != -1: - # if text.find("å¿«") != -1 and text.find("太") == -1 : - # self.speech_rate += 10 - # if self.speech_rate > 50: - - # self.AI_TTS_str = "语速已经是最快了" - # self.speech_rate = 50 - # else: + if text.find("讲话") != -1 or text.find("说话") != -1: + if text.find("å¿«") != -1 and text.find("太") == -1 : + self.speech_rate += 10 + if self.speech_rate > 50: + + self.AI_TTS_str = "语速已经是最快了" + self.speech_rate = 50 + else: - # EventMesh.publish("set_storage_config",["speech_rate",self.speech_rate]) + EventMesh.publish("set_storage_config",["speech_rate",self.speech_rate]) - # self.AI_TTS_str = "明白,语速已经调快了,当前语速是{}".format(self.speech_rate) + self.AI_TTS_str = "明白,语速已经调快了,当前语速是{}".format(self.speech_rate) - # return 0 - # if text.find("慢") != -1 and text.find("太") == -1 : - # self.speech_rate -= 10 - # if self.speech_rate < -50: - # self.speech_rate = -50 - # #EventMesh.publish("audio_montage_play",["yinliangyizuixiao.mp3"]) - # #self.aud.play(1,0,'U:/static/yinliangyizuixiao.mp3')#音量已最小 - # self.AI_TTS_str = "语速已经是最慢了" - # else: - # EventMesh.publish("set_storage_config",["speech_rate",self.speech_rate]) - - # self.AI_TTS_str = "明白,语速已经调慢了,当前语速是{}".format(self.speech_rate) - # return 0 - # if len(text)<22 and(text.find("聆听") != -1 or text.find("明天")!= -1) : - # #print("text len :{}".format(len(text))) - # if text.find("å¿«") != -1 and text.find("太") == -1 : - # self.vad_silence -= 200 - # if self.vad_silence < 100: - - # self.AI_TTS_str = "已经是最快了" - # self.vad_silence = 100 - # else: - # self.AI_TTS_str = "配置成功,当前语音断句速度是{}毫秒".format(self.vad_silence) - # EventMesh.publish("set_storage_config",["vad_silence",self.vad_silence]) - # return 0 - # if text.find("慢") != -1 and text.find("太") == -1 : - # self.vad_silence += 200 - # if self.vad_silence > 2000: - # self.vad_silence = 2000 - # #EventMesh.publish("audio_montage_play",["yinliangyizuixiao.mp3"]) - # #self.aud.play(1,0,'U:/static/yinliangyizuixiao.mp3')#音量已最小 - # self.AI_TTS_str = "已经是最慢了" - # else: - # self.AI_TTS_str = "配置成功,当前语音断句速度是{}毫秒".format(self.vad_silence) - # EventMesh.publish("set_storage_config",["vad_silence",self.vad_silence]) - # return 0 + return 0 + if text.find("慢") != -1 and text.find("太") == -1 : + self.speech_rate -= 10 + if self.speech_rate < -50: + self.speech_rate = -50 + #EventMesh.publish("audio_montage_play",["yinliangyizuixiao.mp3"]) + #self.aud.play(1,0,'U:/static/yinliangyizuixiao.mp3')#音量已最小 + self.AI_TTS_str = "语速已经是最慢了" + else: + EventMesh.publish("set_storage_config",["speech_rate",self.speech_rate]) + + self.AI_TTS_str = "明白,语速已经调慢了,当前语速是{}".format(self.speech_rate) + return 0 + if len(text)<22 and(text.find("聆听") != -1 or text.find("明天")!= -1) : + #print("text len :{}".format(len(text))) + if text.find("å¿«") != -1 and text.find("太") == -1 : + self.vad_silence -= 200 + if self.vad_silence < 100: + + self.AI_TTS_str = "已经是最快了" + self.vad_silence = 100 + else: + self.AI_TTS_str = "配置成功,当前语音断句速度是{}毫秒".format(self.vad_silence) + EventMesh.publish("set_storage_config",["vad_silence",self.vad_silence]) + return 0 + if text.find("慢") != -1 and text.find("太") == -1 : + self.vad_silence += 200 + if self.vad_silence > 2000: + self.vad_silence = 2000 + #EventMesh.publish("audio_montage_play",["yinliangyizuixiao.mp3"]) + #self.aud.play(1,0,'U:/static/yinliangyizuixiao.mp3')#音量已最小 + self.AI_TTS_str = "已经是最慢了" + else: + self.AI_TTS_str = "配置成功,当前语音断句速度是{}毫秒".format(self.vad_silence) + EventMesh.publish("set_storage_config",["vad_silence",self.vad_silence]) + return 0 if text.find("升级") != -1 and (text.find("OTA") != -1 or text.find("ota") != -1): if self.ai_OTA.min_sys_ota()==1: self.AI_TTS_str = "有新版本,准备开始升级,升级过程会多次重启设备,请保证流量充足及电量充足" @@ -5425,6 +5535,7 @@ class AI_VC(Abstract): # pass print("AI_VC_start4") + #self.VC_Play_Start() #EventMesh.publish("publish_AI_btnInfo",{"func":self.VC_Play_Start}) #开始线程 @@ -5690,14 +5801,14 @@ class AI_VC(Abstract): "payload": {} } print("AI_client_VC_RequestToSpeak!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") - # EventMesh.publish("publish_AI_btnInfo",{"func":self.VC_init}) - # EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_client_VC_send,"data":ujson.dumps(json_data)}) - # utime.sleep_ms(1) - self.websocket_deconnect_VC() + EventMesh.publish("publish_AI_btnInfo",{"func":self.VC_init}) + EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_client_VC_send,"data":ujson.dumps(json_data)}) + utime.sleep_ms(1) + # self.websocket_deconnect_VC() self.AI_audio_queue_thread_close() self.VC_state = VC_State_None - #self.Close() - self.AI_VC_start() + # #self.Close() + # self.AI_VC_start() #TTS播放 def AI_client_VC_synthesis(self): json_data = \ diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/main_init.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/main_init.py index abcf9b94..66d25921 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/main_init.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/main_init.py @@ -256,6 +256,9 @@ def main_init(): pcr.add_support(pro.IOTWeb_user_unbind_devProtoCol()) pcr.add_support(pro.IOTWeb_Nlp_ConfigProtoCol()) pcr.add_support(pro.IOTWeb_play_MusicProtoCol()) + pcr.add_support(pro.IOTWeb_find_deviceProtoCol()) + pcr.add_support(pro.IOTWeb_get_device_stateProtoCol()) + pcr.add_support(pro.IOTWeb_switch_volumeProtoCol()) sm = pro.SockMangager() sm.add_support_resolver(pcr) 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 44f7b278..c1ae9cea 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 @@ -25,6 +25,7 @@ import umqtt import modem SHA256 = uhashlib.sha256 import SecureData +import versions dev_type = "7PIN"#柒牌1代 # dev_type = "7PIN_1_5"#柒牌1.5代 def server_init(server_type = None): @@ -694,6 +695,9 @@ class WEB_CMD_ENUM: NLP_PLAY_R = "ai_cmd_R" NLP_PLAY_S = "ai_cmd_S" + #金三 + GET_DEVICE_STATE_R = "get_device_state_R" + GET_DEVICE_STATE_S = "get_device_state_S" class IOTSendCmdManager(Abstract): # def __init__(self): @@ -4315,7 +4319,138 @@ class IOTWeb_get_chat_configProtoCol(ProtoCol): # } # } print("RECV get_chat_config{}".format(msg)) +#IOT金三 +#接收小程序控制查找设备 +class IOTWeb_find_deviceProtoCol(ProtoCol): + """find_device""" + TYPE = "find_device" + + def send(self, event, msg): + # print("c{}".format(msg)) + # 通过websocket发送到服务器端 + date_tmp = utime.localtime() + time_tmp = utime.mktime(date_tmp) + come_trans = { + "msg": "查找设备", + "data": None, + "cmd": "find_device", + "ts": time_tmp + } + send_data = b'' + send_data = protocol_send_total_data(come_trans) + print("send_data find_device{}".format(send_data)) + EventMesh.publish("CHANNEL_IOT_WEB_SEND", send_data) + + def recv(self, event, msg): + """ + @param event:上行下发translate_app_enter + @param msg: 接收到的下行数据 + """ + tts_str = "我在这呀,我在这呀,我在这呀 " + EventMesh.publish("play_tts",[tts_str,1]) + +#接收小程序控制上传设备状态 +class IOTWeb_get_device_stateProtoCol(ProtoCol): + """get_device_state""" + TYPE = "get_device_state" + + def send(self, event, msg): + battery_state = (EventMesh.publish("screen_get_battery"))[0] + battery = (EventMesh.publish("screen_get_battery"))[1] + if battery >= 100 or battery == None: + battery = 100 + VC_TTS_volume = EventMesh.publish("get_storage_config","VC_TTS_volume")#音量配置 + if VC_TTS_volume == None: + VC_TTS_volume =100 + sourceVersion =versions.Build_Time + Timeversion ="JSWM-"+sourceVersion + ts = utime.mktime(utime.localtime()) + come_trans = { + "data":{ + "version":Timeversion,#版本号 + "charge":battery_state,#0表示未充电,1表示充电中 + "currentRoleName":"",#当前音色的name + "volume":str(VC_TTS_volume),#百分比数值 + "wifiRssi":str(net.csqQueryPoll()//6),#wifi强弱:0,1,2,3,4,5。转成这几个梯度 + "battery":str(battery),#电量 + "bargein": "0",#不能手动设置打断模式 + "deviceId":modem.getDevImei(),#设备号 + }, + "cmd":"device_info", + "msg": "上报设备信息", + "ts": ts + } + send_data = b'' + send_data = protocol_send_total_data(come_trans) + print("send_data get_device_state{}".format(send_data)) + EventMesh.publish("CHANNEL_IOT_WEB_SEND", send_data) + + def recv(self, event, msg): + """ + @param event:get_device_state + @param msg: 接收到的下行数据 + """ + EventMesh.publish(WEB_CMD_ENUM.GET_DEVICE_STATE_S) + +#接收小程序控制设备音量 +class IOTWeb_switch_volumeProtoCol(ProtoCol): + """switch_volume""" + TYPE = "switch_volume" + def send(self, event, msg): + # print("c{}".format(msg)) + # 通过websocket发送到服务器端 + date_tmp = utime.localtime() + time_tmp = utime.mktime(date_tmp) + come_trans = { + "msg": "设置音量", + "data": None, + "cmd": "switch_volume", + "ts": time_tmp + } + send_data = b'' + send_data = protocol_send_total_data(come_trans) + print("send_data switch_volume{}".format(send_data)) + EventMesh.publish("CHANNEL_IOT_WEB_SEND", send_data) + + def recv(self, event, msg): + """ + @param event:switch_volume + @param msg: 接收到的下行数据 + """ + volume = int(msg["data"]["target"]) + 100 + print("音量修改为:{}".format(volume-100)) + EventMesh.publish("change_volume",volume) + +#接收小程序控制设置音量 +class IOTWeb_switch_volumeProtoCol(ProtoCol): + """switch_volume""" + TYPE = "switch_volume" + + def send(self, event, msg): + # print("c{}".format(msg)) + # 通过websocket发送到服务器端 + date_tmp = utime.localtime() + time_tmp = utime.mktime(date_tmp) + come_trans = { + "msg": "设置音量", + "data": None, + "cmd": "switch_volume", + "ts": time_tmp + } + send_data = b'' + send_data = protocol_send_total_data(come_trans) + print("send_data switch_volume{}".format(send_data)) + EventMesh.publish("CHANNEL_IOT_WEB_SEND", send_data) + + def recv(self, event, msg): + """ + @param event:switch_volume + @param msg: 接收到的下行数据 + """ + volume = int(msg["data"]["target"]) + 100 + print("音量修改为:{}".format(volume-100)) + EventMesh.publish("change_volume",volume) class LK_ProtoCol(ProtoCol): """链路保持"""