From 3593099cc35136d18e629e0d26db2f5de88cf3ef Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Tue, 24 Sep 2024 21:24:08 +0800 Subject: [PATCH] =?utf8?q?=E8=AE=AD=E7=BB=83=E5=8D=8F=E8=AE=AE=E4=BF=AE?= =?utf8?q?=E6=94=B9=EF=BC=8C=E5=BE=85=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../service/ble_service/blemoder/bletest.cpp | 63 +++++++ .../service/ble_service/blemoder/bletest.h | 2 + .../service/ble_service/bleservice/bleEvent.c | 163 ++++++++++++++++-- .../service/ble_service/bleservice/bleEvent.h | 7 + 4 files changed, 225 insertions(+), 10 deletions(-) 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 7fe6914b1..53b3d8512 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -367,6 +367,69 @@ cJSON* ble_get_recs_data() return data_arryJSON; } +//通过时间戳获取训练数据 +cJSON* ble_get_Trainingdata_by_timetamp(uint32_t timetamp) +{ + struct Trainingdata * data=NULL; + int i=0; + + time_t currtime=timetamp; + struct tm *timeinfo; + timeinfo = localtime(&currtime); + int y=timeinfo->tm_year+ 1900; + int m=timeinfo->tm_mon+1; + int d=timeinfo->tm_mday; + int h=timeinfo->tm_hour; + int min=timeinfo->tm_min; + + char timeday[24]={0}; + sprintf_s(timeday,24,"%d_%02d_%02d",y,m,d); + + printf("%s\r\n",timeday); + + while(data=read_Trainingdata_data(timeday, i)) + { + if(data!=NULL) + { + printf("%d,%d\r\n",timetamp,data->st); + int time_error= timetamp>data->st ? timetamp-data->st:data->st-timetamp; + if(time_error<=2) + { + cJSON* itemJSON = cJSON_CreateObject(); + + cJSON_AddNumberToObject(itemJSON,"src",data->src); + cJSON_AddNumberToObject(itemJSON,"ty",data->ty); + cJSON_AddNumberToObject(itemJSON,"st",data->st); + cJSON_AddNumberToObject(itemJSON,"sp",data->sp); + cJSON_AddNumberToObject(itemJSON,"tgt",data->tgt); + cJSON_AddNumberToObject(itemJSON,"tg",data->tg); + cJSON_AddNumberToObject(itemJSON,"pg",data->pg); + cJSON_AddNumberToObject(itemJSON,"du",data->du); + cJSON_AddNumberToObject(itemJSON,"ca",data->ca); + cJSON_AddNumberToObject(itemJSON,"di",data->di); + cJSON_AddNumberToObject(itemJSON,"hr",data->hr); + cJSON_AddNumberToObject(itemJSON,"stp",data->stp); + cJSON_AddNumberToObject(itemJSON,"ti",data->ti); + cJSON_AddNumberToObject(itemJSON,"cir",data->cir); + cJSON_AddNumberToObject(itemJSON,"alt",data->alt); + cJSON_AddNumberToObject(itemJSON,"fpc",data->fpc); + cJSON_AddNumberToObject(itemJSON,"spc",data->spc); + cJSON_AddNumberToObject(itemJSON,"std",data->std); + cJSON_AddNumberToObject(itemJSON,"cdc",data->cdc); + free(data); + return itemJSON; + } + + free(data); + data=NULL; + } + else{ + break; + } + i++; + } + return NULL; +} Tag_Trailer_t Mp3Trailer; Tag_ID3V2_TAG_T TAG_T; 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 9cf6cdb92..c3297fbc6 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -376,6 +376,8 @@ bool ble_add_sos_number(uint8_t sex,char *name,char *number); uint8_t* ble_get_sos_all_data_malloc(uint32_t*); +cJSON* ble_get_Trainingdata_by_timetamp(uint32_t timetamp); + #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 afa09591c..df18cbe78 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -1579,7 +1579,7 @@ static void SetOtherTarget(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *tota set_goal_durationcount(target_fattime); set_goal_caloriescount(target_kcal); - + set_SilentMode(ring); set_vibrationremiander(vibratior); @@ -2093,8 +2093,120 @@ void SetmsgfiltrationCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalD } +//通过时间戳来获取训练数据 + +void SYN_train_datatCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue)//同步训练数据 +{ + + if(Check_CRC(data,len,crcvalue)) + { + if(len==4) + { + uint32_t timetamp=0; + memcpy_s((void*)&timetamp,4,data,4); + cJSON *json_data = ble_get_Trainingdata_by_timetamp(timetamp); + if(json_data==NULL) + { + ble_data_type type_={0x02,0x19,0,1,1}; + send_big_data(type_,NULL,0); + return; + } + char *json_str=cJSON_PrintUnformatted(json_data); + uint32_t json_len= strlen(json_str); + cJSON_Delete(json_data); + + + uint32_t surplus_len=json_len; + uint32_t offset=0; + + uint32_t pack; + uint16_t pack_size=(ble_nus_max_data_len-18); + if(pack_size>482)pack_size=482; + + if(json_len%pack_size==0) + { + pack=json_len/pack_size; + } + else + { + pack=json_len/pack_size+1; + } + uint32_t pack_id=1; + while (surplus_len!=0) + { + if(surplus_len>=pack_size) + { + surplus_len=surplus_len-pack_size; + + ble_data_type type_={0x02,0x19,json_len,pack,pack_id}; + send_big_data(type_,(char *)json_str+offset,pack_size); + offset+=pack_size; + } + else + { + + printf("%d %d %d %d\r\n",json_len,surplus_len,pack_id,pack); + ble_data_type type_={0x02,0x19,json_len,pack,pack_id}; + send_big_data(type_,(char *)json_str+offset,surplus_len); + break; + } + pack_id++; + } + + cJSON_free(json_str); + + } + + } + else + { + ble_data_type type_={0x02,0x19,0,1,1}; + send_big_data(type_,NULL,0); + } +} + + +void SYN_train_heart_datatCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue)//同步训练数据 +{ + + if(Check_CRC(data,len,crcvalue)) + { + if(len==4) + { + uint32_t timetamp=0; + memcpy_s((void*)&timetamp,4,data,4); + ble_data_type type_={0x02,0x4B,0,1,1}; + send_big_data(type_,NULL,0); + } + + } + else + { + ble_data_type type_={0x02,0x4B,0,1,1}; + send_big_data(type_,NULL,0); + } +} +void SYN_train_speed_datatCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue)//同步训练数据 +{ + if(Check_CRC(data,len,crcvalue)) + { + if(len==4) + { + uint32_t timetamp=0; + memcpy_s((void*)&timetamp,4,data,4); + ble_data_type type_={0x02,0x18,0,1,1}; + send_big_data(type_,NULL,0); + } + + } + else + { + ble_data_type type_={0x02,0x18,0,1,1}; + send_big_data(type_,NULL,0); + } +} //APP设置步数目标 void SetsteptargetParamCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue) @@ -2308,19 +2420,18 @@ uint8_t parse_jsonCheck_weather(uint8_t *buf,uint8_t *check)//json 格式解析 } - if( cm_custom_ble_service_on_flag() && cm_get_HFP_switch()) + if( uapi_dev_runtime_get_bt_powerstat() && cm_get_HFP_switch()) uapi_pbap_cmd_start_client(); bd_addr_t bdaddr={0}; uapi_get_br_address(&bdaddr); - if( cm_custom_ble_service_on_flag() && (cm_get_HFP_switch()||cm_get_A2DP_switch())) + if( uapi_dev_runtime_get_bt_powerstat() && (cm_get_HFP_switch()||cm_get_A2DP_switch())) { if (false==bt_is_acl_connected(&bdaddr)) { int ret = gap_reconnect_media_device(&bdaddr); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " gap_reconnect_media_device ret = %u", ret); } - } @@ -3130,7 +3241,15 @@ void type2AE4Data(ble_read_data *buffer_handle,uint8_t *buf_cmd,uint8_t *data,ui case DELETE_FILE_CMD: break; case SYN_BASIC_REAL_HEATR_CMD: + SYN_train_heart_datatCmd(typeID,data,datalen,totalData,crcvalue); + break; + case SYN_TRAIN_DATA_CMD: + SYN_train_datatCmd(typeID,data,datalen,totalData,crcvalue); break; + case SYN_TRAIN_SPEED_CMD: + SYN_train_speed_datatCmd(typeID,data,datalen,totalData,crcvalue); + break; + case SYN_TODAY_BASIC_TRAIN_TXT_CMD: break; case SYN_WATCH_LCD_PARAM_CMD://app下发的同步屏幕参数到手表 @@ -3756,6 +3875,17 @@ static void OpenSportModeCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *to sendBleData(value,19); } } + +void reply_APP_StopSportModeCmd(uint16_t time) +{ + char data[3]={0}; + uint32_t data_len=3; + data[0]=1; + memcpy(&data[1],&time,2); + printf("发送训练状态数据%d %d\r\n",data[0],time); + ble_data_type type={0x01,0x0B,data_len,1,1}; + send_big_data(type,data,data_len); +} //结束运动模式 static void StopSportModeCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totaldata,uint8_t crcvalue) { @@ -3778,9 +3908,9 @@ static void StopSportModeCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *to printf("结束运动\r\n"); CustomEventPublish(TOPIC_EVENT_BLE_TRAINING,(uint8_t*)&training_ble_data,sizeof(training_ble)); - value[17] = 1; //1 操作成功 2 操作失败 - value[18] = Calculate_CRC(value,18); - sendBleData(value,19); + // value[17] = 1; //1 操作成功 2 操作失败 + // value[18] = Calculate_CRC(value,18); + // sendBleData(value,19); }else { value[17] = 0; @@ -3960,6 +4090,19 @@ static void SetMaxHrRemindCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *t } } + +void reply_APP_SportPasueResetCmd(uint16_t time) +{ + char data[3]={0}; + uint32_t data_len=3; + data[0]=1; + memcpy(&data[1],&time,2); + printf("发送训练状态数据%d %d\r\n",data[0],time); + ble_data_type type={0x01,0x16,data_len,1,1}; + send_big_data(type,data,data_len); +} + + //训练暂停/恢复 static void GetSportPasueResetCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totaldata,uint8_t crcvalue) { @@ -3994,9 +4137,9 @@ static void GetSportPasueResetCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_ CustomEventPublish(TOPIC_EVENT_BLE_TRAINING,(uint8_t*)&training_ble_data,sizeof(training_ble)); } - value[17] = 1; - value[18] = Calculate_CRC(value,18); - sendBleData(value,19); + // value[17] = 1; + // value[18] = Calculate_CRC(value,18); + // sendBleData(value,19); }else { value[17] = 0; 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 f2e2caeef..9ef2debfe 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h @@ -636,6 +636,8 @@ TYPE:02 #define SET_SEDENTARINESS_PARAM_CMD 0x021D //APP设置久坐提醒 #define SET_ANCS_MSG_FILTRATION_CMD 0x021e //APP设置消息过滤处理 #define SET_APP_AI_TXT_CMD 0x021F //设置AI返回的文本 +#define SYN_TRAIN_SPEED_CMD 0x0218 //同步某次基础训练配速(02,18) +#define SYN_TRAIN_DATA_CMD 0x0219 // 同步某次基础训练汇总记录(02,19) #define SET_WEATHER_DATA_CMD 0x0220 //发送天气数据 #define SET_ALARM_DATA_CMD 0x0221 //发送闹钟数据 #define DELETE_FILE_CMD 0x0222 //删除指定文件 @@ -821,6 +823,11 @@ bool get_ctkd_flag(void); uint8_t parse_jsonCheck_weather(uint8_t *buf,uint8_t *check);//json 格式解析 天气数据 uint8_t read_jsonHistory_weather(void); void GetwatchSaveMac(uint8_t *mac,uint8_t *mactype); + +void reply_APP_SportPasueResetCmd(uint16_t time); + +void reply_APP_StopSportModeCmd(uint16_t time); + ///////////////////////////自定义文件传输协议///////////////////////////// #define OTA_FILE_MSG_CMD 0x0601 #define OTA_FILE_DATA_CMD 0x0602 -- 2.17.1