From c4a2b50ca55415e0a529141ce78ba7e7f990102e Mon Sep 17 00:00:00 2001 From: wangfq Date: Thu, 2 Jul 2026 14:29:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20tcp=5Fjson=5Fsrv=5Finit=20=E5=8A=A0?= =?UTF-8?q?=E4=B8=80=E6=AC=A1=E6=80=A7=E5=AE=88=E5=8D=AB=20+=20callback=20?= =?UTF-8?q?NULL=20=E8=AF=8A=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: NET_SSC_ENABLE 时 g_net_state.flag 保持 1, net_srv_init 反复调用 tcp_json_srv_init 第二次因 socket 已存在失败 → 过早 return → lup_set_sensor_callback 未执行 → 0xC0 回调永远 NULL 修复: - tcp_json_srv_init: 加 static _init_done 守卫,防止重复执行 - lup_set_sensor_callback: 打印注册/清除日志 - lup_process_frame: 回调为 NULL 时打印诊断信息 --- vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c | 3 +++ vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c index 49d16de..21a1f42 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/loop_uart_proto.c @@ -661,6 +661,7 @@ static lup_sensor_cb_t g_lup_sensor_cb = NULL; void lup_set_sensor_callback(lup_sensor_cb_t cb) { g_lup_sensor_cb = cb; + PRINT("LUP: sensor callback %s\n", cb ? "registered" : "cleared"); } /* @@ -697,6 +698,8 @@ void lup_process_frame(const uint8_t *pkg, uint16_t len) if (cmd == LUP_CMD_SENSOR_REPORT) { if (g_lup_sensor_cb) { g_lup_sensor_cb(pkg, len); + } else { + PRINT("LUP: 0xC0 received but no callback registered!\n"); } return; } diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c index 4b22278..3704bc2 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c @@ -787,6 +787,10 @@ static void json_sensor_callback(const uint8_t *pkg, uint16_t len) void tcp_json_srv_init(void) { uint8_t ret; SOCK_INF sock_inf; + static uint8_t _init_done = 0; + + if (_init_done) return; // 防止 net_srv_init 反复调用 + _init_done = 1; memset(&sock_inf, 0, sizeof(SOCK_INF)); sock_inf.SourPort = TCP_JSON_PORT;