fix main console
This commit is contained in:
parent
6ce2de5088
commit
7aa45b9e25
59
main/main.c
59
main/main.c
|
|
@ -7,7 +7,7 @@
|
|||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_console.h"
|
||||
#include "linenoise/linenoise.h"
|
||||
// REMOVED: #include "linenoise/linenoise.h" <-- CAUSE OF CONFLICT
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_netif.h"
|
||||
#include "lwip/inet.h"
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
#include "app_console.h"
|
||||
#include "iperf.h"
|
||||
|
||||
// GUARDED INCLUDE: Prevents issues if csi_manager types aren't available
|
||||
// GUARDED INCLUDE
|
||||
#ifdef CONFIG_ESP_WIFI_CSI_ENABLED
|
||||
#include "csi_log.h"
|
||||
#include "csi_manager.h"
|
||||
|
|
@ -31,8 +31,6 @@ static const char *TAG = "MAIN";
|
|||
|
||||
// --- Event Handler -------------------------------------------------
|
||||
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_id == WIFI_EVENT_STA_START) {
|
||||
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);
|
||||
|
||||
// GUARDED CSI STARTUP LOGIC
|
||||
#ifdef CONFIG_ESP_WIFI_CSI_ENABLED
|
||||
// Start App Services - Only enable CSI if configured in NVS
|
||||
if (csi_mgr_should_enable()) {
|
||||
ESP_LOGI(TAG, "CSI enabled in config - starting capture");
|
||||
csi_mgr_enable_async();
|
||||
|
|
@ -65,7 +61,6 @@ static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_
|
|||
}
|
||||
#endif
|
||||
|
||||
// Always start iperf server
|
||||
iperf_cfg_t cfg = { .flag = IPERF_FLAG_SERVER | IPERF_FLAG_TCP, .sport = 5001 };
|
||||
iperf_start(&cfg);
|
||||
}
|
||||
|
|
@ -79,7 +74,6 @@ void app_main(void) {
|
|||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
|
||||
// 2. Hardware/Driver Init
|
||||
// GUARDED LOG INIT
|
||||
#ifdef CONFIG_ESP_WIFI_CSI_ENABLED
|
||||
ESP_ERROR_CHECK(csi_log_init());
|
||||
#endif
|
||||
|
|
@ -94,21 +88,21 @@ void app_main(void) {
|
|||
gps_sync_init(&gps_cfg, true);
|
||||
|
||||
// 3. Subsystem Init
|
||||
// GUARDED MANAGER INIT
|
||||
#ifdef CONFIG_ESP_WIFI_CSI_ENABLED
|
||||
csi_mgr_init();
|
||||
#endif
|
||||
wifi_ctl_init();
|
||||
wifi_cfg_init(); // Starts cmd_transport (UART/USB)
|
||||
|
||||
// 4. Console/CLI Init
|
||||
setvbuf(stdin, NULL, _IONBF, 0);
|
||||
// THIS call starts the cmd_transport (UART listener task)
|
||||
// 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 = {
|
||||
.max_cmdline_args = 8,
|
||||
.max_cmdline_length = 256,
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_console_init(&console_config));
|
||||
linenoiseSetMultiLine(1);
|
||||
esp_console_register_help_command();
|
||||
|
||||
// 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));
|
||||
|
||||
// 6. Application Start
|
||||
// Display CSI config status
|
||||
// GUARDED PRINT
|
||||
#ifdef CONFIG_ESP_WIFI_CSI_ENABLED
|
||||
bool csi_enabled = csi_mgr_should_enable();
|
||||
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...");
|
||||
}
|
||||
|
||||
// 7. Enter Console Loop
|
||||
ESP_LOGI(TAG, "Initialization complete. Entering console 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> ";
|
||||
}
|
||||
// 7. Keep Main Task Alive
|
||||
// We removed linenoise because cmd_transport.c is already reading UART.
|
||||
ESP_LOGI(TAG, "Initialization complete. Entering idle loop.");
|
||||
|
||||
while (true) {
|
||||
char* line = linenoise(prompt);
|
||||
if (line == NULL) { /* Break on EOF or error */
|
||||
break;
|
||||
}
|
||||
|
||||
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);
|
||||
// Just sleep forever. cmd_transport task handles input.
|
||||
// main event loop task handles wifi events.
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue