From ff17bbbc887474c6325459f007f2fae2fd08358f Mon Sep 17 00:00:00 2001 From: wangfq Date: Thu, 2 Jul 2026 14:35:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9B=9E=E8=B0=83=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E5=89=8D=E7=BD=AE=E5=88=B0=20socket=20=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=20+=20=E5=85=A5=E5=8F=A3=E8=AF=8A=E6=96=AD?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - lup_set_sensor_callback 移到 SocketCreat/SocketListen 之前 避免 socket 失败 return 导致回调漏注册 - json_sensor_callback 入口打印 socket/auth/report 三状态 各检查点分别打印 skip 原因 --- .../OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c index 3704bc2..e05eab6 100644 --- a/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c +++ b/vd960DBN/BLE/OnlyUpdateApp_Peripheral/APP/tcp_json_srv.c @@ -752,10 +752,13 @@ static int format_loop_param_json(char *buf, uint16_t buf_size, const LUP_ParamG static void json_sensor_callback(const uint8_t *pkg, uint16_t len) { + PRINT("JSON: sensor_cb enter socket=%d auth=%d report=%d\n", + g_json_socket_listen, g_json_auth_state, g_report_active); + // Check: socket active, authed, report enabled - if (g_json_socket_listen == 0xFF) return; - if (g_json_auth_state != JSON_STATE_AUTHED) return; - if (!g_report_active) return; + if (g_json_socket_listen == 0xFF) { PRINT("JSON: sensor_cb skip: no socket\n"); return; } + if (g_json_auth_state != JSON_STATE_AUTHED) { PRINT("JSON: sensor_cb skip: not authed\n"); return; } + if (!g_report_active) { PRINT("JSON: sensor_cb skip: report disabled\n"); return; } LUP_SensorReport sr; memset(&sr, 0, sizeof(sr)); @@ -792,6 +795,10 @@ void tcp_json_srv_init(void) { if (_init_done) return; // 防止 net_srv_init 反复调用 _init_done = 1; + // 注册传感器回调 — 必须在 socket 操作之前, + // 避免 socket 失败导致 return 而漏掉注册 + lup_set_sensor_callback(json_sensor_callback); + memset(&sock_inf, 0, sizeof(SOCK_INF)); sock_inf.SourPort = TCP_JSON_PORT; sock_inf.ProtoType = PROTO_TYPE_TCP; @@ -809,9 +816,6 @@ void tcp_json_srv_init(void) { return; } - // Register sensor callback: 0xC0 frames from Loop MCU → TCP push - lup_set_sensor_callback(json_sensor_callback); - PRINT("JSON: TCP listen on port %d (socket %d)\n", TCP_JSON_PORT, g_json_socket_listen); }