From 7bf75b81add13f50aa5fc2f68aa20b4bb8c4dfb2 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Fri, 5 Jul 2024 20:50:26 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E5=A4=A9=E7=BA=BF=E8=93=9D?= =?utf8?q?=E7=89=99=E4=BA=A7=E6=B5=8B=EF=BC=8C=E4=BC=98=E5=8C=96=E4=B9=85?= =?utf8?q?=E5=9D=90=E6=8F=90=E9=86=92=E9=97=B9=E9=92=9F=EF=BC=8C=E6=B7=BB?= =?utf8?q?=E5=8A=A0extra=20info=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../src/AlarmClockTimerConfig.cpp | 10 +--- .../nativeui/traing/include/TraingModel.h | 7 +++ .../nativeui/traing/src/TraingModel.cpp | 60 +++++++++++++++++-- .../factorytest_protocol.c | 21 ++++--- .../drivers/peripheral/cywee/Inc/cywee_hal.h | 1 + .../peripheral/cywee/Inc/cywee_service.h | 6 +- .../peripheral/cywee/service/cywee_service.c | 10 ++++ .../drivers/peripheral/cywee/src/main_dml.c | 13 +++- .../drivers/peripheral/ppg/hx3695/hx3695.c | 19 ++++++ .../drivers/peripheral/ppg/hx3695/hx3695.h | 1 + .../drivers/peripheral/utils/custom_utils.c | 6 +- .../peripheral/utils/custom_utils_at_cmd.c | 4 +- 12 files changed, 125 insertions(+), 33 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp index 8aa3e0af0..8d4b4bdc7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp @@ -283,22 +283,18 @@ extern "C" // 设置状态为小睡 OHOS::SleepModel::GetInstance().set_sleep_state(OHOS::SLEEPSTATE::WAKE); LOS_Msleep(1000); - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_NAP_MODE, NULL); + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_NAP_SEDENTARY_MODE, NULL); } if(sedentary_switch) { if (curTime.tm_hour == ((sedentary_time & 0XFF000000) >> 24) && curTime.tm_min == ((sedentary_time & 0X00FF0000) >> 16) && curTime.tm_sec == 0) { - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, NULL); - LOS_Msleep(1000); - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_NAP_SEDENTARY_MODE, NULL); + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_OPEN_SEDENTARY, NULL); } else if (curTime.tm_hour == ((sedentary_time & 0X0000FF00) >> 8) && curTime.tm_min == (sedentary_time & 0X000000FF) && curTime.tm_sec == 0) { - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, NULL); - LOS_Msleep(1000); - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_NAP_MODE, NULL); + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_CLOSE_SEDENTARY, NULL); } } } 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 58ac87307..a9b70a9b6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h @@ -183,6 +183,11 @@ namespace OHOS Exercisetype sportType; // 训练类型(0:健身类 1:跳舞类 2:休闲运动 3:球类 4:水上运动:5:冰上运动:6:极限运动:7:其他) UIResourceTextId sportId; // 训练Id ExerciseTag sportTagType; // 训练目标类型(0: 距离 1:时长 2:卡路里 3:步数) + int apc; //平均配速 + int fpc; //最快配速 + int spc; //最慢配速 + int cdc; //步频 + int std; //步幅 void Initialize() { @@ -238,6 +243,8 @@ namespace OHOS ExerciseState GetSportState(); /*解析传输过来的数据*/ void AnalysisData(cywee_activity_result_t *cyweeInfo); + /*解析运动额外数据*/ + void AnalysisExtraData(cywee_activity_result_extre_info_t *cyweeInfo); /*获取训练数据*/ SportData *GetSportdata(); /*设置训练数据[为训练记录准备]*/ 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 30e3e8c86..f272e6caa 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp @@ -151,6 +151,20 @@ extern "C" TraingModel::GetInstance()->AnalysisData(cyweeInfo); delete cyweeInfo; // 释放内存 } + if (request->msgId == TOPIC_EVENT_ACTIVITY_EXTRA_INFO_UPDATE) + { + cywee_activity_result_extre_info_t *cyweeInfo = new cywee_activity_result_extre_info_t(); + int rets = memcpy_s(cyweeInfo, sizeof(cywee_activity_result_extre_info_t), (cywee_activity_result_extre_info_t *)request->data, request->len); + if (rets != EOK) + { + delete cyweeInfo; // 处理内存分配失败的情况 + cyweeInfo = NULL; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "memcpy_s cywee_activity_result_extre_info_t fail ret = %d", rets); + return; + } + TraingModel::GetInstance()->AnalysisExtraData(cyweeInfo); + delete cyweeInfo; // 释放内存 + } if (request->msgId == TOPIC_EVENT_BLE_TRAINING) { training_ble *traingbleInfo = new training_ble(); @@ -312,7 +326,20 @@ namespace OHOS ExerciseClass type = GetSportId(); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " AnalysisData %d", type); // 通用数据 + + sportdata->steps = cyweeInfo->steps; + sportdata->distance = cyweeInfo->distance; sportdata->calories = cyweeInfo->calories; + sportdata->cdc = cyweeInfo->step_frequency; + sportdata->std = cyweeInfo->step_length; + sportdata->pc = cyweeInfo->pace; + sportdata->distance = cyweeInfo->distance; + + if (sportdata->spc == 0 || sportdata->spc > sportdata->pc) + { + sportdata->spc = sportdata->pc; + } + sportdata->heart = cyweeInfo->hrs; SetIntensity(sportdata->heart); // 设置训练强度 if (sportdata->heart > 50) @@ -358,6 +385,24 @@ namespace OHOS } } } + + // int avg_step_freq;//平均步频 + // int avg_step_len;//平均步长 + // int avg_pace;//平均配速 + // int max_step_freq;//最大步频 + // int max_pace;//最大配速 + // int activity_zone;//活动程度区间 0低度 1中度 2高度 + // int ativity_zone_moderate_duration;//中度活动时间 + // int ativity_zone_high_duration;//高度活动时间 + // int MHR_zone;//心率区间 + // int distance_motion;//体感距离 + + /*分析activity extra info数据*/ + void TraingModel::AnalysisExtraData(cywee_activity_result_extre_info_t *cyweeInfo) + { + sportdata->apc = cyweeInfo->avg_pace; + sportdata->fpc = cyweeInfo->max_pace; + } /*打印函数*/ void TraingModel::printf_data(SportData *data) @@ -399,6 +444,11 @@ namespace OHOS sportdata->avgheart = data->avgheart; sportdata->steps = data->steps; sportdata->intensity = data->intensity; + sportdata->apc = data->apc; + sportdata->fpc = data->fpc; + sportdata->spc = data->spc; + sportdata->std = data->std; + sportdata->cdc = data->cdc; } printf_data(data); } @@ -722,11 +772,11 @@ namespace OHOS data.cir = 0; data.alt = 0; /*配速相关还未处理 暂时保存0*/ - data.apc = 0; - data.fpc = 0; - data.spc = 0; - data.std = 0; - data.cdc = 0; + data.apc = static_cast(sportdata->apc); + data.fpc = static_cast(sportdata->fpc); + data.spc = static_cast(sportdata->spc); + data.std = static_cast(sportdata->std); + data.cdc = static_cast(sportdata->cdc); // 保存数据到bin if (write_Trainingdata_data(data) != 1) diff --git a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c index 698408ccd..de96d0924 100644 --- a/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c +++ b/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-06-17 14:31:08 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-07-04 17:33:35 + * @LastEditTime: 2024-07-05 19:00:56 * @FilePath: /FD230/code/sdk/application/wearable/service/factorytest_service/factorytest_protocol.c * @Description: * @@ -84,7 +84,6 @@ static uint32_t aging_time = 0; static uint8_t pwr_button_result = 0; static uint8_t func_button_result = 1; -static uint8_t hx3695_chip_id = 0; static int CRC16_XMODEM(uint8_t *bytes,uint16_t length) { int crc = 0x0000; // initial value @@ -1140,14 +1139,13 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint { //获取 ppg_id uint8_t ppg_id; - uapi_ppg_get_id(&ppg_id); - if(ppg_id == 0x65) - hx3695_chip_id = ppg_id; + hx3695_get_id(&ppg_id); + factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_HRS, 0x01, - &hx3695_chip_id, - sizeof(hx3695_chip_id)); + &ppg_id, + 1); } else if(testitem == 0x02) { @@ -1545,7 +1543,7 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint cat1_at_cmd("at*mrd_cdf=Q,LteCalData.nvm"); LOS_Msleep(500); ble_get_cat1_at_msg((char *)&send_data,1); - if(atol(send_data) == 1) + if(send_data == '1') send_data = 1; else send_data = 0; @@ -1574,15 +1572,16 @@ void factorytest_protocol_soft_test_decode(uint8_t submode,uint8_t testitem,uint { //查询信号值 char buf[20] = {0}; + uint8_t send_data[2] = {0}; cat1_at_cmd("AT+QRXFTM=\"LTE BAND1\",300,\"on\",75"); LOS_Msleep(500); ble_get_cat1_at_msg(buf,20); - PRINT("AT+QRXFTM buf : %s \r\n",buf); + sscanf(buf, "+QRXFTM: -%d,-%d", (int *)&send_data[0], (int *)&send_data[1]); factorytest_protocol_replymsg(BLE_TEST_CMD_MODE_SOFT_TEST, BLE_TEST_CMD_SOFT_TEST_SUB_MODE_CAT1, 0x12, - (uint8_t *)buf, - strlen(buf)); + send_data, + 2); } else if(testitem == 0x13) { //关闭强接受 diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h index 36fdcb627..43db0c2e8 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h @@ -547,6 +547,7 @@ void set_fat_time_data(void); void cywee_get_chipinfo(char *databuf,uint8_t len); void cywee_set_sedentary_interval(int time); +void cywee_set_sedentary_switch(int cmd); void cywee_get_acc_switch(int cmd); void cywee_stop(void); diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h index 121a9736a..04227ab72 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h @@ -2,7 +2,7 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-03-26 20:29:58 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-06-28 18:00:01 + * @LastEditTime: 2024-07-05 18:11:57 * @FilePath: /FD230/code/sdk/drivers/peripheral/cywee/Inc/cywee_service.h * @Description: * @@ -89,6 +89,10 @@ extern "C" { #define CYWEE_SERVICE_CMD_STOP_ACC 0x31 +#define CYWEE_SERVICE_CMD_OPEN_SEDENTARY 0x33 + +#define CYWEE_SERVICE_CMD_CLOSE_SEDENTARY 0x34 + errcode_t uapi_cywee_service_init(void); void uapi_cywee_service_deinit(void); diff --git a/code/sdk/drivers/peripheral/cywee/service/cywee_service.c b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c index 0d8b92707..efe40b3be 100644 --- a/code/sdk/drivers/peripheral/cywee/service/cywee_service.c +++ b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c @@ -400,6 +400,16 @@ static void cywee_service_check_task(void const *arg) case CYWEE_SERVICE_CMD_STOP_ACC: cywee_stop(); + break; + + case CYWEE_SERVICE_CMD_OPEN_SEDENTARY: + cywee_set_sedentary_switch(1); + break; + + case CYWEE_SERVICE_CMD_CLOSE_SEDENTARY: + cywee_set_sedentary_switch(0); + break; + default: PRINT("unkonw cmd \r\n"); break; diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index ca6f5beed..e73443db8 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -86,6 +86,15 @@ void cywee_get_acc_switch(int cmd) get_acc_swtich = cmd; } +void cywee_set_sedentary_switch(int cmd) +{ + //设置久坐 0关,1开 + memset(&scl, 0, sizeof(scl)); + scl.iData[0] = 1; + scl.iData[2] = cmd; + CWM_SettingControl(SCL_SEDENTARY, &scl); +} + void cywee_set_sedentary_interval(int time) { sedentary_interval = time; @@ -1020,7 +1029,7 @@ int cywee_main_dml(void) //设置久坐 memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; - scl.iData[2] = 1; + scl.iData[2] = 0; CWM_SettingControl(SCL_SEDENTARY, &scl); //设置静态模式 @@ -1072,7 +1081,7 @@ int cywee_main_dml(void) cywee_activity_mode_change(SPORT_ACTIVE_MODE_NORMAL); - cywee_inactivity_mode_change(INACTIVITY_MODE_NAP); + cywee_inactivity_mode_change(INACTIVITY_MODE_SEDENTARY_AND_NAP); //cywee_inactivity_mode_change(INACTIVITY_MODE_SLEEPING); diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c index b73fa068b..2a23769ce 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.c @@ -381,6 +381,25 @@ bool hx3695_chip_check(void) return false; } +void hx3695_get_id(uint8_t *ppg_id) +{ + uint8_t i = 0; + uint8_t chip_id = 0; + for(i=0; i<5; i++) + { + hx3695_ppg_on(); + hx3695_delay_ms(5); + chip_id = hx3695_read_reg(0x00); + + if (chip_id == 0x65) + { + *ppg_id = chip_id; + break; + } + } + hx3695_ppg_off(); +} + uint8_t hx3695_read_fifo_size(void) { uint8_t data_len_h,data_len_l; diff --git a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.h b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.h index 8eb2b292d..8fcc766ea 100644 --- a/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.h +++ b/code/sdk/drivers/peripheral/ppg/hx3695/hx3695.h @@ -246,6 +246,7 @@ bool hx3695_write_reg(uint8_t addr, uint8_t data); uint8_t hx3695_read_reg(uint8_t addr); bool hx3695_brust_read_reg(uint8_t addr , uint8_t *buf, uint16_t length); bool hx3695_chip_check(void); +void hx3695_get_id(uint8_t *ppg_id); uint8_t hx3695_read_fifo_size(void); uint16_t hx3695_read_fifo_data(int32_t *s_buf, uint8_t size, uint8_t phase_num); void hx3695_ppg_off(void); diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 63edbb417..ff3d9883f 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -1885,15 +1885,11 @@ void test_bandy_time(uint32_t timestamp) get_current_time(&tv, &tm); } - -#include "tyhx_hrs_custom.h" - void uapi_ppg_get_id(uint8_t *chip_id) { - custom_i2c_read_regs(HX3695_I2C_DEV_8ADDR,0x00,1,chip_id,1,I2C_BUS_2); + hx3695_get_id(chip_id); } - #include "hal_i2c.h" #include "i2c.h" #define CUSTOM_I2C_TIME_MAX 3 diff --git a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c index 63696a7c6..90044dc72 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -400,9 +400,9 @@ static uint32_t custom_get_ppg_id(uint8_t *para, uint32_t paraLen, char *strComm { UNUSED(strCommonCmd); - uint8_t chip_id; + uint8_t chip_id = 0; uapi_ppg_get_id(&chip_id); - + PRINT("ppg_id[%x]\n",chip_id); return ERRCODE_SUCC; } -- 2.17.1