LR's corrected calculation override (instead of SX) and minor changes according to radiolib's wiki

This commit is contained in:
liquidraver
2025-07-04 16:40:19 +02:00
parent ff9699c071
commit fa481e832b
2 changed files with 52 additions and 27 deletions

View File

@@ -10,34 +10,58 @@ class CustomLR1110 : public LR1110 {
CustomLR1110(Module *mod) : LR1110(mod) { } CustomLR1110(Module *mod) : LR1110(mod) { }
RadioLibTime_t getTimeOnAir(size_t len) override { RadioLibTime_t getTimeOnAir(size_t len) override {
uint32_t symbolLength_us = ((uint32_t)(1000 * 10) << this->spreadingFactor) / (this->bandwidthKhz * 10) ; // calculate number of symbols
uint8_t sfCoeff1_x4 = 17; // (4.25 * 4) float N_symbol = 0;
uint8_t sfCoeff2 = 8; if(this->codingRate <= RADIOLIB_LR11X0_LORA_CR_4_8_SHORT) {
if(this->spreadingFactor == 5 || this->spreadingFactor == 6) { // legacy coding rate - nice and simple
sfCoeff1_x4 = 25; // 6.25 * 4 // get SF coefficients
sfCoeff2 = 0; float coeff1 = 0;
} int16_t coeff2 = 0;
uint8_t sfDivisor = 4*this->spreadingFactor; int16_t coeff3 = 0;
if(symbolLength_us >= 16000) { if(this->spreadingFactor < 7) {
sfDivisor = 4*(this->spreadingFactor - 2); // SF5, SF6
} coeff1 = 6.25;
const int8_t bitsPerCrc = 16; coeff2 = 4*this->spreadingFactor;
const int8_t N_symbol_header = this->headerType == RADIOLIB_SX126X_LORA_HEADER_EXPLICIT ? 20 : 0; coeff3 = 4*this->spreadingFactor;
} else if(this->spreadingFactor < 11) {
// numerator of equation in section 6.1.4 of SX1268 datasheet v1.1 (might not actually be bitcount, but it has len * 8) // SF7. SF8, SF9, SF10
int16_t bitCount = (int16_t) 8 * len + this->crcTypeLoRa * bitsPerCrc - 4 * this->spreadingFactor + sfCoeff2 + N_symbol_header; coeff1 = 4.25;
if(bitCount < 0) { coeff2 = 4*this->spreadingFactor + 8;
bitCount = 0; coeff3 = 4*this->spreadingFactor;
} } else {
// add (sfDivisor) - 1 to the numerator to give integer CEIL(...) // SF11, SF12
uint16_t nPreCodedSymbols = (bitCount + (sfDivisor - 1)) / (sfDivisor); coeff1 = 4.25;
coeff2 = 4*this->spreadingFactor + 8;
// preamble can be 65k, therefore nSymbol_x4 needs to be 32 bit coeff3 = 4*(this->spreadingFactor - 2);
uint32_t nSymbol_x4 = (this->preambleLengthLoRa + 8) * 4 + sfCoeff1_x4 + nPreCodedSymbols * (this->codingRate + 4) * 4;
return((symbolLength_us * nSymbol_x4) / 4);
} }
// get CRC length
int16_t N_bitCRC = 16;
if(this->crcTypeLoRa == RADIOLIB_LR11X0_LORA_CRC_DISABLED) {
N_bitCRC = 0;
}
// get header length
int16_t N_symbolHeader = 20;
if(this->headerType == RADIOLIB_LR11X0_LORA_HEADER_IMPLICIT) {
N_symbolHeader = 0;
}
// calculate number of LoRa preamble symbols - NO! Lora preamble is already in symbols
// uint32_t N_symbolPreamble = (this->preambleLengthLoRa & 0x0F) * (uint32_t(1) << ((this->preambleLengthLoRa & 0xF0) >> 4));
// calculate the number of symbols - nope
// N_symbol = (float)N_symbolPreamble + coeff1 + 8.0f + ceilf((float)RADIOLIB_MAX((int16_t)(8 * len + N_bitCRC - coeff2 + N_symbolHeader), (int16_t)0) / (float)coeff3) * (float)(this->codingRate + 4);
// calculate the number of symbols - using only preamblelora because it's already in symbols
N_symbol = (float)preambleLengthLoRa + coeff1 + 8.0f + ceilf((float)RADIOLIB_MAX((int16_t)(8 * len + N_bitCRC - coeff2 + N_symbolHeader), (int16_t)0) / (float)coeff3) * (float)(this->codingRate + 4);
} else {
// long interleaving - not needed for this modem
}
// get time-on-air in us
return(((uint32_t(1) << this->spreadingFactor) / this->bandwidthKhz) * N_symbol * 1000.0f);
}
bool isReceiving() { bool isReceiving() {
uint16_t irq = getIrqStatus(); uint16_t irq = getIrqStatus();
bool detected = ((irq & LR1110_IRQ_HEADER_VALID) || (irq & LR1110_IRQ_HAS_PREAMBLE)); bool detected = ((irq & LR1110_IRQ_HEADER_VALID) || (irq & LR1110_IRQ_HAS_PREAMBLE));

View File

@@ -61,7 +61,8 @@ bool radio_init() {
return false; // fail return false; // fail
} }
radio.setCRC(1); radio.setCRC(2);
radio.explicitHeader();
#ifdef RF_SWITCH_TABLE #ifdef RF_SWITCH_TABLE
radio.setRfSwitchTable(rfswitch_dios, rfswitch_table); radio.setRfSwitchTable(rfswitch_dios, rfswitch_table);