feat: Add CSI ON/OFF command to toggle CSI collection
When CSI is OFF, probe request capture remains active. Persisted via NVS key 'csi_enabled'.
This commit is contained in:
@@ -100,6 +100,9 @@ static volatile int8_t s_rssi_min = 0;
|
||||
static volatile int8_t s_rssi_max = -128;
|
||||
static uint32_t s_boot_count = 0;
|
||||
|
||||
/* CSI collection toggle */
|
||||
static bool s_csi_enabled = true;
|
||||
|
||||
/* CSI output mode */
|
||||
typedef enum {
|
||||
CSI_MODE_RAW = 0,
|
||||
@@ -306,11 +309,15 @@ static void config_load_nvs(void)
|
||||
if (nvs_get_i8(h, "led_quiet", &led_quiet) == ESP_OK) {
|
||||
s_led_quiet = (led_quiet != 0);
|
||||
}
|
||||
int8_t csi_en;
|
||||
if (nvs_get_i8(h, "csi_enabled", &csi_en) == ESP_OK) {
|
||||
s_csi_enabled = (csi_en != 0);
|
||||
}
|
||||
nvs_close(h);
|
||||
ESP_LOGI(TAG, "NVS loaded: hostname=%s rate=%d tx_power=%d adaptive=%d threshold=%.6f ble=%d target=%s:%d csi_mode=%d hybrid_n=%d powersave=%d presence=%d pr_thresh=%.4f baseline_nsub=%d led_quiet=%d",
|
||||
ESP_LOGI(TAG, "NVS loaded: hostname=%s rate=%d tx_power=%d adaptive=%d threshold=%.6f ble=%d target=%s:%d csi_mode=%d hybrid_n=%d powersave=%d presence=%d pr_thresh=%.4f baseline_nsub=%d led_quiet=%d csi=%d",
|
||||
s_hostname, s_send_frequency, s_tx_power_dbm, s_adaptive, s_motion_threshold, s_ble_enabled,
|
||||
s_target_ip, s_target_port, (int)s_csi_mode, s_hybrid_interval, s_powersave,
|
||||
s_presence_enabled, s_pr_threshold, s_baseline_nsub, s_led_quiet);
|
||||
s_presence_enabled, s_pr_threshold, s_baseline_nsub, s_led_quiet, s_csi_enabled);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "NVS: no saved config, using defaults");
|
||||
}
|
||||
@@ -536,6 +543,10 @@ static void wifi_csi_rx_cb(void *ctx, wifi_csi_info_t *info)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!s_csi_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
s_last_csi_time = esp_timer_get_time();
|
||||
|
||||
const wifi_pkt_rx_ctrl_t *rx_ctrl = &info->rx_ctrl;
|
||||
@@ -1589,7 +1600,7 @@ static int cmd_handle(const char *cmd, char *reply, size_t reply_size)
|
||||
"OK STATUS uptime=%s uptime_s=%lld heap=%lu rssi=%d channel=%d tx_power=%d rate=%d csi_rate=%d"
|
||||
" hostname=%s version=%s adaptive=%s motion=%d ble=%s target=%s:%d"
|
||||
" temp=%.1f csi_count=%lu boots=%lu rssi_min=%d rssi_max=%d"
|
||||
" csi_mode=%s hybrid_n=%d auth=%s flood_thresh=%d/%d powersave=%s"
|
||||
" csi=%s csi_mode=%s hybrid_n=%d auth=%s flood_thresh=%d/%d powersave=%s"
|
||||
" presence=%s pr_score=%.4f chanscan=%s led=%s"
|
||||
" nvs_used=%lu nvs_free=%lu nvs_total=%lu part_size=%lu"
|
||||
" built=%s_%s idf=%s chip=%sr%dc%d",
|
||||
@@ -1600,7 +1611,7 @@ static int cmd_handle(const char *cmd, char *reply, size_t reply_size)
|
||||
s_ble_enabled ? "on" : "off", s_target_ip, s_target_port,
|
||||
chip_temp, (unsigned long)s_csi_count, (unsigned long)s_boot_count,
|
||||
(int)s_rssi_min, (int)s_rssi_max,
|
||||
csi_mode_str, s_hybrid_interval,
|
||||
s_csi_enabled ? "on" : "off", csi_mode_str, s_hybrid_interval,
|
||||
s_auth_secret[0] ? "on" : "off",
|
||||
s_flood_thresh, s_flood_window_s,
|
||||
s_powersave ? "on" : "off",
|
||||
@@ -1781,6 +1792,28 @@ static int cmd_handle(const char *cmd, char *reply, size_t reply_size)
|
||||
return strlen(reply);
|
||||
}
|
||||
|
||||
/* CSI [ON|OFF] - enable/disable CSI collection */
|
||||
if (strcmp(cmd, "CSI") == 0) {
|
||||
snprintf(reply, reply_size, "OK CSI %s", s_csi_enabled ? "on" : "off");
|
||||
return strlen(reply);
|
||||
}
|
||||
if (strncmp(cmd, "CSI ", 4) == 0) {
|
||||
const char *arg = cmd + 4;
|
||||
if (strncmp(arg, "ON", 2) == 0) {
|
||||
s_csi_enabled = true;
|
||||
config_save_i8("csi_enabled", 1);
|
||||
wifi_ping_router_start();
|
||||
snprintf(reply, reply_size, "OK CSI on");
|
||||
} else if (strncmp(arg, "OFF", 3) == 0) {
|
||||
s_csi_enabled = false;
|
||||
config_save_i8("csi_enabled", 0);
|
||||
snprintf(reply, reply_size, "OK CSI off (probe capture active)");
|
||||
} else {
|
||||
snprintf(reply, reply_size, "ERR CSI ON|OFF");
|
||||
}
|
||||
return strlen(reply);
|
||||
}
|
||||
|
||||
/* CSIMODE [RAW|COMPACT|HYBRID N] */
|
||||
if (strcmp(cmd, "CSIMODE") == 0) {
|
||||
const char *mode_str = (s_csi_mode == CSI_MODE_COMPACT) ? "COMPACT" :
|
||||
|
||||
Reference in New Issue
Block a user