add hostname command

This commit is contained in:
Morgan 'ARR\!' Allen 2020-04-22 23:04:48 -07:00
parent 319e797132
commit f1292d1605

49
main/cmd_hostname.c Normal file
View file

@ -0,0 +1,49 @@
#include <stdio.h>
#include <string.h>
#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));
}