This commit is contained in:
Morgan 'ARR\!' Allen 2020-03-03 17:38:04 -08:00
parent d5b39501fb
commit 7e982fbbb7
5 changed files with 61 additions and 11 deletions

View file

@ -8,6 +8,7 @@ extern "C" {
void cmd_sf_register();
void cmd_cr_register();
void cmd_preamble_register();
void cmd_send_register();
#ifdef __cplusplus
}

View file

@ -4,6 +4,7 @@ set(COMPONENT_SRCS "\
cmd_sf.c\
cmd_cr.c\
cmd_preamble.c\
cmd_send.c\
")
set(COMPONENT_ADD_INCLUDEDIRS ". ../include")

43
main/cmd_send.c Normal file
View file

@ -0,0 +1,43 @@
#include <stdio.h>
#include <string.h>
#include "esp_log.h"
#include "esp_console.h"
#include "argtable3/argtable3.h"
#include "esp32-lora.h"
static struct {
struct arg_str *msg;
struct arg_end *end;
lora32_cfg_t *lora;
} send_args;
int send(int argc, char **argv) {
int nerrors = arg_parse(argc, argv, (void **) &send_args);
if (nerrors != 0) {
arg_print_errors(stderr, send_args.end, argv[0]);
return 1;
}
lora32_send((lora32_cfg_t*)send_args.lora, send_args.msg->sval[0], strlen(send_args.msg->sval[0]));
return 0;
}
void cmd_send_register(lora32_cfg_t *lora) {
send_args.msg = arg_strn(NULL, NULL, "\"message\"", 1, 10, "message");
send_args.end = arg_end(1);
send_args.lora = lora;
const esp_console_cmd_t send_cmd = {
.command = "send",
.help = "Send message",
.hint = NULL,
.func = &send,
.argtable = &send_args
};
ESP_ERROR_CHECK(esp_console_cmd_register(&send_cmd));
}

View file

@ -51,6 +51,7 @@ void console_task(void *args) {
cmd_sf_register(args);
cmd_cr_register(args);
cmd_preamble_register(args);
cmd_send_register(args);
const char* prompt = LOG_COLOR_I "lorcomm> " LOG_RESET_COLOR;

View file

@ -51,9 +51,8 @@ static lora32_cfg_t lora;
uint8_t mac[6] = {0};
static void handle_lora_txdone() {
ESP_LOGI(TAG, "txdone: enabling single RX");
ESP_LOGI(TAG, "txdone: enabling continuous RX");
vTaskDelay(100/portTICK_PERIOD_MS);
lora32_enable_continuous_rx(&lora);
}
@ -63,7 +62,8 @@ void handle_lora_caddone(bool detected) {
if(detected) {
lora32_enable_cad(&lora);
} else {
ESP_LOGI(TAG, "txdone: enabling single RX");
ESP_LOGI(TAG, "candone (no channel activity): enabling continuous RX");
lora32_enable_continuous_rx(&lora);
}
}
@ -101,8 +101,16 @@ static void handle_lora_receive(uint8_t size) {
msg->msg = NULL;
free(msg);
} else if(packet->type == ROUTING) {
// future stuff
} else if((char*)packet[0] >= 32 && (char*)packet[0] <= 126) {
// mostly for dumping purposes
((char*)packet)[size] = '\0';
ESP_LOGI(TAG, "%s", (char*)packet);
goto receive_cleanup;
} else {
ESP_LOGW(TAG, "Unknown packet type: %02X", packet->type);
goto receive_cleanup;
}
@ -158,7 +166,7 @@ void app_main(void) {
esp_efuse_mac_get_default((uint8_t*)&mac);
ESP_LOGI(TAG, "MAC: [%02X:%02X:%02X:%02X:%02X:%02X]", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
lora.bandwidth = bandwidths[F866];
lora.bandwidth = B250;
lora.codingRate = DEFAULT_CR;
lora.dio0 = CONFIG_LORA32_DIO0_PIN;
lora.implicitHeader = false;
@ -177,15 +185,11 @@ void app_main(void) {
lora32_init(&lora);
lora32_dump_regs(&lora);
ESP_LOGI(TAG, "sizeof(lora_msg): %d", sizeof(lora_msg));
send_message(&lora, "an even, super duuper, very much, longer message. and some\0");
xTaskCreate(console_task, "console", 4048, &lora, tskIDLE_PRIORITY + 3, NULL);
printf("%d %f\n", portTICK_PERIOD_MS, (float)(1 / portTICK_PERIOD_MS));
send_message(&lora, "hi\0");
double dr = lora32_calc_datarate(&lora);
ESP_LOGI(TAG, "data rate: %fbps", dr);
while(1) {
vTaskDelay(100 / portTICK_PERIOD_MS);