From 963abf5725e2674a68d0bed83f5e64920c1379a8 Mon Sep 17 00:00:00 2001 From: "cheng.chen" Date: Thu, 18 Jun 2026 11:56:26 +0800 Subject: [PATCH] =?utf8?q?=E7=BC=96=E8=AF=91=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- 2.code/aicos/app/AI_AMP_2_5/CMakeLists.txt | 2 - .../aicos/app/AI_AMP_2_5/dev_authentication.c | 542 +++++++++++++++++- 2 files changed, 524 insertions(+), 20 deletions(-) diff --git a/2.code/aicos/app/AI_AMP_2_5/CMakeLists.txt b/2.code/aicos/app/AI_AMP_2_5/CMakeLists.txt index feb6784..0ed5dfa 100644 --- a/2.code/aicos/app/AI_AMP_2_5/CMakeLists.txt +++ b/2.code/aicos/app/AI_AMP_2_5/CMakeLists.txt @@ -11,8 +11,6 @@ aic_library_sources_ifdef( ${AIC_SOURCE_ROOT}/app/AI_AMP_2_5/bk_key.c ${AIC_SOURCE_ROOT}/app/AI_AMP_2_5/dev_authentication.c ${AIC_SOURCE_ROOT}/app/AI_AMP_2_5/bk_opus_coder.c - ${AIC_SOURCE_ROOT}/app/AI_AMP_2_5/aic_mp3decoder_api.c - ${AIC_SOURCE_ROOT}/app/AI_AMP_2_5/aic_mp3decoder_demo.c ) diff --git a/2.code/aicos/app/AI_AMP_2_5/dev_authentication.c b/2.code/aicos/app/AI_AMP_2_5/dev_authentication.c index 11906aa..6f341ea 100644 --- a/2.code/aicos/app/AI_AMP_2_5/dev_authentication.c +++ b/2.code/aicos/app/AI_AMP_2_5/dev_authentication.c @@ -329,12 +329,19 @@ char * get_token(void) //激活->登录的密钥 - const char *dev_pid = "cqxJZi5CNgzjS3mX21Zw";//PID - const char *dev_key = "uKLrChwrxA1LklgBc3VwawYjUkbT3BgX";//密钥 +// const char *dev_pid = "cqxJZi5CNgzjS3mX21Zw";//PID +// const char *dev_key = "uKLrChwrxA1LklgBc3VwawYjUkbT3BgX";//密钥 //电信 // const char *dev_pid = "DieBeXahZHLrjSnORbgN";//PID // const char *dev_key = "FuXG4ptpGbzvKbdB4vpUypisbENgy2nB";//密钥 +//音箱 +//XbClE3xMZZGZTSnPjFjV +//eWlTnlhmjk5ixBa4KpVTKUhNqLHXnEWy + + const char *dev_pid = "XbClE3xMZZGZTSnPjFjV";//PID + const char *dev_key = "eWlTnlhmjk5ixBa4KpVTKUhNqLHXnEWy";//密钥 + #define HTTP_DEMO_CLIENT_NAME "HTTP Demo Client" #define HTTP_DEMO_URL "http://47.101.171.33/doc/download/10.txt" @@ -350,18 +357,26 @@ static u32 https_demo_handle = 0; static aos_thread_id http_demo_thread; static aos_thread_id https_demo_thread; -void aic_http_demotest() + +int32_t play_audio_done_duplex(const char *buf, uint32_t buf_len, uint32_t sample_rate, uint32_t is_file); + +extern int start_play_music_demo; +void resetClose_time(); + +void aic_http_demotest(char *url_play) { u32 status = 0; long lbytes = 0; u8 *buff; - u32 bytes = 1500; + u32 bytes = 2048; u32 total_length = 0; u32 length_to_be_copied = 0; u32 chunked_mode = 0; bk_printf("aic_http_demotest1213..."); + start_play_music_demo=1; + http_demo_handle = aic_http_client_create(HTTP_DEMO_CLIENT_NAME); if (http_demo_handle == 0) { return; @@ -386,7 +401,10 @@ void aic_http_demotest() do { - bk_printf("aic_http_demotest1213122..."); + // bk_printf("aic_http_demotest1213122..."); + + if(start_play_music_demo!=1) + break; lbytes = aic_https_client_response_data_get(http_demo_handle, buff, bytes, HTTP_DEMO_WAIT_TIME); bk_printf("aic_http_demotest1213123 lbytes %d...",lbytes); @@ -395,6 +413,16 @@ void aic_http_demotest() if (lbytes <= 0) { break; } else { + + bk_printf("https get data %d ",lbytes); + + play_audio_done_duplex(buff, bytes, 16000, 0); + + //audio_data(buff,lbytes,37); + resetClose_time(); + + aos_sleep(20); + chunked_mode = aic_http_client_chunked_mode_check(http_demo_handle); length_to_be_copied = aic_https_client_total_receive_bytes_get(http_demo_handle); if (!chunked_mode && length_to_be_copied) { @@ -409,17 +437,14 @@ void aic_http_demotest() // aicx_error(0x1e6e26, "s", "http get data is %s", buff); bk_printf("aic_http_demotest1213123 finish..."); - + bk_free(buff); aic_http_client_delete(http_demo_handle); return; } -int32_t play_audio_done_duplex(const char *buf, uint32_t buf_len, uint32_t sample_rate, uint32_t is_file); - -void resetClose_time(); -void aic_https_demotest() +void aic_https_demotest(char *url_play) { u32 status = 0; LONG lbytes = 0; @@ -430,6 +455,7 @@ void aic_https_demotest() u32 chunked_mode = 0; AIC_HTTPS_CLIENT_INSTANCE *client_ptr; + start_play_music_demo=1; bk_printf("aic_https_demotest1213..."); https_demo_handle = aic_https_client_create(HTTP_DEMO_CLIENT_NAME); @@ -446,7 +472,8 @@ void aic_https_demotest() /*wait pdp active,only for demo test.*/ // aos_sleep(HTTP_DEMO_SLEEP_TIME); - status = aic_https_client_get_start(https_demo_handle, HTTPS_DEMO_URL, NULL, + VC_state=VC_State_TTSStart; + status = aic_https_client_get_start(https_demo_handle, url_play, NULL, NULL, 443, HTTP_DEMO_WAIT_TIME); if (status != NX_SUCCESS) { aic_https_client_delete(https_demo_handle); @@ -458,6 +485,9 @@ void aic_https_demotest() bk_printf("aic_https_demotest12132..."); do { + + if(start_play_music_demo!=1) + break; lbytes = aic_https_client_response_data_get(https_demo_handle, buff , bytes, HTTP_DEMO_WAIT_TIME); if (lbytes <= 0) { @@ -466,12 +496,12 @@ void aic_https_demotest() bk_printf("https get data %d ",lbytes); - play_audio_done_duplex(buff, bytes, 16000, 0); + // play_audio_done_duplex(buff, bytes, 16000, 0); //audio_data(buff,lbytes,37); resetClose_time(); - aos_sleep(20); + aos_sleep(20); chunked_mode = aic_http_client_chunked_mode_check(https_demo_handle); length_to_be_copied = aic_https_client_total_receive_bytes_get(https_demo_handle); if (!chunked_mode && length_to_be_copied) { @@ -482,9 +512,10 @@ void aic_https_demotest() } while (total_length < length_to_be_copied || chunked_mode); // aicx_error(0x0f0971, "s", "https get data is %s", buff); - + start_play_music_demo=0; bk_printf("download123 finish %d...",total_length); - + // VC_state=VC_State_TTSEnd; + bk_free(buff); aic_https_client_delete(https_demo_handle); return; @@ -893,7 +924,256 @@ aut_active_return: aic_http_client_delete(aut_active_http_handle); } - char ota_url[200] ={0}; + + +void get_alarm_info13(void)//设备激活 +{ + int ret; + bk_printf("get_alarm_info13"); + + + AIC_HTTPS_CLIENT_INSTANCE *http_client; + char deviceId[30] = {0}; + //char dev_pass_base64[100] ={0}; + // char enc_iv[65] = {0}; + + char dev_iccid[100] ={0}; + + // http创建客户端句柄 + u32 aut_active_http_handle = 0; + char *aut_buf =NULL; + char *json_string =NULL; + char form_data_string[200]={0}; + + + char sign_url[200]={0}; + + cJSON *root = NULL; + aut_buf = bk_malloc(5*1024); + if(aut_buf) + memset(aut_buf , 0,5*1024); + else + goto aut_active_return; + + bk_get_imei(deviceId); + + bk_get_iccid(dev_iccid); + + + // const char *signMethod ="MD5"; + + // alog_info("http demo start"); + //登陆数据 + + // bk_printf("dev_id:%s timestamp:%s ",deviceId,timestamp_str); + // char *sign_url = "http://dmp.raisound.com/bz-api/dev/iccid"; + + sprintf(sign_url,"http://wsiot-nocdn.raisound.com/ws-bus/alarm/system/list/%s?devToken=%s",deviceId,get_token()); + + bk_printf(sign_url); + + + // http://dmp.raisound.com/bz-api/dev/iccid + u32 response = 0; + //创建客户端实例 + aut_active_http_handle = aic_http_client_create("HTTP_DEMO_CLIENT_NAME"); + if (aut_active_http_handle == 0) { + bk_printf("Failed to create HTTP client instance\n"); + goto aut_active_return; + } + int url_value = aic_process_https_url(aut_active_http_handle,sign_url,AIC_HTTP_HEAD); + bk_printf("url_value:%d",url_value); + http_client = (AIC_HTTPS_CLIENT_INSTANCE *)aut_active_http_handle; + http_client->login_info.server_port = 80; + aic_http_client_connect(aut_active_http_handle, 5000); + + // 创建JSON对象 + root = cJSON_CreateObject(); + if (root == NULL) { + bk_printf( "Failed to create JSON object\n"); + goto aut_active_return; ; + } + + // 添加字段 + cJSON_AddStringToObject(root, "devToken", get_token()); + // cJSON_AddStringToObject(root, "iccid", dev_iccid); + //cJSON_AddStringToObject(root, "sign", md5_buf); + //cJSON_AddStringToObject(root, "timeStamp", timestamp_str); + // cJSON_AddStringToObject(root, "signMethod", signMethod); + + // 生成JSON字符串 + json_string = cJSON_Print(root); + if (json_string == NULL) { + bk_printf("Failed to print JSON\n"); + //cJSON_Delete(root); + goto aut_active_return; + } + + // 输出JSON + // bk_printf("JSON output: %s\n", json_string); + + //sprintf(form_data_string,"deviceId=%s&iccid=%s",deviceId,dev_iccid); + + //bk_printf("form_data_string: %s\n", form_data_string); + + + aic_https_client_request_initialize(aut_active_http_handle,AIC_HTTPS_METHOD_GET, 0, + 0, NULL,NULL, 10000); + + // aic_https_client_request_header_add(aut_active_http_handle,"Content-Type",strlen("Content-Type"),"application/json",strlen("application/json"),10000);//添加头 + // bk_printf("aic_https_client_request_header_add1"); + + // aic_https_client_request_header_add(aut_active_http_handle,"bz-dt",strlen("bz-dt"),aut_token,strlen(aut_token),10000);//添加头 + // bk_printf("aic_https_client_request_header_add3"); + + + response = nx_web_http_client_request_send(http_client->https_client,10 * 1000); + + + http_client->https_client->nx_web_http_client_state = NX_WEB_HTTP_CLIENT_STATE_POST; + +// ret = aic_https_client_put_data(aut_active_http_handle, json_string, strlen(json_string), +// 1000); +// if (ret == 0) { +// bk_printf("数据发送成功\n"); + +// } else { +// // 处理错误 +// bk_printf("数据发送失败,错误码: %d\n", ret); +// goto aut_active_return; +// } + long read_bytes=0; + + long read_bytes_tmp = aic_https_client_response_data_get(aut_active_http_handle,aut_buf,5*1024,10000); + + while(read_bytes_tmp>0){ + + bk_printf("read_bytes :%d\n",read_bytes_tmp); + + read_bytes+=read_bytes_tmp; + + read_bytes_tmp = aic_https_client_response_data_get(aut_active_http_handle,aut_buf+read_bytes,5*1024,10000); + + } + + + if(read_bytes<=0) + goto aut_active_return; + + bk_printf("get_alarm_info13 :%s",aut_buf); + + cJSON* root123 = cJSON_Parse(aut_buf); + // parse_object(root123,aut_buf); + + // cJSON_Array *test=cJSON_GetObjectItem(root123,"data"); + + cJSON* tmp123=cJSON_GetObjectItem(root123,"msg"); + + bk_printf("get_alarm_info13 count :%s",cJSON_GetStringValue(tmp123)); + + cJSON* cjarray1=cJSON_GetObjectItemCaseSensitive(root123,"data"); + + int count_alarm=cJSON_GetArraySize(cjarray1); + + bk_printf("get_alarm_info13 count :%d",cJSON_GetArraySize(cjarray1)); + + vc_cfg.alarm_count=0; + + for(int i=0;i=0&&temp_bag<10){ + + // // if(temp_bag==1) + // // vc_cfg.VC_mode=0; + // // else + // vc_cfg.VC_mode=temp_bag; + // } + // // vc_cfg.VC_mode= + + // // vc_cfg.VC_TTS_volume + + + + // } + // else + // { + // bk_printf("bargein"); + // } + + // str_tmp = strstr(str_data,"\"time\":\""); + // } + + + +aut_active_return: + // 释放内存 + if(aut_buf) + bk_free(aut_buf); + if(json_string) + cJSON_free(json_string); + if(root) + cJSON_Delete(root); + if(aut_active_http_handle) + aic_http_client_delete(aut_active_http_handle); +} + + +char ota_url[200] ={0}; static int apifota_start_h3(void) { @@ -1106,6 +1386,233 @@ aut_active_return: } + + +void get_alarm_info12() +{ + u32 status = 0; + LONG lbytes = 0; + u8 *buff; + u32 bytes = 1024*2; + u32 total_length = 0; + u32 length_to_be_copied = 0; + u32 chunked_mode = 0; + AIC_HTTPS_CLIENT_INSTANCE *client_ptr; + + bk_printf("get_alarm_info12..."); + + https_demo_handle = aic_https_client_create(HTTP_DEMO_CLIENT_NAME); + if (https_demo_handle == 0) { + return; + } + + bk_printf("get_alarm_info12..."); + + char sign_url[300]={0}; + + char deviceId[30] = {0}; + + bk_get_imei(deviceId); + + sprintf(sign_url,"https://wsiot-nocdn.raisound.com/ws-bus/alarm/system/list/%s?devToken=%s",deviceId,get_token()); + + + bk_printf(sign_url); + + /*for https test,set auth_type to 0, do not need certifica1*/ + client_ptr = (AIC_HTTPS_CLIENT_INSTANCE *)https_demo_handle; + client_ptr->https_client->auth_type = 0; + + /*wait pdp active,only for demo test.*/ + // aos_sleep(HTTP_DEMO_SLEEP_TIME); + + status = aic_https_client_get_start(https_demo_handle, sign_url, NULL, + NULL, 443, HTTP_DEMO_WAIT_TIME); + if (status != NX_SUCCESS) { + aic_https_client_delete(https_demo_handle); + return; + } + + buff = aos_zalloc(bytes); + + bk_printf("get_alarm_info12..."); + + do { + lbytes = aic_https_client_response_data_get(https_demo_handle, buff , bytes, + HTTP_DEMO_WAIT_TIME); + if (lbytes <= 0) { + break; + } else { + + bk_printf("https get data %d ",lbytes); + + // play_audio_done_duplex(buff, bytes, 16000, 0); + + //audio_data(buff,lbytes,37); + // resetClose_time(); + + aos_sleep(20); + chunked_mode = aic_http_client_chunked_mode_check(https_demo_handle); + length_to_be_copied = aic_https_client_total_receive_bytes_get(https_demo_handle); + if (!chunked_mode && length_to_be_copied) { + total_length += lbytes; + } + } + + } while (total_length < length_to_be_copied || chunked_mode); + + // aicx_error(0x0f0971, "s", "https get data is %s", buff); + + bk_printf("download123 finish %d...",total_length); + + aic_https_client_delete(https_demo_handle); + + return; +} + + +void get_alarm_info(void)//OTA更新 +{ + int ret; + bk_printf("get_alarm_info"); + + + AIC_HTTPS_CLIENT_INSTANCE *http_client; + char deviceId[30] = {0}; + //char dev_pass_base64[100] ={0}; + + // http创建客户端句柄 + u32 aut_active_http_handle = 0; + char *aut_buf =NULL; + + //char *json_string =NULL; + //char form_data_string[200]={0}; + + char sign_url[200]={0}; + + cJSON *root = NULL; + aut_buf = bk_malloc(5*1024); + if(aut_buf) + memset(aut_buf , 0,5*1024); + else + goto aut_active_return; + + bk_get_imei(deviceId); + //// DMPTEST + + + //http://app-api.raisound.com/dev/device/info/simple/867686073050930 + #if 1 + sprintf(sign_url,"https://wsiot-nocdn.raisound.com/ws-bus/alarm/system/list/%s?devToken=%s",deviceId,get_token()); + + #else + //https://app-api.raisound.com + + sprintf(sign_url,"https://app-api.raisound.com/dev/device/info/simple/%s",deviceId); + + #endif + + + bk_printf(sign_url); + + u32 response = 0; + //创建客户端实例 + aut_active_http_handle = aic_http_client_create("HTTP_DEMO_CLIENT_NAME"); + if (aut_active_http_handle == 0) { + bk_printf("Failed to create HTTP client instance\n"); + goto aut_active_return; + } + int url_value = aic_process_https_url(aut_active_http_handle,sign_url,AIC_HTTP_HEAD); + bk_printf("url_value:%d",url_value); + http_client = (AIC_HTTPS_CLIENT_INSTANCE *)aut_active_http_handle; + http_client->login_info.server_port = 80; + aic_http_client_connect(aut_active_http_handle, 5000); + + // 创建JSON对象 + root = cJSON_CreateObject(); + if (root == NULL) { + bk_printf( "Failed to create JSON object\n"); + goto aut_active_return; ; + } + + // 输出JSON + // bk_printf("JSON output: %s\n", json_string); + + aic_https_client_request_initialize(aut_active_http_handle,AIC_HTTPS_METHOD_GET, 0, + 0, NULL,NULL, 10000); + + + response = nx_web_http_client_request_send(http_client->https_client,10 * 1000); + + ret=0; + if (ret == 0) { + bk_printf("数据发送成功\n"); + + } else { + // 处理错误 + bk_printf("数据发送失败,错误码: %d\n", ret); + goto aut_active_return; + } + + long read_bytes = aic_https_client_response_data_get(aut_active_http_handle,aut_buf,5*1024,10000); + + bk_printf("read_bytes :%d\n",read_bytes); + + if(read_bytes<=0) + goto aut_active_return; + + bk_printf("get_alarm_info :%s",aut_buf); + + + char *str_tmp = NULL; + + str_tmp = strstr(aut_buf,"\"bargein\":\""); + //bk_printf("str_tmp:%p",str_tmp); + // if(str_tmp)//解析password + // { + // str_tmp += strlen("\"bargein\":\""); + // int count = str_count(str_tmp,'\"'); + // bk_printf("count:%d",count); + // if(count < sizeof(ota_url)) + // { + // memcpy(ota_url,str_tmp,count); + // ota_url[count] = 0; + // bk_printf("bargein:%s",ota_url); + + // int temp_bag=atoi(ota_url); + // if(temp_bag>=0&&temp_bag<10){ + + // // if(temp_bag==1) + // // vc_cfg.VC_mode=0; + // // else + // vc_cfg.VC_mode=temp_bag; + // } + // // vc_cfg.VC_mode= + + // // vc_cfg.VC_TTS_volume + + + + // } + // else + // { + // bk_printf("bargein"); + // } + // } + +aut_active_return: + // 释放内存 + if(aut_buf) + bk_free(aut_buf); + // if(json_string) + // cJSON_free(json_string); + if(root) + cJSON_Delete(root); + if(aut_active_http_handle) + aic_http_client_delete(aut_active_http_handle); +} + + void ota_check_version(void)//OTA更新 { int ret; @@ -1261,8 +1768,7 @@ void ota_check_version(void)//OTA更新 } - - + aut_active_return: // 释放内存 if(aut_buf) -- 2.17.1