fix: 0xC0 帧通过回调直接驱动网络上报

loop_uart_proto:
- 新增 lup_sensor_cb_t 回调类型 + lup_set_sensor_callback
- lup_process_frame 收到 0xC0 → 调用注册的回调推送数据

tcp_json_srv:
- json_sensor_callback: 检查 g_report_active → 解析 → TCP 发送
- tcp_json_srv_init: 注册回调

usart_biz:
- uart_srv: 0xC0 由回调直接 TCP 推送,BLE 连接时也转发 BLE
- 移除旧的 _report_flag 轮询路径

数据流: ISR → lup_process_frame(校验) → json_sensor_callback → WCHNET_SocketSend
This commit is contained in:
wangfq
2026-07-02 14:15:28 +08:00
parent 7c2927d836
commit 6acd788d13
4 changed files with 62 additions and 13 deletions

View File

@@ -742,6 +742,39 @@ static void json_process_frame(uint8_t socket, const char *frame) {
}
/*===========================================================================
* json_sensor_callback — 注册到 lup_process_frame0xC0 帧到达时直接推送
*===========================================================================*/
static void json_sensor_callback(const uint8_t *pkg, uint16_t len)
{
// 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;
LUP_SensorReport sr;
memset(&sr, 0, sizeof(sr));
int ret = lup_parse_sensor_report(pkg, len, &sr);
if (ret != 0) {
PRINT("JSON: sensor callback parse failed (%d)\n", ret);
return;
}
char data_json[2048];
if (format_sensor_json(data_json, sizeof(data_json), &sr) == 0) {
char *out = (char *)malloc(TCP_JSON_MAX_FRAME);
if (out) {
snprintf(out, TCP_JSON_MAX_FRAME,
"{\"msg_id\":0,\"cmd\":\"sensor_report\",\"ts\":%lu,"
"\"code\":0,\"msg\":\"success\",\"data\":%s}\n",
(unsigned long)mstick(), data_json);
uint32_t slen = strlen(out);
WCHNET_SocketSend(g_json_socket_listen, (uint8_t *)out, &slen);
free(out);
}
}
}
/*===========================================================================
* Public API
*===========================================================================*/
@@ -767,6 +800,9 @@ 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);
}