From 40e664844556bd4cc1bb088788db709bdcf7de79 Mon Sep 17 00:00:00 2001 From: wangfq Date: Thu, 27 Aug 2026 08:27:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(vd960Loop):=20LOOP=5FMEASURE=5FBASE=20?= =?UTF-8?q?=E5=BD=92=E4=B8=80=E5=8C=96=E5=9F=BA=E6=95=B0=E4=B8=8A=E6=8A=A5?= =?UTF-8?q?=20(=E5=8D=8F=E8=AE=AE=20V1.09)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 跨产品 MEASUREMENT_BASE 对齐(2026-08-26 DLD110S ×4 事故):variation 是周期域 计数值,归一化必须除设备自身的 MEASUREMENT_BASE。960Loop 此前 0x64 读参响应裸发 参数,第三方平台无从换算(写死 131072 恰好蒙对,写 524288 就 ÷4 失真)。 - docs(DLD960Loop_串口通信协议.md): V1.09 — 0x64 响应尾部追加 3B LE LOOP_MEASURE_BASE(响应 34B→37B)+ 换算公式 ΔL/L≈-2×variation/BASE、 Δf/f≈variation/BASE + 修订记录 - inc/cmcng.h: #define LOOP_MEASURE_BASE 131072L(注释标明与 TaskLoop.h MEASUREMENT_BASE 同步) - src/main.c: CMD_DBN_GET_MCJQ_PARAM (0x64) handler for 循环后追加 3B LE - docs/devlog.md: 置顶 2026-08-27 条目 设计决策:常量走 0x64 查询响应(低频)不进 0xC0 高频帧(避免分包); 向后兼容老客户端(只读前 34B 不受影响)。 联动待办:DBN 侧对外(BLE/TCP/MQTT)暴露基数未落地。 --- docs/DLD960Loop_串口通信协议.md | 27 ++++++++++++--- vd960Loop/docs/devlog.md | 34 +++++++++++++++++++ .../at32f421_freertos_demo/inc/cmcng.h | 5 +++ .../at32f421_freertos_demo/src/main.c | 5 +++ 4 files changed, 67 insertions(+), 4 deletions(-) diff --git a/docs/DLD960Loop_串口通信协议.md b/docs/DLD960Loop_串口通信协议.md index fc50a44..d190ec7 100644 --- a/docs/DLD960Loop_串口通信协议.md +++ b/docs/DLD960Loop_串口通信协议.md @@ -176,10 +176,28 @@ A2 00 51 00: 第0级灵敏度,0x00A2为进入 162,0x0051为离开 81 返回: -| | Header | AutoMode+Amount + Data\[Sensitivity, Loop_Delay, Output_Mode, Exist_Mode, Direction_Mode, freq1,  freq2, freq3\] | +| | Header | AutoMode + Amount + Data\[Sensitivity, Loop_Delay, Output_Mode, Exist_Mode, Direction_Mode, freq1, freq2, freq3\] + **LOOP_MEASURE_BASE(3B LE)** | | --- | --- | --- | -| **Value(Hex)** | 00 xx 64 | XX | -| **Length** | 3 Byte | (2 + 8 \* Amount) Byte | +| **Value(Hex)** | 00 xx 64 | XX | +| **Length** | 3 Byte | (2 + 8 \* Amount + **3**) Byte | + +**V1.09 起响应尾部追加 3B LE `LOOP_MEASURE_BASE`(variation 归一化基数,本产品 = 131072 = 2^17)**: + +| 偏移(相对 Data 起点) | 字节 | 内容 | +| --- | --- | --- | +| 0 | 1 | AutoMode(smart_mode) | +| 1 | 1 | 线圈数量 Amount | +| 2 .. 2+8×Amount−1 | 8×Amount | 每路线圈参数(Sensitivity, Loop_Delay, Output_Mode, Exist_Mode, Direction_Mode, freq1, freq2, freq3) | +| 2+8×Amount .. +2 | 3 | **LOOP_MEASURE_BASE** 小端(低字节在前)。本产品固定 `00 00 02` = 0x00020000 = **131072** | + +**用途(第三方评估换算)**:上报变化量 variation 是**周期域计数值**(`variation = Origin − CAPVD`,CAPVD ∝ √L 而非 L),归一化必须除本基数: + +``` +Δf/f ≈ variation / LOOP_MEASURE_BASE +ΔL/L ≈ -2 × variation / LOOP_MEASURE_BASE (系数 2 来自 CAPVD ∝ √L 展开,阈值区间残差 <0.2%) +``` + +> ⚠ **各产品 MEASUREMENT_BASE 不同**(AT32@120MHz = 131072;CH59x@60MHz = 524288),接收端/第三方应用**禁止写死任一型号常量**,一律从 0x64 响应读取本基数,否则所有百分比放大/缩小 4 倍。 ## 3.07 设备主动上报传感信息(0xC0) @@ -262,4 +280,5 @@ FE 38 校验字节(XOR=0xFE, SUM=0x38) | V1.05 | 2026-07-14 | 多线圈上报(0x0C)变化量 variation 由 2 字节无符号扩展为 **3 字节有符号**(补码, 小端),定义 `variation = Origin − CAPVD`(正=车/裕量, 负=反向漂移);每单元 11→12 字节,Len 47→51。接收端须做符号扩展。**Loop 固件与 DBN 固件须同版本发布。** | wangfq | | V1.06 | 2026-07-15 | 修正杂项时间量单位说明:5ms → **50ms**(对齐固件 50ms tick 实现,TMR15 5ms×10 分频) | wangfq | | V1.07 | 2026-08-25 | variation 值域表述勘误:`±8388607` → **−8388608 ~ +8388607**(对齐代码负向饱和边界 0x800000,3B 补码标准值域) | wangfq | -| V1.08 | 2026-08-25 | 灵敏度收敛为 **4级制 0~3**(0 最低,3 最高,默认 2):修复 9级制映射 `&0x03` 折叠(7→3、8→0 错乱)导致"改灵敏度感应高度无区别";运行中配置灵敏度立即生效(不再依赖重启)。9级制后续版本实现 | wangfq | \ No newline at end of file +| V1.08 | 2026-08-25 | 灵敏度收敛为 **4级制 0~3**(0 最低,3 最高,默认 2):修复 9级制映射 `&0x03` 折叠(7→3、8→0 错乱)导致"改灵敏度感应高度无区别";运行中配置灵敏度立即生效(不再依赖重启)。9级制后续版本实现 | wangfq | +| V1.09 | 2026-08-27 | 0x64 读参响应尾部追加 **3B LE `LOOP_MEASURE_BASE`**(variation 归一化基数 131072 = 2^17,与固件 MEASUREMENT_BASE 同步);新增换算公式 `ΔL/L ≈ -2×variation/LOOP_MEASURE_BASE`、`Δf/f ≈ variation/LOOP_MEASURE_BASE`(跨产品基数对齐,防第三方评估 ×4/÷4 陷阱) | wangfq | \ No newline at end of file diff --git a/vd960Loop/docs/devlog.md b/vd960Loop/docs/devlog.md index bbb35fc..23661dc 100644 --- a/vd960Loop/docs/devlog.md +++ b/vd960Loop/docs/devlog.md @@ -4,6 +4,40 @@ --- +## 2026-08-27 — LOOP_MEASURE_BASE 归一化基数上报(协议 V1.09) + +### 背景 + +跨产品 MEASUREMENT_BASE 对齐(2026-08-26 DLD110S ×4 事故:第三方小程序把 ΔL/L 报成 8.85%,真实 2.21%)。variation 是周期域计数值(`variation = Origin − CAPVD`,CAPVD ∝ √L),归一化必须除**设备自身**的 MEASUREMENT_BASE。960Loop 是产品线中唯一未上报基数的型号——0x64 读参响应裸发参数,第三方平台无从换算(写死 131072 恰好蒙对,写 524288 就 ÷4 失真)。 + +### 改动 + +| 文件 | 内容 | +|------|------| +| `docs/DLD960Loop_串口通信协议.md`(vd_960 仓库) | **V1.09**:0x64 响应尾部追加 3B LE `LOOP_MEASURE_BASE`(响应 34B→37B)+ 换算公式 + 修订记录 | +| `inc/cmcng.h` | `#define LOOP_MEASURE_BASE 131072L`(注释标明与 TaskLoop.h MEASUREMENT_BASE 同步) | +| `src/main.c` | `CMD_DBN_GET_MCJQ_PARAM` (0x64) handler for 循环后追加 3B LE(小端,响应 2+8×4+3=37B) | + +### 换算公式(写入协议文档) + +``` +Δf/f ≈ variation / LOOP_MEASURE_BASE (131072, AT32@120MHz) +ΔL/L ≈ -2 × variation / LOOP_MEASURE_BASE (系数 2 来自 CAPVD ∝ √L 展开) +``` + +### 设计决策 + +- 常量放 **0x64 查询响应**(低频),不进 0xC0 高频帧(每线圈 12B 已贴边,加字段触发分包) +- 向后兼容:老客户端只读前 34B 不受影响;新客户端读 37B 拿基数 +- ⚠ 联动待办:DBN 侧对外(BLE/TCP/MQTT)暴露基数未落地——平台走网络协议评估时仍需加字段 + +### 验证 + +- ✅ `check_c_balance.py` 语法平衡 OK;编码保持 UTF-8+CRLF +- [ ] 板级验证:0x64 响应长度 37B、尾部 3B = `00 00 02`(131072 LE) + +--- + ## 2026-08-25 — 灵敏度 4 级制修复(协议 V1.08) ### 背景 diff --git a/vd960Loop/utilities/at32f421_freertos_demo/inc/cmcng.h b/vd960Loop/utilities/at32f421_freertos_demo/inc/cmcng.h index 2365ea2..612d6fa 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/inc/cmcng.h +++ b/vd960Loop/utilities/at32f421_freertos_demo/inc/cmcng.h @@ -25,6 +25,11 @@ #define HARDWARE_VER_SUB 0 #define HARDWARE_VER_SSUB 0 +// LOOP_MEASURE_BASE: variation 归一化基数 (协议 0x64 响应尾部 3B LE 上报) +// ⚠ 必须与 TaskLoop.h 的 MEASUREMENT_BASE 同步 (AT32F421 @120MHz = 2^17 = 131072) +// 第三方评估换算: Δf/f ≈ variation/LOOP_MEASURE_BASE; ΔL/L ≈ -2×variation/LOOP_MEASURE_BASE +#define LOOP_MEASURE_BASE 131072L + #define FUNCTION_A 0x01 // 二次判断 #define FUNCTION_B 0x02 // 二次判断增强条件判断 diff --git a/vd960Loop/utilities/at32f421_freertos_demo/src/main.c b/vd960Loop/utilities/at32f421_freertos_demo/src/main.c index ced4b83..e5da543 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/src/main.c +++ b/vd960Loop/utilities/at32f421_freertos_demo/src/main.c @@ -839,6 +839,11 @@ void manage_dbn_ble_default(uint8_t *pkg, uint8_t len) _cng++; } + // LOOP_MEASURE_BASE: variation 归一化基数 (3B LE, 与 TaskLoop.h MEASUREMENT_BASE 同步) + tmp_ble_buf[i++] = (uint8_t)(LOOP_MEASURE_BASE & 0xFF); + tmp_ble_buf[i++] = (uint8_t)((LOOP_MEASURE_BASE >> 8) & 0xFF); + tmp_ble_buf[i++] = (uint8_t)((LOOP_MEASURE_BASE >> 16) & 0xFF); + response_uart_pkg(_cmd, tmp_ble_buf, i); } break;