fix main console

This commit is contained in:
Bob 2025-12-11 12:12:55 -08:00
parent 6ce2de5088
commit 7aa45b9e25
1 changed files with 13 additions and 46 deletions

View File

@ -7,7 +7,7 @@
#include "esp_event.h" #include "esp_event.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_console.h" #include "esp_console.h"
#include "linenoise/linenoise.h" // REMOVED: #include "linenoise/linenoise.h" <-- CAUSE OF CONFLICT
#include "nvs_flash.h" #include "nvs_flash.h"
#include "esp_netif.h" #include "esp_netif.h"
#include "lwip/inet.h" #include "lwip/inet.h"
@ -21,7 +21,7 @@
#include "app_console.h" #include "app_console.h"
#include "iperf.h" #include "iperf.h"
// GUARDED INCLUDE: Prevents issues if csi_manager types aren't available // GUARDED INCLUDE
#ifdef CONFIG_ESP_WIFI_CSI_ENABLED #ifdef CONFIG_ESP_WIFI_CSI_ENABLED
#include "csi_log.h" #include "csi_log.h"
#include "csi_manager.h" #include "csi_manager.h"
@ -31,8 +31,6 @@ static const char *TAG = "MAIN";
// --- Event Handler ------------------------------------------------- // --- Event Handler -------------------------------------------------
static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) { static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
// Let the controller handle mode transitions, but we handle high-level LED/App logic here
if (event_base == WIFI_EVENT) { if (event_base == WIFI_EVENT) {
if (event_id == WIFI_EVENT_STA_START) { if (event_id == WIFI_EVENT_STA_START) {
if (wifi_ctl_get_mode() == WIFI_CTL_MODE_STA) { if (wifi_ctl_get_mode() == WIFI_CTL_MODE_STA) {
@ -53,9 +51,7 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
status_led_set_state(LED_STATE_CONNECTED); status_led_set_state(LED_STATE_CONNECTED);
// GUARDED CSI STARTUP LOGIC
#ifdef CONFIG_ESP_WIFI_CSI_ENABLED #ifdef CONFIG_ESP_WIFI_CSI_ENABLED
// Start App Services - Only enable CSI if configured in NVS
if (csi_mgr_should_enable()) { if (csi_mgr_should_enable()) {
ESP_LOGI(TAG, "CSI enabled in config - starting capture"); ESP_LOGI(TAG, "CSI enabled in config - starting capture");
csi_mgr_enable_async(); csi_mgr_enable_async();
@ -65,7 +61,6 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
} }
#endif #endif
// Always start iperf server
iperf_cfg_t cfg = { .flag = IPERF_FLAG_SERVER | IPERF_FLAG_TCP, .sport = 5001 }; iperf_cfg_t cfg = { .flag = IPERF_FLAG_SERVER | IPERF_FLAG_TCP, .sport = 5001 };
iperf_start(&cfg); iperf_start(&cfg);
} }
@ -79,7 +74,6 @@ void app_main(void) {
ESP_ERROR_CHECK(esp_event_loop_create_default()); ESP_ERROR_CHECK(esp_event_loop_create_default());
// 2. Hardware/Driver Init // 2. Hardware/Driver Init
// GUARDED LOG INIT
#ifdef CONFIG_ESP_WIFI_CSI_ENABLED #ifdef CONFIG_ESP_WIFI_CSI_ENABLED
ESP_ERROR_CHECK(csi_log_init()); ESP_ERROR_CHECK(csi_log_init());
#endif #endif
@ -94,21 +88,21 @@ void app_main(void) {
gps_sync_init(&gps_cfg, true); gps_sync_init(&gps_cfg, true);
// 3. Subsystem Init // 3. Subsystem Init
// GUARDED MANAGER INIT
#ifdef CONFIG_ESP_WIFI_CSI_ENABLED #ifdef CONFIG_ESP_WIFI_CSI_ENABLED
csi_mgr_init(); csi_mgr_init();
#endif #endif
wifi_ctl_init(); wifi_ctl_init();
wifi_cfg_init(); // Starts cmd_transport (UART/USB)
// 4. Console/CLI Init // THIS call starts the cmd_transport (UART listener task)
setvbuf(stdin, NULL, _IONBF, 0); // which effectively replaces the manual console loop below.
wifi_cfg_init();
// 4. Console Registry Init (Still needed for registering commands)
esp_console_config_t console_config = { esp_console_config_t console_config = {
.max_cmdline_args = 8, .max_cmdline_args = 8,
.max_cmdline_length = 256, .max_cmdline_length = 256,
}; };
ESP_ERROR_CHECK(esp_console_init(&console_config)); ESP_ERROR_CHECK(esp_console_init(&console_config));
linenoiseSetMultiLine(1);
esp_console_register_help_command(); esp_console_register_help_command();
// Register App Commands // Register App Commands
@ -119,8 +113,6 @@ void app_main(void) {
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, NULL)); ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL, NULL));
// 6. Application Start // 6. Application Start
// Display CSI config status
// GUARDED PRINT
#ifdef CONFIG_ESP_WIFI_CSI_ENABLED #ifdef CONFIG_ESP_WIFI_CSI_ENABLED
bool csi_enabled = csi_mgr_should_enable(); bool csi_enabled = csi_mgr_should_enable();
ESP_LOGI(TAG, "CSI Capture: %s", csi_enabled ? "ENABLED" : "DISABLED"); ESP_LOGI(TAG, "CSI Capture: %s", csi_enabled ? "ENABLED" : "DISABLED");
@ -139,38 +131,13 @@ void app_main(void) {
ESP_LOGW(TAG, "No Config Found. Waiting for setup..."); ESP_LOGW(TAG, "No Config Found. Waiting for setup...");
} }
// 7. Enter Console Loop // 7. Keep Main Task Alive
ESP_LOGI(TAG, "Initialization complete. Entering console loop."); // We removed linenoise because cmd_transport.c is already reading UART.
ESP_LOGI(TAG, "Initialization complete. Entering idle loop.");
const char* prompt = LOG_COLOR_I "esp32> " LOG_RESET_COLOR;
int probe_status = linenoiseProbe();
if (probe_status) {
printf("\n"
"Your terminal application does not support escape sequences.\n"
"Line editing and history features are disabled.\n"
"On Windows, try using Putty instead.\n");
linenoiseSetDumbMode(1);
prompt = "esp32> ";
}
while (true) { while (true) {
char* line = linenoise(prompt); // Just sleep forever. cmd_transport task handles input.
if (line == NULL) { /* Break on EOF or error */ // main event loop task handles wifi events.
break; vTaskDelay(pdMS_TO_TICKS(1000));
}
if (strlen(line) > 0) {
linenoiseHistoryAdd(line);
int ret;
esp_err_t err = esp_console_run(line, &ret);
if (err == ESP_ERR_NOT_FOUND) {
printf("Unrecognized command\n");
} else if (err == ESP_OK && ret != ESP_OK) {
printf("Command returned non-zero error code: 0x%x (%s)\n", ret, esp_err_to_name(ret));
} else if (err != ESP_OK) {
printf("Internal error: %s\n", esp_err_to_name(err));
}
}
linenoiseFree(line);
} }
} }