Files
ESP32_Serial_Swiss_Army_Knife/src/system_console.c
T
Commander1024 326119812f Extend browser admin lifecycle actions
Support browser reboot and HTTPS stop through deferred control, plus
exact
`web certificate rotate --force` handoff to the dispatcher. Add typed
request
validation and focused boundary and lifecycle coverage.
2026-09-07 09:36:38 +02:00

91 lines
2.8 KiB
C

/* SPDX-License-Identifier: GPL-3.0-only */
/* Root-level system lifecycle commands for the physical administration console. */
#include "system_console.h"
#include <stdint.h>
#include <stdio.h>
#include "admin_ssh_console.h"
#include "esp_console.h"
#include "esp_heap_caps.h"
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
static void print_heap_region(const char *name, uint32_t capabilities)
{
printf("%s: free=%u minimum-free=%u largest-block=%u bytes\n",
name,
(unsigned int)heap_caps_get_free_size(capabilities),
(unsigned int)heap_caps_get_minimum_free_size(capabilities),
(unsigned int)heap_caps_get_largest_free_block(capabilities));
}
static int command_memory(int argc, char **argv)
{
(void)argv;
if (argc != 1) {
printf("Usage: memory\n");
return 1;
}
print_heap_region("Internal 8-bit heap",
MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
print_heap_region("Internal DMA heap",
MALLOC_CAP_INTERNAL | MALLOC_CAP_DMA | MALLOC_CAP_8BIT);
print_heap_region("External PSRAM",
MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
printf("Minimum-free is a conservative sum of each matching heap region's lifetime minimum.\n");
return 0;
}
static int command_reboot(int argc, char **argv)
{
(void)argv;
if (argc != 1) {
printf("Usage: reboot\n");
return 1;
}
if (admin_ssh_console_dispatch_is_remote()) {
esp_err_t error = admin_ssh_console_dispatch_defer(ADMIN_SSH_DEFER_REBOOT, 0U);
if (error != ESP_OK) {
printf("Could not schedule reboot: %s\n", esp_err_to_name(error));
return 1;
}
printf("Reboot scheduled after console output drains; unsaved changes will be lost.\n");
return 0;
}
printf("Rebooting now; unsaved RAM-only configuration changes will be lost.\n");
fflush(stdout);
/* Give the UART driver time to transmit the acknowledgement before reset. */
vTaskDelay(pdMS_TO_TICKS(100U));
esp_restart();
return 0;
}
esp_err_t system_console_register_commands(void)
{
const esp_console_cmd_t reboot_command = {
.command = "reboot",
.help = "Restart the ESP32; unsaved RAM-only configuration is lost",
.hint = NULL,
.func = &command_reboot,
.argtable = NULL,
};
esp_err_t error = esp_console_cmd_register(&reboot_command);
if (error != ESP_OK) {
return error;
}
const esp_console_cmd_t memory_command = {
.command = "memory",
.help = "Show internal and PSRAM heap availability/low-water marks",
.hint = NULL,
.func = &command_memory,
.argtable = NULL,
};
return esp_console_cmd_register(&memory_command);
}