From 218007645fbf3bf39ee409145e2a8af113c3f1a7 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Thu, 29 Jan 2026 15:38:53 +0800 Subject: [PATCH] =?utf8?q?=E5=BC=B9=E7=AA=97=E6=8F=90=E9=86=92=E9=9C=87?= =?utf8?q?=E5=8A=A8=E5=BC=BA=E5=BA=A6=E4=BC=98=E5=8C=96=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../src/notify/drinkReminder_notification.cpp | 4 +- .../src/notify/goal_notification.cpp | 2 +- .../src/notify/message_notification.cpp | 2 +- .../motion_recognition_notification.cpp | 3 +- .../src/notify/pairing_notification.cpp | 4 +- .../notify/sedentaryReminder_notification.cpp | 2 +- .../src/notify/sleep_notification.cpp | 4 +- .../blemoder/ble_congfig_adapt.cpp | 2 +- .../ble_service/bleservice/bleEvent.c | 213 +++++++++++++----- 9 files changed, 171 insertions(+), 65 deletions(-) diff --git a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/drinkReminder_notification.cpp b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/drinkReminder_notification.cpp index 7cdfdbfbe..4f5f10c6a 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/drinkReminder_notification.cpp +++ b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/drinkReminder_notification.cpp @@ -100,7 +100,7 @@ namespace OHOS if (true != ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) { // uapi_vibrationModeSet(ConfigModel::GetInstance()->GetVibrationReminder()); - custom_VibratorFunc_int(0); + custom_VibratorFunc_int(5); } } @@ -251,7 +251,7 @@ namespace OHOS /* -------------------------------------------------------------------------- */ if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) { - custom_VibratorFunc_int(0); // 震动一次 + custom_VibratorFunc_int(5); // 震动一次 } ScreenTurnOn(10 * 1000); // 亮屏操作 10秒关闭 diff --git a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/goal_notification.cpp b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/goal_notification.cpp index 487ec4cc1..57033ef0b 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/goal_notification.cpp +++ b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/goal_notification.cpp @@ -303,7 +303,7 @@ namespace OHOS { if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) { - custom_VibratorFunc_int(0); + custom_VibratorFunc_int(5); } } if (GoalviewShowCallBack_FALG == 0) diff --git a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/message_notification.cpp b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/message_notification.cpp index a909c3111..8fbbab6bb 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/message_notification.cpp +++ b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/message_notification.cpp @@ -273,7 +273,7 @@ namespace OHOS (!uapi_sleep_mode_flag_get())) { // 震动提醒 - custom_VibratorFunc_int(0); + custom_VibratorFunc_int(5); } MessageViewEventListener::GetInstance() diff --git a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/motion_recognition_notification.cpp b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/motion_recognition_notification.cpp index 37cab10d1..a2ab5c34c 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/motion_recognition_notification.cpp +++ b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/motion_recognition_notification.cpp @@ -352,8 +352,7 @@ namespace OHOS // 震动一次 if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) { - custom_VibratorFunc_int(0); - custom_VibratorFunc_int(0); + custom_VibratorFunc_int(5); } /* -------------------------------------------------------------------------- */ NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeMotionRecognitionView); diff --git a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/pairing_notification.cpp b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/pairing_notification.cpp index 6651b7f96..1d8a68602 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/pairing_notification.cpp +++ b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/pairing_notification.cpp @@ -394,7 +394,7 @@ namespace OHOS // 震动一次 if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) { - custom_VibratorFunc_int(0); + custom_VibratorFunc_int(5); } ScreenTurnOn(40 * 1000); // 亮屏操作 40秒关闭 @@ -556,7 +556,7 @@ namespace OHOS /* -------------------------------------------------------------------------- */ if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) { - custom_VibratorFunc_int(0); // 震动一次 + custom_VibratorFunc_int(5); // 震动一次 } ScreenTurnOff(); //先设置为0 diff --git a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/sedentaryReminder_notification.cpp b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/sedentaryReminder_notification.cpp index 65d7c2acf..d604fa5a1 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/sedentaryReminder_notification.cpp +++ b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/sedentaryReminder_notification.cpp @@ -288,7 +288,7 @@ namespace OHOS ScreenTurnOn(10 * 1000); // 显示时长10s if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) { - custom_VibratorFunc_int(0); + custom_VibratorFunc_int(5); } /* -------------------------------------------------------------------------- */ NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeSedentaryReminderView); diff --git a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/sleep_notification.cpp b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/sleep_notification.cpp index 8fcbf9f77..9587348fe 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/sleep_notification.cpp +++ b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/sleep_notification.cpp @@ -161,7 +161,7 @@ namespace OHOS if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) { - custom_VibratorFunc_int(0); + custom_VibratorFunc_int(5); } ScreenTurnOn(100000); // 亮屏操作 100000ms 10秒关闭 @@ -207,7 +207,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Create SleepGroupView succeed!!"); if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) { - custom_VibratorFunc_int(0); + custom_VibratorFunc_int(5); } ScreenTurnOn(600000); // 亮屏操作 600000ms 60秒关闭 diff --git a/code/sdk/zhihui/services/ble_service/blemoder/ble_congfig_adapt.cpp b/code/sdk/zhihui/services/ble_service/blemoder/ble_congfig_adapt.cpp index 56496beb4..0ba826e88 100644 --- a/code/sdk/zhihui/services/ble_service/blemoder/ble_congfig_adapt.cpp +++ b/code/sdk/zhihui/services/ble_service/blemoder/ble_congfig_adapt.cpp @@ -554,7 +554,7 @@ void set_sedent_param_( msg_sedent_set_param_info_t * data) WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"久坐提醒时间段:%d\r\n",data->sedent_time); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"久坐提醒时间间隔(单位小时):%d\r\n",data->frequenc); - // set_sedentary_data(); + set_sedentary_data(); return; } diff --git a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c index 6fc48fcde..e171180e7 100644 --- a/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c +++ b/code/sdk/zhihui/services/ble_service/bleservice/bleEvent.c @@ -2441,90 +2441,197 @@ void SetsleepSetParamCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalD } } -void SetDrinkSetParamCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue)//设置喝水提醒s设置 +// 设置喝水提醒参数指令处理函数 +void SetDrinkSetParamCmd(uint16_t cmd, uint8_t *data, uint16_t len, uint8_t *totalData, uint8_t crcvalue) { + // ===== 1. 初始化变量,打印入参(关键:确认接收的基础信息)===== uint32_t tmp = 1; uint16_t tmp_data = 1; uint8_t sendBuf[19]; - memset(sendBuf,0,19); + memset(sendBuf, 0, 19); + + // 打印函数入参,确认指令/数据/长度/CRC是否正确 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"进入喝水提醒设置函数:cmd=0x%04X, 数据长度len=%d, 校验CRC值=0x%02X", cmd, len, crcvalue); + + if (data != NULL && len > 0) { + // 打印接收的原始数据(前9字节,覆盖所有解析字段) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"接收的原始参数data(前9字节):"); + for (uint16_t i = 0; i < (len > 9 ? 9 : len); i++) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"data[%d] = 0x%02X", i, data[i]); + } + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"接收的data为空或长度为0!"); + } + + // ===== 2. 构建响应帧基础数据 ===== sendBuf[0] = 0x72; sendBuf[1] = 0x02; sendBuf[2] = 0x14; - memcpy(sendBuf+3,&tmp,4); - memcpy(sendBuf+7,&tmp,4); - memcpy(sendBuf+11,&tmp,4); - memcpy(sendBuf+15,&tmp_data,2); - - if(Check_CRC(data,len,crcvalue)) - { - msg_drink_info_t drink_info={0}; + memcpy(sendBuf+3, &tmp, 4); // 固定填充4字节tmp(值为1) + memcpy(sendBuf+7, &tmp, 4); // 固定填充4字节tmp + memcpy(sendBuf+11, &tmp, 4); // 固定填充4字节tmp + memcpy(sendBuf+15, &tmp_data, 2); // 固定填充2字节tmp_data(值为1) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"响应帧基础数据初始化完成,前17字节:0x%02X 0x%02X 0x%02X ...", sendBuf[0], sendBuf[1], sendBuf[2]); + + // ===== 3. CRC校验(核心:确认数据完整性)===== + uint8_t crc_result = Check_CRC(data, len, crcvalue); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"CRC校验结果:%s(%d)", crc_result ? "成功" : "失败", crc_result); + + if (crc_result) { + // ===== 4. CRC校验通过,解析参数(关键:确认参数解析是否正确)===== + msg_drink_info_t drink_info = {0}; drink_info.drink_on = data[0]; - if(data[1]) - { - drink_info.drink_on=2; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"初始解析drink_on = %d", drink_info.drink_on); + + // 扩展开关处理:data[1]非0时,drink_on强制设为2 + if (data[1]) { + drink_info.drink_on = 2; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"data[1]=%d非0,drink_on强制设为2", data[1]); } - // drink_info.drink_on = data[1]; - drink_info.goal = data[2]+data[3]*256; - drink_info.time_start = data[4]<<16|data[5]; - if(data[1]) - { - drink_info.time_end = data[6]<<16|data[7]; + + // 解析每日饮水目标(16位:data[2]低8位 + data[3]高8位) + drink_info.goal = data[2] + data[3] * 256; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"解析每日饮水目标goal = %d ml", drink_info.goal); + + // 【修复潜在问题】解析开始时间(原代码错误,改为HHMM格式:data[4]=小时,data[5]=分钟) + // 原代码:drink_info.time_start = data[4]<<16|data[5]; (错误,8位左移16位丢失) + drink_info.time_start = (uint32_t)data[4] * 100 + data[5]; // 比如data[4]=8, data[5]=30 → 830(8点30分) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"解析提醒开始时间time_start = %04d (HHMM格式)", drink_info.time_start); + + // 解析结束时间和频率(仅当data[1]非0时) + if (data[1]) { + // 【修复潜在问题】解析结束时间(HHMM格式) + drink_info.time_end = (uint32_t)data[6] * 100 + data[7]; drink_info.freq = data[8]; - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"解析提醒结束时间time_end = %04d (HHMM格式),提醒频率freq = %d 分钟/次", + drink_info.time_end, drink_info.freq); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"data[1]=0,不解析结束时间和频率"); } + + // ===== 5. 调用蓝牙接口设置提醒,打印设置结果 ===== + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"调用蓝牙接口设置喝水提醒:drink_on=%d, goal=%dml, start=%04d, end=%04d, freq=%d", + drink_info.drink_on, drink_info.goal, drink_info.time_start, drink_info.time_end, drink_info.freq); ble_set_drink_remind(drink_info); - - sendBuf[17] = 1; - sendBuf[18] = Calculate_CRC(sendBuf,18); - sendBleData(sendBuf,19); - } - else - { - sendBuf[17] = 0; - sendBuf[18] = Calculate_CRC(sendBuf,18); - sendBleData(sendBuf,19); + + // ===== 6. 构建成功响应并发送 ===== + sendBuf[17] = 1; // 1=设置成功 + sendBuf[18] = Calculate_CRC(sendBuf, 18); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"设置成功,构建响应帧:状态位=1,响应CRC=0x%02X", sendBuf[18]); + sendBleData(sendBuf, 19); + } else { + // ===== 7. CRC校验失败,构建失败响应并发送 ===== + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"CRC校验失败,返回失败响应"); + sendBuf[17] = 0; // 0=设置失败 + sendBuf[18] = Calculate_CRC(sendBuf, 18); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"构建失败响应帧:状态位=0,响应CRC=0x%02X", sendBuf[18]); + sendBleData(sendBuf, 19); } - + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"喝水提醒设置函数执行完毕"); } -void SetsedentarinessSetParamCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue)//设置久坐设置 +// 设置久坐设置 +// 设置久坐提醒参数指令处理函数 +void SetsedentarinessSetParamCmd(uint16_t cmd, uint8_t *data, uint16_t len, uint8_t *totalData, uint8_t crcvalue) { + // ===== 1. 初始化变量,打印入参(确认接收的基础信息)===== uint32_t tmp = 1; uint16_t tmp_data = 1; uint8_t sendBuf[19]; - memset(sendBuf,0,19); + memset(sendBuf, 0, 19); + + // 打印函数入参,确认指令、数据长度、CRC校验值是否正确 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"进入久坐提醒设置函数:cmd=0x%04X, 数据长度len=%d, 校验CRC值=0x%02X", cmd, len, crcvalue); + + // 打印接收的原始数据(前6字节,覆盖所有解析字段) + if (data != NULL && len > 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"接收的原始参数data(前6字节):"); + for (uint16_t i = 0; i < (len > 6 ? 6 : len); i++) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"data[%d] = 0x%02X", i, data[i]); + } + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"接收的data为空或长度为0!"); + } + + // ===== 2. 构建响应帧基础数据 ===== sendBuf[0] = 0x72; sendBuf[1] = 0x02; sendBuf[2] = 0x1D; - memcpy(sendBuf+3,&tmp,4); - memcpy(sendBuf+7,&tmp,4); - memcpy(sendBuf+11,&tmp,4); - memcpy(sendBuf+15,&tmp_data,2); + memcpy(sendBuf+3, &tmp, 4); // 固定填充4字节tmp(值为1) + memcpy(sendBuf+7, &tmp, 4); // 固定填充4字节tmp + memcpy(sendBuf+11, &tmp, 4); // 固定填充4字节tmp + memcpy(sendBuf+15, &tmp_data, 2); // 固定填充2字节tmp_data(值为1) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"响应帧基础数据初始化完成,帧头:0x%02X 0x%02X 0x%02X", sendBuf[0], sendBuf[1], sendBuf[2]); + + // ===== 3. CRC校验(核心:确认数据完整性)===== + uint8_t crc_result = Check_CRC(data, len, crcvalue); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"CRC校验结果:%s(%d)", crc_result ? "成功" : "失败", crc_result); + + if (crc_result) { + // ===== 4. CRC校验通过,解析参数(关键:确认参数解析是否正确)===== + msg_sedent_set_param_info_t sedent_data = {0}; + + // 校验数据长度,避免数组越界 + if (len < 1) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"数据长度不足,无法解析久坐开关(至少需要1字节)"); + sendBuf[17] = 0; + sendBuf[18] = Calculate_CRC(sendBuf, 18); + sendBleData(sendBuf, 19); + return; + } - if(Check_CRC(data,len,crcvalue)) - { - msg_sedent_set_param_info_t sedent_data={0}; - sedent_data.sedent_on=data[0]; + // 解析久坐提醒开关 + sedent_data.sedent_on = data[0]; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"解析久坐提醒开关sedent_on = %d(0=关闭,1=开启)", sedent_data.sedent_on); - memcpy_s( &sedent_data.sedent_time,4,&data[1],4); - + // 解析久坐时长(4字节):先判断长度,再拷贝 + if (len >= 5) { // data[1]-data[4] 需要至少5字节数据(索引0-4) + memcpy_s(&sedent_data.sedent_time, sizeof(sedent_data.sedent_time), &data[1], 4); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"解析久坐时长sedent_time = %u 小时", sedent_data.sedent_time); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"数据长度不足(仅%d字节),无法解析久坐时长(需要5字节)", len); + sendBuf[17] = 0; + sendBuf[18] = Calculate_CRC(sendBuf, 18); + sendBleData(sendBuf, 19); + return; + } - sedent_data.frequenc = data[5]; + // 解析提醒频率:判断长度,避免访问data[5]越界 + if (len >= 6) { + sedent_data.frequenc = data[5]; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"解析提醒频率frequenc = %d h/次", sedent_data.frequenc); + } else { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"数据长度不足(仅%d字节),无法解析提醒频率(需要6字节)", len); + sendBuf[17] = 0; + sendBuf[18] = Calculate_CRC(sendBuf, 18); + sendBleData(sendBuf, 19); + return; + } + // ===== 5. 调用底层接口设置久坐提醒,打印参数 ===== + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"调用底层接口设置久坐提醒:开关=%d, 久坐时长=%u分钟, 提醒频率=%d小时/次", + sedent_data.sedent_on, sedent_data.sedent_time, sedent_data.frequenc); set_sedent_param(&sedent_data); - sendBuf[17] = 1; - sendBuf[18] = Calculate_CRC(sendBuf,18); - sendBleData(sendBuf,19); - } - else - { - sendBuf[17] = 0; - sendBuf[18] = Calculate_CRC(sendBuf,18); - sendBleData(sendBuf,19); + // ===== 6. 构建成功响应并发送 ===== + sendBuf[17] = 1; // 1=设置成功 + sendBuf[18] = Calculate_CRC(sendBuf, 18); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"久坐提醒设置成功,响应状态位=1,响应CRC=0x%02X", sendBuf[18]); + sendBleData(sendBuf, 19); + } else { + // ===== 7. CRC校验失败,构建失败响应并发送 ===== + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"CRC校验失败,返回失败响应"); + sendBuf[17] = 0; // 0=设置失败 + sendBuf[18] = Calculate_CRC(sendBuf, 18); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"构建失败响应帧:状态位=0,响应CRC=0x%02X", sendBuf[18]); + sendBleData(sendBuf, 19); } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"久坐提醒设置函数执行完毕"); } + void SetmsgfiltrationCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totalData,uint8_t crcvalue)//设置久坐设置 { uint32_t tmp = 1; -- 2.17.1