refactor(vd960DBN): tcp_json_srv data_json[2048] 宏化 → TCP_JSON_DATA_BUF_LEN(1024)

三处 char data_json[2048] (sensor_report×2 + loop_param_query×1)
改用头文件宏 TCP_JSON_DATA_BUF_LEN, 默认 1024。

容量核验: format_sensor_json 4通道~660B / format_loop_param_json~920B
均 < 1024, format 函数有 snprintf 溢出保护; 最终帧受 MAX_FRAME=800 截断。
附带: 栈上缓冲 2048→1024 每处省 1KB
This commit is contained in:
wangfq
2026-08-04 17:06:29 +08:00
parent 5155219c92
commit 2b1e888a73
3 changed files with 14 additions and 4 deletions
@@ -18,6 +18,7 @@
*===========================================================================*/
#define TCP_JSON_PORT 5960 // TCP JSON protocol default port
#define TCP_JSON_MAX_FRAME 800 //4096 // Max JSON frame length
#define TCP_JSON_DATA_BUF_LEN 1024 // 本地 JSON 组装缓冲长度 (data_json)
#define TCP_JSON_AUTH_TIMEOUT_MS 60000 // 60s auth timeout (ms)
#define TCP_JSON_RECV_BUF_LEN (TCP_JSON_MAX_FRAME * 2)
#define TCP_JSON_MAX_PWD_RETRY 3 // Max password retries before lockout
@@ -829,7 +829,7 @@ static void json_sensor_callback(const uint8_t *pkg, uint16_t len)
return;
}
char data_json[2048];
char data_json[TCP_JSON_DATA_BUF_LEN];
if (format_sensor_json(data_json, sizeof(data_json), &sr) == 0) {
char *out = (char *)malloc(TCP_JSON_MAX_FRAME);
if (out) {
@@ -1102,7 +1102,7 @@ static void json_check_pending(void) {
memset(&pg, 0, sizeof(pg));
int ret = lup_parse_param_get(g_lup_cmd.resp_buf, g_lup_cmd.resp_len, &pg);
if (ret == 0) {
char data_json[2048];
char data_json[TCP_JSON_DATA_BUF_LEN];
if (format_loop_param_json(data_json, sizeof(data_json), &pg) == 0) {
json_send_ok(g_json_pending.socket, g_json_pending.msg_id,
g_json_pending.cmd, data_json);
@@ -1319,7 +1319,7 @@ void tcp_json_push_sensor(void) {
return;
}
char data_json[2048];
char data_json[TCP_JSON_DATA_BUF_LEN];
if (format_sensor_json(data_json, sizeof(data_json), &sr) == 0) {
char *out = (char *)malloc(TCP_JSON_MAX_FRAME);
if (out) {
+10 -1
View File
@@ -703,14 +703,23 @@ TCP 超时要等 ~2 分钟才触发 `SINT_STAT_TIM_OUT`,
- [ ] 复位原因寄存器布局**待板上验证** (RCC_RSTSCKR 按 STM32F1 兼容写)
- [ ] MRS 工程编译确认 offlog.c 被自动收集
## 2026-08-04 — tcp_json_srv 缓冲宏化: data_json[2048] → TCP_JSON_DATA_BUF_LEN(1024)
三处 `char data_json[2048]`sensor_report 推送×2、loop_param_query 响应×1)改用头文件宏 `TCP_JSON_DATA_BUF_LEN`(默认 1024)。
**容量核验**format_sensor_json 4 通道最大 ~660B、format_loop_param_json ~920B,均 < 1024 且 format 函数有 snprintf 溢出保护(`written >= remaining` 返回 -1)。最终发送帧受 TCP_JSON_MAX_FRAME=800 截断,data_json 只做中间组装,1024 足够。
**附带收益**:栈上缓冲 2048→1024,每处省 1KB 栈(CH32V208 栈紧张,中断路径 832/1322 在回调/主循环调用)。
## 修订记录
| 版本 | 时间 | 说明 |
|------|------|------|
| V3.7 | 2026-08-04 | tcp_json_srv 缓冲宏化: data_json[2048]→TCP_JSON_DATA_BUF_LEN(1024), 省栈1KB×3 |
| V3.6 | 2026-08-04 | 脱机事件日志系统: W25Q32 256KB 环形(8064条) + BOOT/网络/事件/线圈/时钟锚点 8 类事件 + 掉电恢复 + gcc 单测 6 例 |
| V3.5 | 2026-07-23 | 保活精简(去heartbeat+IWDG) + SocketSend故障恢复(3次失败重连+重建socket) |
| V3.4 | 2026-07-23 | MQTT 栈重构: 发送缓冲隔离/命令处理/msg_id统一/看门狗, 共10项修复 |
| V3.3 | 2026-07-23 | loop_data: 消灭 data_json[1024] BSS 缓冲 + coil_count 硬限, 防 mqttBuf 重叠致 _raw 异常 |
|------|------|------|
| V3.2 | 2026-07-10 | 双主题发布统一 + initialize 数据格式对齐 V1.03 + mqtt_publish packet_id=0 断连修复 |
| V3.1 | 2026-07-09 | V1.03: 订阅后发 initialize 上线消息; iot_mqtt_srv 订阅改双主题 |
| V3.0 | 2026-07-08 | MQTT 稳定性修复: socket初始化/buffer溢出/分批发送/hex dump/PINGREQ |