remove all the files

This commit is contained in:
Morgan 'ARR\!' Allen 2020-10-12 21:38:35 -07:00
parent 639d7f9e80
commit abf4cfd8a4
9 changed files with 0 additions and 550 deletions

View File

@ -1,50 +0,0 @@
#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 *bandwidth;
struct arg_end *end;
lora32_cfg_t *lora;
} bw_args;
int set_bw(int argc, char **argv) {
if(argc == 1) {
printf(" > %d\n", bw_args.lora->bandwidth);
return 0;
}
int nerrors = arg_parse(argc, argv, (void **) &bw_args);
if (nerrors != 0) {
arg_print_errors(stderr, bw_args.end, argv[0]);
return 1;
}
lora32_set_bandwidth((lora32_cfg_t*)bw_args.lora, bw_args.bandwidth->ival[0]);
return 0;
}
void cmd_bw_register(lora32_cfg_t *lora) {
bw_args.bandwidth = arg_int0(NULL, NULL, "<bw>", "Bandwidth");
bw_args.end = arg_end(1);
bw_args.lora = lora;
const esp_console_cmd_t bw_cmd = {
.command = "bandwidth",
.help = "Set bandwidth",
.hint = NULL,
.func = &set_bw,
.argtable = &bw_args
};
ESP_ERROR_CHECK(esp_console_cmd_register(&bw_cmd));
}

View File

@ -1,44 +0,0 @@
#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

@ -1,33 +0,0 @@
#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_end *end;
lora32_cfg_t *lora;
} dump_args;
int dump(int argc, char **argv) {
lora32_dump_regs((lora32_cfg_t*)dump_args.lora);
return 0;
}
void cmd_dump_register(lora32_cfg_t *lora) {
dump_args.end = arg_end(1);
dump_args.lora = lora;
const esp_console_cmd_t dump_cmd = {
.command = "dump",
.help = "Dump SX127x registers",
.hint = NULL,
.func = &dump,
.argtable = &dump_args
};
ESP_ERROR_CHECK(esp_console_cmd_register(&dump_cmd));
}

View File

@ -1,71 +0,0 @@
#include <stdio.h>
#include <string.h>
#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"
#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]);
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;
}
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;
size_t hostname_len;
printf("nvs_handle: %d\n\n\n", lorcomm_cfg.nvs_handle);
esp_err_t err = nvs_get_str(lorcomm_cfg.nvs_handle, "hostname", NULL, &hostname_len);
if(err == ESP_OK && hostname_len > 0) {
printf("hostname_len: %d\n", hostname_len);
lorcomm_cfg.hostname = malloc(hostname_len);
nvs_get_str(lorcomm_cfg.nvs_handle, "hostname", lorcomm_cfg.hostname, &hostname_len);
printf("hostname: %s\n", lorcomm_cfg.hostname);
} else {
lorcomm_cfg.hostname = malloc(7);
memcpy(lorcomm_cfg.hostname, "lorcomm\0", 8);
}
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));
}

View File

@ -1,46 +0,0 @@
#include <stdio.h>
#include <string.h>
#include "esp_log.h"
#include "esp_console.h"
#include "esp_partition.h"
#include "esp_ota_ops.h"
#include "argtable3/argtable3.h"
#include "esp32-lora.h"
static struct {
struct arg_end *end;
lora32_cfg_t *lora;
} ota_args;
int ota(int argc, char **argv) {
esp_partition_t *factory = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, "factory");
if(factory != NULL) {
ESP_LOGI("cmd_ota", "found partition: addr: 0x%02X size: %d", factory->address, factory->size);
esp_ota_set_boot_partition(factory);
esp_restart();
} else {
ESP_LOGE("cmd_ota", "failed to find factory partition");
}
return 0;
}
void cmd_ota_register(lora32_cfg_t *lora) {
ota_args.end = arg_end(1);
ota_args.lora = lora;
const esp_console_cmd_t ota_cmd = {
.command = "ota",
.help = "Reboots into WiFi OTA mode",
.hint = NULL,
.func = &ota,
.argtable = &ota_args
};
ESP_ERROR_CHECK(esp_console_cmd_register(&ota_cmd));
}

