From: hcj <1224667075@qq.com> Date: Tue, 2 Jul 2024 09:35:41 +0000 (+0800) Subject: 协议bug修复,增加MP3目录获取(解析MP3还有问题) X-Git-Tag: release_V1.2.70_20241020_135402~895^2~1 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=95babe745f1aecec893afb9bc2257388abbb1048;p=mirrors%2FFD230.git 协议bug修复,增加MP3目录获取(解析MP3还有问题) --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneDirView.cpp b/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneDirView.cpp index 454b38ee8..5ab5893cb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneDirView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneDirView.cpp @@ -106,7 +106,7 @@ namespace OHOS label1_phone_name = new UILabel(); } label1_phone_name->SetPosition(173, 53); // widget's left position and top position - label1_phone_name->Resize(120, 35); // widget's width and height + label1_phone_name->Resize(120, 55); // widget's width and height label1_phone_name->SetViewId("label1");// Set style label1_phone_name->SetStyle(STYLE_TEXT_FONT, 50); @@ -185,8 +185,8 @@ namespace OHOS { if(strcmp("container_one_page",idstr)==0) { - // container_->SetVisible(true); - // container_one_page->SetVisible(false); + container_->SetVisible(true); + container_one_page->SetVisible(false); return; } diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index db85d49c1..6f7d3b84c 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -82,15 +82,82 @@ void ble_set_ai_Answer_str(char *buf) { OHOS::AiVoiceModel::GetInstance().SetaiAnswerStrStr(std::string(buf)); } - + +// { +// "type":3, +// "list":[ +// { +// "uid":3758, +// "name":"plate_3758.bin", +// "size":129600 +// }, +// { +// "uid":3759, +// "name":"plate_3759.bin", +// "size":129600 +// } +// ] +// } +// 注:MP3文件目录格式 +// { +// "type":2, +// "list": [ +// { +// "uid":2461, //指定唯一编号,便于APP发送编号删除文件 +// "name":"夜曲.mp3", +// "size":3894464, +// "artist":"周杰伦", +// "dur":223000 //歌曲时长,单位毫秒 +// }, +// { +// "uid":2465, //指定唯一编号,便于APP发送编号删除文件 +// "name":"告白气球.mp3", +// "size":3894464, +// "artist":"周杰伦", +// "dur":223000 //歌曲时长,单位毫秒 +// } +// ] +// } +// Tag_Trailer_t Mp3Trailer; + +// void Tag_GetTrailer( FILE *fp) +// { +// // Get Header +// fseek(fp,-128,SEEK_END); +// fread(Mp3Trailer.Header,3,1,fp); +// // Get Title +// fseek(fp,-125,SEEK_END); +// fread(Mp3Trailer.Title,30,1,fp); +// // Get Artist +// fseek(fp,-95,SEEK_END); +// fread(Mp3Trailer.Artist,30,1,fp); +// // Get Album +// fseek(fp,-65,SEEK_END); +// fread(Mp3Trailer.Album,30,1,fp); +// // Get Year +// fseek(fp,-35,SEEK_END); +// fread(Mp3Trailer.Year,4,1,fp); +// // Get Comment +// fseek(fp,-31,SEEK_END); +// fread(Mp3Trailer.Comment,30,1,fp); +// // Get Cenre +// fseek(fp,-1,SEEK_END); +// fread(Mp3Trailer.Cenre,1,1,fp); +// } + + char * dir_to_json_buf_malloc_(uint8_t type) { char dir_path[128]={0}; + type=2; switch (type) { - case 0x43: //同步步数历史数据 - sprintf_s(dir_path,64,"%s","user/userdata/music"); + case 2: // + sprintf_s(dir_path,64,"%s","user/music"); + break; + case 3: // + sprintf_s(dir_path,64,"%s","user/userdata/dial"); break; default: break; @@ -101,6 +168,7 @@ char * dir_to_json_buf_malloc_(uint8_t type) struct DIR *dir; struct dirent *ent; uint32_t file_size=0; + uint8_t file_index=1; if ((dir = opendir(dir_path)) != NULL) { while ((ent = readdir(dir)) != NULL) @@ -114,54 +182,40 @@ char * dir_to_json_buf_malloc_(uint8_t type) if (ent->d_type == DT_REG || ent->d_type == DT_UNKNOWN ) // 普通文件 { - - //*file_size=ent->d_reclen; - // char file_path[128]={0}; - // sprintf_s(file_path,128,"%s/%s",TAR_PATH,ent->d_name); + char file_path[128]={0}; + sprintf_s(file_path,128,"%s/%s","user/music",ent->d_name); - // FILE * fp = fopen(file_path,"rb+"); - // if(fp==NULL) - // { - // printf(" fopen fail %s\r\n",file_path); - // return NULL; - // } - // if (fp != NULL) - // { - // fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 - // file_size = ftell(fp); // 获取当前文件指针位置,即文件大小 - // fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 - // } - // fclose(fp); - - // cJSON* itemJSON = cJSON_CreateObject(); - - // cJSON_AddNumberToObject(itemJSON,"index",file_index); - // cJSON_AddNumberToObject(itemJSON,"count",file_count); - - // cJSON_AddNumberToObject(itemJSON,"crc",crc); - - // cJSON_AddStringToObject(itemJSON,"name",fileName.c_str()); - // cJSON_AddNumberToObject(itemJSON,"size",file_size); - - // char *json_format = cJSON_PrintUnformatted(itemJSON); - - // int pSize = cJSON_GetArraySize(dataJSON); - // printf("文件数据:%s\r\n",json_format); - // cJSON_Delete(dataJSON); - // file_index++; + FILE * fp = fopen(file_path,"rb+"); + if(fp==NULL) + { + printf(" fopen fail %s\r\n",file_path); + return NULL; + } + if (fp != NULL) + { + fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 + file_size = ftell(fp); // 获取当前文件指针位置,即文件大小 + fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 + } + //Tag_GetTrailer(fp); - // return json_format; + fclose(fp); - //cJSON_AddItemReferenceToArray(data_arryJSON,itemJSON); + cJSON* itemJSON = cJSON_CreateObject(); + cJSON_AddNumberToObject(itemJSON,"uid",file_index); + cJSON_AddStringToObject(itemJSON,"name",fileName.c_str()); + cJSON_AddNumberToObject(itemJSON,"size",file_size); + cJSON_AddStringToObject(itemJSON,"artist", "未知"); + cJSON_AddStringToObject(itemJSON,"dur", "未知"); + cJSON_AddItemReferenceToArray(data_arryJSON,itemJSON); + file_index++; } else if (ent->d_type == DT_DIR) // 目录 { continue; } - } - } closedir(dir); } @@ -169,7 +223,16 @@ char * dir_to_json_buf_malloc_(uint8_t type) { printf("opendir fail\r\n"); } - return NULL; + cJSON_AddNumberToObject(dataJSON,"type",2); + + cJSON_AddItemToObject(dataJSON,"list",data_arryJSON); + + char *json_format = cJSON_PrintUnformatted(dataJSON); + + int pSize = cJSON_GetArraySize(dataJSON); + cJSON_Delete(dataJSON); + printf("mp3 :%s\r\n",json_format); + return json_format; } @@ -519,8 +582,8 @@ void ble_get_sleep_remind(msg_get_sleep_param_info_t *data) printf("开始时间:%d\r\n",data->bedtime_min); uint32_t wakettime= p_ConfigModel->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SLEEP_GET_UP); - data->waketime_hour=bedtime>>16; - data->waketime_min=bedtime&0x00ff; + data->waketime_hour=wakettime>>16; + data->waketime_min=wakettime&0x00ff; printf("结束时间:%d\r\n",data->waketime_hour); printf("结束时间:%d\r\n",data->waketime_min); diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h index af82ebc6d..e8ca3112a 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -261,6 +261,23 @@ void ble_set_ai_Question_str(char *buf); void ble_set_ai_Answer_str(char *buf); +/////////////////////////////MP3相关///////////////////////// + +typedef struct Tag_Trailer +{ +char Header[3]; +char Title[30]; +char Artist[30]; +char Album[30]; +char Year[4]; +char Comment[30]; +char Cenre[1]; +}Tag_Trailer_t; + +char * dir_to_json_buf_malloc_(uint8_t type); + +char * dir_to_json_buf_malloc_(uint8_t type); + #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c index f91965c58..413982566 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -2143,6 +2143,9 @@ void GetWeatherCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,ui // printf("GetWeatherCmd:len:%d data:%s\r\n",len,data); if(Check_CRC(data,len,crcvalue)) { + // uint32_t y=(0xff00); + // uint32_t x =(0xff00& 0Xff00)>>16; + // printf("GetWeatherCmd %u\r\n",x); uint8_t check = 1; jsonCheck_weather(data,&check); sendBuf[17] = check; @@ -3997,8 +4000,8 @@ static void GetAiRecordCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *tota FILE *fp=fopen(file_name,"rb+"); printf("GetAiRecordCmd size %d\r\n",file_size); - uint16_t pack=file_size/num+1; - uint8_t pack_id=1; + uint32_t pack=file_size/num+1; + uint32_t pack_id=1; if(fp==NULL) { printf("fopen fail %s\r\n",file_name); @@ -4012,7 +4015,7 @@ static void GetAiRecordCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *tota send_big_data(1,data,read_size,file_size,pack_id,pack,0x34,1); pack_id++; - msleep(20); + msleep(10); } while (read_size==num); free(data); @@ -4239,7 +4242,7 @@ static void Send_json_Data_Cmd(uint8_t day,uint16_t pack_size,uint8_t id) json_format=struct_to_json_buf_malloc_Alarm(); break; case 0x21: - json_format=NULL; + json_format=dir_to_json_buf_malloc_(day); break; default: @@ -4566,9 +4569,6 @@ void type2AE3Data(ble_read_data *buffer_handle,uint8_t *cmd_buf ,uint8_t *data,u case REVOKE_CURR_FILE_TRANS_CMD://撤销文件传输 RemoveFileCmd(buffer_handle,cmd,data,datalen,totaldata,crcvalue); break; - case GET_SPECIF_TYPE_FILE_CMD://获取指定类型文件目录 - GetFileTypeCmd(data,datalen); // - break; case DELETE_SPECIF_TYPE_FILE_CMD://删除指定类型的所有文件 DeleteFileTypeCmd(cmd,data,datalen,totaldata,crcvalue); break; @@ -4666,6 +4666,7 @@ void type2AE3Data(ble_read_data *buffer_handle,uint8_t *cmd_buf ,uint8_t *data,u case APP_GET_AI_PCM_DATA_CMD: GetAiRecordCmd(cmd,data,datalen,totaldata,crcvalue); break; + case GET_SPECIF_TYPE_FILE_CMD://获取指定类型文件目录 case AI_IS_READ_DATA_CMD: case SYN_HEART_HISTORY_DATA_CMD://同步心率历史数据 //heartDataCmd(cmd,data,datalen,totaldata,crcvalue); @@ -4834,12 +4835,12 @@ bool Read_Health_BIN_file_buf_send_bin_Data(uint8_t day, uint16_t num,uint16_t i buf = (char *)ym_malloc(sizeof(char)*num+1); if(buf==NULL)return false; - uint16_t pack=1; + uint32_t pack=1; if(file_size%num==0) pack=data_len/num; else pack=data_len/num+1; - uint8_t pack_id=1; + uint32_t pack_id=1; uint32_t read_size=0; do { @@ -5842,8 +5843,8 @@ bool Read_tar_file_buf_send_Data(uint16_t pack_size,uint8_t id) printf("Read_tar_file_buf_send_Data size %d\r\n",file_size); - uint16_t pack=file_size/pack_size+1; - uint8_t pack_id=1; + uint32_t pack=file_size/pack_size+1; + uint32_t pack_id=1; if(fp==NULL) { printf("fopen fail %s\r\n",file_name);