From: dxy15521469561 <1731678236@qq.com> Date: Mon, 13 Nov 2023 10:16:10 +0000 (+0800) Subject: K01: X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=7a715de356054125fd2408b3e29e803c4ecdcd77;p=mirrors%2FASR1603_G5.git K01: 对接云米协议定位数据 --- diff --git a/2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/appWechat.py b/2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/appWechat.py index eb5ec846..f6a0f769 100644 --- a/2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/appWechat.py +++ b/2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/appWechat.py @@ -150,444 +150,6 @@ wechat_press_label_countdown.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) # wechat_update_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) # wechat_update_label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) -#*****************AI语音*******************# -# -------------------------------------------wechat screen---------------------------------------------------------- -aivoice_screen = lv.obj() -print("aivoice_screen") -aivoice_screen.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF) -aivoice_screen.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) - - -ai_screen_luyin_screen = lv.obj(aivoice_screen) -ai_screen_luyin_screen.set_pos(0, 0) -ai_screen_luyin_screen.set_size(LCD_X, 96) -ai_screen_luyin_screen.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF) -ai_screen_luyin_screen.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) - -ai_detail_cont_obj = lv.obj(aivoice_screen) -ai_detail_cont_obj.set_pos(0, 5) -ai_detail_cont_obj.set_size(128, 90) -ai_detail_cont_obj.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF) -ai_detail_cont_obj.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) - -aivoice_press_btn = lv.btn(aivoice_screen) -aivoice_press_btn.set_pos(10, 100) -aivoice_press_btn.set_size(LCD_X-20, 26) -aivoice_press_btn.add_style(style_wechat_btn, lv.PART.MAIN | lv.STATE.DEFAULT) -aivoice_press_btn.add_style(style_common_bg_rect_btn_pressed, lv.PART.MAIN | lv.STATE.PRESSED) -aivoice_press_btn.set_style_radius(30,0) - -aivoice_press_label = lv.label(aivoice_screen) -aivoice_press_label.set_text("AI智能说话") -aivoice_press_label.set_size(LCD_X, 20) -aivoice_press_label.set_pos(0,103) -aivoice_press_label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) -aivoice_press_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) - -aivoice_left_label = lv.label(ai_detail_cont_obj) -aivoice_left_label.set_pos(0, 10) -aivoice_left_label.set_size(LCD_X, 40) -aivoice_left_label.set_text(" ") -aivoice_left_label.set_long_mode(lv.label.LONG.WRAP) -aivoice_left_label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) -aivoice_left_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) - -aivoice_right_label = lv.label(ai_detail_cont_obj) -aivoice_right_label.set_pos(0, 60) -aivoice_right_label.set_size(LCD_X, 40) -aivoice_right_label.set_text(" ") -aivoice_right_label.set_long_mode(lv.label.LONG.WRAP) -aivoice_right_label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) -aivoice_right_label.add_style(style_font_youyuan_20_red, lv.PART.MAIN | lv.STATE.DEFAULT) - - - -aivoice_press_label_countdown = lv.label(ai_screen_luyin_screen) -aivoice_press_label_countdown.set_pos(0, 30) -aivoice_press_label_countdown.set_size(LCD_X, 20) -aivoice_press_label_countdown.set_text(" ") -aivoice_press_label_countdown.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) -aivoice_press_label_countdown.set_long_mode(lv.label.LONG.WRAP) -aivoice_press_label_countdown.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) - -class AIScreen(Screen):#AI语音 - NAME = "ai_page" - - def __init__(self): - super().__init__() - self.MXA_MSG = 5 - self.wechat_recode_list = {} - self.wechat_num = 0 - self.volum_size = 8 - self.msg_tmp = "" - self.record_test = audio.Record() - self.play_timer = osTimer() - self.record_test.gain(4,12) - self.aud = audio.Audio(0) - self.second_timer = osTimer() - self.send_data_time = osTimer() - self.press_state = 0 - self.meta = aivoice_screen - aivoice_press_btn.add_event_cb(lambda e: EventMesh.callback_wrapper(self.talking_cb(e)), - lv.EVENT.LONG_PRESSED, None) - aivoice_press_btn.add_event_cb(lambda e: EventMesh.callback_wrapper(self.sending_cb(e)), - lv.EVENT.RELEASED, None) - - EventMesh.subscribe("send_ai_data", self.send_ai_data) - EventMesh.subscribe("show_ai_data", self.show_ai_data) - EventMesh.subscribe("websocket_client", self.websocket_client) - self.count_img = 0 - self.play_sec = 0 - self.ble_send = 0 - - self.countdown = 1 - self.count_img = 0 - self.paay_btn_count = 0 - self.paay_btn_old_count = 99999 - self.play_text = None - self.play_sec = 0 - self.sec_num = 0 - self.countdown_old = 0 - self.press_state = 0 - self.ble_send = 0 - self.wechat_show = 0 - self.wechat_show_list = 0 - self.ws_url = "ws://ability.raisound.com:10180/qianwen/chinese/recognize" - self.secret_id = "Q4NPLBLyidvRc4TAUByUhcVfRFM1kQBi" - self.api_key = b'P7vNsYTv' - self.file_name = None #"/usr/test.wav"#file_name#"/usr/static/storage_file/1.wav" #"/usr/static/storage_file/3.amr"##file_name#"/usr/test.wav" - self.ws_conn = 0 - self.Client = 0 - self.session_id='' - self.timeSecond = 0 - self.data_flag = 0 - self.asr_data = queue.Queue(16) - - def websocket_client(self, event, msg): - self.data_flag = 0 - self.timeSecond = 0 - self.ws_url = msg[0] #websocket_url - self.secret_id = msg[1] #secret_id - self.api_key = msg[2] #api_key - self.file_name = "/usr/test.wav"#msg[3]# file_name #"/usr/test.wav"#file_name#"/usr/static/storage_file/1.wav" #"/usr/static/storage_file/3.amr"##file_name#"/usr/test.wav" - self.ws_conn = uwebsocket.Client() - self.tasks = [] - self.__init_websocket_conn() - self.__start_init() - - self.session_id = "" - self.__run() - # self.asr_result = queue.Queue(16) - - def HMAC(self,k, m): - SHA1_BLOCK_SIZE = 64 - KEY_BLOCK = k + (b'\0' * (SHA1_BLOCK_SIZE - len(k))) - KEY_INNER = bytes((x ^ 0x36) for x in KEY_BLOCK) - KEY_OUTER = bytes((x ^ 0x5C) for x in KEY_BLOCK) - inner_message = KEY_INNER + m - outer_message = KEY_OUTER + SHA1(inner_message).digest() - return SHA1(outer_message) - - - def get_hmac_sha1(self,k, m): - data = self.HMAC(k, m).digest() - print("HMAC(k, m).digest():", data) - print("HMAC(k, m).digest():", ubinascii.hexlify(data)) - hex_data = ubinascii.hexlify(data) - hex_data = hex_data.decode('ascii') - return hex_data - # 连接 - def __init_websocket_conn(self): - uri = self.__get_entire_url() - print("__init_websocket_conn",uri) - try: - self.Client = self.ws_conn.connect(uri) - - except Exception as e: - print(e) - return - - def __get_entire_url(self):#连接地址 - - time = utime.localtime()#本地时间戳 - t = utime.mktime(time) - - string = "secretID={}×tamp={}".format(self.secret_id,t) - - - md5_str = uhashlib.md5(string.format(t)) - res = md5_str.digest() - # 转成十六进制表示 - MD5_head = ubinascii.hexlify(res)# - MD5_head = MD5_head.decode('ascii') - print("uri!!",MD5_head) - signature = self.get_hmac_sha1(self.api_key, MD5_head)#对api_key进行再加密 - - # signature = hmac.new(self.api_key.encode(), md5_str.encode(), uhashlib.sha1).hexdigest() - uri = "{}?secretID={}&signature={}×tamp={}".format(self.ws_url,self.secret_id,signature,t) - print("uri",uri,MD5_head,signature) - return uri - - # 初始化 - def __start_init(self): - json_data = ujson.dumps({"action": "InitStreamingASR"}) - print(json_data) - if self.Client != 0: - self.Client.send(json_data) - result = self.Client.recv() - print(result) - self.session_id = ujson.loads(result)["session_id"] - - # # 发送数据 - def __send_data(self): - while True: - try: - data = self.asr_data.get() - print("__send_data1",len(data)) - if self.Client != 0: - self.Client.send(data) - print("__send_data2",len(data)) - except Exception as e: - print(e) - self.__close() - break - - # # 读取音频数据到队列逻辑 - def __send_queue(self): - file = open(self.file_name, "rb+") - while True: - data = file.read(3200) - if data: - encode_audio = base64.standard_b64encode(data).decode("utf-8") - session_id = "" - session_id = self.session_id - json_data = ujson.dumps({ - "action": "StreamingASR", - "audio_data": encode_audio, - "session_id":str(session_id) - }) - # print(json_data) - print("__send_queue:put",len(json_data)) - self.asr_data.put(json_data) - else: - print("__close111111111") - utime.sleep_ms(1) - self.__close() - print("__close!!!!!!!!!!") - break - # print("json_data",json_data) - # utime.sleep_ms(1) - - - # # 读取数据 - def read_data(self): - while True: - try: - result = self.Client.recv() - print("result",result) - json_load = ujson.loads(result) - print("json_load",json_load) - if "type" in json_load.keys(): - - if json_load["type"] == "real_asr": - - print("转写结果",json_load) - if json_load["type"] == "model_answer": - self.data_flag = 1 - question = str(json_load["question"]) - answer = str(json_load["answer"]) - print("\033[0;31;40m模型问答结果\033[0m", json_load,question,answer) - EventMesh.publish("show_ai_data",[question,answer]) - time = utime.localtime()#本地时间戳 - second_old = utime.mktime(time) - if self.timeSecond == 0: - self.timeSecond = second_old - - if second_old - self.timeSecond >= 30: - self.timeSecond = second_old - if self.data_flag == 0: - print("data is null") - self.__close() - break - - except Exception as e: - self.__close() - break - - # # 释放结束 - def __close(self): - json_data = ujson.dumps({"action":"PausedASR"})#{"action": "PausedASR"} - print("__close3333333") - if self.Client != 0: - self.Client.send(json_data) - print(json_data) - - - - def __relase(self):#结束不再录音 - json_data = ujson.dumps({"action":"RelStreamingASR"})#{"action": "RelStreamingASR"} - print(self.Client) - if self.Client != 0: - self.Client.send(json_data) - print("__relase") - - # # 运行 - def __run(self): - _thread.stack_size(10*1024) - _thread.start_new_thread(self.__send_queue,()) - _thread.stack_size(8*1024) - - _thread.stack_size(11*1024) - _thread.start_new_thread(self.__send_data, ()) - _thread.stack_size(8*1024) - - - - def send_ai_data(self, event, msg): - data = ["ws://ability.raisound.com:10180/qianwen/chinese/recognize","Q4NPLBLyidvRc4TAUByUhcVfRFM1kQBi",b'P7vNsYTv',msg] - EventMesh.publish("websocket_client",data) - # websocket_client_conn("ws://ability.raisound.com:10180/qianwen/chinese/recognize","Q4NPLBLyidvRc4TAUByUhcVfRFM1kQBi",b'P7vNsYTv',msg) - self.read_data() - - def show_ai_data(self, event, msg): - self.__relase() - print("show_ai_data",msg) - ai_screen_luyin_screen.add_flag(lv.obj.FLAG.HIDDEN) - ai_detail_cont_obj.clear_flag(lv.obj.FLAG.HIDDEN) - aivoice_left_label.set_text(str(msg[0])) - aivoice_right_label.set_text(str(msg[1])) - - pass - - - def initialization(self): - Wechat_log("ai_page") - self.aud.setVolume(11)#设置最大声录音 - self.count_img = 0 - self.play_sec = 0 - self.ble_send = 0 - # utime.sleep(1) - # for j in range( 200): - # self.updata_list_show(1) - Wechat_log("initialization2") - if ai_detail_cont_obj != None: - ai_detail_cont_obj.scroll_to(0, 0, lv.ANIM.OFF) - - def talking_cb(self,e): - Wechat_log("talking_cb1") - EventMesh.publish("publish_message_event_ui",{"func":self.talking,"data":e}) - Wechat_log("talking_cb2") - #按下录音 - def talking(self,e): - if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1:#有卡时触发sos报警 无卡时自动关机 - print("talking1") - self.play_timer.stop() - self.aud.stop() - ai_screen_luyin_screen.clear_flag(lv.obj.FLAG.HIDDEN) - ai_detail_cont_obj.add_flag(lv.obj.FLAG.HIDDEN) - self.countdown = 1 - aivoice_press_label_countdown.set_text("{}S".format(str(self.countdown))) - - - #self.updata_list_show(2)#不需要显示语音列表 - #按下说话 - if self.wechat_num >= self.MXA_MSG: - self.wechat_num = 0 - self.wechat_num += 1 - self.wechat_show = self.wechat_num - self.wechat_recode_list["num"] = self.wechat_num - print("talking1.0") - self.record_test.start("/usr/static/ai_file.wav",10) - self.second_timer.start(1000, 1, self.reduce_second) - self.press_state = 1 - self.ble_send = 1 - #松开发送 - print("talking2") - else: - EventMesh.publish("load_screen", {"screen": "no_sim_popup_screen"}) - - - def sending_cb(self,e): - if self.press_state == 1: - if EventMesh.publish(constants.EVENT.GET_CONNECT) == 1:#有卡时触发sos报警 无卡时自动关机 - Wechat_log("sending_cb1") - EventMesh.publish("publish_message_event_ui",{"func":self.sending,"data":e}) - #self.sending(e) - Wechat_log("sending_cb2") - else: - self.press_state = 0 - EventMesh.publish("load_screen", {"screen": "no_sim_popup_screen"}) - else: - pass - def reduce_second(self,*args): - if self.countdown < 10: - self.countdown += 1 - else: - self.countdown = 10 - self.sending_cb(0) - - if self.countdown >= 10: - self.countdown = 10 - - aivoice_press_label_countdown.set_text("{}S".format(str(self.countdown))) - #松开发送 - def sending(self,e): - Wechat_log("sending1") - if self.press_state == 1: - # wechat_label.clear_flag(lv.obj.FLAG.HIDDEN) - # wechat_label.set_text("发送中") - ai_screen_luyin_screen.add_flag(lv.obj.FLAG.HIDDEN) - ai_detail_cont_obj.clear_flag(lv.obj.FLAG.HIDDEN) - - if self.countdown >= 10: - self.countdown = 10 - - #写序号 - self.record_test.stop() #停止錄音 - self.second_timer.stop() #停止计时器 - #修改或添加词典键值 - self.press_state = 0 - self.ble_send = 0 - ##隐藏显示文本 显示列表显示框 - - path = "/usr/static/ai_file.wav" - aivoice_press_label_countdown.set_text(" ") - self.send_data_time.start(2000,0,self.send_file) - # EventMesh.publish("send_ai_data", path) - # ws_client = websocket_client_conn("ws://ability.raisound.com:10180/qianwen/chinese/recognize","Q4NPLBLyidvRc4TAUByUhcVfRFM1kQBi",b'P7vNsYTv',path) - # ws_client.read_data() - - - Wechat_log("sending2") - def send_file(self,*argc): - path = "/usr/static/ai_file.wav" - check_file = ql_fs.path_exists(path) - if check_file == True: - self.file_name = path - # self.__send_queue() - EventMesh.publish("send_ai_data", path) - - def done_return(self): - EventMesh.publish("load_screen", {"screen": "main_menu"}) - - def btn1_release(self): - EventMesh.publish("load_screen", {"screen": "main_menu"}) - - def btn8_press(self): - EventMesh.publish("watch_top_show") - EventMesh.publish("load_screen", {"screen": "main_menu"}) - - def Close(self): - Wechat_log("Close1") - self.record_test.stop() #停止錄音 - self.second_timer.stop() #停止计时器 - self.aud.stop() - num = EventMesh.publish("get_volum_size") - if num == None: - num = 8 - self.aud.setVolume(num)#恢复原始音量 - Wechat_log("Close2") - self.__close() class WechatScreen(Screen): NAME = "wechat" diff --git a/2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/main_init.py b/2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/main_init.py index 2e480886..7ab0a45d 100644 --- a/2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/main_init.py +++ b/2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/main_init.py @@ -92,9 +92,9 @@ def main_init(): ui.add_screen(_ui.Spo2Screen()) ui.add_screen(_ui.TemperatureScreen()) ui.add_screen(_ui.ContactsScreen()) - from appWechat import WechatScreen,NewWechatPopupScreen,AIScreen + from appWechat import WechatScreen,NewWechatPopupScreen ui.add_screen(WechatScreen()) - ui.add_screen(AIScreen()) + from alarm import ClkListScreen,ClockManager,PopupAlarmScreen # from ui_health import HealthScreen from calculator import calculatorScreen diff --git a/2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/mgr.py b/2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/mgr.py index 92cc0cf3..1be60a79 100644 --- a/2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/mgr.py +++ b/2.sdk/project/K01/sdk/services/microPython/ports/quectel/core/mgr.py @@ -1709,6 +1709,8 @@ def wifiScan_cb(args): EventMesh.publish(constants.EVENT.WIFIINFO, args) wifiScan.control(0) +from protocol import server_init + class LocationManager(Abstract): def __init__(self): @@ -1834,11 +1836,45 @@ class LocationManager(Abstract): self.location_check_data_timer_count = self.location_check_data_timer_count+1 def Location_send(self, msg) : - #print("Location_send1") + #print("Location_send1") if self.location_queue.empty() == True: return - date = "{:04d}{:02d}{:02d},{:02d}{:02d}{:02d}".format(*utime.localtime()[0:6]) - date = date[2:] + server_data = server_init() + # print("SockManager:server_data:{}".format(server_data)) + server_addr = server_data[0] + server_port = server_data[1] + ip_infor = {} + ip_infor = EventMesh.publish("get_new_ip") + print("ip_infor1:{} \n\n\n".format(ip_infor)) + + if ip_infor != None: #已经改过服务器 + server_addr = ip_infor[0] + server_port = ip_infor[1] + d_server_addr = "device.miwitracker.com" + d_server_port = 8505 + print("server_addr:{} server_port:{}".format(server_addr,server_port)) + self.date_info = "{:04d}{:02d}{:02d},{:02d}{:02d}{:02d}".format(*utime.localtime()[0:6]) + self.date_info = self.date_info[2:] + if server_addr == d_server_addr and server_port == d_server_port: + + data = RTC().datetime() + hour = data[4] + min = data[5] + sec = data[6] + + week = data[3] + + year = data[0]#å¹´ + month = data[1]#月 + day = data[2]#日 + year_date = int(str(year)[2:]) + # print("year_date",year_date) + self.date_info = "%02d"%(day)+"%02d"%(month)+"%02d"%(year_date)+','+"%02d"%(hour)+"%02d"%(min)+"%02d"%(sec)#云米要日月年 + # self.date_info = "%02d"%(utime.localtime()[1])+"%02d"%(utime.localtime()[2])+"%02d"%(year_date)+','+"%02d"%(utime.localtime()[3])+"%02d"%(utime.localtime()[4])+"%02d"%(utime.localtime()[5]) + # print("date_info",self.date_info) + + #date = "180916,025723" + date = self.date_info #date = "180916,025723" GPS_type = "V" latitude = "0.000000,N"