utime.sleep_ms(500)
self.KeyAI_timer = osTimer()
self.KeySOS_timer = osTimer()
+ self.play_imei_timer = osTimer()
+ self.play_imei_timer_count=0
self.KeySOS_timer_count = 0
self.KeySOS_timer_flag = 0
if dev_type == "G10" :
if self.KeyAI_press == 0 :
if EventMesh.publish("get_play_new_voice_state") == 1:
EventMesh.publish("set_play_new_voice_state",0)
- EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
+
+ EventMesh.publish("set_VC_stop_play_audio_flag",0)#按键按下不允许播放之前下发的音频数据
self.extint_AI.disable()
self.KeyAI_press = 1
self.KeyAI_long_press = 0
self.KeyAI_timer.start(100, 1, self.KeyAI_timer_cb)
self.KeyAI_timer_count = 0
#EventMesh.publish("AI_key_press")
- if dev_type == "7PIN" or dev_type == "7PIN_coze" :
- self.aud.aud_tone_play(10,400)#播放按键音
+
+
EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_key_press})
except Exception as e:
usys.print_exception(e)
EventMesh.publish("open_led_red")
utime.sleep_ms(2000)
self.aud.stopPlayStream()
+ print("stopAll:8")
self.aud.stopAll()
Power.powerDown()
if self.KeyAI_status == 1:#松开
usys.print_exception(e)
def AI_key_press(self):
- EventMesh.publish("wakeup_BT")
+ # EventMesh.publish("wakeup_BT")
+ EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
+ # if dev_type == "7PIN" or dev_type == "7PIN_coze" :
+ # # self.aud.aud_tone_play(10,60)#播放按键音
+ # EventMesh.publish("audio_montage_play",["chenggong.mp3"])
self.check_rest_timer_count = 0
print("AI_key_press")
EventMesh.publish("AI_key_press")
str_data = str_data[:-1]
print("audio_montage_play:{}".format(str_data))
self.aud.montage_play('U:/static/audio.bin',1,1,str_data)
+ self.play_imei_timer_count=1
+ self.play_imei_timer.stop()
+ self.play_imei_timer.start(1000,1,self.play_imei_timer_cb)
def paly_iccid_imei(self,event,msg):
+
self.wakeup_BT()
str_data = 'mp3files={}.mp3+'.format(audio_buf.index("liuliangtishi"))#流量提示
imei = modem.getDevImei()
audio_buf.index("R_READ_TIME_{}".format(iccid[16])),audio_buf.index("R_READ_TIME_{}".format(iccid[17])),audio_buf.index("R_READ_TIME_{}".format(iccid[18])),audio_buf.index("R_READ_TIME_{}".format(iccid[19])))
str_data += '{}.mp3+'.format(audio_buf.index("shouhou"))#可联系售后解决,联系方式见售后客服电话是400-886-8777或到微信公众号柒牌SEVENBRAND自行充值:
self.aud.montage_play('U:/static/audio.bin',1,1,str_data)
+ #开定时器不让系统休眠
+ self.play_imei_timer_count=1
+ self.play_imei_timer.stop()
+ self.play_imei_timer.start(1000,1,self.play_imei_timer_cb)
+
+ def play_imei_timer_cb(self,event=None,msg=None):
+ if self.play_imei_timer_count == 1:
+ if EventMesh.publish("get_audio_play_state") == 0:
+ print("音频文件播放完成")
+ self.play_imei_timer_count=0
+ self.play_imei_timer.stop()
+ return
+ EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
+
#鉴权出错,播放imei号
def paly_device_res_error(self,event,msg):
self.wakeup_BT()
audio_buf.index("R_READ_TIME_{}".format(imei[12])),audio_buf.index("R_READ_TIME_{}".format(imei[13])),audio_buf.index("R_READ_TIME_{}".format(imei[14])))
#print("str_data:{}".format(str_data))
self.aud.montage_play('U:/static/audio.bin',1,1,str_data)
+ self.play_imei_timer_count=1
+ self.play_imei_timer.stop()
+ self.play_imei_timer.start(1000,1,self.play_imei_timer_cb)
#存储信息
class getStorageDataManager(Abstract):#获取内存数据
EventMesh.subscribe("set_record_data_save_flag", self.set_record_data_save_flag)
EventMesh.subscribe("set_VC_TTS_voice_type", self.set_VC_TTS_voice_type)
EventMesh.subscribe("SET_TTS_VOLUME", self.set_tts_volume)
+ EventMesh.subscribe("set_VC_stop_play_audio_flag", self.set_VC_stop_play_audio_flag)
+ EventMesh.subscribe("set_yuyinaudio_flag",self.set_yuyinaudio_flag)
+ EventMesh.subscribe("get_audio_play_state",self.get_audio_play_state)
+ # EventMesh.subscribe("chenggong_tone",self.chenggong_tone)
+
pass
EventMesh.publish("close_led")
self.dialog_attributes_provider = EventMesh.publish("get_storage_config","dialog_attributes_provider")#智能体类型配置
except Exception as e:
usys.print_exception(e)
+ def set_VC_stop_play_audio_flag(self,event = None, msg = None):
+ self.VC_stop_play_audio_flag = msg
+ print("self.VC_stop_play_audio_flag:{}".format(self.VC_stop_play_audio_flag))
def audio_test(self,event = None, msg = None):
self.VC_Speech_Start()
else:
self.aud.setVolume(self.VC_TTS_volume //10)
pass
+ def set_yuyinaudio_flag(self, event=None, msg = None):
+ self.voice_flag=0
+ def get_audio_play_state(self, event=None, msg = None):
+ return self.audio_play_state
+
def AI_key_press(self, event=None, msg = None):#按键按下
EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
+ if EventMesh.publish("get_sos_flag")== 1:
+ return
if self.voice_flag == 1: #语音留言模式
# EventMesh.publish("stop_AI_record")
self.Close()
EventMesh.publish("open_led_green")
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
self.key_state = 1
self.Close()
-
+ if dev_type == "7PIN":
+ self.chenggong_tone()
#self.aud.aud_tone_play(10,200)#播放按键音
self.AI_TTS_str = ""#"你好,有什么吩咐"
self.AI_ASR_str = ""
self.AI_VC_start()
- # if dev_type != "7PIN":
- # self.chenggong_tone()
+
# self.Close()
# self.AI_VC_start()
self.AI_key_long_press_flag = 0
utime.sleep_ms(1)
self.VC_record_thread_lock = 0
print("VC_record_thread_thread_close")
- try:
- _thread.stop_thread(self.VC_record_thread_id)
- except Exception as e:
- usys.print_exception(e)
+ if self.VC_record_thread_id != 0:
+ try:
+ _thread.stop_thread(self.VC_record_thread_id)
+ except Exception as e:
+ usys.print_exception(e)
self.VC_record_thread_id = 0
#获取录音数据
self.AI_TTS_str = TTS_str
EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_VC_start})
self.Close_flag = 1
- print("websocket_error2")
+ print("websocket_error2{}".format(self.websocket_error_count))
print("websocket_error4")
self.AI_VC_send_data_queue.clear()
self.AI_VC_send_data_queue_thread_lock = 0
print("AI_VC_send_data_queue_thread_close")
- try:
- _thread.stop_thread(self.AI_VC_send_data_queue_thread_id)
- except Exception as e:
- usys.print_exception(e)
+ if self.AI_VC_send_data_queue_thread_id != 0:
+ try:
+ _thread.stop_thread(self.AI_VC_send_data_queue_thread_id)
+ except Exception as e:
+ usys.print_exception(e)
self.AI_VC_send_data_queue_thread_id = 0
#发送数据队列
def AI_VC_send_data_queue_thread(self):
utime.sleep_ms(1)
self.AI_client_VC_recv_lock = 0
print("AI_client_VC_recv_thread_close")
- try:
- _thread.stop_thread(self.AI_client_VC_recv_id)
- except Exception as e:
- usys.print_exception(e)
+ if self.AI_client_VC_recv_id!= 0:
+ try:
+ _thread.stop_thread(self.AI_client_VC_recv_id)
+ except Exception as e:
+ usys.print_exception(e)
self.AI_client_VC_recv_id = 0
#Ai VC websocket返回数据
def AI_client_VC_recv(self,cli):
EventMesh.publish("open_led_green")#绿色
-
+ if self.VC_stop_play_audio_flag == 0:
+ print("新的AI对话不允许以前的播放数据:")
+ break
print("下发音频数据1:{}".format(len(recv_data)))
if self.play_data_save_flag == 1:
print("AI_client_VC_recv END!!!!!!!!!!!!!!!!!!!!!!!!!!!")
def put_record_data(self,data):
+
#print("下发音频数据1:{}".format(len(data[0])))
ret=self.AI_audio_queue.put(data)
self.tts_in_data_len += len(data[0])
return 0
- if text.find("解绑设备") != -1 or text.find("设备解绑") != -1:
+ if text.find("确认解绑设备") != -1 or text.find("确认设备解绑") != -1:
self.AI_TTS_str = "设备解绑中...."
self.Close_flag = 1
EventMesh.publish("send_unbind_dev_to_iot")
#VC开始
def AI_VC_start(self):
print("AI_VC_start1")
+
EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
self.VC_satrt_flag = 1
self.VC_stop_play_audio_flag = 1
self.VC_Thinking_timerout = 0
EventMesh.publish("open_led_all")
EventMesh.publish("wakeup_BT")
- self.VC_Play_End()#关闭音频播放
+ #self.VC_Play_End()#关闭音频播放
print("AI_VC_start2")
#self.aud.aud_tone_play(16,200)#播放按键音
self.LocalRespondingEnded_timerout = 0
print("self.VC_state :{}".format(self.VC_state ))
EventMesh.publish("system_sleep_rest")#防止黑屏
if self.AI_client_VC_isconnect == 0:
- self.Close()
+ #self.Close()
return
+ # self.aud.stopPlayStream()
+ # self.aud.stopAll()
self.AI_client_VC_start_requset()
print("AI_VC_start3")
utime.sleep_ms(1)
self.AI_audio_queue_thread_lock = 0
print("AI_audio_queue_thread_close2!!!!!!!!!!!!!!!!!")
- try:
- _thread.stop_thread(self.AI_audio_queue_thread_id)
- except Exception as e:
- usys.print_exception(e)
+ if self.AI_audio_queue_thread_id != 0:
+ try:
+ _thread.stop_thread(self.AI_audio_queue_thread_id)
+ except Exception as e:
+ usys.print_exception(e)
self.AI_audio_queue_thread_id = 0
# 音频队列
def AI_audio_queue_thread(self):
print("AI_audio_queue_thread:ERROR:")
usys.print_exception(e)
self.AI_audio_queue_thread_lock = 0
- #print("AI_audio_queue_thread:exit")
+ self.AI_audio_queue_thread_id = 0
+ print("AI_audio_queue_thread:exit")
def factory_mode(self):
print("factory_mode")
EventMesh.publish("publish_AI_btnInfo",{"func":self.Close})
self.VC_Speech_End()
print("ai_VC Close1.1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
- self.VC_init()
+
print("ai_VC Close1.2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
try:
self.AI_ASR_send_buf_len = 0
#self.AI_WS_connect_Queue.put(self.AI_client_VC)
EventMesh.publish("close_led")
+ self.VC_init()
self.VC_satrt_flag = 0
# try:
# while True:
# self.timer_read_GPS_info.stop()
if self.location_queue.empty() == False:
self.location_queue.clear()
- if self.location_thread_id == 1:
+ if self.location_thread_id != 0:
try:
_thread.stop_thread(self.location_thread_id)
except Exception as e:
def __init__(self):
self.thread_buf_size = 16*1024
self.iot_web_send_queue = Queue(100)
- self.iot_web_protoclo_recv_id=None
+ self.iot_web_protoclo_recv_id=0
self.iot_protocol_client = None
self.connect_web_timer = osTimer()
self.connect_web_timer_count = 0
self.vbat_buf = []
self.network_state = 0
self.curr_battery_level = 0
- self.socket_send_queue_id = None
+ self.iot_web_send_queue_id = 0
self.bat_count = 0
self.minute_now_old = 0
self.old_minute = 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.iot_protocol_client=uwebsocket.Client.connect(url_t, debug=True)
-
+ 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.socket_send_queue_id = _thread.start_new_thread(self.socket_send_queue_thread, ())
+ 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)
# EventMesh.publish("connect_iot_websocket_cb")
EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket})
break
+ elif recv_data == "":
+ print("下发的空数据 不做处理")
else:
if len(recv_data) != 0:
self.reconnect_count = 0
# EventMesh.publish("connect_iot_websocket_cb")
EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket})
break
- self.iot_web_protoclo_recv_id =None
+ self.iot_web_protoclo_recv_id =0
def iot_web_send_queue_close(self):
- if self.socket_send_queue_id != None:
+ if self.iot_web_send_queue_id != 0:
if self.iot_web_send_queue.empty()!=True:
self.iot_web_send_queue.clear()
+
try:
- _thread.stop_thread(self.socket_send_queue_id)
+ _thread.stop_thread(self.iot_web_send_queue_id)
except Exception as e:
- print("iot_web_protoclo_recv_id !!!!!!!!")
- print("iot_web_protoclo_recv_id 1111!!!!!!!!")
- self.socket_send_queue_id = None
+ print("iot_web_send_queue_close !!!!!!!!")
+ print("iot_web_send_queue_close 1111!!!!!!!!")
+ self.iot_web_send_queue_id = 0
def iot_web_protoclo_recv_close_therad(self):
- if self.iot_web_protoclo_recv_id != None:
+ if self.iot_web_protoclo_recv_id != 0:
try:
_thread.stop_thread(self.iot_web_protoclo_recv_id)
except Exception as e:
print("self.iot_web_protoclo_recv_id !!!!!!!!")
- self.iot_web_protoclo_recv_id = None
+ self.iot_web_protoclo_recv_id = 0
if self.iot_protocol_client != None:
try:
print("关闭websocke")
def recv(self, event, msg):
"""
- @param event: 心跳成功
+ @param event: 上报蓝牙耳机连接状态
@param msg: 接收到的下行数据
"""
print("recv post_bt_connect_rest{}".format(msg))
def recv(self, event, msg):
"""
- @param event: 心跳成功
+ @param event: 电子围栏警告
@param msg: 接收到的下行数据
"""
EventMesh.publish(WEB_CMD_ENUM.FENCE_SOS_S)
print(read_soslist)
EventMesh.publish(WEB_CMD_ENUM.SOS_LIST_S_CMD)
-#é\97¹é\92\9fé\93\83声下发
+#é\9f³é\87\8f下发
class IOTWeb_volumeProtoCol(ProtoCol):
"""volume"""
TYPE = "volume"
get_sos_flag = EventMesh.publish("get_sos_flag")
if get_sos_flag != 0:
s_rest = "0"
+ print("正在电话")
EventMesh.publish(WEB_CMD_ENUM.VOICE_RECORD_S_CMD,s_rest)
return
record_mode = EventMesh.publish("get_voice_record_mode")
EventMesh.publish("set_storage_config",["switch_bt_state","1"])
EventMesh.publish("send_bt_switch_toble","1")
EventMesh.publish("play_tts",[play_str,1])
+ # ret = 0
+ # ret = ql_fs.path_exists("/usr/static/storage_file")#配置文件
+ # if ret == True:
+ # ql_fs.rmdirs("/usr/static/storage_file")
+ # ql_fs.mkdirs("/usr/static/storage_file")
+ # utime.sleep_ms(2000)
+ # Power.powerRestart()
pass
else:
play_str = "设备解绑失败"
EventMesh.publish("set_storage_config",["switch_bt_state","1"])
EventMesh.publish("send_bt_switch_toble","1")
EventMesh.publish(WEB_CMD_ENUM.USER_UNBIND_DEV_S)
+ # ret = 0
+ # ret = ql_fs.path_exists("/usr/static/storage_file")#配置文件
+ # if ret == True:
+ # ql_fs.rmdirs("/usr/static/storage_file")
+ # ql_fs.mkdirs("/usr/static/storage_file")
+ # utime.sleep_ms(100)
+ # Power.powerRestart()
print("recv user_unbind_dev{}".format(msg))
#下发位子留言
class IOTWeb_text_msgProtoCol(ProtoCol):
EventMesh.publish("set_schedule_info",schedule)#
print(schedule)
EventMesh.publish(WEB_CMD_ENUM.SCHEDULE_S_CMD)
-#
+#下发新的语音未读留言
class IOTWeb_new_voice_msgProtoCol(ProtoCol):
"""new_voice_msg"""
TYPE = "new_voice_msg"
EventMesh.publish(WEB_CMD_ENUM.NEW_VOICE_MSG_S)
print("recv new_voice_msg{}".format(msg))
-
+#请求未读的语音消息列表
class IOTWeb_get_new_voice_msgProtoCol(ProtoCol):
"""get_new_voice_msg"""
TYPE = "get_new_voice_msg"
@param msg: 接收到的下行数据
"""
print("recv put_voice_msg_state{}".format(msg))
-
+#收到蓝牙连接记录获取请求
class IOTWeb_get_bt_connect_record_listProtoCol(ProtoCol):
"""get_bt_connect_record_list"""
TYPE = "get_bt_connect_record_list"