From: DXY <1731678236@qq.com> Date: Sat, 11 May 2024 11:43:30 +0000 (+0800) Subject: debug 1 X-Git-Tag: release_V1.2.70_20241020_135402~1108^2~10 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=a6bca1c7737fd4ff14b3679e7caea489d9adbae4;p=mirrors%2FFD230.git debug 1 --- diff --git a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c index a4a53d4f2..7826e0872 100755 --- a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -406,6 +406,8 @@ static void thread_main(const void *unused) cat1_server_init(); #endif + uapi_blesrv_service_init(); + start_custom_ble_service(); startup_post_init(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp index 23adfee7b..edac3ba73 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp @@ -108,6 +108,7 @@ namespace OHOS void openBle(void); // 主动开启蓝牙 bool get_ble_status(void); // 获取蓝牙是否关闭还是开启 1就是开启 0关闭 一开机默认是开启蓝牙 void getDeviceState(void); + void malloc_test(void); } bool ClassicBlueToothPresenter::OnChange(UICheckBox::UICheckBoxState state) { @@ -116,17 +117,18 @@ namespace OHOS { case UICheckBox::SELECTED: WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Enabled"); + malloc_test(); + // start_custom_ble_service(); // 主动开启蓝牙 - start_custom_ble_service(); // 主动开启蓝牙 - - ConfigModel::GetInstance()->SetClassicBlueToothState(true); + // ConfigModel::GetInstance()->SetClassicBlueToothState(true); break; case UICheckBox::UNSELECTED: + malloc_test(); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Disabled"); - stop_custom_ble_service(); + // stop_custom_ble_service(); - ConfigModel::GetInstance()->SetClassicBlueToothState(false); + // ConfigModel::GetInstance()->SetClassicBlueToothState(false); break; default: break; 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 58d4379e7..46311d2f8 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -423,8 +423,10 @@ void set_user_data(msg_user_info_t data) //目标站立 + printf("目标站立\r\n"); p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES,data.target_stand); //目标燃脂 + printf("目标燃脂\r\n"); p_ConfigModel->set_condigData_Int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION,data.fat_time); /* 时制 @@ -660,7 +662,7 @@ const char *get_health_data_path(void) } JSON_F_buf=(char *)malloc(strlen(buf)+1); strcpy(JSON_F_buf,buf); - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s",JSON_F_buf); return JSON_F_buf; } @@ -772,6 +774,7 @@ void read_message_data(void) } } } + cJSON_Delete(data_root); } // printf("message_infor_s.num%d\r\n",message_infor_s.num); //2 1 0 // for(uint8_t i = message_infor_s.num-1;i > 0 ;i--) 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 ee5f23c51..7d52fb8c6 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -55,7 +55,29 @@ static uint16_t data_len = 0; ble_recv_data_info_t ble_recv_data; ble_recv_msg_callback_t g_recv_msg_toUI = NULL; #if 1 +#include "app_msg_manager.h" +#include "app_tx_process.h" +static int ym_malloc_count = 0,ym_free_count = 0; +static void *ym_malloc(unsigned int size) +{ + // app_pkg_msg_send(HEAPINFO, DIAG_CONTROL_FALSE, NULL, 0); + return malloc(size); +} +static void ym_free(void * p) +{ + free(p); +} +void malloc_test(void) +{ + for(int i = 0;i<1000;i++) + { + char * temp = ym_malloc(i*10); + printf("i:%d,addr:%x\r\n",i,temp); + + } + app_pkg_msg_send(HEAPINFO, DIAG_CONTROL_FALSE, NULL, 0); +} // typedef void (*hx3695_msg_callback_t)(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datalen); uint32_t ble_recv_register_msg_callback(ble_recv_msg_callback_t func) { @@ -135,9 +157,6 @@ int ble_recv_msg_callback(uint8_t writ_read,uint16_t msg_typeID, uint8_t *msg_da drink_info.end_hour = msg_data[6]; drink_info.end_min = msg_data[7]; drink_info.frequenc = msg_data[8]; - printf("drink_info %d %d %d %d %d %d\r\n",drink_info.drink_on,drink_info.alarm_mode, - drink_info.target_drink,drink_info.start_hour,drink_info.startt_min,drink_info.end_hour, - drink_info.end_min,drink_info.frequenc); // memcpy(msg_data,&drink_info,sizeof(msg_drink_set_param_info_t)); break; case GET_DRINK_SWITCH_CMD: @@ -156,10 +175,6 @@ int ble_recv_msg_callback(uint8_t writ_read,uint16_t msg_typeID, uint8_t *msg_da break; } } - for(uint16_t i = 0;i= 'a' && src_str[i] <= 'z') { src_str[i] = src_str[i] - 32; - printf("src_tr:\r\n"); } } memcpy(res_str,src_str,len); @@ -189,7 +203,6 @@ void cameram_data(void)//拍照发送数据 调用这个接口即可 osal_msleep(100); /* wait 100 ms */ memset(data,0,2); (void)ble_hid_server_send_input_report(&data, 2); /* 上报按下按键 把停止发送指令也要发送 防止一直拍照*/ - printf("cameram_send_data:0x%x",ret); } bool bigDataBufState=false;//大数据传输状态 @@ -274,10 +287,6 @@ errcode_t sendBleData(uint8_t *buf,uint16_t len) errcode_t ret = ERRCODE_FAIL; printf("bigDataBufState:%d and sendbigDataBufState %d\r\n",bigDataBufState,sendbigDataBufState); if(bigDataBufState == true || sendbigDataBufState == true)return ERRCODE_FAIL; //在手表发送分包数据时 手表不允许发指令给app - for(uint16_t i = 0;ivaluestring,strlen(pn->valuestring)); } - printf("设备名称: %s\n", pn->valuestring); + // printf("设备名称: %s\n", pn->valuestring); } cJSON* tp = cJSON_GetObjectItem(root, "tp"); @@ -515,7 +521,6 @@ errcode_t UnbindSucessCmd(uint8_t flag)//发送解绑指令,解绑界面调用 void getDeviceState(void) { bool ret = bt_is_acl_connected(&phone_addr); - printf("remove11111!!!!!!:%d",ret); } void clearPaireFlag(uint8_t flag) @@ -570,25 +575,25 @@ void comfirmPaire(uint8_t flag) if(flag == 1) { first_bond = 1; - printf("gap_ble_pair_remote_device 333333333 %x-%x-%x-%x-%x-%x\r\n",phone_addr.addr[0],phone_addr.addr[1],phone_addr.addr[2],phone_addr.addr[3],phone_addr.addr[4],phone_addr.addr[5]); + // printf("gap_ble_pair_remote_device 333333333 %x-%x-%x-%x-%x-%x\r\n",phone_addr.addr[0],phone_addr.addr[1],phone_addr.addr[2],phone_addr.addr[3],phone_addr.addr[4],phone_addr.addr[5]); errcode_t code = gap_ble_pair_remote_device(&phone_addr); if(code!=ERRCODE_SUCC) { printf("gap_ble_pair_remote_device fail %X\r\n",code); } - }else{ first_bond = 0; errcode_t ret = 0; ret = gap_ble_disconnect_remote_device(&disconect_addr);//与固定的mac设置地址进行断开连接 - printf("gap_ble_disconnect_remote_device %x\r\n",ret); + // printf("gap_ble_disconnect_remote_device %x\r\n",ret); ret = gap_ble_remove_all_pairs(); bool ret_ok = gap_remove_all_pairs(); - printf("gap_remove_all_pairs %x %x\r\n",ret,ret_ok); + // printf("gap_remove_all_pairs %x %x\r\n",ret,ret_ok); if(savephonename != NULL) { - free(savephonename); + ym_free(savephonename); + savephonename = NULL; } } } @@ -619,14 +624,14 @@ static void getRecvPhoneInfo(uint8_t *phonemac,uint8_t *name,uint8_t *len,uint8_ long fileSize = ftell(jsfile); fseek(jsfile, 0, SEEK_SET); - char *jsonData = (char *)malloc(fileSize + 1); + char *jsonData = (char *)ym_malloc(fileSize + 1); fread(jsonData, 1, fileSize, jsfile); jsonData[fileSize] = '\0'; fclose(jsfile); // 解析JSON数据 cJSON *root = cJSON_Parse(jsonData); - free(jsonData); + ym_free(jsonData); if (root != NULL) { cJSON *modifiedJson = cJSON_GetObjectItem(root,"mac"); @@ -710,13 +715,13 @@ static uint8_t *getPhoneName(uint8_t *crcnum)//获取手机设备名称 uint8_t datalen = strlen(pn->valuestring)+1; if(datalen - 1 > 0){ pn->valuestring[datalen-1]='\0'; - str = malloc(sizeof(char)*datalen); - savephonename = malloc(sizeof(char)*datalen); + str = ym_malloc(sizeof(char)*datalen); + savephonename = ym_malloc(sizeof(char)*datalen); memcpy(str,(uint8_t *)pn->valuestring,datalen); // strcpy(str,pn->valuestring); memcpy(savephonename,(uint8_t *)pn->valuestring,datalen); // strcpy(savephonename,pn->valuestring); - printf("str:%s savephonename:%s\n",str,savephonename); + // printf("str:%s savephonename:%s\n",str,savephonename); } printf("设备名称: %s\n", pn->valuestring); } @@ -777,14 +782,14 @@ void GetwatchSaveMac(uint8_t *mac,uint8_t *mactype)//获取手表本地保存的 long fileSize = ftell(jsfile); fseek(jsfile, 0, SEEK_SET); - char *jsonData = (char *)malloc(fileSize + 1); + char *jsonData = (char *)ym_malloc(fileSize + 1); fread(jsonData, 1, fileSize, jsfile); jsonData[fileSize] = '\0'; fclose(jsfile); // 解析JSON数据 cJSON *root = cJSON_Parse(jsonData); // 释放资源 - free(jsonData); + ym_free(jsonData); if (root != NULL) { cJSON *modifiedJson = cJSON_GetObjectItem(root,"mac"); if (cJSON_IsArray(modifiedJson)) { @@ -833,15 +838,14 @@ static void GetwatchSaveNameLen(uint8_t *datalen)//获取手表本地保存的 long fileSize = ftell(jsfile); fseek(jsfile, 0, SEEK_SET); - char *jsonData = (char *)malloc(fileSize + 1); + char *jsonData = (char *)ym_malloc(fileSize + 1); fread(jsonData, 1, fileSize, jsfile); jsonData[fileSize] = '\0'; fclose(jsfile); // 解析JSON数据 cJSON *root = cJSON_Parse(jsonData); - free(jsonData); - + ym_free(jsonData); if (root != NULL) { cJSON *pn = cJSON_GetObjectItem(root,"pn"); if(cJSON_IsString(pn)) @@ -869,22 +873,22 @@ static uint8_t *GetwatchSaveName(void)//获取手表本地保存的手机设备 long fileSize = ftell(jsfile); fseek(jsfile, 0, SEEK_SET); - char *jsonData = (char *)malloc(fileSize + 1); + char *jsonData = (char *)ym_malloc(fileSize + 1); fread(jsonData, 1, fileSize, jsfile); jsonData[fileSize] = '\0'; fclose(jsfile); // 解析JSON数据 cJSON *root = cJSON_Parse(jsonData); - free(jsonData); - + ym_free(jsonData); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ym_free ym_malloc_count:%d ym_free_count:%d\r\n",ym_malloc_count,ym_free_count); if (root != NULL) { cJSON *pn = cJSON_GetObjectItem(root,"pn"); if(cJSON_IsString(pn)) { uint8_t showname_len = strlen(pn->valuestring)+1; if(showname_len-1 > 0){ - str = malloc(sizeof(char)*showname_len); + str = ym_malloc(sizeof(char)*showname_len); pn->valuestring[showname_len-1]='\0'; str[showname_len]=0; memcpy(str,(uint8_t *)pn->valuestring,showname_len); @@ -994,7 +998,8 @@ void sendBindInfor(uint8_t *crcnum) CustomEventPublish(TOPIC_EVENT_DEVICE_BIND,(uint8_t *)buf,devnamelen+2); if(devname) { - free(devname); + ym_free(devname); + devname = NULL; } }else{ printf("phone devname is no name11111!!!!!!!!!:"); @@ -1060,7 +1065,8 @@ void sendBindInfor(uint8_t *crcnum) CustomEventPublish(TOPIC_EVENT_DEVICE_BIND,(uint8_t *)buf,devnamelen+2); if(devname) { - free(devname); + ym_free(devname); + devname = NULL; } }else{ uint8_t buf[2]; @@ -1141,7 +1147,7 @@ void sendParieSuccess(uint8_t flag,bd_addr_t *addr)//发送配对成功指令to if(savephonename != NULL) { cJSON_AddStringToObject(dataJSON,"pn",(char *)savephonename); - free(savephonename); + ym_free(savephonename); savephonename = NULL; } cJSON_AddNumberToObject(dataJSON,"phoneType",phoneType); @@ -1159,7 +1165,8 @@ void sendParieSuccess(uint8_t flag,bd_addr_t *addr)//发送配对成功指令to } fclose(file); } - free(jsonString); + // ym_free(jsonString); + cJSON_free(jsonString); cJSON_Delete(dataJSON); // 读取JSON文件 @@ -1247,7 +1254,7 @@ static uint8_t jsonCheck_time(uint8_t *buf)//json 格式解析 cJSON* time = cJSON_GetObjectItem(root, "time"); if (cJSON_IsNumber(time)) { printf("time: %d\n", time->valueint); - printf("time: %d\n", time->valueint); + // printf("time: %d\n", time->valueint); } cJSON* jsweek = cJSON_GetObjectItem(root, "week"); if (cJSON_IsNumber(jsweek)) { @@ -1890,12 +1897,15 @@ void SetsteptargetParamCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *to } -uint8_t jsonCheck_weather(uint8_t *buf)//json 格式解析 天气数据 +uint8_t jsonCheck_weather(uint8_t *buf,uint8_t *check)//json 格式解析 天气数据 { - + uint8_t flag = 0; + // flag = 2; + // memcpy(check,&flag,1); + // return 0; uint8_t *json; json = buf; - printf("jsonCheck_weather:len: json:%f jsonlen:%d\r\n",0.011,strlen((char *)json)); + // printf("jsonCheck_weather:len: json:%f jsonlen:%d\r\n",0.011,strlen((char *)json)); #if 0 FILE *fp=fopen("user/weather.json","wb+"); @@ -1904,10 +1914,13 @@ uint8_t jsonCheck_weather(uint8_t *buf)//json 格式解析 天气数据 fputs((char *)buf,fp); fclose(fp); #endif + printf("开始解析天气数据\n"); cJSON* root = cJSON_Parse((const char *)json); if (root == NULL) { printf("天气 JSON解析错误\n"); - return 2; + flag = 2; + memcpy(check,&flag,1); + return 0; } printf("开始解析天气 JSON\n"); cJSON *now_cjson = cJSON_GetObjectItem(root, "now"); @@ -1920,7 +1933,7 @@ uint8_t jsonCheck_weather(uint8_t *buf)//json 格式解析 天气数据 int iconNight = cJSON_GetObjectItem(now_cjson, "iconNight")->valueint; set_weather_now_data(humidity,windScale,textNight,uvIndex,temp,iconNight); - printf("开始解析天气 JSON!!!!\n"); + // "address": // {"lat":225737664, // "atm":"1010", @@ -1935,7 +1948,7 @@ uint8_t jsonCheck_weather(uint8_t *buf)//json 格式解析 天气数据 int lat = cJSON_GetObjectItem(address_cjson, "lat")->valueint; int lon = cJSON_GetObjectItem(address_cjson, "lon")->valueint; set_weather_address_data(lat,atm,city,subLocality,lon); - printf("开始解析天气 JSON11111\n"); + cJSON *daily = cJSON_GetObjectItem(root, "daily"); for(int i=0;i<7;i++) { @@ -1948,9 +1961,9 @@ uint8_t jsonCheck_weather(uint8_t *buf)//json 格式解析 天气数据 int tempMax=cJSON_GetObjectItem(data,"tempMax")->valueint; set_weather_one_data(tempMin,iconDay,fxDate,tempMax,textDay,i); } - printf("开始解析天气 JSON2222222\n"); cJSON_Delete(root); - printf("weather data!!!!!!!!!!end\r\n"); + flag = 1; + memcpy(check,&flag,1); return 1; } @@ -1968,11 +1981,11 @@ void GetWeatherCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totalData, memcpy(sendBuf+7,&tmp,4); memcpy(sendBuf+11,&tmp,4); memcpy(sendBuf+15,&tmp_data,2); - printf("GetWeatherCmd:len:%d crcnum:%s\r\n",len,crcnum); + // printf("GetWeatherCmd:len:%d crcnum:%s\r\n",len,crcnum); if(Check_CRC(crcnum,len,crcvalue)) { uint8_t check = 1; - check = jsonCheck_weather(crcnum); + jsonCheck_weather(crcnum,&check); sendBuf[17] = check; sendBuf[18] = Calculate_CRC(sendBuf,18); sendBleData(sendBuf,19); @@ -2175,7 +2188,7 @@ void getAPPaddressbook(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totalD void type2AE4Data(uint8_t *buf_cmd,uint8_t *data,uint16_t datalen,uint8_t *totalData,uint8_t crcvalue) { uint16_t typeID = buf_cmd[1]*256+buf_cmd[2]; - printf("type2AE4Data typeID:0x%x\r\n",typeID); + // printf("type2AE4Data typeID:0x%x\r\n",typeID); switch (typeID) //ID { case USER_INFOR_CMD://app下发的获取用户信息 @@ -2328,7 +2341,7 @@ static void GetAlarmDataCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *t }else{ if(data_len != 0){ memcpy(value+17,json_format,data_len); - free(json_format); + cJSON_free(json_format); } } @@ -2388,7 +2401,7 @@ static void aboutDeviceCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *to if(Check_CRC(crcnum,len,crcvalue)) { memcpy(value+17,(uint8_t *)json_format,data_len);//17+69 = 86 - free(json_format); + cJSON_free(json_format); value[data_len+17] = Calculate_CRC(value,data_len+17);// // printf("data_len:%d %x %d!!!!!\r\n",data_len,value[data_len+17],data_len+17); sendBleData(value,data_len+18); @@ -2510,7 +2523,7 @@ static void GetCurDataCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *tot if(Check_CRC(crcnum,len,crcvalue)) { memcpy(value+17,(uint8_t *)json_format,data_len); - free(json_format); + cJSON_free(json_format); uint8_t lrc = Calculate_CRC(value,data_len+17); printf("lrc:%d",lrc); value[data_len+18] = lrc; @@ -2596,9 +2609,9 @@ static void RemoveFileCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *tot memcpy(value+15,&tmp_data,2); if(Check_CRC(crcnum,len,crcvalue)) { - uint8_t switch_on = crcnum[0];//0 关闭 1 开启 + uint8_t file_type= crcnum[0];//1 ota 2 MP3 - value[17] = 1; //1 操作成功 2 操作失败 + value[17] = 1; // value[18] = Calculate_CRC(value,18); sendBleData(value,19); }else @@ -3811,7 +3824,8 @@ static void Send_json_Data_Cmd(uint16_t pack_size,uint8_t id) } pack_id++; } - free(json_format); + cJSON_free(json_format); + // ym_free(json_format); } //同步睡眠数据 static void sleepDataCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totaldata,uint8_t crcvalue) @@ -4199,7 +4213,7 @@ uint32_t EACH_DATA_LEN=0;//每种数据类型的的长度 void Read_file_buf_send_bin_Data(uint8_t num,uint16_t id,char *data_item) { sendbigDataBufState = true;//分包同步数据不允许打断 - char *buf=(char *)malloc(sizeof(char)*512); + char *buf=NULL; const char *path=NULL; uint8_t timeBit = 4;//默认是4个字节的时间戳 uint8_t dataBit = 1;//默认是1个字节的数据 @@ -4240,7 +4254,6 @@ void Read_file_buf_send_bin_Data(uint8_t num,uint16_t id,char *data_item) { send_big_data(1,NULL,0,0,1,1,id,1); sendbigDataBufState = false;//分包同步数据不允许打断 - free(buf); return; } @@ -4249,10 +4262,15 @@ void Read_file_buf_send_bin_Data(uint8_t num,uint16_t id,char *data_item) { send_big_data(1,NULL,0,0,1,1,id,1); printf("打开文件失败%s\r\n",path); - free(buf); + if(path) + { + free(path); + path = NULL; + } sendbigDataBufState = false;//分包同步数据不允许打断 return; } + buf = (char *)ym_malloc(sizeof(char)*512); int ret=fread(buf,1,512,fp); uint8_t count=1; while (ret==512) @@ -4262,15 +4280,17 @@ void Read_file_buf_send_bin_Data(uint8_t num,uint16_t id,char *data_item) count++; } cJSON *heart_data=cJSON_Parse(buf); - free(buf); + ym_free(buf); + printf("读文件\r\n"); if(heart_data==NULL) { printf("解析失败\r\n"); + return; } cJSON * heart_data_list=cJSON_GetObjectItem(heart_data,data_item); int item_num=cJSON_GetArraySize(heart_data_list); - char *send_buf=(char *)malloc(sizeof(char)*HEART_DATA_LEN); + char *send_buf=(char *)ym_malloc(sizeof(char)*HEART_DATA_LEN); int send_len=0; uint32_t Packet_id=1; uint16_t packet_total; @@ -4302,21 +4322,35 @@ void Read_file_buf_send_bin_Data(uint8_t num,uint16_t id,char *data_item) { printf("sendbuf :%s sendbuf_len%d\r\n",send_buf,send_len); send_big_data(1,send_buf,send_len,item_num*5,Packet_id,packet_total,id,1); - free(send_buf); + if(send_buf) + { + ym_free(send_buf); + send_buf = NULL; + } sendbigDataBufState=false; }else { send_big_data(1,send_buf,send_len,item_num*5,Packet_id,packet_total,id,1); - free(send_buf); - send_buf=(char *)malloc(sizeof(char)*HEART_DATA_LEN); + if(send_buf) + { + ym_free(send_buf); + send_buf = NULL; + } + + send_buf=(char *)ym_malloc(sizeof(char)*HEART_DATA_LEN); send_len=0; Packet_id++; } } send_buf=realloc(send_buf,i*5+10); } - cJSON_free(heart_data); + if(send_buf) + { + ym_free(send_buf); + send_buf = NULL; + } + cJSON_Delete(heart_data); } //type @@ -4542,7 +4576,7 @@ void message_data(int uid,int appid,char *title,char *msg,int hasCode) fseek(jsfile, 0, SEEK_END); long fileSize = ftell(jsfile); fseek(jsfile, 0, SEEK_SET); - char *jsonData = (char *)malloc(fileSize + 1); + char *jsonData = (char *)ym_malloc(fileSize + 1); fread(jsonData, 1, fileSize, jsfile); jsonData[fileSize] = '\0'; fclose(jsfile); @@ -4550,7 +4584,7 @@ void message_data(int uid,int appid,char *title,char *msg,int hasCode) // printf("jsonData %s",jsonData); data_root= cJSON_Parse(jsonData); // data_root = cJSON_GetObjectItem(modifiedJson,"infor"); - free(jsonData); + ym_free(jsonData); }else{ data_root = cJSON_Parse("{\ @@ -4628,9 +4662,11 @@ void message_data(int uid,int appid,char *title,char *msg,int hasCode) fwrite(jsonString, 1, strlen(jsonString), fp); fclose(fp); } - free(jsonString); + cJSON_free(jsonString); + cJSON_Delete(data_root); read_message_data(); + } int uft8_check(char *chinese_string,int length) { @@ -4638,7 +4674,7 @@ int uft8_check(char *chinese_string,int length) for (i = 0; i < length;) { // 判断是否为ASCII字符 if ((unsigned char)chinese_string[i] < 0x80) { - printf("ASCII character: %d\n", (int)(unsigned char)chinese_string[i]); + // printf("ASCII character: %d\n", (int)(unsigned char)chinese_string[i]); i++; } else { // 假设这里我们只处理3字节的UTF-8字符 @@ -4665,7 +4701,6 @@ int uft8_check(char *chinese_string,int length) //安卓消息接收解析数据 //ANCS 2AE1 uint8_t jscheck_ancs(uint8_t *data) { - uint8_t *json; json = data; cJSON* root = cJSON_Parse((const char *)json); @@ -4680,8 +4715,8 @@ uint8_t jscheck_ancs(uint8_t *data) int hasCode_t = 0; char *titleBuf; char *msgBuf; - titleBuf = malloc(TITLE_BUF_LEN); - msgBuf = malloc(MSG_BUF_LEN); + titleBuf = ym_malloc(TITLE_BUF_LEN); + msgBuf = ym_malloc(MSG_BUF_LEN); if(titleBuf == NULL || msgBuf == NULL)//申请内存失败不在申请 { return 2; @@ -4738,11 +4773,11 @@ uint8_t jscheck_ancs(uint8_t *data) cJSON_Delete(root); message_data(uid_t,appid_t,titleBuf,msgBuf,hasCode_t); if(titleBuf != NULL){ - free(titleBuf); + ym_free(titleBuf); titleBuf = NULL; } if(msgBuf != NULL){ - free(msgBuf); + ym_free(msgBuf); msgBuf = NULL; } return 1; @@ -4824,9 +4859,8 @@ void bleDataRecv(uint8_t *totalData, uint16_t event_size,uint16_t handle) { return; } - + printf("bleDataRecv handle:%d\r\n",handle); ble_read_data* read_data_tmp = NULL; - printf("bleDataRecv\r\n"); for(int i = 0;i event_size-17)//多包数据第一包处理,大于一包的数据长度 514-17=494 { packdataLen = event_size-17;//多包数据第一包数据不带CRC校验和的 - handle_l[i].data = malloc(totalDataLen+1); + + handle_l[i].data = ym_malloc(totalDataLen+1); + printf("bleDataRecv!!!!!!!%d\r\n",totalDataLen); memcpy(handle_l[i].data,totalData+17,packdataLen);//从第十七个字节开始接收数据data handle_l[i].data_len = packdataLen; memset(handle_l[i].cmd_data,0,17); memcpy(handle_l[i].cmd_data,totalData,17); }else{//一包数据 + printf("bleDataRecv one %d\r\n",totalDataLen); packdataLen = event_size-18; if(totalDataLen != 0) { - handle_l[i].data = malloc(totalDataLen+1); + handle_l[i].data =ym_malloc(totalDataLen+1); memcpy(handle_l[i].data,totalData+17,packdataLen); } memset(handle_l[i].cmd_data,0,17); @@ -4880,25 +4917,21 @@ void bleDataRecv(uint8_t *totalData, uint16_t event_size,uint16_t handle) } }else//多包数据存储 { - printf("muilt 122222;%d handle_l[i].data_len:%d\r\n",handle_l[i].data_len,handle_l[i].data_len); - + handle_l[i].data_len = handle_l[i].data_len+event_size; - printf("muilt 133333;%d handle_l[i].data_len:%d\r\n",handle_l[i].data_len,handle_l[i].data_len); + printf("muilt 133333 handle_l[i].data_len:%d\r\n",handle_l[i].data_len); if(handle_l[i].data_len >= handle_l[i].totalDataLen)//接收完整的数据 { uint32_t packEndLen = handle_l[i].data_len-event_size;//这是最后一包的起始地址 handle_l[i].data_len = handle_l[i].data_len-1;//减去最后一个字节的CRC校验和 才算是总的数据长度 memcpy(handle_l[i].data+packEndLen,totalData,handle_l[i].data_len);//为了不把CRC copy到data所以多一步操作 - - printf("muilt END2;!!!!!\r\n"); handle_l[i].crcvalue = totalData[event_size-1];//最后一个字节为总的数据包的CRC read_data_tmp = &handle_l[i]; }else{ memcpy(handle_l[i].data+handle_l[i].data_len,totalData,event_size); //这是不带CRC数据说明还有下一包直接copy } - } break; } @@ -4906,20 +4939,24 @@ void bleDataRecv(uint8_t *totalData, uint16_t event_size,uint16_t handle) } if(read_data_tmp)//获取到完整数据,处理数据且释放内存 { - printf("pack data end!!!!!!\r\n"); + printf("pack data start!!!!!\r\n"); //处理数据.. if(read_data_tmp->data) { read_data_tmp->data[read_data_tmp->totalDataLen]=0; } bleLongRecvData(read_data_tmp->data,read_data_tmp->totalDataLen,read_data_tmp->cmd_data,NULL,read_data_tmp->crcvalue); - free(read_data_tmp->data); + if(read_data_tmp->data)//只有数据不为NULL的才释放 + { + ym_free(read_data_tmp->data); + } read_data_tmp->data_len = 0; read_data_tmp->data = NULL; read_data_tmp->totalDataLen = 0; //read_data_tmp->handle = 0; read_data_tmp->crcvalue = 0; memset(read_data_tmp->cmd_data,0,17); + printf("pack data end!!!!!!\r\n"); } @@ -4938,7 +4975,6 @@ void free_ble_data(void)//以防断开蓝牙没有释放数据类型 //接收app下发的原始数据 void revBleOldData(uint8_t *buf, uint16_t event_size,uint16_t handle)//每包的数据大小 { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "xxxxxxxxxxxxxxxx"); printf("handle :%d data2ae3Cmd:%d data2ae4Cmd:%d event_size %d\r\n",handle,data2ae3Cmd,data2ae4Cmd,event_size); bleDataRecv(buf,event_size,handle); } diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h index 23c093870..900f0015e 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h @@ -33,6 +33,7 @@ ble_recv_msg_callback_t ble_recv_get_send_msg_callback_func(void); //msg_datalen 数据内容长度 //返回值 解析数据成功返回 1 解析失败返回 0 // +void malloc_test(void); int ble_recv_msg_callback(uint8_t writ_read,uint16_t msg_typeID, uint8_t *msg_data, uint16_t msg_datalen); void cameram_send_data(void); /*********************TYPE+ID*********************************** diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c index bbe557fe7..56641dbd8 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -37,6 +37,9 @@ extern "C" { #include "ppgBleService.h" #include "build_version.h" #include "custom_runtime.h" +#include "custom_utils.h" + + // extern void bts_data_to_uuid_len2(uint16_t uuid_data, bt_uuid_t *out_uuid); // extern void bts_init_128bit_uuid(const bt_uuid_t *uuid); @@ -106,8 +109,8 @@ uint16_t data2ae3Cmd = 0;//2ae3短指令特征值 uint16_t data2ae4Cmd = 0; uint16_t data2ae5Cmd = 0; uint16_t data2ae1Cmd = 0;//安卓消息来电 +uint16_t data2ae0Cmd = 0;//OTA -#if 1//def SUPPORT_BLE_SERVICE static void set_phone_info(bd_addr_t *addr)//保存手机信息 包含手机mac地址 { memcpy(&phone_addr,addr,sizeof(bd_addr_t)); @@ -167,7 +170,7 @@ static void svr_ble_adv_data_set(int adv_id) char watchName[32]; memset_s(watchName, sizeof(watchName), 0, sizeof(watchName)); - (void)sprintf_s(watchName, sizeof(watchName), "%s %02x%02x",BLE_DEFAULT_NAME,addr[1],addr[0]); + (void)sprintf_s(watchName, sizeof(watchName), "%s %02X%02X",BLE_DEFAULT_NAME,addr[1],addr[0]); // (void)sprintf_s(watchName, sizeof(watchName), "%s",BLE_DEFAULT_NAME); ret = bluetooth_set_local_name((unsigned char*)watchName, strlen((char*)watchName) + 1); @@ -876,11 +879,14 @@ static void svr_ble_bt_gatts_characteristic_add_cb(uint8_t server_id, bt_uuid_t if(ble_gatts_cmp_uuid(uuid, &chara_uuid_data4)) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "2ae0 result->value_handle4 %d\r\n",result->value_handle); - // shortCmdChara = result->value_handle; + if(data2ae0Cmd == 0) + { + data2ae0Cmd = result->value_handle; + } } if(ble_gatts_cmp_uuid(uuid, &chara_uuid_data5)) { - if(data2ae3Cmd == 0) + if(data2ae1Cmd == 0) { data2ae1Cmd = result->value_handle; } @@ -1011,34 +1017,27 @@ static void svr_ble_bt_gatts_req_read_cb(uint8_t server_id, uint16_t conn_id, ga static uint8_t falg = 0; + static void svr_ble_bt_gatts_req_write_cb(uint8_t server_id, uint16_t conn_id, gatts_req_write_cb_t *write_cb_para, errcode_t status) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "g_ble_server_handle %d conn_id :%d write_cb_para->length:%d write_cb_para->handle %d write_cb_para->request_id:%d",g_ble_server_handle,conn_id,write_cb_para->length, write_cb_para->handle,write_cb_para->request_id); // printf("alipay_handle%d",alipay_handle); - for(uint16_t i = 0;ilength;i++) + #if 0 + char *hex_str_tmp = malloc(10*1024); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"hex_str_tmp:%x\r\n",hex_str_tmp); + uint16_t i=0; + for( i = 0;ilength;i++) { - printf("%x ",write_cb_para->value[i]); - - } - //WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"handle :%d %d %d".write_cb_para->handle,get_factory_ate_write_handl(),get_factory_ota_write_handl()); - if (write_cb_para->handle == get_factory_ate_write_handl()) - { - factory_recv_cmd_data(write_cb_para->value,write_cb_para->length,write_cb_para->handle); - } - else if (write_cb_para->handle == get_factory_ota_write_handl()) - { - factory_recv_ota_data(write_cb_para->value,write_cb_para->length,write_cb_para->handle); - }else if(write_cb_para->handle == alipay_handle) - { - printf("alipay wirte!!!!!"); - // svr_alipay_bt_gatts_noyify(buf,5); - errcode_t ret = svr_alipay_msg_write(ALIPAY_MSG_BT, write_cb_para->value, write_cb_para->length, false); - - }else{ - revBleOldData(write_cb_para->value,write_cb_para->length,write_cb_para->handle); + //WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"%x ",write_cb_para->value[i]); + sprintf(hex_str_tmp+i*3,"%02X ",write_cb_para->value[i]); } + hex_str_tmp[i*3] = 0; + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"hex_str_tmp:%s\r\n",hex_str_tmp); + free(hex_str_tmp); + #endif + blesrv_service_recv_msg_handler(write_cb_para->handle,write_cb_para->value,write_cb_para->length); } static void svr_ble_mtu_exchange(uint8_t server_id, uint16_t conn_id, uint16_t mtu_size, errcode_t status) { @@ -1284,7 +1283,131 @@ void ble_avd_mode_change(uint8_t mode) break; } } -#endif +/**=================protocol recv decode service (task)=============================================================================================*/ +typedef struct +{ + uint16_t service_handle; + uint32_t msg_len; + uint8_t *msg_data; +} blesrv_custom_cmd_t; + +#define MAX_BUF_LEN (2+4+4) //sizeof(blesrv_custom_cmd_t) /*MTU max 514 , sizeof(blesrv_custom_cmd_t)*/ +static unsigned long g_blesrv_queue = 0xFFFFFFFF; +static uint8_t g_blesrv_queue_created = 0; +void blesrv_service_recv_msg_handler(uint16_t srv_handle, uint8_t * msg_data, uint32_t msg_len) +{ + int ret; + + if( g_blesrv_queue_created == 0) return ; + if (msg_data == NULL) return ; + + blesrv_custom_cmd_t mail={0}; + uint32_t sendlen = MAX_BUF_LEN; + + + mail.service_handle = srv_handle; + mail.msg_len = msg_len; + mail.msg_data = (uint8_t*)malloc(msg_len); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ble_recv:mail.msg_data %x\r\n",mail.msg_data); + if(mail.msg_data==NULL) + { + return ; + } + memcpy_s(mail.msg_data,msg_len,msg_data,msg_len); + + ret = osal_msg_queue_write_copy(g_blesrv_queue, (void *)&mail, MAX_BUF_LEN , 0); + if (ret != OSAL_SUCCESS) + { + PRINT("Error blesrv Check send failed! err=0x%x! \r\n", ret); + } + +} + +static void blesrv_service_check_task(void const *arg) +{ + unused(arg); + int32_t ret; + blesrv_custom_cmd_t mail={0}; + uint32_t msgsize = MAX_BUF_LEN; + + while (1) + { + ret = osal_msg_queue_read_copy(g_blesrv_queue, (void *)&mail, &msgsize, + OSAL_MSGQ_WAIT_FOREVER); + if (ret != OSAL_SUCCESS) + { + continue; + } + + uint8_t *p_msgbuf = mail.msg_data; + uint16_t server_handle = mail.service_handle; + uint32_t msg_len = mail.msg_len; + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ble_recv:%d %d %x %x %x\r\n",msg_len,server_handle,p_msgbuf[0],p_msgbuf[1],p_msgbuf[2]); + #if 0 + if (server_handle == get_factory_ate_write_handl()) + { + factory_recv_cmd_data(p_msgbuf,msg_len,server_handle); + } + else if (server_handle == get_factory_ota_write_handl()) + { + factory_recv_ota_data(p_msgbuf,msg_len,server_handle); + }else if(server_handle == alipay_handle) + { + printf("alipay wirte!!!!!"); + // svr_alipay_bt_gatts_noyify(buf,5); + errcode_t ret = svr_alipay_msg_write(ALIPAY_MSG_BT, p_msgbuf, msg_len, false); + + }else{ + revBleOldData(p_msgbuf,msg_len,server_handle); + } + #endif + + // free(mail.msg_data); + // mail.msg_data = NULL; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ble_recv:end\r\n"); + } +} +#define BLESRV_APP_BOARD_MSG_COUNT 50 +#define BLESRV_APP_BOARD_TASK_SIZE 0x2000 +#define BLESRV_BOARD_TASK_PRIO 7 +void create_blesrv_queue(void) +{ + if (osal_msg_queue_create("blesrv_service_queue", BLESRV_APP_BOARD_MSG_COUNT, &g_blesrv_queue, + 0, MAX_BUF_LEN) != ERRCODE_SUCC) + { + printf("[blesrv][service] app create mail fail\n"); + g_blesrv_queue_created = 0; + }else{ + g_blesrv_queue_created = 1; + } + +} +errcode_t uapi_blesrv_service_init(void) +{ + + PRINT("uapi_blesrv_service_init !\r\n"); + app_task_definition_t taskcfg = {0}; + taskcfg.create_queue_handle = create_blesrv_queue; + taskcfg.attr.name = "blesrv_recv_service"; + taskcfg.attr.priority = osPriorityNormal; + taskcfg.attr.stack_size = BLESRV_APP_BOARD_TASK_SIZE; + taskcfg.func = blesrv_service_check_task; + taskcfg.use_mem = USE_DTCM_MEM; + + errcode_t ret = uapi_create_osThread_custom(&taskcfg); + if (ret != ERRCODE_SUCC) + { + PRINT("create blesrv_service failed %d!\r\n", ret); + return ERRCODE_FAIL; + } + + return ERRCODE_SUCC; +} + + + + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h index 5dd5eaaf7..5ffdb72b3 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.h @@ -37,6 +37,9 @@ errcode_t svr_ble_bt_gatts_noyify(uint8_t *data, uint16_t data_len); void svr_ble_adv_start(void); void svr_ble_adv_stop(void); void ble_avd_mode_change(uint8_t mode); +// +void blesrv_service_recv_msg_handler(uint16_t srv_handle, uint8_t * msg_data, uint32_t msg_len); +errcode_t uapi_blesrv_service_init(void); #ifdef __cplusplus } #endif