From eb7419b3e85955470dc2496a664c85f8e27f7d0b Mon Sep 17 00:00:00 2001 From: wangfq Date: Thu, 2 Jul 2026 10:55:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=20lup=5Fappend=5Fchec?= =?UTF-8?q?ksum=20total=5Flen=20=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF=20(CM?= =?UTF-8?q?D=20=E9=87=8D=E5=A4=8D=E8=AE=A1=E6=95=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: 1 + 3 + LEN + 2 把 CMD 计入两次 (Header(3) 和 Value(LEN) 各含一次) Fix: 5 + LEN = Magic(1)+Addr(1)+LEN(1)+Value(LEN)+Check(2) 影响: 校验字节偏移1位,导致 XOR 写到错误位置,地感MCU 校验失败无响应 同时修正 lup_build_sensor_ack 的 padding 长度和返回值 --- .../OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c index 411491b..f4b1ac4 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c @@ -92,9 +92,11 @@ int lup_verify_checksum(const uint8_t *pkg, uint16_t len) */ void lup_append_checksum(uint8_t *pkg) { - // pkg[0]=7F, pkg[1]=Addr, pkg[2]=LEN, pkg[3]=CMD, ... - uint8_t total_len = 1 + 3 + pkg[2] + 2; // Magic(1) + Header(3) + Value(LEN) + Check(2) - uint16_t check_len = 2 + pkg[2]; // Addr(1) + LEN_field(1) + Value(LEN) + // Frame: [Magic][Addr][LEN][Value(LEN bytes)][XOR][SUM] + // Total = 1 + 1 + 1 + LEN + 2 = 5 + LEN + // (Addr + LEN_field are NOT inside Value; CMD is the 1st byte of Value) + uint8_t total_len = 5 + pkg[2]; // Magic(1)+Addr(1)+LEN(1)+Value(LEN)+Check(2) + uint16_t check_len = 2 + pkg[2]; // Addr(1)+LEN_field(1)+Value(LEN) pkg[total_len - 2] = lup_calc_xor(pkg + 1, check_len); pkg[total_len - 1] = lup_calc_sum(pkg + 1, check_len); @@ -248,7 +250,7 @@ uint16_t lup_build_sensor_ack(uint8_t *buf, uint8_t sens_type, { buf[0] = LUP_MAGIC; buf[1] = LUP_ADDR_DEFAULT; - buf[2] = 0x07; // LEN = 7 (CMD + SensType + Seq + SubAmount) + buf[2] = 0x07; // LEN = 7 (CMD + SensType + Seq + SubAmount + 3 padding) buf[3] = LUP_CMD_SENSOR_REPORT; buf[4] = sens_type; buf[5] = seq; @@ -256,9 +258,8 @@ uint16_t lup_build_sensor_ack(uint8_t *buf, uint8_t sens_type, buf[7] = 0x00; // padding buf[8] = 0x00; buf[9] = 0x00; - buf[10] = 0x00; lup_append_checksum(buf); - return 13; // Magic(1)+Header(3)+Value(7)+Check(2) + return 5 + buf[2]; // = 12: Magic+Addr+LEN+Value(7)+Check(2) } /*===========================================================================