initial refactoring

This commit is contained in:
Sebastien L
2023-12-04 23:25:57 -05:00
parent d03678ea81
commit c0ddf0a997
331 changed files with 29663 additions and 16553 deletions

View File

@@ -9,14 +9,16 @@
#include "freertos/event_groups.h"
#include "pthread.h"
#include "platform_esp32.h"
#include "platform_config.h"
#include "Configurator.h"
#include "esp_app_format.h"
#include "tools.h"
#include "messaging.h"
extern esp_err_t process_recovery_ota(const char * bin_url, char * bin_buffer, uint32_t length);
extern int squeezelite_main_start();
static const char * TAG = "squeezelite_cmd";
#define SQUEEZELITE_THREAD_STACK_SIZE (8*1024)
#define ADDITIONAL_SQUEEZELITE_ARGS 5
const __attribute__((section(".rodata_desc"))) esp_app_desc_t esp_app_desc = {
@@ -41,19 +43,9 @@ 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_rotary_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();
#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);
@@ -61,11 +53,14 @@ cJSON * get_gpio_list(bool refresh){
return cJSON_CreateArray();
#endif
}
void register_optional_cmd(void) {
// #if CONFIG_WITH_CONFIG_UI
// register_rotary_config();
// #endif
register_audio_config();
// register_ledvu_config();
extern int squeezelite_main(int argc, char **argv);
static int launchsqueezelite(int argc, char **argv);
}
/** Arguments used by 'squeezelite' function */
static struct {
@@ -77,7 +72,6 @@ static struct {
char ** argv;
} thread_parms ;
#define ADDITIONAL_SQUEEZELITE_ARGS 5
static void squeezelite_thread(void *arg){
ESP_LOGV(TAG ,"Number of args received: %u",thread_parms.argc );
ESP_LOGV(TAG ,"Values:");
@@ -85,13 +79,14 @@ static void squeezelite_thread(void *arg){
ESP_LOGV(TAG ," %s",thread_parms.argv[i]);
}
ESP_LOGI(TAG ,"Calling squeezelite");
int ret = squeezelite_main(thread_parms.argc, thread_parms.argv);
int ret = squeezelite_main_start(thread_parms.argc, thread_parms.argv);
cmd_send_messaging("cfg-audio-tmpl",ret > 1 ? MESSAGING_ERROR : MESSAGING_WARNING,"squeezelite exited with error code %d\n", ret);
if (ret <= 1) {
int wait = 60;
wait_for_commit();
// wait_for_commit();
// TODO: Add support for the commented code
cmd_send_messaging("cfg-audio-tmpl",MESSAGING_ERROR,"Rebooting in %d sec\n", wait);
vTaskDelay( pdMS_TO_TICKS(wait * 1000));
esp_restart();
@@ -119,26 +114,26 @@ static int launchsqueezelite(int argc, char **argv) {
ESP_LOGV(TAG ,"Begin");
isRunning = true;
ESP_LOGV(TAG, "Parameters:");
for(int i = 0;i<argc; i++){
ESP_LOGV(TAG, " %s",argv[i]);
}
ESP_LOGV(TAG,"Saving args in thread structure");
// ESP_LOGV(TAG, "Parameters:");
// for(int i = 0;i<argc; i++){
// ESP_LOGV(TAG, " %s",argv[i]);
// }
// ESP_LOGV(TAG,"Saving args in thread structure");
thread_parms.argc=0;
thread_parms.argv = malloc_init_external(sizeof(char**)*(argc+ADDITIONAL_SQUEEZELITE_ARGS));
// thread_parms.argc=0;
// thread_parms.argv = malloc_init_external(sizeof(char**)*(argc+ADDITIONAL_SQUEEZELITE_ARGS));
for(int i=0;i<argc;i++){
ESP_LOGD(TAG ,"assigning parm %u : %s",i,argv[i]);
thread_parms.argv[thread_parms.argc++]=strdup(argv[i]);
}
// for(int i=0;i<argc;i++){
// ESP_LOGD(TAG ,"assigning parm %u : %s",i,argv[i]);
// thread_parms.argv[thread_parms.argc++]=strdup(argv[i]);
// }
if(argc==1){
// There isn't a default configuration that would actually work
// if no parameter is passed.
ESP_LOGV(TAG ,"Adding argv value at %u. Prev value: %s",thread_parms.argc,thread_parms.argv[thread_parms.argc-1]);
thread_parms.argv[thread_parms.argc++]=strdup("-?");
}
// if(argc==1){
// // There isn't a default configuration that would actually work
// // if no parameter is passed.
// ESP_LOGV(TAG ,"Adding argv value at %u. Prev value: %s",thread_parms.argc,thread_parms.argv[thread_parms.argc-1]);
// thread_parms.argv[thread_parms.argc++]=strdup("-?");
// }
ESP_LOGD(TAG,"Starting Squeezelite Thread");
xTaskCreateStaticPinnedToCore(squeezelite_thread, "squeezelite", SQUEEZELITE_THREAD_STACK_SIZE,
@@ -147,35 +142,34 @@ static int launchsqueezelite(int argc, char **argv) {
return 0;
}
void register_squeezelite() {
squeezelite_args.parameters = arg_str0(NULL, NULL, "<parms>", "command line for squeezelite. -h for help, --defaults to launch with default values.");
squeezelite_args.end = arg_end(1);
const esp_console_cmd_t launch_squeezelite = {
.command = "squeezelite",
.help = "Starts squeezelite",
.hint = NULL,
.func = &launchsqueezelite,
.argtable = &squeezelite_args
};
ESP_ERROR_CHECK( esp_console_cmd_register(&launch_squeezelite) );
void start_squeezelite(){
launchsqueezelite(0,NULL);
}
// void register_squeezelite() {
// squeezelite_args.parameters = arg_str0(NULL, NULL, "<parms>", "command line for squeezelite. -h for help, --defaults to launch with default values.");
// squeezelite_args.end = arg_end(1);
// const esp_console_cmd_t launch_squeezelite = {
// .command = "squeezelite",
// .help = "Starts squeezelite",
// .hint = NULL,
// .func = &launchsqueezelite,
// .argtable = &squeezelite_args
// };
// ESP_ERROR_CHECK( esp_console_cmd_register(&launch_squeezelite) );
// }
esp_err_t start_ota(const char * bin_url, char * bin_buffer, uint32_t length) {
if(!bin_url){
if(!bin_url || strlen(bin_url)==0){
ESP_LOGE(TAG,"missing URL parameter. Unable to start OTA");
return ESP_ERR_INVALID_ARG;
}
ESP_LOGW(TAG, "Called to update the firmware from url: %s",bin_url);
if(config_set_value(NVS_TYPE_STR, "fwurl", bin_url) != ESP_OK){
ESP_LOGE(TAG,"Failed to save the OTA url into nvs cache");
return ESP_FAIL;
}
configurator_set_string(&sys_State_msg,sys_State_ota_url_tag,sys_state,bin_url);
configurator_raise_state_changed();
if(!wait_for_commit()){
if(!configurator_waitcommit()){
ESP_LOGW(TAG,"Unable to commit configuration. ");
}
ESP_LOGW(TAG, "Rebooting to recovery to complete the installation");
return guided_factory();
return ESP_OK;