View File

@ -1,45 +0,0 @@
#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;
} preamble_args;
int set_preamble(int argc, char **argv) {
int nerrors = arg_parse(argc, argv, (void **) &preamble_args);
if (nerrors != 0) {
arg_print_errors(stderr, preamble_args.end, argv[0]);
return 1;
}
//lora32_set_preamble((lora32_cfg_t*)preamble_args.lora, preamble_args.codingrate->ival[0]);
return 0;
}
void cmd_preamble_register(lora32_cfg_t *lora) {
preamble_args.codingrate = arg_int0(NULL, NULL, "<preamble>", "Preamble");
preamble_args.end = arg_end(1);
preamble_args.lora = lora;
const esp_console_cmd_t preamble_cmd = {
.command = "preamble",
.help = "Set preamble",
.hint = NULL,
.func = &set_preamble,
.argtable = &preamble_args
};
ESP_ERROR_CHECK(esp_console_cmd_register(&preamble_cmd));
}

View File

@ -1,45 +0,0 @@
#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 *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;
}
lorcomm_send_message((lora32_cfg_t*)send_args.lora, 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

@ -1,43 +0,0 @@
#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_int *spreadfactor;
struct arg_end *end;
lora32_cfg_t *lora;
} sf_args;
int set_sf(int argc, char **argv) {
int nerrors = arg_parse(argc, argv, (void **) &sf_args);
if (nerrors != 0) {
arg_print_errors(stderr, sf_args.end, argv[0]);
return 1;
}
lora32_set_spreadfactor((lora32_cfg_t*)sf_args.lora, sf_args.spreadfactor->ival[0]);
return 0;
}
void cmd_sf_register(lora32_cfg_t *lora) {
sf_args.spreadfactor = arg_int0(NULL, NULL, "<sf>", "Spreadfactor");
sf_args.end = arg_end(1);
sf_args.lora = lora;
const esp_console_cmd_t sf_cmd = {
.command = "spreadfactor",
.help = "Set spreadfactor",
.hint = NULL,
.func = &set_sf,
.argtable = &sf_args
};
ESP_ERROR_CHECK(esp_console_cmd_register(&sf_cmd));
}

View File

