diff --git a/main/cmd_hostname.c b/main/cmd_hostname.c new file mode 100644 index 0000000..5edf802 --- /dev/null +++ b/main/cmd_hostname.c @@ -0,0 +1,49 @@ +#include +#include +#include "esp_log.h" +#include "esp_console.h" +#include "argtable3/argtable3.h" + +#include "esp32-lora.h" +#include "lorcomm.h" +#include "main.h" + +static struct { + struct arg_str *hostname; + struct arg_end *end; + lora32_cfg_t *lora; +} hostname_args; + +int hostname(int argc, char **argv) { + int nerrors = arg_parse(argc, argv, (void **)&hostname_args); + + if (nerrors != 0) { + arg_print_errors(stderr, hostname_args.end, argv[0]); + + return 1; + } + + if(argc == 1) { + printf(" > %s\n", lorcomm_cfg.hostname); + } else { + asprintf(&lorcomm_cfg.hostname, "%s", hostname_args.hostname->sval[0]); + } + + return 0; +} + +void cmd_hostname_register(lora32_cfg_t *lora) { + hostname_args.hostname = arg_strn(NULL, NULL, "\"hostname\"", 0, 1, "hostname"); + hostname_args.end = arg_end(1); + hostname_args.lora = lora; + + const esp_console_cmd_t hostname_cmd = { + .command = "hostname", + .help = "Set/Get Hostname", + .hint = NULL, + .func = &hostname, + .argtable = &hostname_args + }; + + ESP_ERROR_CHECK(esp_console_cmd_register(&hostname_cmd)); +}