#include "app_console.h" #include "esp_console.h" #include "esp_log.h" #include "argtable3/argtable3.h" #include #include #include // Dependencies #include "wifi_controller.h" #include "status_led.h" #include "gps_sync.h" #include "iperf.h" #ifdef CONFIG_ESP_WIFI_CSI_ENABLED #include "csi_manager.h" #endif // --- Command Handlers --- static int cmd_iperf(int argc, char **argv) { if (argc < 2) { printf("Usage: iperf \n"); return 1; } if (strcmp(argv[1], "start") == 0) { iperf_cfg_t cfg = { .time = 0 }; // Infinite iperf_start(&cfg); // iperf_start already logs "IPERF_STARTED" via printf in iperf.c, // but keeping it here is fine/redundant. // To be safe and clean, we rely on iperf.c's output or just return success. return 0; } else if (strcmp(argv[1], "stop") == 0) { iperf_stop(); return 0; } else if (strcmp(argv[1], "pps") == 0) { // Syntax: iperf pps 100 if (argc < 3) { printf("Error: Missing value. Usage: iperf pps \n"); return 1; } int pps = atoi(argv[2]); if (pps <= 0) { printf("Error: Invalid PPS.\n"); return 1; } iperf_set_pps((uint32_t)pps); // iperf_set_pps prints "IPERF_PPS_UPDATED: ..." return 0; } else if (strcmp(argv[1], "status") == 0) { // [FIXED] Use the new API to print detailed stats iperf_print_status(); return 0; } printf("Error: Unknown subcommand '%s'.\n", argv[1]); return 1; } static int cmd_mode_monitor(int argc, char **argv) { int channel = wifi_ctl_get_monitor_channel(); if (argc > 1) channel = atoi(argv[1]); if (wifi_ctl_switch_to_monitor(channel, WIFI_BW_HT20) != ESP_OK) { printf("Failed to switch to monitor mode\n"); return 1; } return 0; } static int cmd_mode_sta(int argc, char **argv) { if (wifi_ctl_switch_to_sta(WIFI_BAND_MODE_AUTO) != ESP_OK) { printf("Failed to switch to STA mode\n"); return 1; } return 0; } static int cmd_mode_status(int argc, char **argv) { wifi_ctl_mode_t mode = wifi_ctl_get_mode(); printf("\n=== WiFi Mode Status ===\n"); printf("Current mode: %s\n", mode == WIFI_CTL_MODE_STA ? "STA" : "MONITOR"); printf("LED state: %d\n", status_led_get_state()); printf("GPS synced: %s\n", gps_is_synced() ? "Yes" : "No"); return 0; } static int cmd_csi_dump(int argc, char **argv) { #ifdef CONFIG_ESP_WIFI_CSI_ENABLED csi_mgr_schedule_dump(); #else printf("Error: CSI feature is disabled in this firmware build.\n"); #endif return 0; } void app_console_register_commands(void) { const esp_console_cmd_t cmds[] = { { .command = "mode_monitor", .help = "Switch to monitor mode", .func = &cmd_mode_monitor }, { .command = "mode_sta", .help = "Switch to STA mode", .func = &cmd_mode_sta }, { .command = "mode_status", .help = "Show device status", .func = &cmd_mode_status }, { .command = "csi_dump", .help = "Dump collected CSI data", .func = &cmd_csi_dump }, { .command = "iperf", .help = "Control iperf (start, stop, pps, status)", .func = &cmd_iperf }, }; for (int i = 0; i < sizeof(cmds)/sizeof(cmds[0]); i++) { ESP_ERROR_CHECK(esp_console_cmd_register(&cmds[i])); } }