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); }