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:
@@ -653,11 +653,21 @@ int lup_feed_byte(uint8_t byte)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*===========================================================================
|
||||
* Sensor Report Callback
|
||||
*===========================================================================*/
|
||||
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;
|
||||
}
|
||||
|
||||
/*
|
||||
* 收到完整帧后的处理:
|
||||
* 1. 校验 checksum
|
||||
* 2. 如果是当前命令的响应 → 通知状态机
|
||||
* 3. 如果是主动上报 (0xC0) → 处理传感器数据
|
||||
* 2. 如果是主动上报 (0xC0) → 调用回调(网络推送等)
|
||||
* 3. 如果是命令响应 → 匹配挂起命令
|
||||
*/
|
||||
void lup_process_frame(const uint8_t *pkg, uint16_t len)
|
||||
{
|
||||
@@ -683,10 +693,11 @@ void lup_process_frame(const uint8_t *pkg, uint16_t len)
|
||||
// --- Dispatch by CMD ---
|
||||
uint8_t cmd = pkg[3];
|
||||
|
||||
// Active reports (0xC0) are NOT responses to commands
|
||||
// Active reports (0xC0) → trigger callback for network/upstream forwarding
|
||||
if (cmd == LUP_CMD_SENSOR_REPORT) {
|
||||
// Sensor report — will be handled in upper layer (uart_srv + TCP JSON)
|
||||
// Don't consume as command response
|
||||
if (g_lup_sensor_cb) {
|
||||
g_lup_sensor_cb(pkg, len);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user