}
}
-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;