move commands to own files

This commit is contained in:
Morgan 'ARR\!' Allen 2020-02-29 11:56:40 -08:00
parent 5de07ad8ad
commit b9c865eaed
5 changed files with 50 additions and 4 deletions

View file

@ -5,7 +5,8 @@
extern "C" { extern "C" {
#endif #endif
void cmd_lora_register(); void cmd_sf_register();
void cmd_cr_register();
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,4 +1,4 @@
set(COMPONENT_SRCS "main.c console.c cmd_lora.c") set(COMPONENT_SRCS "main.c console.c cmd_sf.c cmd_cr.c")
set(COMPONENT_ADD_INCLUDEDIRS ". ../include") set(COMPONENT_ADD_INCLUDEDIRS ". ../include")
register_component() register_component()

44
main/cmd_cr.c Normal file
View file

@ -0,0 +1,44 @@
#include <stdio.h>
#include <string.h>
#include "esp_log.h"
#include "esp_console.h"
#include "argtable3/argtable3.h"
#include "cmd_lora.h"
#include "esp32-lora.h"
static struct {
struct arg_int *codingrate;
struct arg_end *end;
lora32_cfg_t *lora;
} cr_args;
int set_cr(int argc, char **argv) {
int nerrors = arg_parse(argc, argv, (void **) &cr_args);
if (nerrors != 0) {
arg_print_errors(stderr, cr_args.end, argv[0]);
return 1;
}
lora32_set_coding_rate((lora32_cfg_t*)cr_args.lora, cr_args.codingrate->ival[0]);
return 0;
}
void cmd_cr_register(lora32_cfg_t *lora) {
cr_args.codingrate = arg_int0(NULL, NULL, "<cr>", "Coding Rate");
cr_args.end = arg_end(1);
cr_args.lora = lora;
const esp_console_cmd_t cr_cmd = {
.command = "codingrate",
.help = "Set codingrate",
.hint = NULL,
.func = &set_cr,
.argtable = &cr_args
};
ESP_ERROR_CHECK(esp_console_cmd_register(&cr_cmd));
}

View file

@ -26,7 +26,7 @@ int set_sf(int argc, char **argv) {
return 0; return 0;
} }
void cmd_lora_register(lora32_cfg_t *lora) { void cmd_sf_register(lora32_cfg_t *lora) {
sf_args.spreadfactor = arg_int0(NULL, NULL, "<sf>", "Spreadfactor"); sf_args.spreadfactor = arg_int0(NULL, NULL, "<sf>", "Spreadfactor");
sf_args.end = arg_end(1); sf_args.end = arg_end(1);
sf_args.lora = lora; sf_args.lora = lora;

View file

@ -48,7 +48,8 @@ void console_task(void *args) {
linenoiseSetHintsCallback((linenoiseHintsCallback*) &esp_console_get_hint); linenoiseSetHintsCallback((linenoiseHintsCallback*) &esp_console_get_hint);
linenoiseHistorySetMaxLen(100); linenoiseHistorySetMaxLen(100);
cmd_lora_register(args); cmd_sf_register(args);
cmd_cr_register(args);
const char* prompt = LOG_COLOR_I "lorcomm> " LOG_RESET_COLOR; const char* prompt = LOG_COLOR_I "lorcomm> " LOG_RESET_COLOR;