WIP hostname cmd and dynamic prompt
This commit is contained in:
parent
f1292d1605
commit
c294d7944b
6 changed files with 30 additions and 7 deletions
|
@ -11,6 +11,7 @@ void cmd_sf_register();
|
|||
void cmd_preamble_register();
|
||||
void cmd_send_register();
|
||||
void cmd_dump_register();
|
||||
void cmd_hostname_register();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -9,8 +9,10 @@ extern uint8_t mac[6];
|
|||
extern lora32_cfg_t lora;
|
||||
|
||||
struct lorcomm_cfg {
|
||||
char *hostname;
|
||||
|
||||
lora32_cfg_t *lora;
|
||||
nvs_handle_t *nvs_handle;
|
||||
nvs_handle_t nvs_handle;
|
||||
} lorcomm_cfg;
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ set(COMPONENT_SRCS "\
|
|||
cmd_preamble.c\
|
||||
cmd_send.c\
|
||||
cmd_dump.c\
|
||||
cmd_hostname.c\
|
||||
")
|
||||
set(COMPONENT_ADD_INCLUDEDIRS ". ../include")
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include "esp_log.h"
|
||||
#include "esp_console.h"
|
||||
#include "argtable3/argtable3.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "esp_vfs_dev.h"
|
||||
|
||||
#include "esp32-lora.h"
|
||||
#include "lorcomm.h"
|
||||
|
@ -27,6 +29,10 @@ int hostname(int argc, char **argv) {
|
|||
printf(" > %s\n", lorcomm_cfg.hostname);
|
||||
} else {
|
||||
asprintf(&lorcomm_cfg.hostname, "%s", hostname_args.hostname->sval[0]);
|
||||
|
||||
nvs_set_str(lorcomm_cfg.nvs_handle, "hostname", hostname_args.hostname->sval[0]);
|
||||
esp_err_t err = nvs_commit(lorcomm_cfg.nvs_handle);
|
||||
printf((err != ESP_OK) ? "Failed!\n" : "Done\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -37,6 +43,17 @@ void cmd_hostname_register(lora32_cfg_t *lora) {
|
|||
hostname_args.end = arg_end(1);
|
||||
hostname_args.lora = lora;
|
||||
|
||||
/*
|
||||
size_t hostname_len;
|
||||
|
||||
printf("nvs_handle: %d\n\n\n", lorcomm_cfg.nvs_handle);
|
||||
nvs_get_str(lorcomm_cfg.nvs_handle, "hostname", NULL, &hostname_len);
|
||||
nvs_get_str(lorcomm_cfg.nvs_handle, "hostname", lorcomm_cfg.hostname, &hostname_len);
|
||||
printf("hostname: %s\n", lorcomm_cfg.hostname);
|
||||
*/
|
||||
|
||||
lorcomm_cfg.hostname = "lorcomm";
|
||||
|
||||
const esp_console_cmd_t hostname_cmd = {
|
||||
.command = "hostname",
|
||||
.help = "Set/Get Hostname",
|
||||
|
|
|
@ -56,13 +56,17 @@ void console_task(void *args) {
|
|||
cmd_preamble_register(lorcomm_cfg.lora);
|
||||
cmd_send_register(lorcomm_cfg.lora);
|
||||
cmd_dump_register(lorcomm_cfg.lora);
|
||||
cmd_hostname_register(lorcomm_cfg.lora);
|
||||
|
||||
char *prompt;
|
||||
|
||||
while(true) {
|
||||
asprintf(&prompt, LOG_COLOR_I "%s > " LOG_RESET_COLOR, "lorcomm");
|
||||
asprintf(&prompt, LOG_COLOR_I "%s > " LOG_RESET_COLOR, lorcomm_cfg.hostname == NULL ? "lorcomm" : lorcomm_cfg.hostname);
|
||||
|
||||
char* line = linenoise(prompt);
|
||||
|
||||
free(prompt);
|
||||
|
||||
if (line == NULL) { /* Ignore empty lines */
|
||||
continue;
|
||||
}
|
||||
|
@ -84,6 +88,3 @@ void console_task(void *args) {
|
|||
linenoiseFree(line);
|
||||
}
|
||||
}
|
||||
|
||||
void console_init() {
|
||||
}
|
||||
|
|
|
@ -101,9 +101,10 @@ void app_main(void) {
|
|||
if (err != ESP_OK) {
|
||||
printf("Error (%s) opening NVS handle!\n", esp_err_to_name(err));
|
||||
|
||||
lorcomm_cfg.nvs_handle = NULL;
|
||||
//lorcomm_cfg.nvs_handle = NULL;
|
||||
} else {
|
||||
lorcomm_cfg.nvs_handle = &nvs_handle;
|
||||
lorcomm_cfg.nvs_handle = nvs_handle;
|
||||
ESP_LOGI(TAG, "nvs_handle: %d", nvs_handle);
|
||||
}
|
||||
|
||||
esp_efuse_mac_get_default((uint8_t*)&mac);
|
||||
|
|
Loading…
Reference in a new issue