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)
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()
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})
#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()
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')#关机音频
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")
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):
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上传
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
}
}
}
+ self.AI_new_voice_url = ""
print("AI_client_new_voice!!!!!!!!!!!!!!!!!!!!!!!!!!!!!{}".format(json_data))
self.AI_client_VC_send(ujson.dumps(json_data))
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")
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)])
#设备上报状态上报数据格式
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,
"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)
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)
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)) {
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:
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
self.num_len = 0
self.sos_flag = 0
#未设置号码
+
def voice_callback(self,args):
EventMesh.debug_log('111test voicecall iinfo:{}'.format(args))
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):
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):
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"}}
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:
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])
# 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
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")
if sim.getStatus() != 1 or self.start_voice_flag == 1:#网络正常
return
-
if self.reconnect_count >= WEB_CONNECT_MAX_COUNT: #重连次数大于10次不在进重连只有下发心跳才重新连接
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, ())
_thread.stack_size(8*1024)
_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
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:
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 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))
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):
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("开始录音")
@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"]