From: Caisking <3449750381@qq.com> Date: Sun, 28 Apr 2024 06:57:35 +0000 (+0800) Subject: 增加蓝牙开启关闭获取获取实时数据;优化部分显示逻辑 X-Git-Tag: release_V1.2.70_20241020_135402~1025^2~56 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=d7e2e1bb73ad1bc8d2793f2439701658860233f9;p=mirrors%2FFD230.git 增加蓝牙开启关闭获取获取实时数据;优化部分显示逻辑 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h index 7990109a5..9778300f3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h @@ -64,13 +64,16 @@ namespace OHOS CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION, //运动目标时长 CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE, //运动目标距离 CONFIGMODEL_ITEM_DNOTDISTURB,//勿扰模式 - CONFIGMODEL_ITEM_TRANING_FREQ,//训练实时数据上传频率 CONFIGMODEL_ITEM_SYSTEM_VOLUME,//系统音量 CONFIGMODEL_ITEM_CALL_VOLUME,//通话音量 CONFIGMODEL_ITEM_VOLTE_CALL,//VoLTE通话 CONFIGMODEL_ITEM_MOTIONRECOGNITION,//运动识别 CONFIGMODEL_ITEM_HFP, //通话蓝牙开关 CONFIGMODEL_ITEM_A2DP,//媒体蓝牙开关 + + CONFIGMODEL_ITEM_TRANING_FREQ,//训练实时数据上传频率 + CONFIGMODEL_ITEM_TRANING_AUTO,//开启关闭自动获取实时数据 + CONFIFMOFEL_ITEM_HEARTRATE_DETECTED,//心率周期频率 0(关闭) 1 5 10 CONFIFMOFEL_ITEM_HEARTRATE_MAX,//最大心率 CONFIFMOFEL_ITEM_HEARTRATE_MIN,//最小心率 @@ -214,17 +217,19 @@ namespace OHOS {ConfigDataType::DATATYPE_INT, "GoalDuration", "30" },// CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION, //运动目标时长 30(分钟) {ConfigDataType::DATATYPE_DOUBLE, "GoalDistance", "8.0" },// CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE, //运动目标距离 8.0(km) {ConfigDataType::DATATYPE_BOOL, "Dnotdisturb", "false" },// CONFIGMODEL_ITEM_DNOTDISTURB //勿扰模式默认关闭 - {ConfigDataType::DATATYPE_INT, "traningfreq", "10" },// CONFIGMODEL_ITEM_TRANING_FREQ //训练实时数据上传频率//单位秒 {ConfigDataType::DATATYPE_INT, "SystemVolume", "100" },// CONFIGMODEL_ITEM_SYSTEM_VOLUME // {ConfigDataType::DATATYPE_INT, "CallVolume", "100" },// CONFIGMODEL_ITEM_CALL_VOLUME // {ConfigDataType::DATATYPE_BOOL, "VoLTECall", "false" },// CONFIGMODEL_ITEM_VOLTE_CALL {ConfigDataType::DATATYPE_BOOL, "MotionRecognition", "false" },// CONFIGMODEL_ITEM_MOTIONRECOGNITION {ConfigDataType::DATATYPE_BOOL, "HFP", "false" },// CONFIGMODEL_ITEM_HFP {ConfigDataType::DATATYPE_BOOL, "A2DP", "false" },// CONFIGMODEL_ITEM_A2DP + + {ConfigDataType::DATATYPE_INT, "traningfreq", "10" },// CONFIGMODEL_ITEM_TRANING_FREQ //训练实时数据上传频率//单位秒 + {ConfigDataType::DATATYPE_BOOL, "traningauto", "false" },//CONFIGMODEL_ITEM_TRANING_AUTO,//开启关闭自动获取实时数据 + {ConfigDataType::DATATYPE_INT, "traningheart", "190" },//CONFIGMODEL_ITEM_TRAINING_HEART_MAX//训练最高心率 {ConfigDataType::DATATYPE_INT, "HeartRateDetected", "0" },// CONFIFMOFEL_ITEM_HEARTRATE_DETECTED//心率周期检测频率 {ConfigDataType::DATATYPE_INT, "HeartRateMax", "0" },// CONFIFMOFEL_ITEM_HEARTRATE_MAX//最大心率 {ConfigDataType::DATATYPE_INT, "HeartRateMin", "0" },// CONFIFMOFEL_ITEM_HEARTRATE_MIN//最小心率 - {ConfigDataType::DATATYPE_INT, "traningheart", "250" },//CONFIGMODEL_ITEM_TRAINING_HEART_MAX//训练最高心率 }; ConfigModel(); // 私有构造函数,确保无法在外部实例化 ConfigModel(const ConfigModel &) = delete; // 禁止拷贝构造 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 853c1e37a..6a396a41b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h @@ -277,7 +277,7 @@ namespace OHOS UIResourceTextId sportId_ = STR_EXTREME_SPORTS; // 训练项目 Exercisetype sportType_ = Exercisetype::FITNESS; // 训练类型 ExerciseState sportState_ = ExerciseState::General; // 训练状态 - ExerciseTag sportTagType_ = ExerciseTag::Distance; // 训练目标类型 + ExerciseTag sportTagType_ = ExerciseTag::UNKNOW; // 训练目标类型 int sportTag_ = 0; // 训练目标 int totalHeartRate = 0; 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 70917ef52..f8b5cd14d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp @@ -29,6 +29,7 @@ #include #include #include "bleEvent.h" +#include "power_display_service.h" #define TIMER 1 #define BLETEST 0 @@ -705,9 +706,14 @@ namespace OHOS if (g_motionTimes != 0) { sportdata->duration = g_motionTimes; // 训练时长 - if (sportdata->duration % freq == 0) + /*判断是否开启自动获取*/ + if (ConfigModel::GetInstance()->get_configData_bool(ConfigModel::CONFIGMODEL_ITEM_TRANING_AUTO)) { - SendLiveData(); // 发送实时数据 + if (sportdata->duration % freq == 0) + { + PRINT("SendLiveData\r\n"); + SendLiveData(); // 发送实时数据 + } } PRINT("duration:[%d] g_motionTimes[%d]\r\n", sportdata->duration, g_motionTimes); } @@ -715,11 +721,12 @@ namespace OHOS int hour = g_motionTimes / NUM_TIME_HOUR; int min = (g_motionTimes % NUM_TIME_HOUR) / NUM_TIME_MIN; int sec = (g_motionTimes % NUM_TIME_HOUR) % NUM_TIME_MIN; - + // PRINT("ostringstream is end!\r\n"); std::ostringstream oss; oss << std::setfill('0') << std::setw(2) << hour << ":" << std::setw(2) << min << ":" << std::setw(2) << sec; - + // PRINT("motionDuration is end!\r\n"); motionDuration = oss.str(); + // PRINT("DisplayMotionDuration is end!\r\n"); return motionDuration; } #ifdef __cplusplus @@ -737,6 +744,7 @@ namespace OHOS return; } gTraingCardPresenter->ModifiesTime(); + PRINT("TraingTimerCallback\r\n"); } /* 开启定时器 */ diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp index 227dafe59..5c381587d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp @@ -17,6 +17,7 @@ #include "traing/training_card/include/TrainingControlView.h" #include "traing/include/TraingModel.h" #include "uicomponents/UIComponents.h" +#include "config/include/ConfigModel.h" #include "custom_utils.h" #include "vibrator_service.h" #include @@ -92,7 +93,13 @@ namespace OHOS // 计时器更新timer void TraingCardPresenter::ModifiesTime() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ModifiesTime begin"); std ::string TimeStr = TraingModel::GetInstance()->DisplayMotionDuration(); + + /*灭屏状态不刷新UI*/ + if (uapi_get_screen_state() == 1) + return; + if (TimeStr.empty()) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel::GetInstance()->DisplayMotionDuration() nullptr"); @@ -106,6 +113,7 @@ namespace OHOS { TrainingDataView::GetInstance()->GetTimeLabel()->SetText(TimeStr.c_str()); } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ModifiesTime end"); } /* --------------------------------- cywee库操作 -------------------------------- */ @@ -273,12 +281,22 @@ namespace OHOS { // 设置目标:在非运动情况下设置 [单指令,执行后退出] TraingModel::GetInstance()->SetSportTag(static_cast(cmd->sportTagType), cmd->sportTag); + PRINT("SetSportTag is succeed!\r\n"); return true; } break; + case SENDDATA: TraingModel::GetInstance()->SendLiveData(); // 发送实时数据 [单指令,执行后退出] + PRINT("SendLiveData is succeed!\r\n"); return true; + + case SETAUTO: + // 设置开启关闭获取实时数据 [单指令,执行后退出] + ConfigModel::GetInstance()->set_condigData_Bool(ConfigModel::CONFIGMODEL_ITEM_TRANING_AUTO, cmd->controlauto); + PRINT("SendTrainingAuto is succeed!\r\n"); + return true; + default: break; } 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 227c99419..fbac84801 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -66,8 +66,9 @@ enum TRANING START, STOP, RECOVER, - SETGOAL, - SENDDATA, + SETGOAL,//设置训练目标 + SENDDATA,//获取实时训练数据 + SETAUTO,//开启关闭自动获取实时数据 }; typedef struct @@ -75,6 +76,7 @@ typedef struct uint8_t sportType; //训练项目 uint8_t sportTagType; //训练目标类型 uint32_t sportTag; //训练目标 + uint8_t controlauto; //开启关闭自动获取实时数据 uint8_t controlmd; //训练控制md } training_ble; 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 cb2947805..440068ebe 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -273,37 +273,37 @@ void sendDataNow(uint8_t *buf,uint16_t len) } } -void send_big_data(uint8_t flag,char *data,int datalen,int total,uint32_t Packet_id,uint32_t packet_total,uint8_t type_id,uint8_t type) +void send_big_data(uint8_t flag, char *data, int datalen, int total, uint32_t Packet_id, uint32_t packet_total, uint8_t type_id, uint8_t type) { - uint8_t buf[512]={0}; - buf[0]=0x72; - buf[1]=type; - buf[2]=type_id; - memcpy(buf+3,&packet_total,4); - memcpy(buf+7,&total,4); - memcpy(buf+11,&Packet_id,4); - memcpy(buf+15,&datalen,2); - if(data==NULL) - { - data="\0"; - // buf[17+datalen] = Calculate_CRC_Big((uint8_t *)data,datalen); - if(flag) - sendDataNow(buf,17+1); - else - sendBleData(buf,17+1); + uint8_t *buf = malloc(17 + datalen + 1); // 动态分配内存空间,防止堆栈溢出 + if (buf == NULL) { + printf("内存分配失败\n"); + return; + } - }else - { - memcpy(buf+17,data,datalen); - buf[17+datalen] = Calculate_CRC_Big((uint8_t *)data,datalen); - printf("xxxxxxxxxxxxx\r\n"); - if(flag) - sendDataNow(buf,17+datalen+1); - else - sendBleData(buf,17+datalen+1); + buf[0] = 0x72; + buf[1] = type; + buf[2] = type_id; + memcpy(buf + 3, &packet_total, 4); + memcpy(buf + 7, &total, 4); + memcpy(buf + 11, &Packet_id, 4); + memcpy(buf + 15, &datalen, 2); + + if (data == NULL) { + data = "\0"; + buf[17 + datalen] = Calculate_CRC_Big((uint8_t *)data, datalen); + } else { + memcpy(buf + 17, data, datalen); + buf[17 + datalen] = Calculate_CRC_Big((uint8_t *)data, datalen); + } + if (flag) { + sendDataNow(buf, 17 + datalen + 1); + } else { + sendBleData(buf, 17 + datalen + 1); } - // } + + free(buf); // 释放内存空间 } //发送训练状态 void sendtraningstatedata(uint8_t state ,uint16_t time) @@ -331,10 +331,11 @@ void sendtraningdata(msg_get_train_data_info_t *data) char *jsonString = cJSON_PrintUnformatted(dataJSON); uint32_t data_len=strlen(jsonString); + cJSON_Delete(dataJSON); printf("发送训练实时数据%d %s\r\n",data_len,jsonString); send_big_data(0,jsonString,data_len,data_len,1,1,0x0f,1); cJSON_free(jsonString); - cJSON_Delete(dataJSON); + } //发送ble数据 uint8_t phone_mac[6];//手机下发的mac地址 第一次连接为空 @@ -1259,9 +1260,9 @@ void GetUTCtime(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totalData,uin } static training_ble training_ble_data; -static uint8_t jsonCheck_targetparam(uint8_t *buf)//训练目标参数 +//设置训练目标 +static uint8_t jsonCheck_targetparam(uint8_t *buf) { - uint8_t *json; json = buf; cJSON* root = cJSON_Parse((const char *)json); @@ -1269,46 +1270,48 @@ static uint8_t jsonCheck_targetparam(uint8_t *buf)//训练目标参数 printf("时间 JSON解析错误\n"); return 2; } - // { - // "ty":0, - // "di":5000, - // } - memset(&training_ble_data,0,sizeof(training_ble)); + + memset(&training_ble_data, 0, sizeof(training_ble)); + cJSON* ty = cJSON_GetObjectItem(root, "ty");//目标类型 if (cJSON_IsNumber(ty)) { printf("ty: %d\n", ty->valueint); - training_ble_data.sportTagType=ty->valueint; - training_ble_data.controlmd=SETGOAL; - } - - cJSON* di = cJSON_GetObjectItem(root, "di");//目标距离 - if (cJSON_IsNumber(di)) { - printf("di: %d\n", di->valueint); - training_ble_data.sportTag=di->valueint; - } - cJSON* ca = cJSON_GetObjectItem(root, "ca");//目标卡路里 - if (cJSON_IsNumber(ca)) { - printf("ca: %d\n", ca->valueint); - training_ble_data.sportTag=ca->valueint; - } - cJSON* tm = cJSON_GetObjectItem(root, "tm");//目标时间 - if (cJSON_IsNumber(tm)) { - printf("tm: %d\n", tm->valueint); - training_ble_data.sportTag=tm->valueint; - } - cJSON* st = cJSON_GetObjectItem(root, "st");//目标步数 - if (cJSON_IsNumber(st)) { - printf("st: %d\n", st->valueint); - training_ble_data.sportTag=st->valueint; - + training_ble_data.sportTagType = ty->valueint; + training_ble_data.controlmd = SETGOAL; + + cJSON* targetItem = NULL; + switch (training_ble_data.sportTagType) + { + case 0: // 距离 + targetItem = cJSON_GetObjectItem(root, "di");//目标距离 + break; + case 1: // 卡路里 + targetItem = cJSON_GetObjectItem(root, "ca");//目标卡路里 + break; + case 2: // 时间 + targetItem = cJSON_GetObjectItem(root, "tm");//目标时间 + break; + case 3: // 步数 + targetItem = cJSON_GetObjectItem(root, "st");//目标步数 + break; + default: + break; + } + + if (targetItem && cJSON_IsNumber(targetItem)) { + printf("%s: %d\n", targetItem->string, targetItem->valueint); + training_ble_data.sportTag = targetItem->valueint; + cJSON_Delete(root); + CustomEventPublish(TOPIC_EVENT_BLE_TRAINING, (uint8_t*)&training_ble_data, sizeof(training_ble)); + return JSON_CHECK_OK; + } } - CustomEventPublish(TOPIC_EVENT_BLE_TRAINING,(uint8_t*)&training_ble_data,sizeof(training_ble)); + cJSON_Delete(root); - return 1; + return JSON_CHECK_ERR; } - void GetTarinTarget(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *totalData,uint8_t crcvalue)//获取时间 { uint32_t tmp = 1; @@ -2521,10 +2524,14 @@ static void SetRealTimeDataCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t if(Check_CRC(crcnum,len,crcvalue)) { uint8_t autoSportData = crcnum[0];//开关 1开启 0关闭 - value[17] = 1; //1 操作成功 2 操作失败 value[18] = Calculate_CRC(value,18); sendBleData(value,19); + /*进行开启关闭操作*/ + training_ble_data.controlmd = SETAUTO; + training_ble_data.controlauto = autoSportData; + printf("开启自动获取 %d\r\n", training_ble_data.controlauto); + CustomEventPublish(TOPIC_EVENT_BLE_TRAINING,(uint8_t*)&training_ble_data,sizeof(training_ble)); }else { value[17] = 0; @@ -2553,6 +2560,7 @@ static void SetRTDataFreCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *t value[17] = 1; //1 操作成功 2 操作失败 value[18] = Calculate_CRC(value,18); sendBleData(value,19); + /*设置获取频率*/ }else { value[17] = 0;