From 1db9c29d1ef8a79b36ea76c7754d8d580a2b784f Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Sun, 29 Sep 2024 20:18:28 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E8=AE=AD=E7=BB=83=E9=85=8D?= =?utf8?q?=E9=80=9F=E5=BF=83=E7=8E=87=E6=95=B0=E6=8D=AE=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/traing/include/TraingModel.h | 6 +- .../nativeui/traing/src/TraingModel.cpp | 2 +- .../service/ble_service/blemoder/bletest.cpp | 25 ++++ .../service/ble_service/blemoder/bletest.h | 4 + .../service/ble_service/bleservice/bleEvent.c | 126 +++++++++++++++++- 5 files changed, 153 insertions(+), 10 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h index 47d665dd0..7f469f3b9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h @@ -179,7 +179,7 @@ enum ENTEYTYPE { //心率表结构体 struct HeartRateEntry { uint32_t timestamp; - uint16_t heartRate; + uint8_t heartRate; }; //配速结果体 struct PaceEntry { @@ -324,7 +324,7 @@ public: std::string GetTagStr(); /*获取训练目标Str*/ /*配速表以及心率表配置*/ - bool AddHeartRateData(uint32_t timestamp, uint16_t heartRate); + bool AddHeartRateData(uint32_t timestamp, uint8_t heartRate); bool AddPaceData(uint32_t timestamp, uint16_t pace); bool SaveHeartTable(); bool SavePaceTable(); @@ -374,7 +374,7 @@ private: uint32_t heartcount{0}; std::vector heartRateTable; // 心率表 - std::vector paceTable; //配速表 + std::vector paceTable; // 配速表 const size_t MAX_ENTRIES = 10000; // 规定最大进场条目数 /*std::unique_ptr sportdata;*/ // 使用 std::unique_ptr 管理 // SportData 对象 diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp index a9fe901ca..4e8d8a053 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp @@ -1111,7 +1111,7 @@ void TraingModel::ClearPaceTable() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Pace Table Cleared.\r\n"); } // 添加心率数据 -bool TraingModel::AddHeartRateData(uint32_t timestamp, uint16_t heartRate) { +bool TraingModel::AddHeartRateData(uint32_t timestamp, uint8_t heartRate) { // 检查重复时间戳 for (const auto &entry : heartRateTable) { if (entry.timestamp == timestamp) { 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 034ea5c67..1f65365f4 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -87,6 +87,31 @@ extern "C" { #include "alipay_feature.h" #include "transmitting.h" +bool get_training_spead_path(char *path ,uint32_t time,uint32_t max_len) +{ + std::string str= OHOS::TraingModel::GetInstance()->GetPaceTablePath(time); + if(str.length()<=3) + { + return false; + } + memcpy_s(path,max_len,str.c_str(),str.length()); + return true; + +} + + +bool get_training_heart_path(char *path ,uint32_t time,uint32_t max_len) +{ + std::string str= OHOS::TraingModel::GetInstance()->GetHeartTablePath(time); + if(str.length()<=3) + { + return false; + } + memcpy_s(path,max_len,str.c_str(),str.length()); + return true; +} + + void ble_sos_data_save(void) { OHOS::SOS_number_save(); 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 a9354a21b..8f9242b6b 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -388,6 +388,10 @@ void ble_sos_data_save(void); void ble_SOS_data_init(void); +bool get_training_spead_path(char *path ,uint32_t time,uint32_t max_len); + +bool get_training_heart_path(char *path ,uint32_t time,uint32_t max_len); + #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 46679966a..a7e1f16f2 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -980,7 +980,7 @@ void cleanUnbindInfor(uint8_t flag)//和旧手机解绑清除配对信息 uint8_t mac_data[6]; memset(mac_data,0,6); GetwatchSaveMac(&mac_data,&MacType); - + bd_addr_t addr={0}; get_phone_addr(&addr,g_ble_conn_id); @@ -2234,8 +2234,64 @@ void SYN_train_heart_datatCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *t { 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); + char path[128]={0}; + if(get_training_heart_path(path,timetamp,128)) + { + FILE *fp= fopen(path,"rb+"); + uint32_t file_size=0; + if(fp==NULL) + { + printf("打开文件失败 %s \r\n",path); + + ble_data_type type_={0x02,0x4b,0,1,1}; + send_big_data(type_,NULL,0); + + return ; + } + fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 + file_size = ftell(fp); // 获取当前文件指针位置,即文件大小 + fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 + + int num=(ble_nus_max_data_len-18); + if(num>482)num=482; + + int num_check=file_size%6; + if(num_check!=0) + { + printf("数据有误 %d \r\n",cmd); + + ble_data_type type_={0x02,0x4b,0,1,1}; + send_big_data(type_,NULL,0); + return ; + } + + char* buf = (char *)ym_malloc(sizeof(char)*num+1); + if(buf==NULL){fclose(fp); return ;} + + uint32_t pack=1; + + if(file_size%num==0) + pack=data_len/num; + else + pack=data_len/num+1; + + uint32_t pack_id=1; + uint32_t read_size=0; + do + { + memset_s(buf,num+1,0,num+1); + read_size=fread(buf,1,num,fp); + if(read_size!=0) + { + ble_data_type type_={0x02,0x4b,file_size,pack,pack_id}; + send_big_data(type_,buf,read_size); + } + pack_id++; + } while (read_size==num); + fclose(fp); + free(buf); + + } } } @@ -2255,10 +2311,68 @@ void SYN_train_speed_datatCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *t { 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); - } + char path[128]={0}; + if(get_training_spead_path(path,timetamp,128)) + { + FILE *fp= fopen(path,"rb+"); + uint32_t file_size=0; + if(fp==NULL) + { + printf("打开文件失败 %s \r\n",path); + + ble_data_type type_={0x02,0x18,0,1,1}; + send_big_data(type_,NULL,0); + + return ; + } + fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 + file_size = ftell(fp); // 获取当前文件指针位置,即文件大小 + fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 + + int num=(ble_nus_max_data_len-18); + if(num>482)num=482; + + int num_check=file_size%6; + if(num_check!=0) + { + printf("数据有误 %d \r\n",cmd); + + ble_data_type type_={0x02,0x18,0,1,1}; + send_big_data(type_,NULL,0); + return ; + } + + char* buf = (char *)ym_malloc(sizeof(char)*num+1); + if(buf==NULL){fclose(fp); return ;} + + uint32_t pack=1; + if(file_size%num==0) + pack=data_len/num; + else + pack=data_len/num+1; + uint32_t pack_id=1; + uint32_t read_size=0; + do + { + memset_s(buf,num+1,0,num+1); + read_size=fread(buf,1,num,fp); + if(read_size!=0) + { + ble_data_type type_={0x02,0x18,file_size,pack,pack_id}; + send_big_data(type_,buf,read_size); + } + + + //send_big_data(1,buf,read_size,file_size,pack_id,pack,id,1); + pack_id++; + } while (read_size==num); + + fclose(fp); + free(buf); + + } + } } else { -- 2.17.1