Update ESP32 platform and LoRa batching

This commit is contained in:
2026-02-01 17:03:08 +01:00
parent 16c65744e3
commit 430b0d7054
5 changed files with 213 additions and 92 deletions

View File

@@ -1,6 +1,7 @@
#include "lora_transport.h"
#include <LoRa.h>
#include <SPI.h>
#include <math.h>
static uint16_t crc16_ccitt(const uint8_t *data, size_t len) {
uint16_t crc = 0xFFFF;
@@ -106,3 +107,28 @@ bool lora_receive(LoraPacket &pkt, uint32_t timeout_ms) {
void lora_sleep() {
LoRa.sleep();
}
uint32_t lora_airtime_ms(size_t packet_len) {
if (packet_len == 0) {
return 0;
}
const double bw = static_cast<double>(LORA_BANDWIDTH);
const double sf = static_cast<double>(LORA_SPREADING_FACTOR);
const double cr = static_cast<double>(LORA_CODING_RATE - 4); // coding rate denominator: 4/(4+cr)
const double tsym = (1 << LORA_SPREADING_FACTOR) / bw;
const double t_preamble = (static_cast<double>(LORA_PREAMBLE_LEN) + 4.25) * tsym;
const bool low_data_rate_opt = (LORA_SPREADING_FACTOR >= 11) && (LORA_BANDWIDTH <= 125000);
const double de = low_data_rate_opt ? 1.0 : 0.0;
const double ih = 0.0;
const double crc = 1.0;
const double payload_symb_nb = 8.0 + max(
ceil((8.0 * packet_len - 4.0 * sf + 28.0 + 16.0 * crc - 20.0 * ih) / (4.0 * (sf - 2.0 * de))) * (cr + 4.0),
0.0);
const double t_payload = payload_symb_nb * tsym;
const double t_packet = t_preamble + t_payload;
return static_cast<uint32_t>(ceil(t_packet * 1000.0));
}