From adb0afeb5eb5735978801e7bcdd8244850df7e87 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Thu, 4 Jul 2024 18:39:07 +0800 Subject: [PATCH] =?utf8?q?=E6=B7=BB=E5=8A=A00106=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../service/ble_service/blemoder/bletest.cpp | 77 ++++++++++++ .../service/ble_service/blemoder/bletest.h | 39 +++++- .../service/ble_service/bleservice/bleEvent.c | 116 ++++++++++++------ .../service/ble_service/bleservice/bleEvent.h | 2 + .../drivers/peripheral/cywee/Inc/cywee_hal.h | 1 + .../drivers/peripheral/cywee/src/main_dml.c | 4 + 6 files changed, 201 insertions(+), 38 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 285a9d48b..2e3018074 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -83,6 +83,83 @@ void ble_set_ai_Answer_str(char *buf) OHOS::AiVoiceModel::GetInstance().SetAiAnswerStrStr(std::string(buf)); } +uint8_t ble_get_heart_data() +{ + OHOS::HeartRateData *data=(OHOS::HeartRateData*)malloc(sizeof(OHOS::HeartRateData)); + data=OHOS::HealthService ::GetInstance()->ReadHeartRateData(); + uint8_t heart=0; + if(data==NULL) + heart=0; + else + heart=data->Heart; + + free(data); + return heart; +} + +uint8_t ble_get_oxygen_data() +{ + OHOS::BloodOxygenData *data=(OHOS::BloodOxygenData*)malloc(sizeof(OHOS::BloodOxygenData)); + data=OHOS::HealthService ::GetInstance()->ReadBloodOxygenData(); + uint8_t spo2=0; + if(data==NULL) + spo2=0; + else + spo2=data->SPO2; + + free(data); + return spo2; +} + + +cJSON* ble_get_recs_data() +{ + cJSON* data_arryJSON = cJSON_CreateArray(); + struct Trainingdata * data=NULL; + int i=0; + //char file_path[128] = {0}; + char timeday[12] = {0}; + uapi_get_YYMMDD_Time_extend(timeday, '_',0); + printf("%s\r\n",timeday); + //sprintf(file_path, "%s%s.bin", TRAINING_PATH_BLE, timeday); + + while(data=read_Trainingdata_data(timeday, i)) + { + cJSON* itemJSON = cJSON_CreateObject(); + if(data!=NULL) + { + 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); + + cJSON_AddItemReferenceToArray(data_arryJSON,itemJSON); + free(data); + data=NULL; + } + else{ + break; + } + i++; + } + return data_arryJSON; +} + // { // "type":3, // "list":[ 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 e8ca3112a..21cc0ef33 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -26,7 +26,7 @@ extern "C" #include "stdint.h" #include "errcode.h" #include "bleEvent.h" - +#include "cJSON.h" @@ -274,10 +274,47 @@ char Comment[30]; char Cenre[1]; }Tag_Trailer_t; +typedef struct Tag_ID3V2 +{ + char Header[3]; /*必须为"ID3"否则认为标签不存在*/ + + char Ver; /*版本号ID3V2.3 就记录3*/ + + char Revision; /*副版本号此版本记录为0*/ + + char Flag; /*存放标志的字节,这个版本只定义了三位,稍后详细解说*/ + + char Size[4]; /*标签大小,包括标签头的10 个字节和所有的标签帧的大小*/ +}Tag_ID3V2_t; + + +typedef struct Tag_ID3V2_TAG +{ + char ID[4]; /*用四个字符标识一个帧,说明其内容,稍后有常用的标识对照表*/ + + char Size[4]; /*帧内容的大小,不包括帧头,不得小于1*/ + + char Flags[2]; /*存放标志,只定义了6 位,稍后详细解说*/ + +}Tag_ID3V2_TAG_T; + + + + char * dir_to_json_buf_malloc_(uint8_t type); char * dir_to_json_buf_malloc_(uint8_t type); + + +/////////////////////数据同步//////////////////////////// + +uint8_t ble_get_heart_data(void); + +uint8_t ble_get_oxygen_data(void); + +cJSON* ble_get_recs_data(void); + #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 6aba681b9..1f5e91bb0 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -2763,55 +2763,97 @@ static void GetSDSpaceCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *total } } //获取当前数据 -static void GetCurDataCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totaldata,uint8_t crcvalue) +void GetCurDataCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totaldata,uint8_t crcvalue) { + if(!Check_CRC(data,len,crcvalue)) + { + send_big_data(1,NULL,0,0,1,1,0x06,1); + return; + } cJSON *dataJSON = cJSON_CreateObject(); - const char *string_value[8]={"hr","spo2","stress","steps","duration","standup","calories","distance"}; - for(uint8_t i = 0;i<8;i++) + const char *string_value[7]={"hr","spo2","steps","duration","standup","calories","distance"}; + for(uint8_t i = 0;i<7;i++) { cJSON* data_arryJSON = cJSON_CreateObject(); - - cJSON_AddNumberToObject(data_arryJSON,"value",80); - cJSON_AddNumberToObject(data_arryJSON,"time",1633686477); - cJSON_AddItemToObject(dataJSON,string_value[i],data_arryJSON); - } + uint32_t value=0; + if(i==0) + { + value=ble_get_heart_data(); + } + else if(i==1) + { + value=ble_get_oxygen_data(); + } + else if(i==2) + { + value=get_step_data(); + } + else if(i==3) + { + value=get_fat_time_data(); + } + else if(i==4) + { + value=1; + } + else if(i==5) + { + value=get_calories_data(); + } + else if(i==6) + { + value=get_distance_data(); + } + + cJSON_AddNumberToObject(data_arryJSON,"value",value); + uint32_t creationTime; + int ret =uapi_get_timestampe_ss(&creationTime); + cJSON_AddNumberToObject(data_arryJSON,"time",creationTime); + + cJSON_AddItemToObject(dataJSON,string_value[i],data_arryJSON); + } + cJSON *recJSON= ble_get_recs_data(); + cJSON_AddItemToObject(dataJSON,"recs",recJSON); char *json_format = cJSON_PrintUnformatted(dataJSON); - printf("%d\n",strlen(json_format)); + printf("GetCurDataCmd %d %s\n",strlen(json_format),json_format); cJSON_Delete(dataJSON); - printf("%s\n",json_format); + uint32_t data_len = strlen(json_format); - uint8_t value[data_len+18]; - memset(value,0,data_len+18); - uint32_t tmp = 1; - uint16_t tmp_data = data_len; - uint32_t dataLen = data_len; - value[0] = 0x72; - value[1] = 0x01; - value[2] = 0x06; - memcpy(value+3,&tmp,4); - memcpy(value+7,&dataLen,4); - memcpy(value+11,&tmp,4); - memcpy(value+15,&tmp_data,2); - - // uint8_t buf[22] = {0x7b,0x22,0x74,0x70,0x22,0x3a,0x31,0x2c,0x22,0x70,0x6e,0x22,0x3a,0x22,0x69,0x50,0x68,0x6f,0x6e,0x65,0x22,0x7d}; - - if(Check_CRC(data,len,crcvalue)) + uint32_t surplus_len=data_len; + uint32_t pack; + uint16_t pack_size=(ble_nus_max_data_len-18); + if(pack_size>482)pack_size=482; + + if(data_len%pack_size==0) { - memcpy(value+17,(uint8_t *)json_format,data_len); - - uint8_t lrc = Calculate_CRC(value,data_len+17); - printf("lrc:%d",lrc); - value[data_len+18] = lrc; - sendBleData(value,data_len+18); - }else + pack=data_len/pack_size; + } + else + { + pack=data_len/pack_size+1; + } + uint32_t pack_id=1; + uint32_t offset=0; + while (surplus_len!=0) { - value[17] = 0; - uint8_t lrc = Calculate_CRC(value,18); - value[18] = lrc; - sendBleData(value,19); + if(surplus_len>=pack_size) + { + surplus_len=surplus_len-pack_size; + send_big_data(1,json_format+offset,pack_size,data_len,pack_id,pack,0x06,1); + offset+=pack_size; + } + else + { + + printf("%d %d %d %d\r\n",data_len,surplus_len,pack_id,pack); + send_big_data(1,json_format+offset,surplus_len,data_len,pack_id,pack,0x06,1); + break; + } + pack_id++; } cJSON_free(json_format); + } //获取当手表电池电量 static void GetBatteryLevelCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totaldata,uint8_t crcvalue) 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 ce675a9fa..57fd69f00 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h @@ -779,6 +779,8 @@ void CustomEventPublish_TOPIC_EVENT_MESSAGENOTE(void); void send_AI_is_ready(uint8_t type); +void GetCurDataCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totaldata,uint8_t crcvalue); + #ifdef __cplusplus } #endif diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h index 606773616..36fdcb627 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h @@ -527,6 +527,7 @@ void cywee_hand_updown_switch(int cmd); void cywee_ar_alert_switch(int cmd); void step_history_save(void); +uint32_t get_step_data(void); void stand_history_save(void); void calories_history_save(void); void distances_history_save(void); diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index a5f69bf97..328d56961 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -117,6 +117,10 @@ void cywee_restoreData(void) //WM_OS_restoreData(int* data, uint32_t len,uint8_t type)(int* data, uint32_t len,uint8_t type); } +uint32_t get_step_data(void) +{ + return stepcount; +} void step_history_save(void) { CWM_OS_saveData_history(&stepcount,&history_step_,sizeof(int),CYWEE_SAVE_DATA_STEP); -- 2.17.1