more cmd stuff
This commit is contained in:
parent
b769dbc356
commit
64446be628
34
main/main.c
34
main/main.c
|
|
@ -33,6 +33,8 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/time.h> // Added for gettimeofday
|
||||||
|
#include <time.h> // Added for time structs
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
|
|
@ -42,7 +44,7 @@
|
||||||
#include "esp_vfs_dev.h"
|
#include "esp_vfs_dev.h"
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
#include "nvs_flash.h"
|
#include "nvs_flash.h"
|
||||||
#include "nvs.h" // Added for NVS read
|
#include "nvs.h"
|
||||||
#include "esp_netif.h"
|
#include "esp_netif.h"
|
||||||
#include "esp_event.h"
|
#include "esp_event.h"
|
||||||
|
|
||||||
|
|
@ -67,6 +69,18 @@ static const char *TAG = "MAIN";
|
||||||
// --- Global Prompt Buffer (Mutable) ---
|
// --- Global Prompt Buffer (Mutable) ---
|
||||||
static char s_cli_prompt[32] = "esp32> ";
|
static char s_cli_prompt[32] = "esp32> ";
|
||||||
|
|
||||||
|
// --- Custom Log Formatter (Epoch Timestamp) ---
|
||||||
|
// This ensures logs match tcpdump/wireshark format: [Seconds.Microseconds]
|
||||||
|
static int custom_log_vprintf(const char *fmt, va_list args) {
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
|
||||||
|
// Print [1766437791.123456] prefix
|
||||||
|
printf("[%ld.%06ld] ", (long)tv.tv_sec, (long)tv.tv_usec);
|
||||||
|
|
||||||
|
return vprintf(fmt, args);
|
||||||
|
}
|
||||||
|
|
||||||
// --- Prompt Updater ---
|
// --- Prompt Updater ---
|
||||||
void app_console_update_prompt(void) {
|
void app_console_update_prompt(void) {
|
||||||
bool dirty = false;
|
bool dirty = false;
|
||||||
|
|
@ -136,7 +150,11 @@ void app_main(void) {
|
||||||
}
|
}
|
||||||
ESP_ERROR_CHECK(ret);
|
ESP_ERROR_CHECK(ret);
|
||||||
|
|
||||||
// 2. Initialize Netif & Event Loop
|
// 2. Register Custom Log Formatter (Epoch Time)
|
||||||
|
// Must be done before any logs are printed to ensure consistency
|
||||||
|
esp_log_set_vprintf(custom_log_vprintf);
|
||||||
|
|
||||||
|
// 3. Initialize Netif & Event Loop
|
||||||
ESP_ERROR_CHECK(esp_netif_init());
|
ESP_ERROR_CHECK(esp_netif_init());
|
||||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||||
|
|
||||||
|
|
@ -155,18 +173,18 @@ void app_main(void) {
|
||||||
ESP_LOGW(TAG, "GPS initialization skipped (Disabled in NVS)");
|
ESP_LOGW(TAG, "GPS initialization skipped (Disabled in NVS)");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Hardware Init
|
// 4. Hardware Init
|
||||||
status_led_init(RGB_LED_GPIO, HAS_RGB_LED);
|
status_led_init(RGB_LED_GPIO, HAS_RGB_LED);
|
||||||
#ifdef CONFIG_ESP_WIFI_CSI_ENABLED
|
#ifdef CONFIG_ESP_WIFI_CSI_ENABLED
|
||||||
ESP_ERROR_CHECK(csi_log_init());
|
ESP_ERROR_CHECK(csi_log_init());
|
||||||
csi_mgr_init();
|
csi_mgr_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 4. Initialize WiFi Controller & iPerf
|
// 5. Initialize WiFi Controller & iPerf
|
||||||
wifi_ctl_init();
|
wifi_ctl_init();
|
||||||
iperf_param_init();
|
iperf_param_init();
|
||||||
|
|
||||||
// 5. Initialize Console
|
// 6. Initialize Console (REPL)
|
||||||
esp_console_repl_t *repl = NULL;
|
esp_console_repl_t *repl = NULL;
|
||||||
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
|
esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT();
|
||||||
|
|
||||||
|
|
@ -176,14 +194,14 @@ void app_main(void) {
|
||||||
esp_console_dev_uart_config_t hw_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
|
esp_console_dev_uart_config_t hw_config = ESP_CONSOLE_DEV_UART_CONFIG_DEFAULT();
|
||||||
ESP_ERROR_CHECK(esp_console_new_repl_uart(&hw_config, &repl_config, &repl));
|
ESP_ERROR_CHECK(esp_console_new_repl_uart(&hw_config, &repl_config, &repl));
|
||||||
|
|
||||||
// 6. Register Commands
|
// 7. Register Commands
|
||||||
register_system_common();
|
register_system_common();
|
||||||
app_console_register_commands();
|
app_console_register_commands();
|
||||||
|
|
||||||
// 7. Initial Prompt State Check
|
// 8. Initial Prompt State Check
|
||||||
app_console_update_prompt();
|
app_console_update_prompt();
|
||||||
|
|
||||||
// 8. Start Shell
|
// 9. Start Shell
|
||||||
printf("\n ==================================================\n");
|
printf("\n ==================================================\n");
|
||||||
printf(" | ESP32 iPerf Shell - Ready |\n");
|
printf(" | ESP32 iPerf Shell - Ready |\n");
|
||||||
printf(" | Type 'help' for commands |\n");
|
printf(" | Type 'help' for commands |\n");
|
||||||
|
|
|
||||||
|
|
@ -7,3 +7,14 @@ CONFIG_FREERTOS_HZ=1000
|
||||||
CONFIG_CONSOLE_UART_RX_BUF_SIZE=1024
|
CONFIG_CONSOLE_UART_RX_BUF_SIZE=1024
|
||||||
CONFIG_PARTITION_TABLE_CUSTOM=y
|
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||||
CONFIG_ESP_WIFI_CSI_ENABLED=n
|
CONFIG_ESP_WIFI_CSI_ENABLED=n
|
||||||
|
# Use System Time (Wall Clock) for Logs instead of Boot Time
|
||||||
|
# Shared Base Defaults
|
||||||
|
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||||
|
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=6144
|
||||||
|
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
|
||||||
|
CONFIG_FREERTOS_ISR_STACKSIZE=2048
|
||||||
|
CONFIG_FREERTOS_HZ=1000
|
||||||
|
CONFIG_CONSOLE_UART_RX_BUF_SIZE=1024
|
||||||
|
CONFIG_PARTITION_TABLE_CUSTOM=y
|
||||||
|
CONFIG_ESP_WIFI_CSI_ENABLED=n
|
||||||
|
CONFIG_LOG_TIMESTAMP_SOURCE_NONE=y
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue