mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 04:27:12 +03:00
Trim app and recovery binaries
This commit is contained in:
@@ -8,7 +8,7 @@ idf_component_register( SRCS
|
||||
cmd_config.c
|
||||
INCLUDE_DIRS .
|
||||
REQUIRES nvs_flash
|
||||
PRIV_REQUIRES console app_update tools services spi_flash platform_config vfs pthread wifi-manager platform_config newlib telnet display squeezelite tools)
|
||||
PRIV_REQUIRES console app_update tools services spi_flash platform_config vfs pthread wifi-manager platform_config newlib telnet display squeezelite tools metrics)
|
||||
|
||||
set_source_files_properties(cmd_config.c
|
||||
PROPERTIES COMPILE_FLAGS
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
idf_component_register( SRC_DIRS .
|
||||
INCLUDE_DIRS .
|
||||
PRIV_REQUIRES bootloader_support
|
||||
PRIV_REQUIRES bootloader_support json
|
||||
)
|
||||
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--undefined=esp_app_desc")
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
#include "application_name.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_app_format.h"
|
||||
|
||||
#include "cJSON.h"
|
||||
#include "stdbool.h"
|
||||
extern esp_err_t process_recovery_ota(const char * bin_url, char * bin_buffer, uint32_t length);
|
||||
|
||||
extern cJSON * gpio_list;
|
||||
const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
|
||||
.magic_word = ESP_APP_DESC_MAGIC_WORD,
|
||||
.version = PROJECT_VER,
|
||||
@@ -26,7 +27,12 @@ const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
|
||||
.date = "",
|
||||
#endif
|
||||
};
|
||||
|
||||
cJSON * get_gpio_list(bool refresh){
|
||||
if(!gpio_list){
|
||||
gpio_list = cJSON_CreateArray();
|
||||
}
|
||||
return gpio_list;
|
||||
}
|
||||
void register_optional_cmd(void) {
|
||||
}
|
||||
|
||||
|
||||
@@ -43,12 +43,25 @@ const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
|
||||
extern void register_audio_config(void);
|
||||
extern void register_rotary_config(void);
|
||||
extern void register_ledvu_config(void);
|
||||
|
||||
extern void register_nvs();
|
||||
extern cJSON * get_gpio_list_handler(bool refresh);
|
||||
void register_optional_cmd(void) {
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
register_rotary_config();
|
||||
register_ledvu_config();
|
||||
#endif
|
||||
register_audio_config();
|
||||
}
|
||||
register_ledvu_config();
|
||||
register_nvs();
|
||||
|
||||
}
|
||||
cJSON * get_gpio_list(bool refresh){
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
return get_gpio_list_handler(refresh);
|
||||
#else
|
||||
return cJSON_CreateArray();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
extern int squeezelite_main(int argc, char **argv);
|
||||
|
||||
|
||||
@@ -20,7 +20,10 @@
|
||||
#include "tools.h"
|
||||
#include "cJSON.h"
|
||||
#include "cmd_i2ctools.h"
|
||||
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
#include "metrics.h"
|
||||
#endif
|
||||
#include "cmd_system.h"
|
||||
const char * desc_squeezelite ="Squeezelite Options";
|
||||
const char * desc_dac= "DAC Options";
|
||||
const char * desc_cspotc= "Spotify (cSpot) Options";
|
||||
@@ -330,9 +333,8 @@ static int do_bt_source_cmd(int argc, char **argv){
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
// char value[100] ={0};
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
FILE *f = system_open_memstream(argv[0],&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
if(nerrors >0){
|
||||
@@ -441,9 +443,8 @@ static int do_audio_cmd(int argc, char **argv){
|
||||
int nerrors = arg_parse(argc, argv,(void **)&audio_args);
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
FILE *f = system_open_memstream(argv[0],&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
if(nerrors >0){
|
||||
@@ -529,9 +530,8 @@ static int do_spdif_cmd(int argc, char **argv){
|
||||
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
FILE *f = system_open_memstream(argv[0],&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
if(nerrors >0){
|
||||
@@ -568,9 +568,8 @@ static int do_rotary_cmd(int argc, char **argv){
|
||||
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
FILE *f = system_open_memstream(argv[0],&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
if(nerrors >0){
|
||||
@@ -640,9 +639,8 @@ static int do_cspot_config(int argc, char **argv){
|
||||
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
FILE *f = system_open_memstream(argv[0],&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -699,9 +697,8 @@ static int do_ledvu_cmd(int argc, char **argv){
|
||||
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
FILE *f = system_open_memstream(argv[0],&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
if(nerrors >0){
|
||||
@@ -759,10 +756,8 @@ static int do_i2s_cmd(int argc, char **argv)
|
||||
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
FILE *f = system_open_memstream(argv[0],&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
ESP_LOGE(TAG, "do_i2s_cmd: Failed to open memstream");
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
if(nerrors >0){
|
||||
@@ -873,7 +868,9 @@ cJSON * i2s_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
|
||||
const i2s_platform_config_t * i2s_conf= config_dac_get( );
|
||||
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
metrics_add_feature("i2s",i2s_conf->pin.data_out_num>=0);
|
||||
#endif
|
||||
if(i2s_conf->pin.bck_io_num>0 ) {
|
||||
cJSON_AddNumberToObject(values,i2s_args.clock->hdr.longopts,i2s_conf->pin.bck_io_num);
|
||||
}
|
||||
@@ -910,6 +907,11 @@ cJSON * i2s_cb(){
|
||||
cJSON * spdif_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
const i2s_platform_config_t * spdif_conf= config_spdif_get( );
|
||||
if(spdif_conf->pin.data_out_num>=0) {
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
metrics_add_feature("spdif","enabled");
|
||||
#endif
|
||||
}
|
||||
if(spdif_conf->pin.bck_io_num>0 ) {
|
||||
cJSON_AddNumberToObject(values,"clock",spdif_conf->pin.bck_io_num);
|
||||
}
|
||||
@@ -928,7 +930,9 @@ cJSON * rotary_cb(){
|
||||
bool raw_mode = p && (*p == '1' || *p == 'Y' || *p == 'y');
|
||||
free(p);
|
||||
const rotary_struct_t *rotary= config_rotary_get();
|
||||
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
metrics_add_feature("rotary",GPIO_IS_VALID_GPIO(rotary->A ));
|
||||
#endif
|
||||
if(GPIO_IS_VALID_GPIO(rotary->A ) && rotary->A>=0 && GPIO_IS_VALID_GPIO(rotary->B) && rotary->B>=0){
|
||||
cJSON_AddNumberToObject(values,rotary_args.A->hdr.longopts,rotary->A);
|
||||
cJSON_AddNumberToObject(values,rotary_args.B->hdr.longopts,rotary->B);
|
||||
@@ -947,7 +951,11 @@ cJSON * rotary_cb(){
|
||||
cJSON * ledvu_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
const ledvu_struct_t *ledvu= config_ledvu_get();
|
||||
|
||||
if(GPIO_IS_VALID_GPIO(ledvu->gpio )){
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
metrics_add_feature("led_vu","enabled");
|
||||
#endif
|
||||
}
|
||||
if(GPIO_IS_VALID_GPIO(ledvu->gpio) && ledvu->gpio>=0 && ledvu->length > 0){
|
||||
cJSON_AddNumberToObject(values,"gpio",ledvu->gpio);
|
||||
cJSON_AddNumberToObject(values,"length",ledvu->length);
|
||||
@@ -965,8 +973,14 @@ cJSON * audio_cb(){
|
||||
cJSON * values = cJSON_CreateObject();
|
||||
char * p = config_alloc_get_default(NVS_TYPE_STR, "jack_mutes_amp", "n", 0);
|
||||
cJSON_AddStringToObject(values,"jack_behavior",(strcmp(p,"1") == 0 ||strcasecmp(p,"y") == 0)?"Headphones":"Subwoofer");
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
metrics_add_feature("jack_mute",atoi(p)>=0);
|
||||
#endif
|
||||
FREE_AND_NULL(p);
|
||||
p = config_alloc_get_default(NVS_TYPE_STR, "loudness", "0", 0);
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
metrics_add_feature("loudness",atoi(p)>=0);
|
||||
#endif
|
||||
cJSON_AddStringToObject(values,"loudness",p);
|
||||
FREE_AND_NULL(p);
|
||||
return values;
|
||||
@@ -976,6 +990,9 @@ cJSON * bt_source_cb(){
|
||||
char * p = config_alloc_get_default(NVS_TYPE_STR, "a2dp_sink_name", NULL, 0);
|
||||
if(p){
|
||||
cJSON_AddStringToObject(values,"sink_name",p);
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
metrics_add_feature("btsource",strlen(p)>0);
|
||||
#endif
|
||||
}
|
||||
FREE_AND_NULL(p);
|
||||
// p = config_alloc_get_default(NVS_TYPE_STR, "a2dp_ctmt", NULL, 0);
|
||||
@@ -1026,9 +1043,8 @@ static int do_squeezelite_cmd(int argc, char **argv)
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr ** )&squeezelite_args);
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
FILE *f = system_open_memstream(argv[0],&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
fprintf(f,"Not yet implemented!");
|
||||
@@ -1047,59 +1063,62 @@ cJSON * squeezelite_cb(){
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
int nerrors=1;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
FILE *f = system_open_memstream(argv[0],&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
log_send_messaging(MESSAGING_ERROR,"Unable to parse squeezelite parameters");
|
||||
return values;
|
||||
}
|
||||
|
||||
if(nvs_config && strlen(nvs_config)>0){
|
||||
ESP_LOGD(TAG,"Parsing command %s",nvs_config);
|
||||
argv = (char **) calloc(22, sizeof(char *));
|
||||
if (argv == NULL) {
|
||||
FREE_AND_NULL(nvs_config);
|
||||
fclose(f);
|
||||
return values;
|
||||
}
|
||||
size_t argc = esp_console_split_argv(nvs_config, argv,22);
|
||||
if (argc != 0) {
|
||||
nerrors = arg_parse(argc, argv,(void **)&squeezelite_args);
|
||||
ESP_LOGD(TAG,"Parsing completed");
|
||||
}
|
||||
}
|
||||
if (nerrors == 0) {
|
||||
get_str_parm_json(squeezelite_args.buffers, values);
|
||||
get_str_parm_json(squeezelite_args.codecs, values);
|
||||
get_lit_parm_json(squeezelite_args.header_format, values);
|
||||
get_str_parm_json(squeezelite_args.log_level, values);
|
||||
|
||||
// get_str_parm_json(squeezelite_args.log_level_all, values);
|
||||
// get_str_parm_json(squeezelite_args.log_level_decode, values);
|
||||
// get_str_parm_json(squeezelite_args.log_level_output, values);
|
||||
// get_str_parm_json(squeezelite_args.log_level_slimproto, values);
|
||||
// get_str_parm_json(squeezelite_args.log_level_stream, values);
|
||||
get_str_parm_json(squeezelite_args.mac_addr, values);
|
||||
get_str_parm_json(squeezelite_args.output_device, values);
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
if(squeezelite_args.output_device->sval[0]!=NULL && strlen(squeezelite_args.output_device->sval[0])>0){
|
||||
metrics_add_feature_variant("output",squeezelite_args.output_device->sval[0]);
|
||||
}
|
||||
#endif
|
||||
get_str_parm_json(squeezelite_args.model_name, values);
|
||||
get_str_parm_json(squeezelite_args.name, values);
|
||||
get_int_parm_json(squeezelite_args.rate, values);
|
||||
get_str_parm_json(squeezelite_args.rates, values);
|
||||
get_str_parm_json(squeezelite_args.server, values);
|
||||
get_int_parm_json(squeezelite_args.timeout, values);
|
||||
char * p = cJSON_Print(values);
|
||||
ESP_LOGD(TAG,"%s",p);
|
||||
free(p);
|
||||
}
|
||||
else {
|
||||
|
||||
if(nvs_config && strlen(nvs_config)>0){
|
||||
ESP_LOGD(TAG,"Parsing command %s",nvs_config);
|
||||
argv = (char **) calloc(22, sizeof(char *));
|
||||
if (argv == NULL) {
|
||||
FREE_AND_NULL(nvs_config);
|
||||
fclose(f);
|
||||
return values;
|
||||
}
|
||||
size_t argc = esp_console_split_argv(nvs_config, argv,22);
|
||||
if (argc != 0) {
|
||||
nerrors = arg_parse(argc, argv,(void **)&squeezelite_args);
|
||||
ESP_LOGD(TAG,"Parsing completed");
|
||||
}
|
||||
}
|
||||
if (nerrors == 0) {
|
||||
get_str_parm_json(squeezelite_args.buffers, values);
|
||||
get_str_parm_json(squeezelite_args.codecs, values);
|
||||
get_lit_parm_json(squeezelite_args.header_format, values);
|
||||
get_str_parm_json(squeezelite_args.log_level, values);
|
||||
|
||||
// get_str_parm_json(squeezelite_args.log_level_all, values);
|
||||
// get_str_parm_json(squeezelite_args.log_level_decode, values);
|
||||
// get_str_parm_json(squeezelite_args.log_level_output, values);
|
||||
// get_str_parm_json(squeezelite_args.log_level_slimproto, values);
|
||||
// get_str_parm_json(squeezelite_args.log_level_stream, values);
|
||||
get_str_parm_json(squeezelite_args.mac_addr, values);
|
||||
get_str_parm_json(squeezelite_args.output_device, values);
|
||||
get_str_parm_json(squeezelite_args.model_name, values);
|
||||
get_str_parm_json(squeezelite_args.name, values);
|
||||
get_int_parm_json(squeezelite_args.rate, values);
|
||||
get_str_parm_json(squeezelite_args.rates, values);
|
||||
get_str_parm_json(squeezelite_args.server, values);
|
||||
get_int_parm_json(squeezelite_args.timeout, values);
|
||||
char * p = cJSON_Print(values);
|
||||
ESP_LOGD(TAG,"%s",p);
|
||||
free(p);
|
||||
}
|
||||
else {
|
||||
arg_print_errors(f, squeezelite_args.end, desc_squeezelite);
|
||||
}
|
||||
fflush (f);
|
||||
if(strlen(buf)>0){
|
||||
log_send_messaging(nerrors?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
}
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
arg_print_errors(f, squeezelite_args.end, desc_squeezelite);
|
||||
}
|
||||
fflush (f);
|
||||
if(strlen(buf)>0){
|
||||
log_send_messaging(nerrors?MESSAGING_ERROR:MESSAGING_INFO,"%s", buf);
|
||||
}
|
||||
fclose(f);
|
||||
FREE_AND_NULL(buf);
|
||||
FREE_AND_NULL(nvs_config);
|
||||
FREE_AND_NULL(argv);
|
||||
return values;
|
||||
@@ -1212,9 +1231,8 @@ static int do_register_known_templates_config(int argc, char **argv){
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
cJSON * config_name =NULL;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
FILE *f = system_open_memstream(argv[0],&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.\n");
|
||||
return 1;
|
||||
}
|
||||
if(nerrors >0){
|
||||
@@ -1396,7 +1414,7 @@ void register_ledvu_config(void){
|
||||
|
||||
void register_audio_config(void){
|
||||
audio_args.jack_behavior = arg_str0("j", "jack_behavior","Headphones|Subwoofer","On supported DAC, determines the audio jack behavior. Selecting headphones will cause the external amp to be muted on insert, while selecting Subwoofer will keep the amp active all the time.");
|
||||
audio_args.loudness = arg_int0("l", "loudness","0-10","Sets the loudness level, from 0 to 10. 0 will disable the loudness completely.");
|
||||
audio_args.loudness = arg_int0("l", "loudness","0-10","Sets a loudness level, from 0 to 10. 0 will disable the loudness completely. Note that LMS has priority over setting this value, so use it only when away from your server.");
|
||||
audio_args.end = arg_end(6);
|
||||
audio_args.end = arg_end(6);
|
||||
const esp_console_cmd_t cmd = {
|
||||
@@ -1468,22 +1486,36 @@ static void register_squeezelite_config(void){
|
||||
cmd_to_json_with_cb(&cmd,&squeezelite_cb);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
||||
}
|
||||
|
||||
void dummy_register_cmd(){
|
||||
|
||||
}
|
||||
void register_config_cmd(void){
|
||||
if(!is_dac_config_locked()){
|
||||
register_known_templates_config();
|
||||
|
||||
register_known_templates_config();
|
||||
}
|
||||
|
||||
#ifdef CONFIG_CSPOT_SINK
|
||||
register_cspot_config();
|
||||
#endif
|
||||
register_bt_source_config();
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
if(!is_dac_config_locked()){
|
||||
register_i2s_config();
|
||||
}
|
||||
else {
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
metrics_add_feature("i2s",true);
|
||||
#endif
|
||||
}
|
||||
if(!is_spdif_config_locked()){
|
||||
register_spdif_config();
|
||||
}
|
||||
else {
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
metrics_add_feature("spdif",true);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
register_optional_cmd();
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -589,6 +589,7 @@ void register_nvs()
|
||||
.func = &list_entries,
|
||||
.argtable = &list_args
|
||||
};
|
||||
|
||||
MEMTRACE_PRINT_DELTA_MESSAGE("registering list_entries_cmd");
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&list_entries_cmd));
|
||||
MEMTRACE_PRINT_DELTA_MESSAGE("registering set_cmd");
|
||||
|
||||
@@ -62,7 +62,7 @@ static int perform_ota_update(int argc, char **argv)
|
||||
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "update",
|
||||
.help = "Updates the application binary from the provided URL",
|
||||
.help = "Update from URL",
|
||||
.hint = NULL,
|
||||
.func = &perform_ota_update,
|
||||
.argtable = &ota_args
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
#include "messaging.h"
|
||||
#include "platform_console.h"
|
||||
#include "tools.h"
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
#include "Metrics.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
|
||||
#pragma message("Runtime stats enabled")
|
||||
@@ -73,24 +76,42 @@ static void register_set_services();
|
||||
static void register_tasks();
|
||||
#endif
|
||||
extern BaseType_t network_manager_task;
|
||||
FILE * system_open_memstream(const char * cmdname,char **buf,size_t *buf_size){
|
||||
FILE *f = open_memstream(buf, buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(cmdname,MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
}
|
||||
return f;
|
||||
}
|
||||
void register_system()
|
||||
{
|
||||
register_free();
|
||||
|
||||
register_set_services();
|
||||
register_setdevicename();
|
||||
register_free();
|
||||
register_heap();
|
||||
register_dump_heap();
|
||||
register_setdevicename();
|
||||
register_version();
|
||||
register_restart();
|
||||
register_deep_sleep();
|
||||
register_light_sleep();
|
||||
register_factory_boot();
|
||||
register_restart_ota();
|
||||
#if WITH_TASKS_INFO
|
||||
register_tasks();
|
||||
#endif
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
register_deep_sleep();
|
||||
register_light_sleep();
|
||||
#endif
|
||||
}
|
||||
void simple_restart()
|
||||
{
|
||||
log_send_messaging(MESSAGING_WARNING,"Rebooting.");
|
||||
if(!wait_for_commit()){
|
||||
log_send_messaging(MESSAGING_WARNING,"Unable to commit configuration. ");
|
||||
}
|
||||
vTaskDelay(750/ portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
/* 'version' command */
|
||||
static int get_version(int argc, char **argv)
|
||||
{
|
||||
@@ -128,36 +149,23 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype)
|
||||
{
|
||||
if(is_recovery_running){
|
||||
if(partition_subtype ==ESP_PARTITION_SUBTYPE_APP_FACTORY){
|
||||
log_send_messaging(MESSAGING_WARNING,"RECOVERY application is already active");
|
||||
if(!wait_for_commit()){
|
||||
log_send_messaging(MESSAGING_WARNING,"Unable to commit configuration. ");
|
||||
}
|
||||
|
||||
vTaskDelay(750/ portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
return ESP_OK;
|
||||
// log_send_messaging(MESSAGING_WARNING,"RECOVERY application is already active");
|
||||
simple_restart();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(partition_subtype !=ESP_PARTITION_SUBTYPE_APP_FACTORY){
|
||||
log_send_messaging(MESSAGING_WARNING,"SQUEEZELITE application is already active");
|
||||
if(!wait_for_commit()){
|
||||
log_send_messaging(MESSAGING_WARNING,"Unable to commit configuration. ");
|
||||
}
|
||||
|
||||
vTaskDelay(750/ portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
return ESP_OK;
|
||||
// log_send_messaging(MESSAGING_WARNING,"SQUEEZELITE application is already active");
|
||||
simple_restart();
|
||||
}
|
||||
}
|
||||
esp_err_t err = ESP_OK;
|
||||
bool bFound=false;
|
||||
log_send_messaging(MESSAGING_INFO, "Looking for partition type %u",partition_subtype);
|
||||
// log_send_messaging(MESSAGING_INFO, "Looking for partition type %u",partition_subtype);
|
||||
const esp_partition_t *partition;
|
||||
esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_APP, partition_subtype, NULL);
|
||||
|
||||
if(it == NULL){
|
||||
log_send_messaging(MESSAGING_ERROR,"Reboot failed. Cannot iterate through partitions");
|
||||
log_send_messaging(MESSAGING_ERROR,"Reboot failed. Partitions error");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -166,15 +174,11 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype)
|
||||
ESP_LOGD(TAG, "Releasing partition iterator");
|
||||
esp_partition_iterator_release(it);
|
||||
if(partition != NULL){
|
||||
log_send_messaging(MESSAGING_INFO, "Found application partition %s sub type %u", partition->label,partition_subtype);
|
||||
log_send_messaging(MESSAGING_INFO, "Rebooting to %s", partition->label);
|
||||
err=esp_ota_set_boot_partition(partition);
|
||||
if(err!=ESP_OK){
|
||||
bFound=false;
|
||||
log_send_messaging(MESSAGING_ERROR,"Unable to select partition for reboot: %s",esp_err_to_name(err));
|
||||
}
|
||||
else{
|
||||
bFound=true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -183,13 +187,7 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype)
|
||||
}
|
||||
ESP_LOGD(TAG, "Yielding to other processes");
|
||||
taskYIELD();
|
||||
if(bFound) {
|
||||
if(!wait_for_commit()){
|
||||
log_send_messaging(MESSAGING_WARNING,"Unable to commit configuration changes. ");
|
||||
}
|
||||
vTaskDelay(750/ portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
}
|
||||
simple_restart();
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
@@ -197,46 +195,31 @@ esp_err_t guided_boot(esp_partition_subtype_t partition_subtype)
|
||||
|
||||
static int restart(int argc, char **argv)
|
||||
{
|
||||
log_send_messaging(MESSAGING_WARNING, "\n\nPerforming a simple restart to the currently active partition.");
|
||||
if(!wait_for_commit()){
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING,"Unable to commit configuration. ");
|
||||
}
|
||||
vTaskDelay(750/ portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
simple_restart();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void simple_restart()
|
||||
{
|
||||
log_send_messaging(MESSAGING_WARNING,"System reboot requested.");
|
||||
if(!wait_for_commit()){
|
||||
log_send_messaging(MESSAGING_WARNING,"Unable to commit configuration. ");
|
||||
}
|
||||
|
||||
|
||||
vTaskDelay(750/ portTICK_PERIOD_MS);
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
esp_err_t guided_restart_ota(){
|
||||
log_send_messaging(MESSAGING_WARNING,"System reboot to Application requested");
|
||||
log_send_messaging(MESSAGING_WARNING,"Booting to Squeezelite");
|
||||
guided_boot(ESP_PARTITION_SUBTYPE_APP_OTA_0);
|
||||
return ESP_FAIL; // return fail. This should never return... we're rebooting!
|
||||
}
|
||||
esp_err_t guided_factory(){
|
||||
log_send_messaging(MESSAGING_WARNING,"System reboot to recovery requested");
|
||||
log_send_messaging(MESSAGING_WARNING,"Booting to recovery");
|
||||
guided_boot(ESP_PARTITION_SUBTYPE_APP_FACTORY);
|
||||
return ESP_FAIL; // return fail. This should never return... we're rebooting!
|
||||
}
|
||||
static int restart_factory(int argc, char **argv)
|
||||
{
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING, "Executing guided boot into recovery");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING, "Booting to Recovery");
|
||||
guided_boot(ESP_PARTITION_SUBTYPE_APP_FACTORY);
|
||||
return 0; // return fail. This should never return... we're rebooting!
|
||||
}
|
||||
static int restart_ota(int argc, char **argv)
|
||||
{
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING, "Executing guided boot into ota app 0");
|
||||
cmd_send_messaging(argv[0],MESSAGING_WARNING, "Booting to Squeezelite");
|
||||
guided_boot(ESP_PARTITION_SUBTYPE_APP_OTA_0);
|
||||
return 0; // return fail. This should never return... we're rebooting!
|
||||
}
|
||||
@@ -248,7 +231,9 @@ static void register_restart()
|
||||
.hint = NULL,
|
||||
.func = &restart,
|
||||
};
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
cmd_to_json(&cmd);
|
||||
#endif
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
static void register_restart_ota()
|
||||
@@ -259,7 +244,9 @@ static void register_restart_ota()
|
||||
.hint = NULL,
|
||||
.func = &restart_ota,
|
||||
};
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
cmd_to_json(&cmd);
|
||||
#endif
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
|
||||
@@ -271,7 +258,9 @@ static void register_factory_boot()
|
||||
.hint = NULL,
|
||||
.func = &restart_factory,
|
||||
};
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
cmd_to_json(&cmd);
|
||||
#endif
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
/** 'free' command prints available heap memory */
|
||||
@@ -287,11 +276,14 @@ static void register_free()
|
||||
{
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "free",
|
||||
.help = "Get the current size of free heap memory",
|
||||
.help = "Get free heap memory",
|
||||
.hint = NULL,
|
||||
.func = &free_mem,
|
||||
};
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
cmd_to_json(&cmd);
|
||||
#endif
|
||||
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
}
|
||||
static int dump_heap(int argc, char **argv)
|
||||
@@ -303,16 +295,16 @@ static int dump_heap(int argc, char **argv)
|
||||
/* 'heap' command prints minumum heap size */
|
||||
static int heap_size(int argc, char **argv)
|
||||
{
|
||||
ESP_LOGI(TAG,"Heap internal:%zu (min:%zu) (largest block:%zu)\nexternal:%zu (min:%zu) (largest block:%zd)\ndma :%zu (min:%zu) (largest block:%zd)",
|
||||
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_free_size(MALLOC_CAP_DMA),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_DMA),
|
||||
heap_caps_get_largest_free_block(MALLOC_CAP_DMA));
|
||||
// ESP_LOGI(TAG,"Heap internal:%zu (min:%zu) (largest block:%zu)\nexternal:%zu (min:%zu) (largest block:%zd)\ndma :%zu (min:%zu) (largest block:%zd)",
|
||||
// heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
|
||||
// heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
|
||||
// heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL),
|
||||
// heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
|
||||
// heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM),
|
||||
// heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM),
|
||||
// heap_caps_get_free_size(MALLOC_CAP_DMA),
|
||||
// heap_caps_get_minimum_free_size(MALLOC_CAP_DMA),
|
||||
// heap_caps_get_largest_free_block(MALLOC_CAP_DMA));
|
||||
cmd_send_messaging(argv[0],MESSAGING_INFO,"Heap internal:%zu (min:%zu) (largest block:%zu)\nexternal:%zu (min:%zu) (largest block:%zd)\ndma :%zu (min:%zu) (largest block:%zd)",
|
||||
heap_caps_get_free_size(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
|
||||
@@ -457,9 +449,8 @@ static int setdevicename(int argc, char **argv)
|
||||
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
FILE *f = system_open_memstream(argv[0],&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 1;
|
||||
}
|
||||
nerrors+=setnamevar("a2dp_dev_name", f, name);
|
||||
@@ -488,11 +479,13 @@ static void register_heap()
|
||||
{
|
||||
const esp_console_cmd_t heap_cmd = {
|
||||
.command = "heap",
|
||||
.help = "Get minimum size of free heap memory found during execution",
|
||||
.help = "Get minimum size of free heap memory",
|
||||
.hint = NULL,
|
||||
.func = &heap_size,
|
||||
};
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
cmd_to_json(&heap_cmd);
|
||||
#endif
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&heap_cmd) );
|
||||
|
||||
}
|
||||
@@ -521,6 +514,7 @@ static void register_setdevicename()
|
||||
.func = &setdevicename,
|
||||
.argtable = &name_args
|
||||
};
|
||||
|
||||
cmd_to_json_with_cb(&set_name,&setdevicename_cb);
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&set_name));
|
||||
}
|
||||
@@ -618,9 +612,7 @@ static void register_deep_sleep()
|
||||
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "deep_sleep",
|
||||
.help = "Enter deep sleep mode. "
|
||||
"Two wakeup modes are supported: timer and GPIO. "
|
||||
"If no wakeup option is specified, will sleep indefinitely.",
|
||||
.help = "Enter deep sleep mode. ",
|
||||
.hint = NULL,
|
||||
.func = &deep_sleep,
|
||||
.argtable = &deep_sleep_args
|
||||
@@ -649,9 +641,8 @@ static int do_set_services(int argc, char **argv)
|
||||
}
|
||||
char *buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE *f = open_memstream(&buf, &buf_size);
|
||||
FILE *f = system_open_memstream(argv[0],&buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
cmd_send_messaging(argv[0],MESSAGING_ERROR,"Unable to open memory stream.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -674,7 +665,7 @@ static int do_set_services(int argc, char **argv)
|
||||
|
||||
if(err!=ESP_OK){
|
||||
nerrors++;
|
||||
fprintf(f,"Error setting telnet service to %s. %s\n",set_services_args.telnet->sval[0], esp_err_to_name(err));
|
||||
fprintf(f,"Error setting telnet to %s. %s\n",set_services_args.telnet->sval[0], esp_err_to_name(err));
|
||||
}
|
||||
else {
|
||||
fprintf(f,"Telnet service changed to %s\n",set_services_args.telnet->sval[0]);
|
||||
@@ -706,7 +697,6 @@ cJSON * set_services_cb(){
|
||||
#if WITH_TASKS_INFO
|
||||
console_set_bool_parameter(values,"stats",set_services_args.stats);
|
||||
#endif
|
||||
|
||||
if ((p = config_alloc_get(NVS_TYPE_STR, "telnet_enable")) != NULL) {
|
||||
if(strcasestr("YX",p)!=NULL){
|
||||
cJSON_AddStringToObject(values,set_services_args.telnet->hdr.longopts,"Telnet Only");
|
||||
@@ -717,7 +707,9 @@ cJSON * set_services_cb(){
|
||||
else {
|
||||
cJSON_AddStringToObject(values,set_services_args.telnet->hdr.longopts,"Disabled");
|
||||
}
|
||||
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
metrics_add_feature_variant("telnet",p);
|
||||
#endif
|
||||
FREE_AND_NULL(p);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ void register_system();
|
||||
esp_err_t guided_factory();
|
||||
esp_err_t guided_restart_ota();
|
||||
void simple_restart();
|
||||
|
||||
FILE * system_open_memstream(const char * cmdname,char **buf,size_t *buf_size);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -37,6 +37,9 @@ extern bool bypass_network_manager;
|
||||
#define JOIN_TIMEOUT_MS (10000)
|
||||
#include "platform_console.h"
|
||||
|
||||
// To enable wifi configuration from the command line, uncomment the line below
|
||||
// define WIFI_CMDLINE 1
|
||||
|
||||
|
||||
extern EventGroupHandle_t network_event_group;
|
||||
extern const int CONNECTED_BIT;
|
||||
@@ -53,13 +56,6 @@ static struct {
|
||||
|
||||
// todo: implement access point config - cmd_to_json(&i2cdetect_cmd);
|
||||
|
||||
|
||||
///** Arguments used by 'join' function */
|
||||
//static struct {
|
||||
// struct arg_int *autoconnect;
|
||||
// struct arg_end *end;
|
||||
//} auto_connect_args;
|
||||
|
||||
static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data)
|
||||
{
|
||||
@@ -72,27 +68,7 @@ static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
xEventGroupSetBits(network_event_group, CONNECTED_BIT);
|
||||
}
|
||||
}
|
||||
//bool wait_for_wifi(){
|
||||
//
|
||||
// bool connected=(xEventGroupGetBits(wifi_event_group) & CONNECTED_BIT)!=0;
|
||||
//
|
||||
// if(!connected){
|
||||
// ESP_LOGD(TAG,"Waiting for WiFi...");
|
||||
// connected = (xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT,
|
||||
// pdFALSE, pdTRUE, JOIN_TIMEOUT_MS / portTICK_PERIOD_MS)& CONNECTED_BIT)!=0;
|
||||
// if(!connected){
|
||||
// ESP_LOGD(TAG,"wifi timeout.");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// ESP_LOGI(TAG,"WiFi Connected!");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// return connected;
|
||||
//
|
||||
//}
|
||||
|
||||
static void initialise_wifi(void)
|
||||
{
|
||||
static bool initialized = false;
|
||||
@@ -204,8 +180,10 @@ void register_wifi_join()
|
||||
|
||||
void register_wifi()
|
||||
{
|
||||
#ifdef WIFI_CMDLINE
|
||||
register_wifi_join();
|
||||
if(bypass_network_manager){
|
||||
initialise_wifi();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -27,7 +27,9 @@
|
||||
#include "platform_config.h"
|
||||
#include "telnet.h"
|
||||
#include "tools.h"
|
||||
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
#include "metrics.h"
|
||||
#endif
|
||||
#include "messaging.h"
|
||||
|
||||
#include "config.h"
|
||||
@@ -85,14 +87,22 @@ cJSON * get_cmd_list(){
|
||||
}
|
||||
void console_set_bool_parameter(cJSON * root,char * nvs_name, struct arg_lit *arg){
|
||||
char * p=NULL;
|
||||
if(!root) {
|
||||
bool enabled = false;
|
||||
if(!root) {
|
||||
ESP_LOGE(TAG,"Invalid json parameter. Cannot set %s from %s",arg->hdr.longopts?arg->hdr.longopts:arg->hdr.glossary,nvs_name);
|
||||
return;
|
||||
}
|
||||
if ((p = config_alloc_get(NVS_TYPE_STR, nvs_name)) != NULL) {
|
||||
cJSON_AddBoolToObject(root,arg->hdr.longopts,strcmp(p,"1") == 0 || strcasecmp(p,"y") == 0);
|
||||
enabled = strcmp(p,"1") == 0 || strcasecmp(p,"y") == 0;
|
||||
cJSON_AddBoolToObject(root,arg->hdr.longopts,enabled);
|
||||
FREE_AND_NULL(p);
|
||||
}
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
if(enabled){
|
||||
metrics_add_feature(nvs_name,"enabled");
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
struct arg_end *getParmsEnd(struct arg_hdr * * argtable){
|
||||
if(!argtable) return NULL;
|
||||
@@ -360,8 +370,6 @@ void console_start() {
|
||||
register_system();
|
||||
MEMTRACE_PRINT_DELTA_MESSAGE("Registering config commands");
|
||||
register_config_cmd();
|
||||
MEMTRACE_PRINT_DELTA_MESSAGE("Registering nvs commands");
|
||||
register_nvs();
|
||||
MEMTRACE_PRINT_DELTA_MESSAGE("Registering wifi commands");
|
||||
register_wifi();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user