elif jsload_data["event"]=="get_ble_switch":
ble_switch_flag = EventMesh.publish("get_storage_config","switch_ble_state")#ble开关
if ble_switch_flag == None:
- ble_switch_flag = "0"
+ ble_switch_flag = "1"
EventMesh.publish("send_ble_switch_toble",str(ble_switch_flag))
ack_flag=1
pass
elif jsload_data["event"]=="get_bt_switch":
bt_switch_flag = EventMesh.publish("get_storage_config","switch_bt_state")#bt开关
if bt_switch_flag == None:
- bt_switch_flag = "0"
+ bt_switch_flag = "1"
EventMesh.publish("send_bt_switch_toble",bt_switch_flag)
ack_flag=1
pass
"event": "switch_ble_state",
"data":{
- "switch_ble_state":"0"
+ "switch_ble_state":"1"
}
}
"event": "switch_ble_state",
"data":{
- "switch_ble_state":"1"
+ "switch_ble_state":"0"
}
}
"event": "switch_bt_state",
"data":{
- "switch_bt_state":"0"
+ "switch_bt_state":"1"
}
}
"event": "switch_bt_state",
"data":{
- "switch_bt_state":"1"
+ "switch_bt_state":"0"
}
}
def ble_switch_flag_time_cb(self,*args):
bt_switch_flag = EventMesh.publish("get_storage_config","switch_bt_state")#bt开关
if bt_switch_flag == None:
- bt_switch_flag = "0"
+ bt_switch_flag = "1"
EventMesh.publish("send_bt_switch_toble",str(bt_switch_flag))
EventMesh.publish("send_imei_to_ble")
ble_switch_flag = EventMesh.publish("get_storage_config","switch_ble_state")#ble开关
if ble_switch_flag == None:
- ble_switch_flag = "0"
+ ble_switch_flag = "1"
EventMesh.publish("send_ble_switch_toble",str(ble_switch_flag))
pass
print("ble_switch_flag_time_cb!!!!!!!")
def kws_even(self,event = None,msg= None):
EventMesh.publish("publish_AI_btnInfo",{"func":self.kws_even_cb})
def kws_even_cb(self):
+ if EventMesh.publish("get_sos_flag") == 1:
+ return
print("kws_even_cb")
+ if EventMesh.publish("get_voice_record_flag") == 1:#停止静默录音
+ if EventMesh.publish("get_voice_record_mode") == 2:#语音留言不能被打断
+ return
+ elif EventMesh.publish("get_voice_record_mode") == 1: #静默录音需要打断
+ EventMesh.publish("stop_voice_record")#停止静默录音
+
if self.VC_mode == 0:
self.Close()
if dev_type == "7PIN" :
if data[0] != 0xff and data[1] !=0xfe and data[2] != 0x03 and data[3] !=0x03:
return
- print(type(data))
+ # print(type(data))
json_bytes = data[8:]
- print(data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7])
+ # print(data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7])
# 2. 将二进制JSON转换为字符串(使用UTF-8解码)
json_str = json_bytes.decode('utf-8')
print("解析出的JSON字符串:")
EventMesh.subscribe("set_sos_info_call", self.set_sos_info_call)
EventMesh.subscribe("set_sos_list_info",self.set_sos_list_info)
EventMesh.subscribe("stop_sos_call",self.stop_sos_call)
-
+ EventMesh.subscribe("set_sos_config",self.set_sos_config)
+ def set_sos_config(self,event,msg):
+ # sos_config:{'enable110': '1', 'pressDuration': 3, 'enableSos': '0'}
+ print("set_sos_config:{}".format(msg))
+ self.sos_config = msg
+ # self.start_phone110112()
+ pass
def get_sos_flag(self,event,msg):
return self.sos_flag
# import EventMesh
pass
def start_phone110112(self):
+ print("start_phone110112:{} self.sos_config:{}".format(self.call_state,self.sos_config))
if self.call_state == 0:
if self.sos_config != {}:
- enable110 = self.sos_config["state"]
- if enable110 == 1:
- p110 = self.sos_config["enable_110"]
- self.phone110112 = p110
- self.sos_timer1.start(2000, 0, self.phone110112_cb)
- pass
+ if "enableSos" in self.sos_config:
+ enableSos = self.sos_config["enableSos"]
+ print("enableSos{} {}".format(enableSos,self.sos_config["enable110"]))
+ if enableSos == "0":
+ if "enable110" in self.sos_config:
+ p110 = self.sos_config["enable110"]
+ if p110 == "0":
+
+ self.phone110112 = "110"
+ self.sos_timer1.start(2000, 0, self.phone110112_cb)
+ elif p110 == "1":
+ self.phone110112 = "112"
+ self.sos_timer1.start(2000, 0, self.phone110112_cb)
+
def sos_call_out_phone(self, msg):#电话拨出去
if self.call_state == 0:
ret = voiceCall.callStart(self.sos_phone_num)
if self.call_state == 0:
EventMesh.publish("stop_voice_record") #电话优先级最高
EventMesh.publish("stop_AI_record")
- voiceCall.callStart(self.phone110112)
+ ret = voiceCall.callStart(self.phone110112)
+ # print("ret:{} {}".format(ret,self.phone110112))
self.phone110112 = ""
-# if ("btStateSwitch".equals(testType)) {
-# return testBtStateDispatch(deviceId);
-# } else if ("btScan".equals(testType)) {
-# return testBtScanDispatch(deviceId);
-# } else if ("getBtState".equals(testType)) {
-# return testGetBtStateDispatch(deviceId);
-# } else if ("getConnectRecordList".equals(testType)) {
-# return testGetConnectRecordListDispatch(deviceId);
-# } else if ("connectBt".equals(testType)) {
-# return testConnectBtDispatch(deviceId);
-# } else if ("disconnectBt".equals(testType)) {
-# return testDisconnectBtDispatch(deviceId);
-# }
+
def set_sos_list_info(self,event,msg):
self.sos_list = msg
if rest == "unbind": #解绑需要开启蓝牙广播
self.btstate = 0
if self.blestate == 0:
- EventMesh.publish("set_storage_config",["switch_ble_state","0"])
- EventMesh.publish("send_ble_switch_toble","0")
+ EventMesh.publish("set_storage_config",["switch_ble_state","1"])
+ EventMesh.publish("send_ble_switch_toble","1")
- EventMesh.publish("set_storage_config",["switch_bt_state","0"])
- EventMesh.publish("send_bt_switch_toble","0")
+ EventMesh.publish("set_storage_config",["switch_bt_state","1"])
+ EventMesh.publish("send_bt_switch_toble","1")
self.blestate=1
elif rest == "bind": #绑定需要关闭蓝牙广播
self.blestate =0
if self.btstate == 0:
- EventMesh.publish("set_storage_config",["switch_ble_state","1"])
- EventMesh.publish("send_ble_switch_toble","1")
+ EventMesh.publish("set_storage_config",["switch_ble_state","0"])
+ EventMesh.publish("send_ble_switch_toble","0")
self.btstate=1
#定位周期
sos_config = msg["data"]
print("recv sos_config{} type:{}".format(sos_config,type(msg)))
EventMesh.publish("set_storage_config",["sos_config",sos_config])
+ EventMesh.publish("set_sos_config",sos_config)
sos_config = EventMesh.publish("get_storage_config","sos_config")
print("sos_config:{} type:{}".format(sos_config,sos_config["enable110"]))
EventMesh.publish(WEB_CMD_ENUM.SOS_CONFIG_S_CMD)
record_mode = EventMesh.publish("get_voice_record_mode")
if record_mode == None:
record_mode = 0
- if record_mode != 2:#语音留言不允许打断
- s_rest = "1"
+ get_VC_satrt_flag = EventMesh.publish("get_VC_satrt_flag")
+ if get_VC_satrt_flag == None:
+ get_VC_satrt_flag = 0
+ if record_mode == 2 or get_VC_satrt_flag == 1:# 如果在AI对话 或者语音留言不允许静默录音
+ s_rest = "0"
EventMesh.publish(WEB_CMD_ENUM.VOICE_RECORD_S_CMD,s_rest)
- EventMesh.publish("start_voice_record",1)
-
+ EventMesh.publish("stop_voice_record")
else:
- s_rest = "0"
+ s_rest = "1"
EventMesh.publish(WEB_CMD_ENUM.VOICE_RECORD_S_CMD,s_rest)
-
+ EventMesh.publish("start_voice_record",1)
print("开始录音")
#设备解绑
rest = data["rest"]
if rest == "success":
play_str = "设备解绑成功"
- EventMesh.publish("set_storage_config",["switch_ble_state","0"])
- EventMesh.publish("send_ble_switch_toble","0")
+ EventMesh.publish("set_storage_config",["switch_ble_state","1"])
+ EventMesh.publish("send_ble_switch_toble","1")
- EventMesh.publish("set_storage_config",["switch_bt_state","0"])
- EventMesh.publish("send_bt_switch_toble","0")
+ EventMesh.publish("set_storage_config",["switch_bt_state","1"])
+ EventMesh.publish("send_bt_switch_toble","1")
EventMesh.publish("play_tts",[play_str,1])
pass
else:
# }
self.btstate = 0
self.blestate = 0
- EventMesh.publish("set_storage_config",["switch_ble_state","0"]) #用户解绑设备需要开启广播 开启经典蓝牙
- EventMesh.publish("send_ble_switch_toble","0")
+ EventMesh.publish("set_storage_config",["switch_ble_state","1"]) #用户解绑设备需要开启广播 开启经典蓝牙
+ EventMesh.publish("send_ble_switch_toble","1")
- EventMesh.publish("set_storage_config",["switch_bt_state","0"])
- EventMesh.publish("send_bt_switch_toble","0")
+ 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)
print("recv user_unbind_dev{}".format(msg))
#下发位子留言
# 通过websocket发送到服务器端
date_tmp = utime.localtime()
time_tmp = utime.mktime(date_tmp)
+ # {
+ # "cmd":"dispatch_rest",
+ # "ts":1738283829,
+ # "msg":"消息收到响应",
+ # "data":{
+ # "cmd":"switch_bt_state",
+ # "rest":"success|error",
+ # "msg":"收到蓝牙已打开/蓝牙已关闭指令"
+ # }
+ # }
+ s_msg = "蓝牙已关闭指令"
+ if msg == "1":
+ s_msg = "收到蓝牙已打开"
+ elif msg == "0":
+ s_msg = "蓝牙已关闭指令"
switch_bt_state = {
"cmd":"dispatch_rest",
"ts":time_tmp,
"data":{
"cmd":"switch_bt_state",
"rest":"success",
- "msg":"蓝牙已打开"
+ "msg":s_msg
}
}
send_data = b''
@param event:上行下发switch_bt_state
@param msg: 接收到的下行数据
"""
+ s_state = "1"
if "data" in msg:
data = msg["data"]
if data == "0":
+ s_state = "0"
EventMesh.publish("set_storage_config",["switch_bt_state","0"])
EventMesh.publish("send_bt_switch_toble","0")
pass
elif data == "1":
+ s_state = "1"
EventMesh.publish("set_storage_config",["switch_bt_state","1"])
EventMesh.publish("send_bt_switch_toble","1")
pass
print("recv switch_bt_state{}".format(msg))
- EventMesh.publish(WEB_CMD_ENUM.SWITCH_BT_STATE_S_CMD)
+ EventMesh.publish(WEB_CMD_ENUM.SWITCH_BT_STATE_S_CMD,s_state)
#蓝牙扫描
class IOTWeb_bt_scanProtoCol(ProtoCol):
print("recv bt_state{}".format(msg))
switch_bt_state = EventMesh.publish("get_storage_config","switch_bt_state")
if switch_bt_state == None:
- switch_bt_state = 0
+ switch_bt_state = "1"
EventMesh.publish(WEB_CMD_ENUM.GET_BT_STATE_S,str(switch_bt_state))