mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2026-04-11 05:27:39 +03:00
style: apply clang-format and enforce left pointer alignment
This commit is contained in:
@@ -6,8 +6,8 @@
|
||||
#include "esp_app_desc.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;
|
||||
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,
|
||||
@@ -28,35 +28,23 @@ 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();
|
||||
}
|
||||
cJSON* get_gpio_list(bool refresh) {
|
||||
if(!gpio_list) { gpio_list = cJSON_CreateArray(); }
|
||||
return gpio_list;
|
||||
}
|
||||
void register_optional_cmd(void) {
|
||||
}
|
||||
void register_optional_cmd(void) {}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
return 1;
|
||||
}
|
||||
int main(int argc, char** argv) { return 1; }
|
||||
|
||||
// void register_squeezelite(){
|
||||
// }
|
||||
|
||||
void start_squeezelite(){
|
||||
}
|
||||
void start_squeezelite() {}
|
||||
|
||||
void register_external(void) {
|
||||
}
|
||||
void register_external(void) {}
|
||||
|
||||
void deregister_external(void) {
|
||||
}
|
||||
void deregister_external(void) {}
|
||||
|
||||
void decode_restore(int external) {
|
||||
}
|
||||
void decode_restore(int external) {}
|
||||
|
||||
esp_err_t start_ota(const char * bin_url, char * bin_buffer, uint32_t length)
|
||||
{
|
||||
return process_recovery_ota(bin_url,bin_buffer,length);
|
||||
}
|
||||
esp_err_t start_ota(const char* bin_url, char* bin_buffer, uint32_t length) { return process_recovery_ota(bin_url, bin_buffer, length); }
|
||||
|
||||
@@ -19,7 +19,6 @@ extern esp_err_t process_recovery_ota(const char* bin_url, char* bin_buffer, uin
|
||||
extern int squeezelite_main_start();
|
||||
extern sys_dac_default_sets* default_dac_sets;
|
||||
|
||||
|
||||
static const char* TAG = "squeezelite_cmd";
|
||||
#define SQUEEZELITE_THREAD_STACK_SIZE (8 * 1024)
|
||||
#define ADDITIONAL_SQUEEZELITE_ARGS 5
|
||||
@@ -75,42 +74,36 @@ static void squeezelite_thread(void* arg) {
|
||||
int wait = 60;
|
||||
int ret = squeezelite_main_start();
|
||||
|
||||
if (ret == -2) {
|
||||
cmd_send_messaging("cfg-audio-tmpl", MESSAGING_ERROR,
|
||||
"Squeezelite not configured. Rebooting to factory in %d sec\n", wait);
|
||||
if(ret == -2) {
|
||||
cmd_send_messaging("cfg-audio-tmpl", MESSAGING_ERROR, "Squeezelite not configured. Rebooting to factory in %d sec\n", wait);
|
||||
vTaskDelay(pdMS_TO_TICKS(wait * 1000));
|
||||
guided_factory();
|
||||
} else {
|
||||
cmd_send_messaging("cfg-audio-tmpl", ret > 1 ? MESSAGING_ERROR : MESSAGING_WARNING,
|
||||
"squeezelite exited with error code %d\n", ret);
|
||||
if (ret <= 1) {
|
||||
cmd_send_messaging("cfg-audio-tmpl", ret > 1 ? MESSAGING_ERROR : MESSAGING_WARNING, "squeezelite exited with error code %d\n", ret);
|
||||
if(ret <= 1) {
|
||||
|
||||
cmd_send_messaging(
|
||||
"cfg-audio-tmpl", MESSAGING_ERROR, "Rebooting to factory in %d sec\n", wait);
|
||||
cmd_send_messaging("cfg-audio-tmpl", MESSAGING_ERROR, "Rebooting to factory in %d sec\n", wait);
|
||||
vTaskDelay(pdMS_TO_TICKS(wait * 1000));
|
||||
guided_factory();
|
||||
} else {
|
||||
|
||||
cmd_send_messaging(
|
||||
"cfg-audio-tmpl", MESSAGING_ERROR, "Correct command line and reboot\n");
|
||||
cmd_send_messaging("cfg-audio-tmpl", MESSAGING_ERROR, "Correct command line and reboot\n");
|
||||
vTaskSuspend(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
ESP_LOGV(TAG, "Exited from squeezelite's main(). Freeing argv structure.");
|
||||
|
||||
for (int i = 0; i < thread_parms.argc; i++)
|
||||
free(thread_parms.argv[i]);
|
||||
for(int i = 0; i < thread_parms.argc; i++) free(thread_parms.argv[i]);
|
||||
free(thread_parms.argv);
|
||||
}
|
||||
|
||||
static int launchsqueezelite(int argc, char** argv) {
|
||||
static DRAM_ATTR StaticTask_t xTaskBuffer __attribute__((aligned(4)));
|
||||
static EXT_RAM_ATTR StackType_t xStack[SQUEEZELITE_THREAD_STACK_SIZE]
|
||||
__attribute__((aligned(4)));
|
||||
static EXT_RAM_ATTR StackType_t xStack[SQUEEZELITE_THREAD_STACK_SIZE] __attribute__((aligned(4)));
|
||||
static bool isRunning = false;
|
||||
|
||||
if (isRunning) {
|
||||
if(isRunning) {
|
||||
ESP_LOGE(TAG, "Squeezelite already running. Exiting!");
|
||||
return -1;
|
||||
}
|
||||
@@ -118,14 +111,13 @@ static int launchsqueezelite(int argc, char** argv) {
|
||||
ESP_LOGV(TAG, "Begin");
|
||||
isRunning = true;
|
||||
|
||||
// load the presets here, as the squeezelite cannot access the
|
||||
// load the presets here, as the squeezelite cannot access the
|
||||
// spiffs storage
|
||||
// proto_load_file("/spiffs/presets/default_sets.bin", &sys_dac_default_sets_msg, default_dac_sets, false);
|
||||
|
||||
ESP_LOGD(TAG, "Starting Squeezelite Thread");
|
||||
xTaskCreateStaticPinnedToCore(squeezelite_thread, "squeezelite", SQUEEZELITE_THREAD_STACK_SIZE,
|
||||
NULL, CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT, xStack, &xTaskBuffer,
|
||||
CONFIG_PTHREAD_TASK_CORE_DEFAULT);
|
||||
xTaskCreateStaticPinnedToCore(squeezelite_thread, "squeezelite", SQUEEZELITE_THREAD_STACK_SIZE, NULL, CONFIG_ESP32_PTHREAD_TASK_PRIO_DEFAULT,
|
||||
xStack, &xTaskBuffer, CONFIG_PTHREAD_TASK_CORE_DEFAULT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -142,7 +134,7 @@ void start_squeezelite() { launchsqueezelite(0, NULL); }
|
||||
// }
|
||||
|
||||
esp_err_t start_ota(const char* bin_url, char* bin_buffer, uint32_t length) {
|
||||
if (!bin_url || strlen(bin_url) == 0) {
|
||||
if(!bin_url || strlen(bin_url) == 0) {
|
||||
ESP_LOGE(TAG, "missing URL parameter. Unable to start OTA");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
@@ -150,9 +142,7 @@ esp_err_t start_ota(const char* bin_url, char* bin_buffer, uint32_t length) {
|
||||
system_set_string(&sys_state_data_msg, sys_state_data_ota_url_tag, sys_state, bin_url);
|
||||
config_raise_state_changed();
|
||||
|
||||
if (!config_waitcommit()) {
|
||||
ESP_LOGW(TAG, "Unable to commit configuration. ");
|
||||
}
|
||||
if(!config_waitcommit()) { ESP_LOGW(TAG, "Unable to commit configuration. "); }
|
||||
ESP_LOGW(TAG, "Rebooting to recovery to complete the installation");
|
||||
return guided_factory();
|
||||
return ESP_OK;
|
||||
|
||||
@@ -216,12 +216,12 @@ int is_gpio(struct arg_int* gpio, FILE* f, int* gpio_out, bool mandatory, bool o
|
||||
const char* name = gpio->hdr.longopts ? gpio->hdr.longopts : gpio->hdr.glossary;
|
||||
*gpio_out = -1;
|
||||
int t_gpio = gpio->ival[0];
|
||||
if (gpio->count == 0) {
|
||||
if (mandatory) {
|
||||
if(gpio->count == 0) {
|
||||
if(mandatory) {
|
||||
fprintf(f, "Missing: %s\n", name);
|
||||
res++;
|
||||
}
|
||||
} else if ((output && !GPIO_IS_VALID_OUTPUT_GPIO(t_gpio)) || (!GPIO_IS_VALID_GPIO(t_gpio))) {
|
||||
} else if((output && !GPIO_IS_VALID_OUTPUT_GPIO(t_gpio)) || (!GPIO_IS_VALID_GPIO(t_gpio))) {
|
||||
fprintf(f, "Invalid %s gpio: [%d] %s\n", name, t_gpio, GPIO_IS_VALID_GPIO(t_gpio) ? NOT_OUTPUT : NOT_GPIO);
|
||||
res++;
|
||||
} else {
|
||||
@@ -233,14 +233,14 @@ int is_output_gpio(struct arg_int* gpio, FILE* f, int* gpio_out, bool mandatory)
|
||||
int check_missing_parm(struct arg_int* int_parm, FILE* f) {
|
||||
int res = 0;
|
||||
const char* name = int_parm->hdr.longopts ? int_parm->hdr.longopts : int_parm->hdr.glossary;
|
||||
if (int_parm->count == 0) {
|
||||
if(int_parm->count == 0) {
|
||||
fprintf(f, "Missing: %s\n", name);
|
||||
res++;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
char* strip_bt_name(char* opt_str) {
|
||||
if (!opt_str || strlen(opt_str) == 0) {
|
||||
if(!opt_str || strlen(opt_str) == 0) {
|
||||
ESP_LOGW(TAG, "strip_bt_name: opt_str is NULL");
|
||||
return NULL;
|
||||
}
|
||||
@@ -248,27 +248,27 @@ char* strip_bt_name(char* opt_str) {
|
||||
char* str = strdup_psram(opt_str);
|
||||
const char* output_marker = " -o";
|
||||
|
||||
if (!result) {
|
||||
if(!result) {
|
||||
ESP_LOGE(TAG, "Error allocating memory for result.");
|
||||
return opt_str;
|
||||
}
|
||||
if (!str) {
|
||||
if(!str) {
|
||||
ESP_LOGE(TAG, "Error duplicating command line string.");
|
||||
return opt_str;
|
||||
}
|
||||
bool quoted = false;
|
||||
parse_state_t state = SEARCHING_FOR_BT;
|
||||
char* start = strstr(str, output_marker);
|
||||
if (start) {
|
||||
if(start) {
|
||||
ESP_LOGV(TAG, "Found output option : %s\n", start);
|
||||
start += strlen(output_marker);
|
||||
strncpy(result, str, (size_t)(start - str));
|
||||
char* pch = strtok(start, " ");
|
||||
while (pch) {
|
||||
while(pch) {
|
||||
ESP_LOGV(TAG, "Current output: %s\n[%s]", result, pch);
|
||||
switch (state) {
|
||||
switch(state) {
|
||||
case SEARCHING_FOR_BT:
|
||||
if (strcasestr(pch, "BT")) {
|
||||
if(strcasestr(pch, "BT")) {
|
||||
state = SEARCHING_FOR_NAME;
|
||||
quoted = strcasestr(pch, "BT") != NULL;
|
||||
ESP_LOGV(TAG, " - fount BT Start %s", quoted ? "quoted" : "");
|
||||
@@ -279,7 +279,7 @@ char* strip_bt_name(char* opt_str) {
|
||||
strcat(result, pch);
|
||||
break;
|
||||
case SEARCHING_FOR_NAME:
|
||||
if (strcasestr(pch, "name") || strcasestr(pch, "n")) {
|
||||
if(strcasestr(pch, "name") || strcasestr(pch, "n")) {
|
||||
ESP_LOGV(TAG, " - Found name tag");
|
||||
state = SEARCHING_FOR_NAME_START;
|
||||
} else {
|
||||
@@ -294,10 +294,10 @@ char* strip_bt_name(char* opt_str) {
|
||||
state = SEARCHING_FOR_NAME_END;
|
||||
break;
|
||||
case SEARCHING_FOR_NAME_END:
|
||||
if (strcasestr(pch, "\"")) {
|
||||
if(strcasestr(pch, "\"")) {
|
||||
ESP_LOGV(TAG, " - got quoted string");
|
||||
state = FINISHING;
|
||||
} else if (pch[0] == '-') {
|
||||
} else if(pch[0] == '-') {
|
||||
strcat(result, " ");
|
||||
strcat(result, pch);
|
||||
ESP_LOGV(TAG, " - got parameter marker");
|
||||
@@ -308,7 +308,7 @@ char* strip_bt_name(char* opt_str) {
|
||||
break;
|
||||
case SEARCHING_FOR_BT_CMD_END:
|
||||
ESP_LOGV(TAG, " - looking for quoted BT cmd end");
|
||||
if (strcasestr(pch, "\"")) {
|
||||
if(strcasestr(pch, "\"")) {
|
||||
ESP_LOGV(TAG, " - got quote termination");
|
||||
state = FINISHING;
|
||||
}
|
||||
@@ -343,16 +343,14 @@ static int do_bt_source_cmd(int argc, char** argv) {
|
||||
size_t buf_size = 0;
|
||||
// char value[100] ={0};
|
||||
FILE* f = system_open_memstream(argv[0], &buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
return 1;
|
||||
}
|
||||
if (nerrors > 0) {
|
||||
if(f == NULL) { return 1; }
|
||||
if(nerrors > 0) {
|
||||
arg_print_errors(f, bt_source_args.end, desc_bt_source);
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (bt_source_args.sink_name->count > 0) {
|
||||
if(bt_source_args.sink_name->count > 0) {
|
||||
// err = config_set_value(NVS_TYPE_STR, "a2dp_sink_name", bt_source_args.sink_name->sval[0]);
|
||||
// if(err!=ESP_OK){
|
||||
// nerrors++;
|
||||
@@ -378,15 +376,13 @@ static int do_bt_source_cmd(int argc, char** argv) {
|
||||
// }
|
||||
// TODO: Add support for the commented code
|
||||
}
|
||||
if (bt_source_args.pin_code->count > 0) {
|
||||
if(bt_source_args.pin_code->count > 0) {
|
||||
const char* v = bt_source_args.pin_code->sval[0];
|
||||
bool bInvalid = false;
|
||||
for (int i = 0; i < strlen(v) && !bInvalid; i++) {
|
||||
if (v[i] < '0' || v[i] > '9') {
|
||||
bInvalid = true;
|
||||
}
|
||||
for(int i = 0; i < strlen(v) && !bInvalid; i++) {
|
||||
if(v[i] < '0' || v[i] > '9') { bInvalid = true; }
|
||||
}
|
||||
if (bInvalid || strlen(bt_source_args.pin_code->sval[0]) > 16 || strlen(bt_source_args.pin_code->sval[0]) < 4) {
|
||||
if(bInvalid || strlen(bt_source_args.pin_code->sval[0]) > 16 || strlen(bt_source_args.pin_code->sval[0]) < 4) {
|
||||
nerrors++;
|
||||
fprintf(f, "Pin code %s invalid. Should be numbers only with length between 4 and 16 characters. \n", bt_source_args.pin_code->sval[0]);
|
||||
} else {
|
||||
@@ -442,9 +438,7 @@ static int do_bt_source_cmd(int argc, char** argv) {
|
||||
// }
|
||||
// }
|
||||
|
||||
if (!nerrors) {
|
||||
fprintf(f, "Done.\n");
|
||||
}
|
||||
if(!nerrors) { fprintf(f, "Done.\n"); }
|
||||
fflush(f);
|
||||
cmd_send_messaging(argv[0], nerrors > 0 ? MESSAGING_ERROR : MESSAGING_INFO, "%s", buf);
|
||||
fclose(f);
|
||||
@@ -453,34 +447,28 @@ static int do_bt_source_cmd(int argc, char** argv) {
|
||||
}
|
||||
static int do_wifi_join(int argc, char** argv) {
|
||||
int nerrors = arg_parse(argc, argv, (void**)&wifi_join_args);
|
||||
if (nerrors > 0) {
|
||||
return 1;
|
||||
}
|
||||
if(nerrors > 0) { return 1; }
|
||||
|
||||
network_async_connect(wifi_join_args.ap_name->sval[0], wifi_join_args.password->count > 0 ? wifi_join_args.password->sval[0] : "");
|
||||
network_async_connect(wifi_join_args.ap_name->sval[0], wifi_join_args.password->count > 0 ? wifi_join_args.password->sval[0] : "");
|
||||
return 0;
|
||||
}
|
||||
static int do_wifi_add(int argc, char** argv) {
|
||||
int nerrors = arg_parse(argc, argv, (void**)&wifi_join_args);
|
||||
if (nerrors > 0) {
|
||||
return 1;
|
||||
}
|
||||
if(nerrors > 0) { return 1; }
|
||||
|
||||
network_async_add(wifi_join_args.ap_name->sval[0], wifi_join_args.password->count > 0 ? wifi_join_args.password->sval[0] : "");
|
||||
network_async_add(wifi_join_args.ap_name->sval[0], wifi_join_args.password->count > 0 ? wifi_join_args.password->sval[0] : "");
|
||||
return 0;
|
||||
}
|
||||
static int do_wifi_delete(int argc, char** argv) {
|
||||
int nerrors = arg_parse(argc, argv, (void**)&wifi_delete_args);
|
||||
if (nerrors > 0) {
|
||||
return 1;
|
||||
}
|
||||
network_async_delete_connection(wifi_delete_args.ap_name->sval[0]);
|
||||
if(nerrors > 0) { return 1; }
|
||||
network_async_delete_connection(wifi_delete_args.ap_name->sval[0]);
|
||||
return 0;
|
||||
}
|
||||
// Function to handle WiFi scan
|
||||
static int do_wifi_scan(int argc, char** argv) {
|
||||
int nerrors = arg_parse(argc, argv, (void**) &wifi_scan_args);
|
||||
if (nerrors > 0) {
|
||||
int nerrors = arg_parse(argc, argv, (void**)&wifi_scan_args);
|
||||
if(nerrors > 0) {
|
||||
arg_print_errors(stderr, wifi_scan_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
@@ -490,8 +478,8 @@ static int do_wifi_scan(int argc, char** argv) {
|
||||
|
||||
// Function to handle WiFi status
|
||||
static int do_wifi_status(int argc, char** argv) {
|
||||
int nerrors = arg_parse(argc, argv, (void**) &wifi_status_args);
|
||||
if (nerrors > 0) {
|
||||
int nerrors = arg_parse(argc, argv, (void**)&wifi_status_args);
|
||||
if(nerrors > 0) {
|
||||
arg_print_errors(stderr, wifi_status_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
@@ -501,8 +489,8 @@ static int do_wifi_status(int argc, char** argv) {
|
||||
|
||||
// Function to handle WiFi reset
|
||||
static int do_wifi_reset(int argc, char** argv) {
|
||||
int nerrors = arg_parse(argc, argv, (void**) &wifi_reset_args);
|
||||
if (nerrors > 0) {
|
||||
int nerrors = arg_parse(argc, argv, (void**)&wifi_reset_args);
|
||||
if(nerrors > 0) {
|
||||
arg_print_errors(stderr, wifi_reset_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
@@ -511,17 +499,14 @@ static int do_wifi_reset(int argc, char** argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int do_audio_cmd(int argc, char** argv) {
|
||||
esp_err_t err = ESP_OK;
|
||||
int nerrors = arg_parse(argc, argv, (void**)&audio_args);
|
||||
char* buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE* f = system_open_memstream(argv[0], &buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
return 1;
|
||||
}
|
||||
if (nerrors > 0) {
|
||||
if(f == NULL) { return 1; }
|
||||
if(nerrors > 0) {
|
||||
arg_print_errors(f, audio_args.end, desc_audio);
|
||||
fclose(f);
|
||||
return 1;
|
||||
@@ -529,10 +514,10 @@ static int do_audio_cmd(int argc, char** argv) {
|
||||
|
||||
err = ESP_OK; // suppress any error code that might have happened in a previous step
|
||||
|
||||
if (audio_args.loudness->count > 0) {
|
||||
if(audio_args.loudness->count > 0) {
|
||||
char p[4] = {0};
|
||||
int loudness_val = audio_args.loudness->ival[0];
|
||||
if (loudness_val < 0 || loudness_val > 10) {
|
||||
if(loudness_val < 0 || loudness_val > 10) {
|
||||
nerrors++;
|
||||
fprintf(f, "Invalid loudness value %d. Valid values are between 0 and 10.\n", loudness_val);
|
||||
}
|
||||
@@ -542,7 +527,7 @@ static int do_audio_cmd(int argc, char** argv) {
|
||||
// err = config_set_value(NVS_TYPE_STR, "loudness", p);
|
||||
// TODO: Add support for the commented code
|
||||
}
|
||||
if (err != ESP_OK) {
|
||||
if(err != ESP_OK) {
|
||||
nerrors++;
|
||||
fprintf(f, "Error setting Loudness value %s. %s\n", p, esp_err_to_name(err));
|
||||
} else {
|
||||
@@ -551,7 +536,7 @@ static int do_audio_cmd(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (audio_args.jack_behavior->count > 0) {
|
||||
if(audio_args.jack_behavior->count > 0) {
|
||||
err = ESP_OK; // suppress any error code that might have happened in a previous step
|
||||
// TODO: Add support for the commented code
|
||||
// if(strcasecmp(audio_args.jack_behavior->sval[0],"Headphones")==0){
|
||||
@@ -565,7 +550,7 @@ static int do_audio_cmd(int argc, char** argv) {
|
||||
// fprintf(f,"Unknown Audio Jack Behavior %s.\n",audio_args.jack_behavior->sval[0]);
|
||||
// }
|
||||
|
||||
if (err != ESP_OK) {
|
||||
if(err != ESP_OK) {
|
||||
nerrors++;
|
||||
fprintf(f, "Error setting Audio Jack Behavior %s. %s\n", audio_args.jack_behavior->sval[0], esp_err_to_name(err));
|
||||
} else {
|
||||
@@ -573,9 +558,7 @@ static int do_audio_cmd(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!nerrors) {
|
||||
fprintf(f, "Done.\n");
|
||||
}
|
||||
if(!nerrors) { fprintf(f, "Done.\n"); }
|
||||
fflush(f);
|
||||
cmd_send_messaging(argv[0], nerrors > 0 ? MESSAGING_ERROR : MESSAGING_INFO, "%s", buf);
|
||||
fclose(f);
|
||||
@@ -695,11 +678,11 @@ static int do_audio_cmd(int argc, char** argv) {
|
||||
// }
|
||||
static int is_valid_gpio_number(int gpio, const char* name, FILE* f, bool mandatory, struct arg_int* target, bool output) {
|
||||
bool invalid = (!GPIO_IS_VALID_GPIO(gpio) || (output && !GPIO_IS_VALID_OUTPUT_GPIO(gpio)));
|
||||
if (invalid && mandatory && gpio != -1) {
|
||||
if(invalid && mandatory && gpio != -1) {
|
||||
fprintf(f, "Error: Invalid mandatory gpio %d for %s\n", gpio, name);
|
||||
return 1;
|
||||
}
|
||||
if (target && !invalid) {
|
||||
if(target && !invalid) {
|
||||
target->count = 1;
|
||||
target->ival[0] = gpio;
|
||||
}
|
||||
@@ -709,16 +692,12 @@ static int is_valid_gpio_number(int gpio, const char* name, FILE* f, bool mandat
|
||||
#ifdef CONFIG_CSPOT_SINK
|
||||
static int do_cspot_config(int argc, char** argv) {
|
||||
int nerrors = arg_parse_msg(argc, argv, (struct arg_hdr**)&cspot_args);
|
||||
if (nerrors != 0) {
|
||||
return 1;
|
||||
}
|
||||
if(nerrors != 0) { return 1; }
|
||||
|
||||
char* buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE* f = system_open_memstream(argv[0], &buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
return 1;
|
||||
}
|
||||
if(f == NULL) { return 1; }
|
||||
|
||||
// cJSON * cspot_config = config_alloc_get_cjson("cspot_config");
|
||||
// if(!cspot_config){
|
||||
@@ -914,7 +893,7 @@ cJSON* known_model_cb() {
|
||||
#ifdef CONFIG_CSPOT_SINK
|
||||
cJSON* cspot_cb() {
|
||||
cJSON* values = cJSON_CreateObject();
|
||||
if (!values) {
|
||||
if(!values) {
|
||||
ESP_LOGE(TAG, "cspot_cb: Failed to create JSON object");
|
||||
return NULL;
|
||||
}
|
||||
@@ -1087,15 +1066,11 @@ cJSON* bt_source_cb() {
|
||||
|
||||
void get_str_parm_json(struct arg_str* parm, cJSON* entry) {
|
||||
const char* name = parm->hdr.longopts ? parm->hdr.longopts : parm->hdr.glossary;
|
||||
if (parm->count > 0) {
|
||||
cJSON_AddStringToObject(entry, name, parm->sval[0]);
|
||||
}
|
||||
if(parm->count > 0) { cJSON_AddStringToObject(entry, name, parm->sval[0]); }
|
||||
}
|
||||
void get_file_parm_json(struct arg_file* parm, cJSON* entry) {
|
||||
const char* name = parm->hdr.longopts ? parm->hdr.longopts : parm->hdr.glossary;
|
||||
if (parm->count > 0) {
|
||||
cJSON_AddStringToObject(entry, name, parm->filename[0]);
|
||||
}
|
||||
if(parm->count > 0) { cJSON_AddStringToObject(entry, name, parm->filename[0]); }
|
||||
}
|
||||
void get_lit_parm_json(struct arg_lit* parm, cJSON* entry) {
|
||||
const char* name = parm->hdr.longopts ? parm->hdr.longopts : parm->hdr.glossary;
|
||||
@@ -1103,9 +1078,7 @@ void get_lit_parm_json(struct arg_lit* parm, cJSON* entry) {
|
||||
}
|
||||
void get_int_parm_json(struct arg_int* parm, cJSON* entry) {
|
||||
const char* name = parm->hdr.longopts ? parm->hdr.longopts : parm->hdr.glossary;
|
||||
if (parm->count > 0) {
|
||||
cJSON_AddNumberToObject(entry, name, parm->ival[0]);
|
||||
}
|
||||
if(parm->count > 0) { cJSON_AddNumberToObject(entry, name, parm->ival[0]); }
|
||||
}
|
||||
|
||||
static int do_squeezelite_cmd(int argc, char** argv) {
|
||||
@@ -1114,9 +1087,7 @@ static int do_squeezelite_cmd(int argc, char** argv) {
|
||||
char* buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE* f = system_open_memstream(argv[0], &buf, &buf_size);
|
||||
if (f == NULL) {
|
||||
return 1;
|
||||
}
|
||||
if(f == NULL) { return 1; }
|
||||
fprintf(f, "Not yet implemented!");
|
||||
nerrors += 1;
|
||||
fflush(f);
|
||||
@@ -1198,7 +1169,7 @@ static char* get_log_level_options(const char* longname) {
|
||||
const char* template = "<%s=info|%s=debug|%s=sdebug>";
|
||||
char* options = NULL;
|
||||
int len = snprintf(NULL, 0, template, longname, longname, longname);
|
||||
if (len > 0) {
|
||||
if(len > 0) {
|
||||
options = malloc_init_external(len + 1);
|
||||
snprintf(options, len, template, longname, longname, longname);
|
||||
}
|
||||
@@ -1235,10 +1206,8 @@ static char* get_log_level_options(const char* longname) {
|
||||
// return dac_list;
|
||||
// }
|
||||
void replace_char_in_string(char* str, char find, char replace) {
|
||||
for (int i = 0; str[i]; i++) {
|
||||
if (str[i] == find) {
|
||||
str[i] = replace;
|
||||
}
|
||||
for(int i = 0; str[i]; i++) {
|
||||
if(str[i] == find) { str[i] = replace; }
|
||||
}
|
||||
}
|
||||
static esp_err_t save_known_config(cJSON* known_item, const char* name, FILE* f) {
|
||||
@@ -1249,20 +1218,20 @@ static esp_err_t save_known_config(cJSON* known_item, const char* name, FILE* f)
|
||||
FREE_AND_NULL(json_string);
|
||||
cJSON* kvp = NULL;
|
||||
cJSON* config_array = cJSON_GetObjectItem(known_item, "config");
|
||||
if (config_array && cJSON_IsArray(config_array)) {
|
||||
if(config_array && cJSON_IsArray(config_array)) {
|
||||
json_string = cJSON_Print(config_array);
|
||||
ESP_LOGD(TAG, "config_array: %s", STR_OR_BLANK(json_string));
|
||||
FREE_AND_NULL(json_string);
|
||||
cJSON_ArrayForEach(kvp, config_array) {
|
||||
cJSON* kvp_value = kvp->child;
|
||||
if (!kvp_value) {
|
||||
if(!kvp_value) {
|
||||
printf("config entry is not an object!\n");
|
||||
err = ESP_FAIL;
|
||||
continue;
|
||||
}
|
||||
char* key = kvp_value->string;
|
||||
char* value = kvp_value->valuestring;
|
||||
if (!key || !value || strlen(key) == 0) {
|
||||
if(!key || !value || strlen(key) == 0) {
|
||||
printf("Invalid config entry %s:%s\n", STR_OR_BLANK(key), STR_OR_BLANK(value));
|
||||
err = ESP_FAIL;
|
||||
continue;
|
||||
@@ -1271,7 +1240,7 @@ static esp_err_t save_known_config(cJSON* known_item, const char* name, FILE* f)
|
||||
fprintf(f, "Storing %s=%s\n", key, value);
|
||||
// err = config_set_value(NVS_TYPE_STR,key,value);
|
||||
// TODO: Add support for the commented code
|
||||
if (err) {
|
||||
if(err) {
|
||||
fprintf(f, "Failed to store config value: %s\n", esp_err_to_name(err));
|
||||
break;
|
||||
}
|
||||
@@ -1287,12 +1256,10 @@ static esp_err_t save_known_config(cJSON* known_item, const char* name, FILE* f)
|
||||
err = ESP_FAIL;
|
||||
}
|
||||
|
||||
if (err == ESP_OK) {
|
||||
if(err == ESP_OK) {
|
||||
// err = config_set_value(NVS_TYPE_STR,"board_model",name);
|
||||
// TODO: Add support for the commented code
|
||||
if (err != ESP_OK) {
|
||||
fprintf(f, "Failed to save board model %s\n", name);
|
||||
}
|
||||
if(err != ESP_OK) { fprintf(f, "Failed to save board model %s\n", name); }
|
||||
}
|
||||
|
||||
return err;
|
||||
@@ -1564,76 +1531,53 @@ static void register_squeezelite_config(void) {
|
||||
}
|
||||
void dummy_register_cmd() {}
|
||||
|
||||
|
||||
void register_wifi_commands() {
|
||||
// WiFi Join Command
|
||||
wifi_join_args.ap_name = arg_str1(NULL, NULL, "<ap_name>", "Access Point to connect to");
|
||||
wifi_join_args.password = arg_str0(NULL, NULL, "[password]", "Password for the access point");
|
||||
wifi_join_args.end = arg_end(2);
|
||||
const esp_console_cmd_t join_cmd = {
|
||||
.command = "wifi_join",
|
||||
.help = "Join a WiFi network",
|
||||
.hint = NULL,
|
||||
.func = &do_wifi_join,
|
||||
.argtable = &wifi_join_args
|
||||
};
|
||||
.command = "wifi_join", .help = "Join a WiFi network", .hint = NULL, .func = &do_wifi_join, .argtable = &wifi_join_args};
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_console_cmd_register(&join_cmd));
|
||||
wifi_add_args.ap_name = arg_str1(NULL, NULL, "<ap_name>", "Access Point to connect to");
|
||||
wifi_add_args.ap_name = arg_str1(NULL, NULL, "<ap_name>", "Access Point to connect to");
|
||||
wifi_add_args.password = arg_str0(NULL, NULL, "[password]", "Password for the access point");
|
||||
wifi_add_args.end = arg_end(2);
|
||||
const esp_console_cmd_t add_cmd = {
|
||||
.command = "wifi_add",
|
||||
const esp_console_cmd_t add_cmd = {.command = "wifi_add",
|
||||
.help = "Adds a WiFi network to known list without connecting to it",
|
||||
.hint = NULL,
|
||||
.func = &do_wifi_add,
|
||||
.argtable = &wifi_add_args
|
||||
};
|
||||
.argtable = &wifi_add_args};
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_console_cmd_register(&add_cmd));
|
||||
|
||||
// WiFi Delete Command
|
||||
wifi_delete_args.ap_name = arg_str1(NULL, NULL, "<ap_name>", "Access Point to forget");
|
||||
wifi_delete_args.end = arg_end(1);
|
||||
const esp_console_cmd_t delete_cmd = {
|
||||
.command = "wifi_delete",
|
||||
.help = "Delete a WiFi network",
|
||||
.hint = NULL,
|
||||
.func = &do_wifi_delete,
|
||||
.argtable = &wifi_delete_args
|
||||
};
|
||||
.command = "wifi_delete", .help = "Delete a WiFi network", .hint = NULL, .func = &do_wifi_delete, .argtable = &wifi_delete_args};
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_console_cmd_register(&delete_cmd));
|
||||
|
||||
// WiFi Scan Command
|
||||
// WiFi Scan Command
|
||||
wifi_scan_args.end = arg_end(1);
|
||||
const esp_console_cmd_t scan_cmd = {
|
||||
.command = "wifi_scan",
|
||||
.help = "Scan for available WiFi networks",
|
||||
.hint = NULL,
|
||||
.func = &do_wifi_scan,
|
||||
.argtable = &wifi_scan_args
|
||||
};
|
||||
.command = "wifi_scan", .help = "Scan for available WiFi networks", .hint = NULL, .func = &do_wifi_scan, .argtable = &wifi_scan_args};
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_console_cmd_register(&scan_cmd));
|
||||
|
||||
// WiFi Status Command
|
||||
wifi_status_args.end = arg_end(1);
|
||||
const esp_console_cmd_t status_cmd = {
|
||||
.command = "wifi_status",
|
||||
const esp_console_cmd_t status_cmd = {.command = "wifi_status",
|
||||
.help = "Show current WiFi connection status",
|
||||
.hint = NULL,
|
||||
.func = &do_wifi_status,
|
||||
.argtable = &wifi_status_args
|
||||
};
|
||||
.argtable = &wifi_status_args};
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_console_cmd_register(&status_cmd));
|
||||
|
||||
|
||||
// WiFi Reset Command
|
||||
wifi_reset_args.end = arg_end(1);
|
||||
const esp_console_cmd_t reset_cmd = {
|
||||
.command = "wifi_reset",
|
||||
const esp_console_cmd_t reset_cmd = {.command = "wifi_reset",
|
||||
.help = "Reset WiFi configuration to default settings",
|
||||
.hint = NULL,
|
||||
.func = &do_wifi_reset,
|
||||
.argtable = &wifi_reset_args
|
||||
};
|
||||
.argtable = &wifi_reset_args};
|
||||
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_console_cmd_register(&reset_cmd));
|
||||
}
|
||||
void register_config_cmd(void) {
|
||||
@@ -1646,7 +1590,7 @@ void register_config_cmd(void) {
|
||||
// #endif
|
||||
// register_bt_source_config();
|
||||
#if CONFIG_WITH_CONFIG_UI
|
||||
if (!is_dac_config_locked()) {
|
||||
if(!is_dac_config_locked()) {
|
||||
register_i2s_config();
|
||||
} else {
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
void register_i2ctools(void);
|
||||
esp_err_t cmd_i2ctools_scan_bus(FILE *f,int sda, int scl);
|
||||
esp_err_t cmd_i2ctools_scan_bus(FILE* f, int sda, int scl);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -27,27 +27,24 @@
|
||||
#include "platform_console.h"
|
||||
#include "messaging.h"
|
||||
|
||||
static const char * TAG = "ota";
|
||||
extern esp_err_t start_ota(const char * bin_url);
|
||||
static const char* TAG = "ota";
|
||||
extern esp_err_t start_ota(const char* bin_url);
|
||||
static struct {
|
||||
struct arg_str *url;
|
||||
struct arg_end *end;
|
||||
struct arg_str* url;
|
||||
struct arg_end* end;
|
||||
} ota_args;
|
||||
/* 'heap' command prints minumum heap size */
|
||||
static int perform_ota_update(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&ota_args);
|
||||
if (nerrors != 0) {
|
||||
return 1;
|
||||
}
|
||||
static int perform_ota_update(int argc, char** argv) {
|
||||
int nerrors = arg_parse_msg(argc, argv, (struct arg_hdr**)&ota_args);
|
||||
if(nerrors != 0) { return 1; }
|
||||
|
||||
const char *url = ota_args.url->sval[0];
|
||||
const char* url = ota_args.url->sval[0];
|
||||
|
||||
esp_err_t err=ESP_OK;
|
||||
esp_err_t err = ESP_OK;
|
||||
ESP_LOGI(TAG, "Starting ota: %s", url);
|
||||
start_ota(url);
|
||||
|
||||
if (err != ESP_OK) {
|
||||
if(err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "%s", esp_err_to_name(err));
|
||||
return 1;
|
||||
}
|
||||
@@ -55,20 +52,10 @@ static int perform_ota_update(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void register_ota_cmd()
|
||||
{
|
||||
ota_args.url= arg_str1(NULL, NULL, "<url>", "url of the binary app file");
|
||||
ota_args.end = arg_end(2);
|
||||
void register_ota_cmd() {
|
||||
ota_args.url = arg_str1(NULL, NULL, "<url>", "url of the binary app file");
|
||||
ota_args.end = arg_end(2);
|
||||
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "update",
|
||||
.help = "Update from URL",
|
||||
.hint = NULL,
|
||||
.func = &perform_ota_update,
|
||||
.argtable = &ota_args
|
||||
};
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&cmd) );
|
||||
const esp_console_cmd_t cmd = {.command = "update", .help = "Update from URL", .hint = NULL, .func = &perform_ota_update, .argtable = &ota_args};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
// Register system functions
|
||||
void register_ota_cmd();
|
||||
void register_ota_cmd();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
#include <string.h>
|
||||
#include "tools_spiffs_utils.h"
|
||||
|
||||
|
||||
#if defined(CONFIG_WITH_METRICS)
|
||||
#include "Metrics.h"
|
||||
#endif
|
||||
@@ -66,7 +65,7 @@ EXT_RAM_ATTR static struct {
|
||||
} names_args;
|
||||
EXT_RAM_ATTR static struct {
|
||||
struct arg_str* name;
|
||||
struct arg_lit*reset;
|
||||
struct arg_lit* reset;
|
||||
struct arg_end* end;
|
||||
} target_args;
|
||||
|
||||
@@ -114,9 +113,7 @@ static void register_tasks();
|
||||
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.");
|
||||
}
|
||||
if(f == NULL) { cmd_send_messaging(cmdname, MESSAGING_ERROR, "Unable to open memory stream."); }
|
||||
return f;
|
||||
}
|
||||
|
||||
@@ -133,12 +130,9 @@ static int get_version(int argc, char** argv) {
|
||||
"\tcores:%d\r\n"
|
||||
"\tfeature:%s%s%s%s%d%s\r\n"
|
||||
"\trevision number:%d\r\n",
|
||||
esp_get_idf_version(), info.model == CHIP_ESP32 ? "ESP32" : "Unknow", info.cores,
|
||||
info.features & CHIP_FEATURE_WIFI_BGN ? "/802.11bgn" : "",
|
||||
info.features & CHIP_FEATURE_BLE ? "/BLE" : "",
|
||||
info.features & CHIP_FEATURE_BT ? "/BT" : "",
|
||||
info.features & CHIP_FEATURE_EMB_FLASH ? "/Embedded-Flash:" : "/External-Flash:",
|
||||
flash_size / (1024 * 1024), " MB", info.revision);
|
||||
esp_get_idf_version(), info.model == CHIP_ESP32 ? "ESP32" : "Unknow", info.cores, info.features & CHIP_FEATURE_WIFI_BGN ? "/802.11bgn" : "",
|
||||
info.features & CHIP_FEATURE_BLE ? "/BLE" : "", info.features & CHIP_FEATURE_BT ? "/BT" : "",
|
||||
info.features & CHIP_FEATURE_EMB_FLASH ? "/Embedded-Flash:" : "/External-Flash:", flash_size / (1024 * 1024), " MB", info.revision);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -255,14 +249,11 @@ static int heap_size(int argc, char** argv) {
|
||||
"External | %7zu | %7zu | %7zu | %7zu | %7zu | %4.1f%% | %4.1f%%\n"
|
||||
"DMA | %7zu | %7zu | %7zu | %7zu | %7zu | %4.1f%% | %4.1f%%",
|
||||
total_internal, allocated_internal, heap_caps_get_minimum_free_size(MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL), free_internal,
|
||||
(allocated_internal * 100.0) / total_internal, (free_internal * 100.0) / total_internal,
|
||||
total_external, allocated_external, heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM), free_external,
|
||||
(allocated_external * 100.0) / total_external, (free_external * 100.0) / total_external,
|
||||
total_dma, allocated_dma, heap_caps_get_minimum_free_size(MALLOC_CAP_DMA),
|
||||
heap_caps_get_largest_free_block(MALLOC_CAP_DMA), free_dma,
|
||||
(allocated_dma * 100.0) / total_dma, (free_dma * 100.0) / total_dma);
|
||||
heap_caps_get_largest_free_block(MALLOC_CAP_INTERNAL), free_internal, (allocated_internal * 100.0) / total_internal,
|
||||
(free_internal * 100.0) / total_internal, total_external, allocated_external, heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM), free_external, (allocated_external * 100.0) / total_external,
|
||||
(free_external * 100.0) / total_external, total_dma, allocated_dma, heap_caps_get_minimum_free_size(MALLOC_CAP_DMA),
|
||||
heap_caps_get_largest_free_block(MALLOC_CAP_DMA), free_dma, (allocated_dma * 100.0) / total_dma, (free_dma * 100.0) / total_dma);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -382,7 +373,7 @@ int set_squeezelite_player_name(FILE* f, const char* name) {
|
||||
|
||||
static int do_cat(int argc, char** argv) {
|
||||
int nerrors = arg_parse_msg(argc, argv, (struct arg_hdr**)&ls_args);
|
||||
if (nerrors != 0) {
|
||||
if(nerrors != 0) {
|
||||
arg_print_errors(stderr, ls_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
@@ -394,7 +385,7 @@ static int do_cat(int argc, char** argv) {
|
||||
}
|
||||
static int do_ls(int argc, char** argv) {
|
||||
int nerrors = arg_parse_msg(argc, argv, (struct arg_hdr**)&ls_args);
|
||||
if (nerrors != 0) {
|
||||
if(nerrors != 0) {
|
||||
arg_print_errors(stderr, ls_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
@@ -419,14 +410,14 @@ static int do_ls(int argc, char** argv) {
|
||||
// }
|
||||
static int do_erase(int argc, char** argv) {
|
||||
int nerrors = arg_parse_msg(argc, argv, (struct arg_hdr**)&erase_args);
|
||||
if (nerrors != 0) {
|
||||
if(nerrors != 0) {
|
||||
arg_print_errors(stderr, erase_args.end, argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Erase file at the provided path
|
||||
const char* path = erase_args.path->sval[0];
|
||||
if (!erase_path(path, true)) {
|
||||
if(!erase_path(path, true)) {
|
||||
// Handle error if erase_path returns false
|
||||
// For example, log an error message
|
||||
fprintf(stderr, "Failed to erase file at path: %s\n", path);
|
||||
@@ -441,15 +432,13 @@ static int do_erase(int argc, char** argv) {
|
||||
|
||||
static int do_set_target(int argc, char** argv) {
|
||||
int nerrors = arg_parse_msg(argc, argv, (struct arg_hdr**)&target_args);
|
||||
if (nerrors != 0) {
|
||||
if(nerrors != 0) { return 1; }
|
||||
if(target_args.name->count <= 0) {
|
||||
ESP_LOGW(TAG, "Target name must be specified. Current target: %s", STR_OR_ALT(platform->target, "N/A"));
|
||||
return 1;
|
||||
}
|
||||
if (target_args.name->count <= 0) {
|
||||
ESP_LOGW(TAG, "Target name must be specified. Current target: %s",
|
||||
STR_OR_ALT(platform->target, "N/A"));
|
||||
return 1;
|
||||
}
|
||||
network_async_callback((void*)target_args.name->sval[0], (network_manager_cb_t)(target_args.reset->count>0?config_set_target_reset:config_set_target_no_reset));
|
||||
network_async_callback((void*)target_args.name->sval[0],
|
||||
(network_manager_cb_t)(target_args.reset->count > 0 ? config_set_target_reset : config_set_target_no_reset));
|
||||
|
||||
return nerrors;
|
||||
}
|
||||
@@ -457,11 +446,8 @@ static int do_set_target(int argc, char** argv) {
|
||||
static int do_reset_config(int argc, char** argv) {
|
||||
|
||||
int nerrors = arg_parse_msg(argc, argv, (struct arg_hdr**)&reset_config_args);
|
||||
if (nerrors != 0) {
|
||||
return 1;
|
||||
}
|
||||
if (reset_config_args.confirm->count <= 0 ||
|
||||
strcmp(reset_config_args.confirm->sval[0], "YES") != 0) {
|
||||
if(nerrors != 0) { return 1; }
|
||||
if(reset_config_args.confirm->count <= 0 || strcmp(reset_config_args.confirm->sval[0], "YES") != 0) {
|
||||
ESP_LOGW(TAG, "Confirmation needed. Call reset_config YES to confirm");
|
||||
return 1;
|
||||
}
|
||||
@@ -472,8 +458,7 @@ static int do_reset_config(int argc, char** argv) {
|
||||
}
|
||||
|
||||
static void register_reset_config() {
|
||||
reset_config_args.confirm =
|
||||
arg_str0(NULL, NULL, "YES", "To execute the reset, confirm with YES");
|
||||
reset_config_args.confirm = arg_str0(NULL, NULL, "YES", "To execute the reset, confirm with YES");
|
||||
reset_config_args.end = arg_end(1);
|
||||
|
||||
const esp_console_cmd_t reset_config = {.command = "reset_config",
|
||||
@@ -488,51 +473,40 @@ static void register_reset_config() {
|
||||
static int setdevicename(int argc, char** argv) {
|
||||
bool changed = false;
|
||||
int nerrors = arg_parse_msg(argc, argv, (struct arg_hdr**)&names_args);
|
||||
if (nerrors != 0) {
|
||||
return 1;
|
||||
}
|
||||
if (names_args.device->count > 0) {
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_device_tag,
|
||||
&platform->names, names_args.device->sval[0]);
|
||||
if(nerrors != 0) { return 1; }
|
||||
if(names_args.device->count > 0) {
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_device_tag, &platform->names, names_args.device->sval[0]);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Device name must be specified");
|
||||
return 1;
|
||||
}
|
||||
if (names_args.airplay->count > 0) {
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_airplay_tag,
|
||||
&platform->names, names_args.airplay->sval[0]);
|
||||
if(names_args.airplay->count > 0) {
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_airplay_tag, &platform->names, names_args.airplay->sval[0]);
|
||||
}
|
||||
|
||||
if (names_args.bluetooth->count > 0) {
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_bluetooth_tag,
|
||||
&platform->names, names_args.bluetooth->sval[0]);
|
||||
if(names_args.bluetooth->count > 0) {
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_bluetooth_tag, &platform->names, names_args.bluetooth->sval[0]);
|
||||
}
|
||||
if (names_args.spotify->count > 0) {
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_spotify_tag,
|
||||
&platform->names, names_args.spotify->sval[0]);
|
||||
if(names_args.spotify->count > 0) {
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_spotify_tag, &platform->names, names_args.spotify->sval[0]);
|
||||
}
|
||||
if (names_args.squeezelite->count > 0) {
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_squeezelite_tag,
|
||||
&platform->names, names_args.squeezelite->sval[0]);
|
||||
if(names_args.squeezelite->count > 0) {
|
||||
changed =
|
||||
changed | system_set_string(&sys_names_config_msg, sys_names_config_squeezelite_tag, &platform->names, names_args.squeezelite->sval[0]);
|
||||
}
|
||||
if (names_args.wifi_ap_name->count > 0) {
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_wifi_ap_name_tag,
|
||||
&platform->names, names_args.wifi_ap_name->sval[0]);
|
||||
if(names_args.wifi_ap_name->count > 0) {
|
||||
changed =
|
||||
changed | system_set_string(&sys_names_config_msg, sys_names_config_wifi_ap_name_tag, &platform->names, names_args.wifi_ap_name->sval[0]);
|
||||
}
|
||||
if (names_args.all->count > 0) {
|
||||
if(names_args.all->count > 0) {
|
||||
ESP_LOGI(TAG, "Setting all names to %s", platform->names.device);
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_airplay_tag,
|
||||
&platform->names, platform->names.device);
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_bluetooth_tag,
|
||||
&platform->names, platform->names.device);
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_spotify_tag,
|
||||
&platform->names, platform->names.device);
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_squeezelite_tag,
|
||||
&platform->names, platform->names.device);
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_wifi_ap_name_tag,
|
||||
&platform->names, platform->names.device);
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_airplay_tag, &platform->names, platform->names.device);
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_bluetooth_tag, &platform->names, platform->names.device);
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_spotify_tag, &platform->names, platform->names.device);
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_squeezelite_tag, &platform->names, platform->names.device);
|
||||
changed = changed | system_set_string(&sys_names_config_msg, sys_names_config_wifi_ap_name_tag, &platform->names, platform->names.device);
|
||||
}
|
||||
if (changed) {
|
||||
if(changed) {
|
||||
ESP_LOGI(TAG, "Found change(s). Saving");
|
||||
config_raise_changed(false);
|
||||
} else {
|
||||
@@ -575,7 +549,7 @@ static void register_dump_config() {
|
||||
}
|
||||
static void register_settarget() {
|
||||
target_args.name = arg_str0(NULL, NULL, STR_OR_BLANK(platform->target), "New Target Name");
|
||||
target_args.reset = arg_lit0("r","reset","Full reset before setting target (recommended)");
|
||||
target_args.reset = arg_lit0("r", "reset", "Full reset before setting target (recommended)");
|
||||
target_args.end = arg_end(1);
|
||||
const esp_console_cmd_t set_target = {.command = "target",
|
||||
.help = "Set the device target Name (SqueezeAMP, SqueezeIO, Muse, etc. )",
|
||||
@@ -605,22 +579,15 @@ static void register_settarget() {
|
||||
static void register_ls() {
|
||||
ls_args.path = arg_str1(NULL, NULL, "<path>", "Path to list files");
|
||||
ls_args.end = arg_end(1);
|
||||
const esp_console_cmd_t ls_cmd = {.command = "ls",
|
||||
.help = "List files in a path",
|
||||
.hint = NULL,
|
||||
.func = &do_ls,
|
||||
.argtable = &ls_args};
|
||||
const esp_console_cmd_t ls_cmd = {.command = "ls", .help = "List files in a path", .hint = NULL, .func = &do_ls, .argtable = &ls_args};
|
||||
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&ls_cmd));
|
||||
}
|
||||
static void register_cat() {
|
||||
ls_args.path = arg_str1(NULL, NULL, "<path>", "File name to cat");
|
||||
ls_args.end = arg_end(1);
|
||||
const esp_console_cmd_t cat_cmd = {.command = "cat",
|
||||
.help = "Dumps the content of a file to the console",
|
||||
.hint = NULL,
|
||||
.func = &do_cat,
|
||||
.argtable = &ls_args};
|
||||
const esp_console_cmd_t cat_cmd = {
|
||||
.command = "cat", .help = "Dumps the content of a file to the console", .hint = NULL, .func = &do_cat, .argtable = &ls_args};
|
||||
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&cat_cmd));
|
||||
}
|
||||
@@ -628,11 +595,8 @@ static void register_cat() {
|
||||
static void register_erase() {
|
||||
erase_args.path = arg_str1(NULL, NULL, "<path>", "Path of the file(s) to erase");
|
||||
erase_args.end = arg_end(1);
|
||||
const esp_console_cmd_t erase_cmd = {.command = "erase",
|
||||
.help = "Erase file(s) at a given path",
|
||||
.hint = NULL,
|
||||
.func = &do_erase,
|
||||
.argtable = &erase_args};
|
||||
const esp_console_cmd_t erase_cmd = {
|
||||
.command = "erase", .help = "Erase file(s) at a given path", .hint = NULL, .func = &do_erase, .argtable = &erase_args};
|
||||
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&erase_cmd));
|
||||
}
|
||||
@@ -643,16 +607,12 @@ static void register_setdevicename() {
|
||||
names_args.airplay = arg_str0("a", "airplay", default_host_name, "New Airplay Device Name");
|
||||
names_args.bluetooth = arg_str0("b", "bt", default_host_name, "New Bluetooth Device Name");
|
||||
names_args.spotify = arg_str0("s", "spotify", default_host_name, "New Spotify Device Name");
|
||||
names_args.squeezelite =
|
||||
arg_str0("l", "squeezelite", default_host_name, "New Squeezelite Player Name");
|
||||
names_args.squeezelite = arg_str0("l", "squeezelite", default_host_name, "New Squeezelite Player Name");
|
||||
names_args.wifi_ap_name = arg_str0("w", "wifiap", default_host_name, "New Wifi AP Name");
|
||||
names_args.all = arg_lit0(NULL, "all", "Set all names to device name");
|
||||
names_args.end = arg_end(2);
|
||||
const esp_console_cmd_t set_name = {.command = CFG_TYPE_SYST("name"),
|
||||
.help = "Device Name",
|
||||
.hint = NULL,
|
||||
.func = &setdevicename,
|
||||
.argtable = &names_args};
|
||||
const esp_console_cmd_t set_name = {
|
||||
.command = CFG_TYPE_SYST("name"), .help = "Device Name", .hint = NULL, .func = &setdevicename, .argtable = &names_args};
|
||||
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&set_name));
|
||||
}
|
||||
@@ -662,9 +622,8 @@ static void register_setdevicename() {
|
||||
static int tasks_info(int argc, char** argv) {
|
||||
const size_t bytes_per_task = 40; /* see vTaskList description */
|
||||
char* task_list_buffer = malloc_init_external(uxTaskGetNumberOfTasks() * bytes_per_task);
|
||||
if (task_list_buffer == NULL) {
|
||||
cmd_send_messaging(
|
||||
argv[0], MESSAGING_ERROR, "failed to allocate buffer for vTaskList output");
|
||||
if(task_list_buffer == NULL) {
|
||||
cmd_send_messaging(argv[0], MESSAGING_ERROR, "failed to allocate buffer for vTaskList output");
|
||||
return 1;
|
||||
}
|
||||
cmd_send_messaging(argv[0], MESSAGING_INFO,
|
||||
@@ -703,31 +662,27 @@ static struct {
|
||||
|
||||
static int deep_sleep(int argc, char** argv) {
|
||||
int nerrors = arg_parse_msg(argc, argv, (struct arg_hdr**)&deep_sleep_args);
|
||||
if (nerrors != 0) {
|
||||
return 1;
|
||||
}
|
||||
if (deep_sleep_args.wakeup_time->count) {
|
||||
if(nerrors != 0) { return 1; }
|
||||
if(deep_sleep_args.wakeup_time->count) {
|
||||
uint64_t timeout = 1000ULL * deep_sleep_args.wakeup_time->ival[0];
|
||||
cmd_send_messaging(
|
||||
argv[0], MESSAGING_INFO, "Enabling timer wakeup, timeout=%lluus", timeout);
|
||||
cmd_send_messaging(argv[0], MESSAGING_INFO, "Enabling timer wakeup, timeout=%lluus", timeout);
|
||||
ESP_ERROR_CHECK(esp_sleep_enable_timer_wakeup(timeout));
|
||||
}
|
||||
if (deep_sleep_args.wakeup_gpio_num->count) {
|
||||
if(deep_sleep_args.wakeup_gpio_num->count) {
|
||||
int io_num = deep_sleep_args.wakeup_gpio_num->ival[0];
|
||||
if (!rtc_gpio_is_valid_gpio(io_num)) {
|
||||
if(!rtc_gpio_is_valid_gpio(io_num)) {
|
||||
cmd_send_messaging(argv[0], MESSAGING_ERROR, "GPIO %d is not an RTC IO", io_num);
|
||||
return 1;
|
||||
}
|
||||
int level = 0;
|
||||
if (deep_sleep_args.wakeup_gpio_level->count) {
|
||||
if(deep_sleep_args.wakeup_gpio_level->count) {
|
||||
level = deep_sleep_args.wakeup_gpio_level->ival[0];
|
||||
if (level != 0 && level != 1) {
|
||||
if(level != 0 && level != 1) {
|
||||
cmd_send_messaging(argv[0], MESSAGING_ERROR, "Invalid wakeup level: %d", level);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
cmd_send_messaging(argv[0], MESSAGING_INFO, "Enabling wakeup on GPIO%d, wakeup on %s level",
|
||||
io_num, level ? "HIGH" : "LOW");
|
||||
cmd_send_messaging(argv[0], MESSAGING_INFO, "Enabling wakeup on GPIO%d, wakeup on %s level", io_num, level ? "HIGH" : "LOW");
|
||||
|
||||
ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(1ULL << io_num, level));
|
||||
}
|
||||
@@ -738,17 +693,12 @@ static int deep_sleep(int argc, char** argv) {
|
||||
|
||||
static void register_deep_sleep() {
|
||||
deep_sleep_args.wakeup_time = arg_int0("t", "time", "<t>", "Wake up time, ms");
|
||||
deep_sleep_args.wakeup_gpio_num =
|
||||
arg_int0(NULL, "io", "<n>", "If specified, wakeup using GPIO with given number");
|
||||
deep_sleep_args.wakeup_gpio_level =
|
||||
arg_int0(NULL, "io_level", "<0|1>", "GPIO level to trigger wakeup");
|
||||
deep_sleep_args.wakeup_gpio_num = arg_int0(NULL, "io", "<n>", "If specified, wakeup using GPIO with given number");
|
||||
deep_sleep_args.wakeup_gpio_level = arg_int0(NULL, "io_level", "<0|1>", "GPIO level to trigger wakeup");
|
||||
deep_sleep_args.end = arg_end(3);
|
||||
|
||||
const esp_console_cmd_t cmd = {.command = "deep_sleep",
|
||||
.help = "Enter deep sleep mode. ",
|
||||
.hint = NULL,
|
||||
.func = &deep_sleep,
|
||||
.argtable = &deep_sleep_args};
|
||||
const esp_console_cmd_t cmd = {
|
||||
.command = "deep_sleep", .help = "Enter deep sleep mode. ", .hint = NULL, .func = &deep_sleep, .argtable = &deep_sleep_args};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&cmd));
|
||||
}
|
||||
#endif
|
||||
@@ -886,41 +836,32 @@ static struct {
|
||||
|
||||
static int light_sleep(int argc, char** argv) {
|
||||
int nerrors = arg_parse_msg(argc, argv, (struct arg_hdr**)&light_sleep_args);
|
||||
if (nerrors != 0) {
|
||||
return 1;
|
||||
}
|
||||
if(nerrors != 0) { return 1; }
|
||||
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
|
||||
if (light_sleep_args.wakeup_time->count) {
|
||||
if(light_sleep_args.wakeup_time->count) {
|
||||
uint64_t timeout = 1000ULL * light_sleep_args.wakeup_time->ival[0];
|
||||
cmd_send_messaging(
|
||||
argv[0], MESSAGING_INFO, "Enabling timer wakeup, timeout=%lluus", timeout);
|
||||
cmd_send_messaging(argv[0], MESSAGING_INFO, "Enabling timer wakeup, timeout=%lluus", timeout);
|
||||
ESP_ERROR_CHECK(esp_sleep_enable_timer_wakeup(timeout));
|
||||
}
|
||||
int io_count = light_sleep_args.wakeup_gpio_num->count;
|
||||
if (io_count != light_sleep_args.wakeup_gpio_level->count) {
|
||||
cmd_send_messaging(
|
||||
argv[0], MESSAGING_INFO, "Should have same number of 'io' and 'io_level' arguments");
|
||||
if(io_count != light_sleep_args.wakeup_gpio_level->count) {
|
||||
cmd_send_messaging(argv[0], MESSAGING_INFO, "Should have same number of 'io' and 'io_level' arguments");
|
||||
return 1;
|
||||
}
|
||||
for (int i = 0; i < io_count; ++i) {
|
||||
for(int i = 0; i < io_count; ++i) {
|
||||
int io_num = light_sleep_args.wakeup_gpio_num->ival[i];
|
||||
int level = light_sleep_args.wakeup_gpio_level->ival[i];
|
||||
if (level != 0 && level != 1) {
|
||||
if(level != 0 && level != 1) {
|
||||
cmd_send_messaging(argv[0], MESSAGING_ERROR, "Invalid wakeup level: %d", level);
|
||||
return 1;
|
||||
}
|
||||
cmd_send_messaging(argv[0], MESSAGING_INFO, "Enabling wakeup on GPIO%d, wakeup on %s level",
|
||||
io_num, level ? "HIGH" : "LOW");
|
||||
cmd_send_messaging(argv[0], MESSAGING_INFO, "Enabling wakeup on GPIO%d, wakeup on %s level", io_num, level ? "HIGH" : "LOW");
|
||||
|
||||
ESP_ERROR_CHECK(
|
||||
gpio_wakeup_enable(io_num, level ? GPIO_INTR_HIGH_LEVEL : GPIO_INTR_LOW_LEVEL));
|
||||
ESP_ERROR_CHECK(gpio_wakeup_enable(io_num, level ? GPIO_INTR_HIGH_LEVEL : GPIO_INTR_LOW_LEVEL));
|
||||
}
|
||||
if (io_count > 0) {
|
||||
ESP_ERROR_CHECK(esp_sleep_enable_gpio_wakeup());
|
||||
}
|
||||
if (CONFIG_ESP_CONSOLE_UART_NUM <= UART_NUM_1) {
|
||||
cmd_send_messaging(
|
||||
argv[0], MESSAGING_INFO, "Enabling UART wakeup (press ENTER to exit light sleep)");
|
||||
if(io_count > 0) { ESP_ERROR_CHECK(esp_sleep_enable_gpio_wakeup()); }
|
||||
if(CONFIG_ESP_CONSOLE_UART_NUM <= UART_NUM_1) {
|
||||
cmd_send_messaging(argv[0], MESSAGING_INFO, "Enabling UART wakeup (press ENTER to exit light sleep)");
|
||||
ESP_ERROR_CHECK(uart_set_wakeup_threshold(CONFIG_ESP_CONSOLE_UART_NUM, 3));
|
||||
ESP_ERROR_CHECK(esp_sleep_enable_uart_wakeup(CONFIG_ESP_CONSOLE_UART_NUM));
|
||||
}
|
||||
@@ -929,7 +870,7 @@ static int light_sleep(int argc, char** argv) {
|
||||
esp_light_sleep_start();
|
||||
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
|
||||
const char* cause_str;
|
||||
switch (cause) {
|
||||
switch(cause) {
|
||||
case ESP_SLEEP_WAKEUP_GPIO:
|
||||
cause_str = "GPIO";
|
||||
break;
|
||||
@@ -949,10 +890,8 @@ static int light_sleep(int argc, char** argv) {
|
||||
|
||||
static void register_light_sleep() {
|
||||
light_sleep_args.wakeup_time = arg_int0("t", "time", "<t>", "Wake up time, ms");
|
||||
light_sleep_args.wakeup_gpio_num =
|
||||
arg_intn(NULL, "io", "<n>", 0, 8, "If specified, wakeup using GPIO with given number");
|
||||
light_sleep_args.wakeup_gpio_level =
|
||||
arg_intn(NULL, "io_level", "<0|1>", 0, 8, "GPIO level to trigger wakeup");
|
||||
light_sleep_args.wakeup_gpio_num = arg_intn(NULL, "io", "<n>", 0, 8, "If specified, wakeup using GPIO with given number");
|
||||
light_sleep_args.wakeup_gpio_level = arg_intn(NULL, "io_level", "<0|1>", 0, 8, "GPIO level to trigger wakeup");
|
||||
light_sleep_args.end = arg_end(3);
|
||||
|
||||
const esp_console_cmd_t cmd = {.command = "light_sleep",
|
||||
|
||||
@@ -15,7 +15,7 @@ extern "C" {
|
||||
// Register system functions
|
||||
void register_system();
|
||||
|
||||
FILE * system_open_memstream(const char * cmdname,char **buf,size_t *buf_size);
|
||||
FILE* system_open_memstream(const char* cmdname, char** buf, size_t* buf_size);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -40,81 +40,69 @@ extern bool bypass_network_manager;
|
||||
// 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;
|
||||
//static const char * TAG = "cmd_wifi";
|
||||
/** Arguments used by 'join' function */
|
||||
static struct {
|
||||
struct arg_int *timeout;
|
||||
struct arg_str *ssid;
|
||||
struct arg_str *password;
|
||||
struct arg_end *end;
|
||||
struct arg_int* timeout;
|
||||
struct arg_str* ssid;
|
||||
struct arg_str* password;
|
||||
struct arg_end* end;
|
||||
} join_args;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static void event_handler(void* arg, esp_event_base_t event_base,
|
||||
int32_t event_id, void* event_data)
|
||||
{
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
led_blink_pushed(LED_GREEN, 250, 250);
|
||||
static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
|
||||
if(event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
led_blink_pushed(LED_GREEN, 250, 250);
|
||||
esp_wifi_connect();
|
||||
xEventGroupClearBits(network_event_group, CONNECTED_BIT);
|
||||
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||
led_unpush(LED_GREEN);
|
||||
} else if(event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||
led_unpush(LED_GREEN);
|
||||
xEventGroupSetBits(network_event_group, CONNECTED_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
static void initialise_wifi(void)
|
||||
{
|
||||
static void initialise_wifi(void) {
|
||||
static bool initialized = false;
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
if(initialized) { return; }
|
||||
esp_netif_init();
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
|
||||
ESP_ERROR_CHECK( esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &event_handler, NULL) );
|
||||
ESP_ERROR_CHECK( esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL) );
|
||||
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
|
||||
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_NULL) );
|
||||
ESP_ERROR_CHECK( esp_wifi_start() );
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &event_handler, NULL));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &event_handler, NULL));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
initialized = true;
|
||||
led_blink(LED_GREEN, 250, 250);
|
||||
led_blink(LED_GREEN, 250, 250);
|
||||
}
|
||||
|
||||
static void wifi_join(TimerHandle_t timer)
|
||||
{
|
||||
static void wifi_join(TimerHandle_t timer) {
|
||||
(void)timer;
|
||||
const char *ssid = join_args.ssid->sval[0];
|
||||
const char *pass = join_args.password->sval[0];
|
||||
int timeout_ms = join_args.timeout->ival[0];
|
||||
|
||||
const char* ssid = join_args.ssid->sval[0];
|
||||
const char* pass = join_args.password->sval[0];
|
||||
int timeout_ms = join_args.timeout->ival[0];
|
||||
|
||||
initialise_wifi();
|
||||
wifi_config_t wifi_config = { 0 };
|
||||
strncpy((char *) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
|
||||
wifi_config.sta.ssid[sizeof(wifi_config.sta.ssid) - 1] = '\0';
|
||||
if (pass) {
|
||||
strncpy((char *) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
|
||||
wifi_config.sta.password[sizeof(wifi_config.sta.password) - 1] = '\0';
|
||||
wifi_config_t wifi_config = {0};
|
||||
strncpy((char*)wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
|
||||
wifi_config.sta.ssid[sizeof(wifi_config.sta.ssid) - 1] = '\0';
|
||||
if(pass) {
|
||||
strncpy((char*)wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
|
||||
wifi_config.sta.password[sizeof(wifi_config.sta.password) - 1] = '\0';
|
||||
}
|
||||
|
||||
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
|
||||
ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
|
||||
ESP_ERROR_CHECK( esp_wifi_connect() );
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config));
|
||||
ESP_ERROR_CHECK(esp_wifi_connect());
|
||||
|
||||
int bits = xEventGroupWaitBits(network_event_group, CONNECTED_BIT,
|
||||
pdFALSE, pdTRUE, timeout_ms / portTICK_PERIOD_MS);
|
||||
|
||||
if (bits & CONNECTED_BIT) {
|
||||
ESP_LOGI(__func__, "Connected");
|
||||
int bits = xEventGroupWaitBits(network_event_group, CONNECTED_BIT, pdFALSE, pdTRUE, timeout_ms / portTICK_PERIOD_MS);
|
||||
|
||||
if(bits & CONNECTED_BIT) {
|
||||
ESP_LOGI(__func__, "Connected");
|
||||
} else {
|
||||
ESP_LOGW(__func__, "Connection timed out");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//static int set_auto_connect(int argc, char **argv)
|
||||
@@ -143,48 +131,33 @@ static void wifi_join(TimerHandle_t timer)
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
static int connect(int argc, char **argv)
|
||||
{
|
||||
int nerrors = arg_parse_msg(argc, argv,(struct arg_hdr **)&join_args);
|
||||
if (nerrors != 0) {
|
||||
return 1;
|
||||
}
|
||||
ESP_LOGI(__func__, "Connecting to '%s'",
|
||||
join_args.ssid->sval[0]);
|
||||
static int connect(int argc, char** argv) {
|
||||
int nerrors = arg_parse_msg(argc, argv, (struct arg_hdr**)&join_args);
|
||||
if(nerrors != 0) { return 1; }
|
||||
ESP_LOGI(__func__, "Connecting to '%s'", join_args.ssid->sval[0]);
|
||||
|
||||
/* set default value*/
|
||||
if (join_args.timeout->count == 0) {
|
||||
join_args.timeout->ival[0] = JOIN_TIMEOUT_MS;
|
||||
}
|
||||
if(join_args.timeout->count == 0) { join_args.timeout->ival[0] = JOIN_TIMEOUT_MS; }
|
||||
|
||||
// need to use that trick to make sure we use internal stack
|
||||
xTimerStart(xTimerCreate("wifi_join", 1, pdFALSE, NULL, wifi_join), portMAX_DELAY);
|
||||
// need to use that trick to make sure we use internal stack
|
||||
xTimerStart(xTimerCreate("wifi_join", 1, pdFALSE, NULL, wifi_join), portMAX_DELAY);
|
||||
|
||||
return 0;
|
||||
}
|
||||
void register_wifi_join()
|
||||
{
|
||||
void register_wifi_join() {
|
||||
join_args.timeout = arg_int0(NULL, "timeout", "<t>", "Connection timeout, ms");
|
||||
join_args.ssid = arg_str1(NULL, NULL, "<ssid>", "SSID of AP");
|
||||
join_args.password = arg_str0(NULL, NULL, "<pass>", "PSK of AP");
|
||||
join_args.end = arg_end(2);
|
||||
|
||||
const esp_console_cmd_t join_cmd = {
|
||||
.command = "join",
|
||||
.help = "Join WiFi AP as a station",
|
||||
.hint = NULL,
|
||||
.func = &connect,
|
||||
.argtable = &join_args
|
||||
};
|
||||
ESP_ERROR_CHECK( esp_console_cmd_register(&join_cmd) );
|
||||
.command = "join", .help = "Join WiFi AP as a station", .hint = NULL, .func = &connect, .argtable = &join_args};
|
||||
ESP_ERROR_CHECK(esp_console_cmd_register(&join_cmd));
|
||||
}
|
||||
|
||||
void register_wifi()
|
||||
{
|
||||
#ifdef WIFI_CMDLINE
|
||||
void register_wifi() {
|
||||
#ifdef WIFI_CMDLINE
|
||||
register_wifi_join();
|
||||
if(bypass_network_manager){
|
||||
initialise_wifi();
|
||||
}
|
||||
#endif
|
||||
if(bypass_network_manager) { initialise_wifi(); }
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -64,11 +64,11 @@ const char* recovery_prompt = LOG_COLOR_E "recovery-squeezelite-esp32> " LOG_RES
|
||||
#define HISTORY_PATH MOUNT_PATH "/history.txt"
|
||||
static esp_err_t run_command(char* line);
|
||||
#define ADD_TO_JSON(o, t, n) \
|
||||
if (t->n) cJSON_AddStringToObject(o, QUOTE(n), t->n);
|
||||
if(t->n) cJSON_AddStringToObject(o, QUOTE(n), t->n);
|
||||
#define ADD_PARMS_TO_CMD(o, t, n) \
|
||||
{ \
|
||||
cJSON* parms = ParmsToJSON(&t.n->hdr); \
|
||||
if (parms) cJSON_AddItemToObject(o, QUOTE(n), parms); \
|
||||
if(parms) cJSON_AddItemToObject(o, QUOTE(n), parms); \
|
||||
}
|
||||
cJSON* cmdList;
|
||||
cJSON* values_fn_list;
|
||||
@@ -81,13 +81,11 @@ cJSON* get_cmd_list() {
|
||||
cJSON_ArrayForEach(element, cmdList) {
|
||||
cJSON* name = cJSON_GetObjectItem(element, "name");
|
||||
cJSON* vals_fn = cJSON_GetObjectItem(values_fn_list, cJSON_GetStringValue(name));
|
||||
if (vals_fn != NULL) {
|
||||
if(vals_fn != NULL) {
|
||||
parm_values_fn_t* parm_values_fn = (parm_values_fn_t*)strtoul(cJSON_GetStringValue(vals_fn), NULL, 16);
|
||||
;
|
||||
|
||||
if (parm_values_fn) {
|
||||
cJSON_AddItemToObject(values, cJSON_GetStringValue(name), parm_values_fn());
|
||||
}
|
||||
if(parm_values_fn) { cJSON_AddItemToObject(values, cJSON_GetStringValue(name), parm_values_fn()); }
|
||||
}
|
||||
}
|
||||
return list;
|
||||
@@ -95,7 +93,7 @@ cJSON* get_cmd_list() {
|
||||
void console_set_bool_parameter(cJSON* root, char* nvs_name, struct arg_lit* arg) {
|
||||
char* p = NULL;
|
||||
bool enabled = false;
|
||||
if (!root) {
|
||||
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;
|
||||
}
|
||||
@@ -112,20 +110,18 @@ void console_set_bool_parameter(cJSON* root, char* nvs_name, struct arg_lit* arg
|
||||
// TODO: Add support for the commented code
|
||||
}
|
||||
struct arg_end* getParmsEnd(struct arg_hdr** argtable) {
|
||||
if (!argtable) return NULL;
|
||||
if(!argtable) return NULL;
|
||||
struct arg_hdr** table = (struct arg_hdr**)argtable;
|
||||
int tabindex = 0;
|
||||
while (!(table[tabindex]->flag & ARG_TERMINATOR)) {
|
||||
tabindex++;
|
||||
}
|
||||
while(!(table[tabindex]->flag & ARG_TERMINATOR)) { tabindex++; }
|
||||
return (struct arg_end*)table[tabindex];
|
||||
}
|
||||
cJSON* ParmsToJSON(struct arg_hdr** argtable) {
|
||||
if (!argtable) return NULL;
|
||||
if(!argtable) return NULL;
|
||||
cJSON* arg_list = cJSON_CreateArray();
|
||||
struct arg_hdr** table = (struct arg_hdr**)argtable;
|
||||
int tabindex = 0;
|
||||
while (!(table[tabindex]->flag & ARG_TERMINATOR)) {
|
||||
while(!(table[tabindex]->flag & ARG_TERMINATOR)) {
|
||||
cJSON* entry = cJSON_CreateObject();
|
||||
ADD_TO_JSON(entry, table[tabindex], datatype);
|
||||
ADD_TO_JSON(entry, table[tabindex], glossary);
|
||||
@@ -149,40 +145,30 @@ cJSON* ParmsToJSON(struct arg_hdr** argtable) {
|
||||
esp_err_t cmd_to_json(const esp_console_cmd_t* cmd) { return cmd_to_json_with_cb(cmd, NULL); }
|
||||
|
||||
esp_err_t cmd_to_json_with_cb(const esp_console_cmd_t* cmd, parm_values_fn_t parm_values_fn) {
|
||||
if (!cmdList) {
|
||||
cmdList = cJSON_CreateArray();
|
||||
}
|
||||
if (!values_fn_list) {
|
||||
values_fn_list = cJSON_CreateObject();
|
||||
}
|
||||
if(!cmdList) { cmdList = cJSON_CreateArray(); }
|
||||
if(!values_fn_list) { values_fn_list = cJSON_CreateObject(); }
|
||||
|
||||
if (cmd->command == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (strchr(cmd->command, ' ') != NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if(cmd->command == NULL) { return ESP_ERR_INVALID_ARG; }
|
||||
if(strchr(cmd->command, ' ') != NULL) { return ESP_ERR_INVALID_ARG; }
|
||||
cJSON* jsoncmd = cJSON_CreateObject();
|
||||
ADD_TO_JSON(jsoncmd, cmd, help);
|
||||
ADD_TO_JSON(jsoncmd, cmd, hint);
|
||||
if (parm_values_fn) {
|
||||
if(parm_values_fn) {
|
||||
char addr[11] = {0};
|
||||
snprintf(addr, sizeof(addr), "%lx", (unsigned long)parm_values_fn);
|
||||
cJSON_AddStringToObject(values_fn_list, cmd->command, addr);
|
||||
}
|
||||
cJSON_AddBoolToObject(jsoncmd, "hascb", parm_values_fn != NULL);
|
||||
|
||||
if (cmd->argtable) {
|
||||
cJSON_AddItemToObject(jsoncmd, "argtable", ParmsToJSON(cmd->argtable));
|
||||
}
|
||||
if (cmd->hint) {
|
||||
if(cmd->argtable) { cJSON_AddItemToObject(jsoncmd, "argtable", ParmsToJSON(cmd->argtable)); }
|
||||
if(cmd->hint) {
|
||||
cJSON_AddStringToObject(jsoncmd, "hint", cmd->hint);
|
||||
} else if (cmd->argtable) {
|
||||
} else if(cmd->argtable) {
|
||||
/* Generate hint based on cmd->argtable */
|
||||
char* buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE* f = open_memstream(&buf, &buf_size);
|
||||
if (f != NULL) {
|
||||
if(f != NULL) {
|
||||
arg_print_syntax(f, cmd->argtable, NULL);
|
||||
fflush(f);
|
||||
fclose(f);
|
||||
@@ -192,7 +178,7 @@ esp_err_t cmd_to_json_with_cb(const esp_console_cmd_t* cmd, parm_values_fn_t par
|
||||
}
|
||||
cJSON_AddStringToObject(jsoncmd, "name", cmd->command);
|
||||
char* b = cJSON_Print(jsoncmd);
|
||||
if (b) {
|
||||
if(b) {
|
||||
ESP_LOGD(TAG, "Adding command table %s", b);
|
||||
free(b);
|
||||
}
|
||||
@@ -202,11 +188,11 @@ esp_err_t cmd_to_json_with_cb(const esp_console_cmd_t* cmd, parm_values_fn_t par
|
||||
int arg_parse_msg(int argc, char** argv, struct arg_hdr** args) {
|
||||
int nerrors = arg_parse(argc, argv, (void**)args);
|
||||
|
||||
if (nerrors != 0) {
|
||||
if(nerrors != 0) {
|
||||
char* buf = NULL;
|
||||
size_t buf_size = 0;
|
||||
FILE* f = open_memstream(&buf, &buf_size);
|
||||
if (f != NULL) {
|
||||
if(f != NULL) {
|
||||
arg_print_errors(f, getParmsEnd(args), argv[0]);
|
||||
fflush(f);
|
||||
cmd_send_messaging(argv[0], MESSAGING_ERROR, "%s", buf);
|
||||
@@ -219,34 +205,32 @@ int arg_parse_msg(int argc, char** argv, struct arg_hdr** args) {
|
||||
static ssize_t stdin_read(int fd, void* data, size_t size) {
|
||||
size_t bytes = -1;
|
||||
static size_t remain = 0;
|
||||
if (remain > 0) {
|
||||
if(remain > 0) {
|
||||
bytes = uart_read_bytes(CONFIG_ESP_CONSOLE_UART_NUM, data, size < remain ? size : remain, 0);
|
||||
remain -= bytes;
|
||||
for (int i = 0; i < bytes; i++)
|
||||
if (((char*)data)[i] == '\r') ((char*)data)[i] = '\n';
|
||||
return bytes;
|
||||
for(int i = 0; i < bytes; i++)
|
||||
if(((char*)data)[i] == '\r') ((char*)data)[i] = '\n';
|
||||
return bytes;
|
||||
}
|
||||
while (1) {
|
||||
while(1) {
|
||||
QueueSetMemberHandle_t activated = xQueueSelectFromSet(stdin_redir.queue_set, portMAX_DELAY);
|
||||
|
||||
if (activated == uart_queue) {
|
||||
if(activated == uart_queue) {
|
||||
uart_event_t event;
|
||||
xQueueReceive(uart_queue, &event, 0);
|
||||
if (event.type == UART_DATA) {
|
||||
if(event.type == UART_DATA) {
|
||||
bytes = uart_read_bytes(CONFIG_ESP_CONSOLE_UART_NUM, data, size < event.size ? size : event.size, 0);
|
||||
// we have to do our own line ending translation here
|
||||
for (int i = 0; i < bytes; i++)
|
||||
if (((char*)data)[i] == '\r') ((char*)data)[i] = '\n';
|
||||
if (event.size > bytes) {
|
||||
remain = event.size - bytes;
|
||||
}
|
||||
for(int i = 0; i < bytes; i++)
|
||||
if(((char*)data)[i] == '\r') ((char*)data)[i] = '\n';
|
||||
if(event.size > bytes) { remain = event.size - bytes; }
|
||||
break;
|
||||
}
|
||||
} else if (xRingbufferCanRead(stdin_redir.handle, activated)) {
|
||||
} else if(xRingbufferCanRead(stdin_redir.handle, activated)) {
|
||||
char* p = xRingbufferReceiveUpTo(stdin_redir.handle, &bytes, 0, size);
|
||||
// we might receive strings, replace null by \n
|
||||
for (int i = 0; i < bytes; i++)
|
||||
if (p[i] == '\0' || p[i] == '\r') p[i] = '\n';
|
||||
for(int i = 0; i < bytes; i++)
|
||||
if(p[i] == '\0' || p[i] == '\r') p[i] = '\n';
|
||||
memcpy(data, p, bytes);
|
||||
vRingbufferReturnItem(stdin_redir.handle, p);
|
||||
xRingbufferPrintInfo(stdin_redir.handle);
|
||||
@@ -300,8 +284,7 @@ void initialize_console() {
|
||||
setvbuf(stdin, NULL, _IONBF, 0);
|
||||
|
||||
/* Initialize the console */
|
||||
esp_console_config_t console_config = {
|
||||
.max_cmdline_args = 28,
|
||||
esp_console_config_t console_config = {.max_cmdline_args = 28,
|
||||
.max_cmdline_length = 600,
|
||||
#if CONFIG_LOG_COLORS
|
||||
.hint_color = atoi(LOG_COLOR_CYAN)
|
||||
@@ -321,7 +304,6 @@ void initialize_console() {
|
||||
|
||||
/* Set command history size */
|
||||
linenoiseHistorySetMaxLen(100);
|
||||
|
||||
}
|
||||
|
||||
bool console_push(const char* data, size_t size) { return xRingbufferSend(stdin_redir.handle, data, size, pdMS_TO_TICKS(100)) == pdPASS; }
|
||||
@@ -334,13 +316,11 @@ void console_start() {
|
||||
register_config_cmd();
|
||||
register_wifi();
|
||||
|
||||
if (is_recovery_running) {
|
||||
register_ota_cmd();
|
||||
}
|
||||
if(is_recovery_running) { register_ota_cmd(); }
|
||||
register_i2ctools();
|
||||
|
||||
printf("\n");
|
||||
if (is_recovery_running) {
|
||||
if(is_recovery_running) {
|
||||
printf("****************************************************************\n"
|
||||
"RECOVERY APPLICATION\n"
|
||||
"This mode is used to flash Squeezelite into the OTA partition\n"
|
||||
@@ -354,7 +334,7 @@ void console_start() {
|
||||
|
||||
/* Figure out if the terminal supports escape sequences */
|
||||
int probe_status = linenoiseProbe();
|
||||
if (probe_status) { /* zero indicates success */
|
||||
if(probe_status) { /* zero indicates success */
|
||||
printf("\n****************************\n"
|
||||
"Your terminal application does not support escape sequences.\n"
|
||||
"Line editing and history features are disabled.\n"
|
||||
@@ -365,9 +345,7 @@ void console_start() {
|
||||
/* Since the terminal doesn't support escape sequences,
|
||||
* don't use color codes in the prompt.
|
||||
*/
|
||||
if (is_recovery_running) {
|
||||
recovery_prompt = "recovery-squeezelite-esp32>";
|
||||
}
|
||||
if(is_recovery_running) { recovery_prompt = "recovery-squeezelite-esp32>"; }
|
||||
prompt = "squeezelite-esp32> ";
|
||||
#endif // CONFIG_LOG_COLORS
|
||||
}
|
||||
@@ -375,9 +353,7 @@ void console_start() {
|
||||
cfg.thread_name = "console";
|
||||
cfg.inherit_cfg = true;
|
||||
cfg.stack_size = 4 * 1024;
|
||||
if (is_recovery_running) {
|
||||
prompt = recovery_prompt;
|
||||
}
|
||||
if(is_recovery_running) { prompt = recovery_prompt; }
|
||||
esp_pthread_set_cfg(&cfg);
|
||||
pthread_create(&thread_console, NULL, console_thread, NULL);
|
||||
}
|
||||
@@ -387,16 +363,16 @@ static esp_err_t run_command(char* line) {
|
||||
int ret;
|
||||
esp_err_t err = esp_console_run(line, &ret);
|
||||
|
||||
if (err == ESP_ERR_NOT_FOUND) {
|
||||
if(err == ESP_ERR_NOT_FOUND) {
|
||||
ESP_LOGE(TAG, "Unrecognized command: %s", line);
|
||||
} else if (err == ESP_ERR_INVALID_ARG) {
|
||||
} else if(err == ESP_ERR_INVALID_ARG) {
|
||||
// command was empty
|
||||
} else if (err != ESP_OK && ret != ESP_OK) {
|
||||
} else if(err != ESP_OK && ret != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Command returned non-zero error code: 0x%x (%s)", ret, esp_err_to_name(err));
|
||||
} else if (err == ESP_OK && ret != ESP_OK) {
|
||||
} else if(err == ESP_OK && ret != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Command returned in error");
|
||||
err = ESP_FAIL;
|
||||
} else if (err != ESP_OK) {
|
||||
} else if(err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Internal error: %s", esp_err_to_name(err));
|
||||
}
|
||||
return err;
|
||||
@@ -404,12 +380,12 @@ static esp_err_t run_command(char* line) {
|
||||
|
||||
static void* console_thread() {
|
||||
/* Main loop */
|
||||
while (1) {
|
||||
while(1) {
|
||||
/* Get a line using linenoise.
|
||||
* The line is returned when ENTER is pressed.
|
||||
*/
|
||||
char* line = linenoise(prompt);
|
||||
if (line == NULL) { /* Ignore empty lines */
|
||||
if(line == NULL) { /* Ignore empty lines */
|
||||
continue;
|
||||
}
|
||||
/* Add the command to the history */
|
||||
|
||||
@@ -13,17 +13,17 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#define CFG_TYPE_HW(a) "cfg-hw-" a
|
||||
#define CFG_TYPE_AUDIO(a) "cfg-audio-" a
|
||||
#define CFG_TYPE_SYST(a) "cfg-syst-" a
|
||||
#define CFG_TYPE_FW(a) "cfg-fw-" a
|
||||
#define CFG_TYPE_GEN(a) "cfg-gen-" a
|
||||
typedef cJSON * parm_values_fn_t(void);
|
||||
esp_err_t cmd_to_json(const esp_console_cmd_t *cmd);
|
||||
esp_err_t cmd_to_json_with_cb(const esp_console_cmd_t *cmd, parm_values_fn_t parm_values_fn);
|
||||
int arg_parse_msg(int argc, char **argv, struct arg_hdr ** args);
|
||||
#define CFG_TYPE_HW(a) "cfg-hw-" a
|
||||
#define CFG_TYPE_AUDIO(a) "cfg-audio-" a
|
||||
#define CFG_TYPE_SYST(a) "cfg-syst-" a
|
||||
#define CFG_TYPE_FW(a) "cfg-fw-" a
|
||||
#define CFG_TYPE_GEN(a) "cfg-gen-" a
|
||||
typedef cJSON* parm_values_fn_t(void);
|
||||
esp_err_t cmd_to_json(const esp_console_cmd_t* cmd);
|
||||
esp_err_t cmd_to_json_with_cb(const esp_console_cmd_t* cmd, parm_values_fn_t parm_values_fn);
|
||||
int arg_parse_msg(int argc, char** argv, struct arg_hdr** args);
|
||||
void initialize_console();
|
||||
cJSON * get_cmd_list();
|
||||
cJSON* get_cmd_list();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -14,58 +14,52 @@
|
||||
// #include "Config.h"
|
||||
#pragma message("fixme: search for TODO below")
|
||||
#include "string.h"
|
||||
struct arg_lit *arglit;
|
||||
struct arg_int *argint;
|
||||
struct arg_str *argstr;
|
||||
struct arg_end *end;
|
||||
struct arg_lit* arglit;
|
||||
struct arg_int* argint;
|
||||
struct arg_str* argstr;
|
||||
struct arg_end* end;
|
||||
|
||||
extern int is_output_gpio(struct arg_int * gpio, FILE * f, int * gpio_out, bool mandatory);
|
||||
extern int is_output_gpio(struct arg_int* gpio, FILE* f, int* gpio_out, bool mandatory);
|
||||
extern void initialize_console();
|
||||
extern esp_err_t run_command(char * line);
|
||||
static char *buf = NULL;
|
||||
static char * s_tmp_line_buf=NULL;
|
||||
extern esp_err_t run_command(char* line);
|
||||
static char* buf = NULL;
|
||||
static char* s_tmp_line_buf = NULL;
|
||||
static size_t buf_size = 0;
|
||||
static FILE * f;
|
||||
static size_t argc=1;
|
||||
static char ** argv=NULL;
|
||||
static bool config_initialized=false;
|
||||
void init_console(){
|
||||
static FILE* f;
|
||||
static size_t argc = 1;
|
||||
static char** argv = NULL;
|
||||
static bool config_initialized = false;
|
||||
void init_console() {
|
||||
if(config_initialized) return;
|
||||
initialize_console();
|
||||
config_initialized=true;
|
||||
config_initialized = true;
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void open_mem_stream_file(){
|
||||
f = open_memstream(&buf, &buf_size);
|
||||
}
|
||||
void open_mem_stream_file() { f = open_memstream(&buf, &buf_size); }
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
void close_flush_all(void * argtable, int count,bool print){
|
||||
fflush (f);
|
||||
if(print){
|
||||
printf("%s", buf);
|
||||
}
|
||||
void close_flush_all(void* argtable, int count, bool print) {
|
||||
fflush(f);
|
||||
if(print) { printf("%s", buf); }
|
||||
fclose(f);
|
||||
free(buf);
|
||||
arg_freetable(argtable,count);
|
||||
free(argv);
|
||||
arg_freetable(argtable, count);
|
||||
free(argv);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
int alloc_split_command_line(char * cmdline){
|
||||
argv = (char **) calloc(22, sizeof(char *));
|
||||
if(!s_tmp_line_buf){
|
||||
s_tmp_line_buf= calloc(strlen(cmdline), 1);
|
||||
}
|
||||
int alloc_split_command_line(char* cmdline) {
|
||||
argv = (char**)calloc(22, sizeof(char*));
|
||||
if(!s_tmp_line_buf) { s_tmp_line_buf = calloc(strlen(cmdline), 1); }
|
||||
strlcpy(s_tmp_line_buf, cmdline, 22);
|
||||
argc = esp_console_split_argv(s_tmp_line_buf, argv,22);
|
||||
argc = esp_console_split_argv(s_tmp_line_buf, argv, 22);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -73,118 +67,97 @@ int alloc_split_command_line(char * cmdline){
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
int alloc_split_parse_command_line(char * cmdline, void ** args){
|
||||
int alloc_split_parse_command_line(char* cmdline, void** args) {
|
||||
alloc_split_command_line(cmdline);
|
||||
return arg_parse(argc, argv,args);
|
||||
return arg_parse(argc, argv, args);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
TEST_CASE("Invalid GPIO detected", "[config][ui]")
|
||||
{
|
||||
char * cmdline = "test -i 55\n";
|
||||
void *argtable[] = {
|
||||
argint = arg_int1("i","int","<gpio>","GPIO number"),
|
||||
end = arg_end(6)
|
||||
};
|
||||
TEST_CASE("Invalid GPIO detected", "[config][ui]") {
|
||||
char* cmdline = "test -i 55\n";
|
||||
void* argtable[] = {argint = arg_int1("i", "int", "<gpio>", "GPIO number"), end = arg_end(6)};
|
||||
open_mem_stream_file();
|
||||
alloc_split_parse_command_line(cmdline, &argtable);
|
||||
int out_val = 0;
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(1,is_output_gpio(argtable[0], f, &out_val, true),"Invalid GPIO not detected");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(-1,out_val,"GPIO Should be set to -1");
|
||||
fflush (f);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("Invalid int gpio: [55] is not a GPIO\n",buf,"Invalid GPIO message wrong");
|
||||
close_flush_all(argtable,sizeof(argtable)/sizeof(argtable[0]),false);
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(1, is_output_gpio(argtable[0], f, &out_val, true), "Invalid GPIO not detected");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(-1, out_val, "GPIO Should be set to -1");
|
||||
fflush(f);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("Invalid int gpio: [55] is not a GPIO\n", buf, "Invalid GPIO message wrong");
|
||||
close_flush_all(argtable, sizeof(argtable) / sizeof(argtable[0]), false);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
TEST_CASE("Input Only GPIO detected", "[config][ui]")
|
||||
{
|
||||
char * cmdline = "test -i 35\n";
|
||||
void *argtable[] = {
|
||||
argint = arg_int1("i","int","<gpio>","GPIO number"),
|
||||
end = arg_end(6)
|
||||
};
|
||||
TEST_CASE("Input Only GPIO detected", "[config][ui]") {
|
||||
char* cmdline = "test -i 35\n";
|
||||
void* argtable[] = {argint = arg_int1("i", "int", "<gpio>", "GPIO number"), end = arg_end(6)};
|
||||
open_mem_stream_file();
|
||||
alloc_split_parse_command_line(cmdline, &argtable);
|
||||
int out_val = 0;
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(1,is_output_gpio(argtable[0], f, &out_val, true),"Input only GPIO not detected");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(-1,out_val,"GPIO Should be set to -1");
|
||||
fflush (f);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("Invalid int gpio: [35] has input capabilities only\n",buf,"Missing GPIO message wrong");
|
||||
close_flush_all(argtable,sizeof(argtable)/sizeof(argtable[0]),false);
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(1, is_output_gpio(argtable[0], f, &out_val, true), "Input only GPIO not detected");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(-1, out_val, "GPIO Should be set to -1");
|
||||
fflush(f);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("Invalid int gpio: [35] has input capabilities only\n", buf, "Missing GPIO message wrong");
|
||||
close_flush_all(argtable, sizeof(argtable) / sizeof(argtable[0]), false);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
TEST_CASE("Valid GPIO Processed", "[config][ui]")
|
||||
{
|
||||
char * cmdline = "test -i 33\n";
|
||||
void *argtable[] = {
|
||||
argint = arg_int1("i","int","<gpio>","GPIO number"),
|
||||
end = arg_end(6)
|
||||
};
|
||||
TEST_CASE("Valid GPIO Processed", "[config][ui]") {
|
||||
char* cmdline = "test -i 33\n";
|
||||
void* argtable[] = {argint = arg_int1("i", "int", "<gpio>", "GPIO number"), end = arg_end(6)};
|
||||
open_mem_stream_file();
|
||||
alloc_split_parse_command_line(cmdline, &argtable);
|
||||
int out_val = 0;
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(0,is_output_gpio(argtable[0], f, &out_val, true),"Valid GPIO not recognized");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(33,out_val,"GPIO Should be set to 33");
|
||||
fflush (f);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("",buf,"Valid GPIO shouldn't produce a message");
|
||||
close_flush_all(argtable,sizeof(argtable)/sizeof(argtable[0]),false);
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(0, is_output_gpio(argtable[0], f, &out_val, true), "Valid GPIO not recognized");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(33, out_val, "GPIO Should be set to 33");
|
||||
fflush(f);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("", buf, "Valid GPIO shouldn't produce a message");
|
||||
close_flush_all(argtable, sizeof(argtable) / sizeof(argtable[0]), false);
|
||||
}
|
||||
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
TEST_CASE("Missing mandatory GPIO detected", "[config][ui]")
|
||||
{
|
||||
char * cmdline = "test \n";
|
||||
void *argtable[] = {
|
||||
argint = arg_int1("i","int","<gpio>","GPIO number"),
|
||||
end = arg_end(6)
|
||||
};
|
||||
TEST_CASE("Missing mandatory GPIO detected", "[config][ui]") {
|
||||
char* cmdline = "test \n";
|
||||
void* argtable[] = {argint = arg_int1("i", "int", "<gpio>", "GPIO number"), end = arg_end(6)};
|
||||
open_mem_stream_file();
|
||||
alloc_split_parse_command_line(cmdline, &argtable);
|
||||
int out_val = 0;
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(1,is_output_gpio(argtable[0], f, &out_val, true),"Missing GPIO not detected");
|
||||
fflush (f);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("Missing: int\n",buf,"Missing GPIO parameter message wrong");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(-1,out_val,"GPIO Should be set to -1");
|
||||
close_flush_all(argtable,sizeof(argtable)/sizeof(argtable[0]),false);
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(1, is_output_gpio(argtable[0], f, &out_val, true), "Missing GPIO not detected");
|
||||
fflush(f);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("Missing: int\n", buf, "Missing GPIO parameter message wrong");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(-1, out_val, "GPIO Should be set to -1");
|
||||
close_flush_all(argtable, sizeof(argtable) / sizeof(argtable[0]), false);
|
||||
}
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
TEST_CASE("Missing mandatory parameter detected", "[config][ui]")
|
||||
{
|
||||
char * cmdline = "test \n";
|
||||
void *argtable[] = {
|
||||
argint = arg_int1("i","int","<gpio>","GPIO number"),
|
||||
end = arg_end(6)
|
||||
};
|
||||
TEST_CASE("Missing mandatory parameter detected", "[config][ui]") {
|
||||
char* cmdline = "test \n";
|
||||
void* argtable[] = {argint = arg_int1("i", "int", "<gpio>", "GPIO number"), end = arg_end(6)};
|
||||
open_mem_stream_file();
|
||||
alloc_split_parse_command_line(cmdline, &argtable);
|
||||
int out_val = 0;
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(1,is_output_gpio(argtable[0], f, &out_val, true),"Missing parameter not detected");
|
||||
fflush (f);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("Missing: int\n",buf,"Missing parameter message wrong");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(-1,out_val,"GPIO Should be set to -1");
|
||||
close_flush_all(argtable,sizeof(argtable)/sizeof(argtable[0]),false);
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(1, is_output_gpio(argtable[0], f, &out_val, true), "Missing parameter not detected");
|
||||
fflush(f);
|
||||
TEST_ASSERT_EQUAL_STRING_MESSAGE("Missing: int\n", buf, "Missing parameter message wrong");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(-1, out_val, "GPIO Should be set to -1");
|
||||
close_flush_all(argtable, sizeof(argtable) / sizeof(argtable[0]), false);
|
||||
}
|
||||
/****************************************************************************************
|
||||
*
|
||||
*/
|
||||
TEST_CASE("dac config command", "[config_cmd]")
|
||||
{
|
||||
TEST_CASE("dac config command", "[config_cmd]") {
|
||||
config_set_value(NVS_TYPE_STR, "dac_config", "");
|
||||
esp_err_t err=run_command("cfg-hw-dac\n");
|
||||
char * nvs_value = config_alloc_get_str("dac_config", NULL,NULL);
|
||||
esp_err_t err = run_command("cfg-hw-dac\n");
|
||||
char* nvs_value = config_alloc_get_str("dac_config", NULL, NULL);
|
||||
TEST_ASSERT_NOT_NULL(nvs_value);
|
||||
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK,err,"Running command failed");
|
||||
TEST_ASSERT_EQUAL_MESSAGE(ESP_OK, err, "Running command failed");
|
||||
free(nvs_value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user