feat: 实现 sensor_report 主动上报功能
vd960DBN: - 新增 g_report_active 全局标志控制传感器数据主动上报 - handle_report_config: 解析 active_report JSON 字段,设置/清除标志 - tcp_json_push_sensor: 检查 g_report_active 开关,仅在启用时推送 DBNetClient: - tcp_json_client.py: 新增 report_config(active_report) 方法 - main.py: 线圈标签页添加"启用主动上报"复选框 - main.py: 注册 sensor_report push 处理器,实时显示推送数据
This commit is contained in:
@@ -31,6 +31,7 @@ uint32_t g_json_auth_timer = 0;
|
||||
uint8_t g_json_pwd_retry = 0;
|
||||
uint32_t g_json_lockout_timer = 0;
|
||||
TcpJsonPending g_json_pending = {0, 0, 0, "", 0};
|
||||
uint8_t g_report_active = 0; // 0=不主动上报, 1=主动上报传感器数据
|
||||
|
||||
/*===========================================================================
|
||||
* Frame Receive Buffer (line-delimited JSON)
|
||||
@@ -549,17 +550,29 @@ static void handle_loop_param_query(uint8_t socket, uint32_t msg_id, const char
|
||||
PRINT("JSON: loop_param_query sent\n");
|
||||
}
|
||||
|
||||
/* 4.15 report_config */
|
||||
/* 4.15 report_config — 配置主动上报开关 */
|
||||
static void handle_report_config(uint8_t socket, uint32_t msg_id, const char *json) {
|
||||
char *data = json_get_data_str(json);
|
||||
if (!data) {
|
||||
json_send_error(socket, msg_id, "report_config", JSON_CODE_PARAM_ERR, "missing data");
|
||||
return;
|
||||
}
|
||||
// Store report config for future push support
|
||||
|
||||
// Parse active_report flag
|
||||
reset_tmp();
|
||||
simple_parse_json(data, "\"active_report\"", g_tmp_value);
|
||||
if (strlen(g_tmp_value) > 0) {
|
||||
if (strstr(g_tmp_value, "true")) {
|
||||
g_report_active = 1;
|
||||
} else {
|
||||
g_report_active = 0;
|
||||
}
|
||||
}
|
||||
free(data);
|
||||
json_send_ok(socket, msg_id, "report_config", NULL);
|
||||
PRINT("JSON: report_config (push not yet implemented)\n");
|
||||
|
||||
json_send_ok(socket, msg_id, "report_config",
|
||||
g_report_active ? "{\"active_report\":true}" : "{\"active_report\":false}");
|
||||
PRINT("JSON: report_config active_report=%d\n", g_report_active);
|
||||
}
|
||||
|
||||
/* 4.16 loop_version_query — 获取地感MCU版本号 (CMD 0x4A) */
|
||||
@@ -1101,9 +1114,10 @@ void tcp_json_poll(void) {
|
||||
* g_pkg_uart_2 that hasn't been consumed by BLE.
|
||||
*===========================================================================*/
|
||||
void tcp_json_push_sensor(void) {
|
||||
// Check: socket active, authed, and data available
|
||||
// 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; // 主动上报未开启
|
||||
|
||||
// Only proceed if g_pkg_uart_2 has data and it's a 0xC0 sensor report
|
||||
if (g_pkg_uart_2.flag == 0) return;
|
||||
|
||||
Reference in New Issue
Block a user