EventMesh.subscribe("send_get_connect_bt_state",self.send_get_connect_bt_state)
EventMesh.subscribe("recv_bt_connect_rest",self.recv_bt_connect_rest)
EventMesh.subscribe("AI_send_bt_ble_switch_toble",self.AI_send_bt_ble_switch_toble)
+ EventMesh.subscribe("get_bt_versions",self.get_bt_versions)
self.bt_switch = 0
self.ble_switch = 0
self.uart_timer = osTimer()
if "data" in msg:
EventMesh.publish("send_bt_connect_state_to_iot",msg)
pass
+ def get_bt_versions(self,event=None,msg=None):
+ return self.bt_versions
def AI_send_bt_ble_switch_toble(self,event,msg):
# // {
# // "event":"switch_bt_state",
utime.sleep_ms(10)
print("ota_start:count:{}".format(count))
headers_T = {"Content-Type":"application/octet-stream"}
- response = request.get(url = msg,headers=headers_T,decode = False)
+ response = request.get(url = msg,headers=headers_T,timeout = 120,decode = False)
offset = 0
checksum = 0
for i in response.content:
- EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
+ #EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
data = base64.b64encode(i)
break
utime.sleep_ms(1)
self.bt_ota_flag = 0
+ return 1
audio_buf = ['chaobingfatis', 'chenggong', 'didianguanji', 'IMEIhao', 'jianquancuowu', 'key_prompt', 'liuliangtishi', 'Low_power_warning', 'R_CHARGE_FULL', 'R_CHARGE_IN', 'R_CHARGE_OUT', 'R_READ_TIME_0', 'R_READ_TIME_1', 'R_READ_TIME_2', 'R_READ_TIME_3', 'R_READ_TIME_4', 'R_READ_TIME_5', 'R_READ_TIME_6', 'R_READ_TIME_7', 'R_READ_TIME_8', 'R_READ_TIME_9', 'R_READ_TIME_A', 'R_READ_TIME_B', 'R_READ_TIME_C', 'R_READ_TIME_D', 'R_READ_TIME_E', 'R_READ_TIME_F', 'R_READ_TIME_G', 'R_READ_TIME_H', 'R_READ_TIME_I', 'R_READ_TIME_J', 'R_READ_TIME_K', 'R_READ_TIME_L', 'R_READ_TIME_M', 'R_READ_TIME_N', 'R_READ_TIME_O', 'R_READ_TIME_P', 'R_READ_TIME_Q', 'R_READ_TIME_R', 'R_READ_TIME_S', 'R_READ_TIME_T', 'R_READ_TIME_U', 'R_READ_TIME_V', 'R_READ_TIME_W', 'R_READ_TIME_X', 'R_READ_TIME_Y', 'R_READ_TIME_Z', 'send_tone', 'shouhou', 'xinhaoruo1', 'zhengzaiguanji']
class AI_dev(Abstract):
# AI
EventMesh.subscribe("GET_USB_STATE",self.get_usb_state)
EventMesh.subscribe("SET_SPEECH_RATE",self.set_speech_rate)
+ EventMesh.subscribe("rest_TB",self.rest_TB)
print("AI_dev:2")
self.pk = PowerKey()
print("sys_up_cb!!!!!!!!!!!!!!!")
self.wakeup_BT()
self.PIN_wakeup_bt.write(1)
-
+ def rest_TB(self,event=None,msg=None):
+ print("rest_TB!!!!!!!!!!!!!!!")
+ print("rest_TB!!!!!!!!!!!!!!!")
+ print("rest_TB!!!!!!!!!!!!!!!")
+ self.PIN_BT_ON.write(0)
+ utime.sleep_ms(100)
+ self.PIN_BT_ON.write(1)
def wakeup_BT(self,event=None,msg=None):#4G唤醒蓝牙
print("wakeup_BT!!!!!!!!!!!!!!!")
print("wakeup_BT!!!!!!!!!!!!!!!")
+ wakeup_cta1_io = self.extint_wakeup_cta1.read_level()
+ if wakeup_cta1_io == 1:
+ return 1
count = 5
while(True):
count-=1
self.downloadFileVoURL1= ""
self.downloadFileVoURL2= ""
self.downloadFileVoURLBT=""
+ self.ota_task_id = None
+ #蓝牙升级升级,返回0,没有升级;返回,1有升级,正在执行升级;返回2,电压不够
+ def bt_ota(self,event=None,msg=None):
+ print("bt_ota_ota")
+ signal = net.csqQueryPoll()
+ if signal == -1 or sim.getStatus() != 1:#网络不正常
+ print("bt_ota 无 SIM卡!!!!!!!!\r\n")
+ return 0
+ # return 0
+ response = None
+ ret_str =0
+
+ self.downloadFileVoURLBT=""
+ try:
+ #sourceVersion = versions.Build_Time
+ # sourceVersion = "7PIN-"+sourceVersion[:10]+"-"+sourceVersion[11:-3]
+ # print("sourceVersion:{}".format(sourceVersion))
+ # sourceVersion = sourceVersion.replace(" ", "0")
+ # print("sourceVersion2:{}".format(sourceVersion))
+ sourceVersion = "7PIN_BT_000000000000"
+ print("sourceVersion:{}".format(sourceVersion))
+ bt_versions = EventMesh.publish("get_bt_versions")
+ if bt_versions == None:
+ bt_versions=""
+ print("bt_versions:{}".format(bt_versions))
+ #url = "http://iot.api.thisiot.com/ota/task?deviceId=860132060348836&sourceVersion=2024-12-20-15:35-1"
+ url =None
+ # if dev_type == "7PIN_BK_EU":#英文小瑞
+ # url = "http://dmp-global.raisound.com/bz-api/ota/task?deviceId={}&sourceVersion={}".format(modem.getDevImei(),sourceVersion)
+ # if dev_type == "7PIN" or dev_type == "7PIN_coze":#柒牌
+ # url = "http://ota.qipai.com/bz-cmp-api/api/task?deviceId={}&sourceVersion={}".format(modem.getDevImei(),sourceVersion)
+ # else:
+ url = "http://dmp.raisound.com/bz-api/ota/task?deviceId={}&sourceVersion={}".format(modem.getDevImei(),sourceVersion)
+
+ print(url)
+ response = request.get(url,timeout=5)
+ if response.status_code == 200:
+ data = response.json()
+ print("OTA升级请求:{}".format(data))
+
+ if data:
+ try:
+ if data["code"] == 20007:#有新版本
+ if data["data"]["targetVersion"] != bt_versions and "fileList"in data["data"]:
+ #if len(data["data"]["fileList"]) == 2:
+ for fileList in data["data"]["fileList"]:
+
+ if fileList["fileName"] == "update.ufw":
+ self.downloadFileVoURLBT = fileList["url"]
+ if data["code"] == 20006:#已是最新版本
+ ret_str = 0
+
+ except Exception as e:
+ usys.print_exception(e)
+ else:
+ print("bt_ota get error")
+ response.close()
+ except Exception as e:
+ usys.print_exception(e)
+ if response != None:
+ response.close()
+
+ print("downloadFileVoURLBT{}".format(self.downloadFileVoURLBT))
+ print("bt_ota end")
+ if self.downloadFileVoURLBT !="":
+ battery = EventMesh.publish("get_battery")
+ if battery>=40:
+ self.ota_timer = osTimer()
+ #self.ota_timer.start(15000, 0, self.ota_timer_cb)
+ if self.ota_task_id ==None:
+ self.ota_task_id = _thread.start_new_thread(self.ota_task,())
+ ret_str = 1
+ else:
+ ret_str = 2
+ return ret_str
#小系统升级,返回0,没有升级;返回,1有升级,正在执行升级;返回2,电压不够
def min_sys_ota(self,event=None,msg=None):
print("min_sys_ota")
ret_str =0
self.downloadFileVoURL1= ""
self.downloadFileVoURL2= ""
- self.downloadFileVoURLBT=""
+ #self.downloadFileVoURLBT=""
try:
sourceVersion = versions.Build_Time
sourceVersion = "7PIN-"+sourceVersion[:10]+"-"+sourceVersion[11:-3]
print("sourceVersion2:{}".format(sourceVersion))
#url = "http://iot.api.thisiot.com/ota/task?deviceId=860132060348836&sourceVersion=2024-12-20-15:35-1"
url =None
- if dev_type == "7PIN_BK_EU":#英文小瑞
- url = "http://dmp-global.raisound.com/bz-api/ota/task?deviceId={}&sourceVersion={}".format(modem.getDevImei(),sourceVersion)
- if dev_type == "7PIN" or dev_type == "7PIN_coze":#柒牌
- url = "http://ota.qipai.com/bz-cmp-api/api/task?deviceId={}&sourceVersion={}".format(modem.getDevImei(),sourceVersion)
- else:
- url = "http://dmp.raisound.com/bz-api/ota/task?deviceId={}&sourceVersion={}".format(modem.getDevImei(),sourceVersion)
+ # if dev_type == "7PIN_BK_EU":#英文小瑞
+ # url = "http://dmp-global.raisound.com/bz-api/ota/task?deviceId={}&sourceVersion={}".format(modem.getDevImei(),sourceVersion)
+ # if dev_type == "7PIN" or dev_type == "7PIN_coze":#柒牌
+ # url = "http://ota.qipai.com/bz-cmp-api/api/task?deviceId={}&sourceVersion={}".format(modem.getDevImei(),sourceVersion)
+ # else:
+ url = "http://dmp.raisound.com/bz-api/ota/task?deviceId={}&sourceVersion={}".format(modem.getDevImei(),sourceVersion)
print(url)
response = request.get(url,timeout=5)
print("min_sys_ota:downloadFileVoURL1:{},\ndownloadFileVoURL2:{},\ndownloadFileVoURLBT{}".format(self.downloadFileVoURL1,self.downloadFileVoURL2,self.downloadFileVoURLBT))
print("min_sys_ota end")
- if self.downloadFileVoURL2!="" and self.downloadFileVoURL1!="" and self.downloadFileVoURLBT !="":
+ if self.downloadFileVoURL2!="" and self.downloadFileVoURL1!="" :
battery = EventMesh.publish("get_battery")
if battery>=40:
self.ota_timer = osTimer()
#self.ota_timer.start(15000, 0, self.ota_timer_cb)
- self.AI_client_VC_recv_id = _thread.start_new_thread(self.ota_task,())
+ if self.ota_task_id ==None:
+ self.ota_task_id = _thread.start_new_thread(self.ota_task,())
ret_str = 1
else:
ret_str = 2
def ota_task(self):
import fota
- utime.sleep_ms(2000)
+ utime.sleep_ms(15000)
count = 30#最多等待30秒
while 1:
count-=1
if VC_satrt_flag == 0 or count<=0 or voice_record_satrt_flag == 0:
break
utime.sleep_ms(100)
-
- EventMesh.publish("bt_ota_run",self.downloadFileVoURLBT) #升级蓝牙
- utime.sleep_ms(30000)
- fota_obj = fota()
- fota_obj.httpDownload(url1=self.downloadFileVoURL1,url2=self.downloadFileVoURL2)
+ if self.downloadFileVoURLBT != "":
+ EventMesh.publish("bt_ota_run",self.downloadFileVoURLBT) #升级蓝牙
+ utime.sleep_ms(1000)
+ EventMesh.publish("rest_TB") #复位蓝牙
+ utime.sleep_ms(50000)
+ if self.downloadFileVoURL1 == "" and self.downloadFileVoURL2 == "": #cat1没有升级的时候,要重启设备
+ Power.powerRestart()
+ if self.downloadFileVoURL1 != "" and self.downloadFileVoURL2 != "":
+ fota_obj = fota()
+ fota_obj.httpDownload(url1=self.downloadFileVoURL1,url2=self.downloadFileVoURL2)
#ota升级结果返回,开机时调用一次即可
def ota_result(self,event=None,msg=None):
response = None
except Exception as e:
usys.print_exception(e)
try:
- if self.ai_OTA.min_sys_ota()==1:
+ bt_ota_flag = self.ai_OTA.bt_ota()#先检查蓝牙是否要升级
+ cat1_ota_flag = self.ai_OTA.min_sys_ota()
+ if bt_ota_flag==1 or cat1_ota_flag == 1:
#if 0:
self.AI_TTS_str = "检测到有新版本需要升级啦!升级时可千万别断电或乱按哦,升级完成后设备会自动重启,重启就代表升级成功"
EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_VC_start})