add datarate calculation, could probably be useful. right?

This commit is contained in:
Morgan 'ARR\!' Allen 2020-03-02 21:13:17 -08:00
parent d987072745
commit a062ed4dcb
3 changed files with 14 additions and 0 deletions

View File

@ -81,6 +81,9 @@ Sets LoRa Spread Factor.
Accepts `6`-`12`.
### `double lora32_calc_datarate(lora32_cfg_t *lora);`
Returns data rate in Bits Per Second (bps) for given `lora32_cfg_t` configuration.
### `void lora32_dump_regs(lora32_cfg_t *lora)`
Dumps all registers from SX1276.

View File

@ -126,6 +126,7 @@ lora32_cfg_t lora32_create();
uint8_t lora32_init(lora32_cfg_t *config);
uint8_t lora32_data_available(lora32_cfg_t *lora);
double lora32_calc_datarate(lora32_cfg_t *lora);
void lora32_dump_regs(lora32_cfg_t *lora);
void lora32_enable_continuous_rx(lora32_cfg_t *lora);
void lora32_enable_cad(lora32_cfg_t *lora);

View File

@ -1,4 +1,5 @@
#include <string.h>
#include <math.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
@ -97,6 +98,15 @@ void lora32_write_reg(lora32_cfg_t *lora, uint8_t address, uint8_t value) {
ESP_ERROR_CHECK(spi_device_transmit(spi, &t));
};
double lora32_calc_datarate(lora32_cfg_t *lora) {
double cr = (4.0 / (long)lora->codingRate);
double sf = pow(2, lora->spreadingFactor);
double c2 = sf / bandwidths[lora->bandwidth];
ESP_LOGI(TAG, "codingRate: %d cr: %f sf: %f c2: %f", lora->codingRate, cr, sf, c2);
return lora->spreadingFactor * cr / c2 * 1000;
}
void lora23_set_explicit_header(lora32_cfg_t *lora) {
lora->implicitHeader = false;