Added a new console command: "system" #14
4 changed files with 228 additions and 174 deletions
|
|
@ -21,13 +21,15 @@ idf_component_register(
|
|||
"vfs"
|
||||
)
|
||||
|
||||
add_custom_target(generate_git_version ALL
|
||||
target_compile_definitions(${COMPONENT_LIB} PRIVATE HAS_SYSTEMK_GIT_VERSION)
|
||||
|
||||
add_custom_target(generate_git_versions ALL
|
||||
COMMAND ${CMAKE_COMMAND}
|
||||
-DSOURCE_DIR=${CMAKE_SOURCE_DIR}
|
||||
-DOUTPUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/git_version.h
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/generate_git_version.cmake
|
||||
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/git_version.h
|
||||
-DOUTPUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/git_versions.h
|
||||
-P ${CMAKE_CURRENT_SOURCE_DIR}/generate_git_versions.cmake
|
||||
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/git_versions.h
|
||||
)
|
||||
|
||||
add_dependencies(${COMPONENT_LIB} generate_git_version)
|
||||
add_dependencies(${COMPONENT_LIB} generate_git_versions)
|
||||
target_include_directories(${COMPONENT_LIB} PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
#include "linenoise/linenoise.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "git_version.h" // Generated during the build process.
|
||||
#include "git_versions.h" // Generated during the build process.
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -64,7 +64,6 @@ static void print_usage(void)
|
|||
" system mac - Show MAC addresses\n"
|
||||
" system hostname [name]- Show/set hostname\n"
|
||||
" system version - Show firmware version\n"
|
||||
" system idf-version - Show ESP-IDF version\n"
|
||||
" system factory-reset - Clear NVS and restart\n"
|
||||
" system reboot - Reboot the device\n");
|
||||
}
|
||||
|
|
@ -127,33 +126,54 @@ static int system_cmd_tasks(void)
|
|||
task_count = uxTaskGetSystemState(task_array, task_count, &total_runtime);
|
||||
|
||||
printf("Tasks (%lu total):\n", task_count);
|
||||
printf("%-16s %5s %8s %5s", "Name", "State", "Priority", "Stack");
|
||||
printf("%-16s %5s %6s %11s %8s", "Name", "State", "Core", "Priority", "Stack");
|
||||
#if (configGENERATE_RUN_TIME_STATS == 1)
|
||||
printf(" %s", "CPU%%");
|
||||
printf(" %7s", "CPU%");
|
||||
#endif
|
||||
printf("\n");
|
||||
printf("-----------------------------------------------------------\n");
|
||||
printf("----------------------------------------------------------------\n");
|
||||
|
||||
for (uint32_t i = 0; i < task_count; i++)
|
||||
{
|
||||
const char *state_str;
|
||||
switch (task_array[i].eCurrentState)
|
||||
{
|
||||
case eRunning: state_str = "RUN "; break;
|
||||
case eReady: state_str = "READY"; break;
|
||||
case eBlocked: state_str = "BLOCK"; break;
|
||||
case eSuspended: state_str = "SUSP "; break;
|
||||
case eDeleted: state_str = "DEL "; break;
|
||||
default: state_str = "? "; break;
|
||||
case eRunning:
|
||||
state_str = "RUN ";
|
||||
break;
|
||||
case eReady:
|
||||
state_str = "READY";
|
||||
break;
|
||||
case eBlocked:
|
||||
state_str = "BLOCK";
|
||||
break;
|
||||
case eSuspended:
|
||||
state_str = "SUSP ";
|
||||
break;
|
||||
case eDeleted:
|
||||
state_str = "DEL ";
|
||||
break;
|
||||
default:
|
||||
state_str = "? ";
|
||||
break;
|
||||
}
|
||||
|
||||
uint32_t stack_remaining = task_array[i].usStackHighWaterMark;
|
||||
|
||||
printf("%-16s %5s %8u %5lu",
|
||||
task_array[i].pcTaskName,
|
||||
state_str,
|
||||
task_array[i].uxCurrentPriority,
|
||||
stack_remaining);
|
||||
BaseType_t affinity = xTaskGetCoreID(task_array[i].xHandle);
|
||||
|
||||
printf("%-16s %5s ", task_array[i].pcTaskName, state_str);
|
||||
|
||||
if (affinity == tskNO_AFFINITY)
|
||||
{
|
||||
printf("%6s", "ANY");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%6d", (int)affinity);
|
||||
}
|
||||
|
||||
printf(" %11u %8lu", task_array[i].uxCurrentPriority, stack_remaining);
|
||||
|
||||
#if (configGENERATE_RUN_TIME_STATS == 1)
|
||||
float cpu_percent = 0.0;
|
||||
|
|
@ -161,7 +181,7 @@ static int system_cmd_tasks(void)
|
|||
{
|
||||
cpu_percent = (100.0 * task_array[i].ulRunTimeCounter) / total_runtime;
|
||||
}
|
||||
printf(" %5.1f%%", cpu_percent);
|
||||
printf(" %6.1f%%", cpu_percent);
|
||||
#endif
|
||||
printf("\n");
|
||||
}
|
||||
|
|
@ -181,18 +201,42 @@ static int system_cmd_reset_reason(void)
|
|||
printf("Reset reason: ");
|
||||
switch (reason)
|
||||
{
|
||||
case ESP_RST_UNKNOWN: printf("Unknown\n"); break;
|
||||
case ESP_RST_POWERON: printf("Power-on reset\n"); break;
|
||||
case ESP_RST_EXT: printf("External pin reset\n"); break;
|
||||
case ESP_RST_SW: printf("Software reset\n"); break;
|
||||
case ESP_RST_PANIC: printf("Exception/panic\n"); break;
|
||||
case ESP_RST_INT_WDT: printf("Interrupt watchdog\n"); break;
|
||||
case ESP_RST_TASK_WDT: printf("Task watchdog\n"); break;
|
||||
case ESP_RST_WDT: printf("Other watchdog\n"); break;
|
||||
case ESP_RST_DEEPSLEEP: printf("Deep sleep reset\n"); break;
|
||||
case ESP_RST_BROWNOUT: printf("Brownout reset\n"); break;
|
||||
case ESP_RST_SDIO: printf("SDIO reset\n"); break;
|
||||
default: printf("Code %d\n", reason); break;
|
||||
case ESP_RST_UNKNOWN:
|
||||
printf("Unknown\n");
|
||||
break;
|
||||
case ESP_RST_POWERON:
|
||||
printf("Power-on reset\n");
|
||||
break;
|
||||
case ESP_RST_EXT:
|
||||
printf("External pin reset\n");
|
||||
break;
|
||||
case ESP_RST_SW:
|
||||
printf("Software reset\n");
|
||||
break;
|
||||
case ESP_RST_PANIC:
|
||||
printf("Exception/panic\n");
|
||||
break;
|
||||
case ESP_RST_INT_WDT:
|
||||
printf("Interrupt watchdog\n");
|
||||
break;
|
||||
case ESP_RST_TASK_WDT:
|
||||
printf("Task watchdog\n");
|
||||
break;
|
||||
case ESP_RST_WDT:
|
||||
printf("Other watchdog\n");
|
||||
break;
|
||||
case ESP_RST_DEEPSLEEP:
|
||||
printf("Deep sleep reset\n");
|
||||
break;
|
||||
case ESP_RST_BROWNOUT:
|
||||
printf("Brownout reset\n");
|
||||
break;
|
||||
case ESP_RST_SDIO:
|
||||
printf("SDIO reset\n");
|
||||
break;
|
||||
default:
|
||||
printf("Code %d\n", reason);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -247,8 +291,10 @@ static int system_cmd_partition(void)
|
|||
const esp_partition_t *part = esp_partition_get(it);
|
||||
|
||||
const char *type_str = "?";
|
||||
if (part->type == ESP_PARTITION_TYPE_APP) type_str = "app";
|
||||
else if (part->type == ESP_PARTITION_TYPE_DATA) type_str = "data";
|
||||
if (part->type == ESP_PARTITION_TYPE_APP)
|
||||
type_str = "app";
|
||||
else if (part->type == ESP_PARTITION_TYPE_DATA)
|
||||
type_str = "data";
|
||||
|
||||
printf("%-16s %-10s 0x%-8x 0x%08lx %8lu KB\n",
|
||||
part->label,
|
||||
|
|
@ -338,24 +384,6 @@ static int system_cmd_coredump(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int system_cmd_sleep(int argc, char **argv)
|
||||
{
|
||||
if (argc < 3)
|
||||
{
|
||||
printf("Usage: system sleep <milliseconds>\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sleep_ms = atoi(argv[2]);
|
||||
printf("Entering light sleep for %d ms...\n", sleep_ms);
|
||||
|
||||
esp_sleep_enable_timer_wakeup(sleep_ms * 1000);
|
||||
esp_light_sleep_start();
|
||||
|
||||
printf("Woke up from sleep\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int system_cmd_mac(void)
|
||||
{
|
||||
uint8_t mac[6];
|
||||
|
|
@ -388,12 +416,14 @@ static int system_cmd_mac(void)
|
|||
|
||||
return 0;
|
||||
}
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
const char **hostname_out;
|
||||
bool success;
|
||||
} hostname_get_ctx_t;
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
const char *hostname_in;
|
||||
esp_err_t result;
|
||||
} hostname_set_ctx_t;
|
||||
|
|
@ -440,8 +470,7 @@ static int system_cmd_hostname(int argc, char **argv)
|
|||
const char *hostname = NULL;
|
||||
hostname_get_ctx_t ctx = {
|
||||
.hostname_out = &hostname,
|
||||
.success = false
|
||||
};
|
||||
.success = false};
|
||||
|
||||
esp_err_t err = esp_netif_tcpip_exec(get_hostname_tcpip, &ctx);
|
||||
|
||||
|
|
@ -471,8 +500,7 @@ static int system_cmd_hostname(int argc, char **argv)
|
|||
|
||||
hostname_set_ctx_t ctx = {
|
||||
.hostname_in = argv[2],
|
||||
.result = ESP_FAIL
|
||||
};
|
||||
.result = ESP_FAIL};
|
||||
|
||||
esp_err_t err = esp_netif_tcpip_exec(set_hostname_tcpip, &ctx);
|
||||
|
||||
|
|
@ -506,23 +534,13 @@ static int system_cmd_version(void)
|
|||
printf(" Version: %s\n", app_desc->version);
|
||||
printf(" Project: %s\n", app_desc->project_name);
|
||||
printf(" IDF version: %s\n", app_desc->idf_ver);
|
||||
printf(" SystemK version: %s\n", SYSTEMK_VERSION_STRING);
|
||||
printf(" SystemK version: %s (%s)\n", SYSTEMK_VERSION_STRING, SYSTEMK_GIT_COMMIT_HASH_SHORT);
|
||||
printf(" Git commit: %s\n", GIT_COMMIT_HASH_LONG);
|
||||
printf(" Compile time: %s %s\n", app_desc->date, app_desc->time);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int system_cmd_idf_version(void)
|
||||
{
|
||||
printf("ESP-IDF Version: %s\n", IDF_VER);
|
||||
printf(" Major: %d\n", ESP_IDF_VERSION_MAJOR);
|
||||
printf(" Minor: %d\n", ESP_IDF_VERSION_MINOR);
|
||||
printf(" Patch: %d\n", ESP_IDF_VERSION_PATCH);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int system_cmd_factory_reset(void)
|
||||
{
|
||||
printf("WARNING: This will erase all NVS data!\n");
|
||||
|
|
@ -540,7 +558,7 @@ static int system_cmd_factory_reset(void)
|
|||
|
||||
if (strcmp(confirm, "yes") != 0)
|
||||
{
|
||||
printf("Cancelled\n");
|
||||
printf("Factory reset cancelled.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -595,16 +613,12 @@ static int cmd_system(int argc, char **argv)
|
|||
return system_cmd_stats();
|
||||
if (!strcmp(argv[1], "coredump"))
|
||||
return system_cmd_coredump();
|
||||
if (!strcmp(argv[1], "sleep"))
|
||||
return system_cmd_sleep(argc, argv);
|
||||
if (!strcmp(argv[1], "mac"))
|
||||
return system_cmd_mac();
|
||||
if (!strcmp(argv[1], "hostname"))
|
||||
return system_cmd_hostname(argc, argv);
|
||||
if (!strcmp(argv[1], "version"))
|
||||
return system_cmd_version();
|
||||
if (!strcmp(argv[1], "idf-version"))
|
||||
return system_cmd_idf_version();
|
||||
if (!strcmp(argv[1], "factory-reset"))
|
||||
return system_cmd_factory_reset();
|
||||
if (!strcmp(argv[1], "reboot"))
|
||||
|
|
|
|||
|
|
@ -1,34 +0,0 @@
|
|||
execute_process(
|
||||
COMMAND git rev-parse --short HEAD
|
||||
WORKING_DIRECTORY ${SOURCE_DIR}
|
||||
OUTPUT_VARIABLE GIT_HASH_SHORT
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
execute_process(
|
||||
COMMAND git rev-parse HEAD
|
||||
WORKING_DIRECTORY ${SOURCE_DIR}
|
||||
OUTPUT_VARIABLE GIT_HASH_LONG
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
# Check for uncommitted changes
|
||||
execute_process(
|
||||
COMMAND git diff-index --quiet HEAD --
|
||||
WORKING_DIRECTORY ${SOURCE_DIR}
|
||||
RESULT_VARIABLE GIT_DIRTY
|
||||
)
|
||||
|
||||
# If GIT_DIRTY is non-zero, there are local modifications
|
||||
if(NOT GIT_DIRTY EQUAL 0)
|
||||
set(GIT_HASH_SHORT "${GIT_HASH_SHORT}+")
|
||||
set(GIT_HASH_LONG "${GIT_HASH_LONG}+")
|
||||
endif()
|
||||
|
||||
file(WRITE ${OUTPUT_FILE}
|
||||
"#ifndef GIT_VERSION_H
|
||||
#define GIT_VERSION_H
|
||||
#define GIT_COMMIT_HASH_SHORT \"${GIT_HASH_SHORT}\"
|
||||
#define GIT_COMMIT_HASH_LONG \"${GIT_HASH_LONG}\"
|
||||
#endif
|
||||
")
|
||||
72
components/Serial_Console/generate_git_versions.cmake
Normal file
72
components/Serial_Console/generate_git_versions.cmake
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
# Main repository hashes
|
||||
execute_process(
|
||||
COMMAND git rev-parse --short HEAD
|
||||
WORKING_DIRECTORY ${SOURCE_DIR}
|
||||
OUTPUT_VARIABLE GIT_HASH_SHORT
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
execute_process(
|
||||
COMMAND git rev-parse HEAD
|
||||
WORKING_DIRECTORY ${SOURCE_DIR}
|
||||
OUTPUT_VARIABLE GIT_HASH_LONG
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
# Check for uncommitted changes in main repo
|
||||
execute_process(
|
||||
COMMAND git diff-index --quiet HEAD --
|
||||
WORKING_DIRECTORY ${SOURCE_DIR}
|
||||
RESULT_VARIABLE GIT_DIRTY
|
||||
)
|
||||
|
||||
if(NOT GIT_DIRTY EQUAL 0)
|
||||
set(GIT_HASH_SHORT "${GIT_HASH_SHORT}+")
|
||||
set(GIT_HASH_LONG "${GIT_HASH_LONG}+")
|
||||
endif()
|
||||
|
||||
# SystemK hashes
|
||||
set(SYSTEMK_PATH "${SOURCE_DIR}/components/SystemK")
|
||||
|
||||
execute_process(
|
||||
COMMAND git rev-parse --short HEAD
|
||||
WORKING_DIRECTORY ${SYSTEMK_PATH}
|
||||
OUTPUT_VARIABLE SYSTEMK_HASH_SHORT
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
RESULT_VARIABLE SYSTEMK_RESULT
|
||||
)
|
||||
|
||||
execute_process(
|
||||
COMMAND git rev-parse HEAD
|
||||
WORKING_DIRECTORY ${SYSTEMK_PATH}
|
||||
OUTPUT_VARIABLE SYSTEMK_HASH_LONG
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
# Check for uncommitted changes in SystemK.
|
||||
execute_process(
|
||||
COMMAND git diff-index --quiet HEAD --
|
||||
WORKING_DIRECTORY ${SYSTEMK_PATH}
|
||||
RESULT_VARIABLE SYSTEMK_DIRTY
|
||||
)
|
||||
|
||||
# Handle the case where SystemK doesn't exist or is not a git repo.
|
||||
if(SYSTEMK_RESULT EQUAL 0)
|
||||
if(NOT SYSTEMK_DIRTY EQUAL 0)
|
||||
set(SYSTEMK_HASH_SHORT "${SYSTEMK_HASH_SHORT}+")
|
||||
set(SYSTEMK_HASH_LONG "${SYSTEMK_HASH_LONG}+")
|
||||
endif()
|
||||
else()
|
||||
set(SYSTEMK_HASH_SHORT "unknown")
|
||||
set(SYSTEMK_HASH_LONG "unknown")
|
||||
endif()
|
||||
|
||||
file(WRITE ${OUTPUT_FILE}
|
||||
"#ifndef GIT_VERSION_H
|
||||
#define GIT_VERSION_H
|
||||
#define GIT_COMMIT_HASH_SHORT \"${GIT_HASH_SHORT}\"
|
||||
#define GIT_COMMIT_HASH_LONG \"${GIT_HASH_LONG}\"
|
||||
#define SYSTEMK_GIT_COMMIT_HASH_SHORT \"${SYSTEMK_HASH_SHORT}\"
|
||||
#define SYSTEMK_GIT_COMMIT_HASH_LONG \"${SYSTEMK_HASH_LONG}\"
|
||||
#endif
|
||||
")
|
||||
Loading…
Add table
Add a link
Reference in a new issue