@ -1,173 +0,0 @@
#include <string.h>
#include "esp_log.h"
#include "esp32-lora.h"
#include "lorcomm.h"
#include "main.h"
#define TAG "lorcomm"
#define MSG_ID_TRACK (16)
typedef struct {
uint8_t mac[3];
uint8_t ids[MSG_ID_TRACK];
} id_cache_t;
uint8_t mac[6] = {0};
static uint8_t msg_id = 1;
id_cache_t id_cache[MSG_ID_TRACK] = { 0 };
uint8_t acmp(uint8_t a[], uint8_t b[], uint8_t len) {
for(uint8_t i = 0; i < len; i++) {
if(a[i] != b[i]) return 0;
}
return 1;
}
void lorcomm_handle_receive(uint8_t size) {
printf("packet size: %d\n", size);
uint8_t *buf = malloc(size);
lora_packet *packet = malloc(sizeof(lora_packet));
// get data from the lora driver
lora32_read_data(&lora, buf);
// copy buffer onto message headers
memcpy(packet, buf, LORA_PACKET_HEADER_SIZE);
ESP_LOGI(TAG, "[%02X:%02X:%02X] id: %02d type: %02X", packet->src[0], packet->src[1], packet->src[2], packet->id, packet->type);
for(uint8_t i = 0; i < MSG_ID_TRACK; i++) {
if(id_cache[i].mac[0]+id_cache[i].mac[1]+id_cache[i].mac[2] == 0) {
memcpy(id_cache[i].mac, &packet->src, 3);
// this is assumed to be empty
id_cache[i].ids[0] = packet->id;
ESP_LOGI(TAG, "adding new tracking entity");
break;
}
for(uint8_t j = 0; j < MSG_ID_TRACK; j++) {
if(id_cache[i].ids[j] == packet->id) {
ESP_LOGI(TAG, "already seen packet, not relaying");
goto receive_cleanup;
} else if(id_cache[i].ids[j] == 0) {
ESP_LOGI(TAG, "adding id to tracking");
// add id to array
id_cache[i].ids[i] = packet->id;
// set next in queue to zero, rolling over as needed
id_cache[i].ids[(i + 1) % MSG_ID_TRACK] = 0;
goto break_outer;
}
}
}
break_outer:
// update local msg id to incoming +1
// this will give a rolling local area id
if(packet->id < msg_id) {
msg_id = packet->id + 1;
// 0 is an invalid id
if(msg_id == 0) msg_id = 1;
}
if(memcmp(packet->src, &mac[3], 3) == 0) {
ESP_LOGI(TAG, "received own packet, done");
goto receive_cleanup;
}
if(packet->type == TEXT) {
lora_msg *msg = malloc(sizeof(lora_msg));
memcpy(msg, buf + LORA_PACKET_HEADER_SIZE, LORA_MSG_HEADER_SIZE);
// allocate memory for message payload
msg->msg = malloc(msg->length);
memcpy(msg->msg, buf + LORA_PACKET_HEADER_SIZE + LORA_MSG_HEADER_SIZE, msg->length);
// if the msg doesnt end in NULL it's probably already corrupt
// just go ahead and terminate it
//if(msg->msg[msg->length] != '\0')
//msg->msg[msg->length] = '\0';
ESP_LOGI(TAG, "msg (len: %d): %s", msg->length, msg->msg);
free(msg->msg);
msg->msg = NULL;
free(msg);
} else if(packet->type == ROUTING) {
// future stuff
} else {
ESP_LOGW(TAG, "Unknown packet type: %02X", packet->type);
ESP_LOGW(TAG, "msg: %s", (char*)packet);
goto receive_cleanup;
}
vTaskDelay(3000/portTICK_PERIOD_MS);
ESP_LOGI(TAG, "relaying message");
lora32_send(&lora, buf, size);
receive_cleanup:
free(buf);
lora32_enable_continuous_rx(&lora);
}
void lorcomm_send_message(lora32_cfg_t *lora, char *text) {
// allocate and zero out packet and msg payload
uint8_t len = strlen(text) + 1;
lora_packet packet = { 0 };
lora_msg msg = { 0 };
// set packet tracking id
packet.id = msg_id;
msg_id = msg_id + 1;
if(msg_id == 0) msg_id = 1;
// set src and dest (broadcast) addresses
memcpy(packet.src, &mac[3], 3);
memset(packet.dst, 0xFF, 3);
// indicate message payload
packet.type = TEXT;
packet.payload = malloc(LORA_PACKET_HEADER_SIZE + len);
msg.length = len;
msg.msg = malloc(LORA_MSG_HEADER_SIZE + len);
memcpy(msg.msg, text, len);
uint8_t buf_len = LORA_PACKET_HEADER_SIZE + LORA_MSG_HEADER_SIZE + len;
uint8_t *send_buf = malloc(buf_len);
ESP_LOGI(TAG, "packet length: %d", buf_len);
// set src, dst, length
memcpy(send_buf, (uint8_t*)&packet, LORA_PACKET_HEADER_SIZE);
memcpy((uint8_t*)(send_buf + LORA_PACKET_HEADER_SIZE), (void*)&msg, LORA_MSG_HEADER_SIZE);
memcpy((uint8_t*)(send_buf + LORA_PACKET_HEADER_SIZE + LORA_MSG_HEADER_SIZE), (void*)msg.msg, len);
ESP_LOGI(TAG, "id: %02d", packet.id);
ESP_LOGI(TAG, "src: [%02X:%02X:%02X]", packet.src[0], packet.src[1], packet.src[2]);
ESP_LOGI(TAG, "dst: [%02X:%02X:%02X]", packet.dst[0], packet.dst[1], packet.dst[2]);
lora32_send(lora, send_buf, buf_len);
free(packet.payload);
packet.payload = NULL;
free(msg.msg);
msg.msg = NULL;
free(send_buf);
}