Skip to content

Commit eb978f1

Browse files
author
Scott Powell
committed
Merge branch 'LR1110-workaround' into dev
2 parents 910ec59 + 8c80c10 commit eb978f1

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/helpers/CustomLR1110.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,35 @@ class CustomLR1110 : public LR1110 {
99
public:
1010
CustomLR1110(Module *mod) : LR1110(mod) { }
1111

12+
RadioLibTime_t getTimeOnAir(size_t len) override {
13+
uint32_t symbolLength_us = ((uint32_t)(1000 * 10) << this->spreadingFactor) / (this->bandwidthKhz * 10) ;
14+
uint8_t sfCoeff1_x4 = 17; // (4.25 * 4)
15+
uint8_t sfCoeff2 = 8;
16+
if(this->spreadingFactor == 5 || this->spreadingFactor == 6) {
17+
sfCoeff1_x4 = 25; // 6.25 * 4
18+
sfCoeff2 = 0;
19+
}
20+
uint8_t sfDivisor = 4*this->spreadingFactor;
21+
if(symbolLength_us >= 16000) {
22+
sfDivisor = 4*(this->spreadingFactor - 2);
23+
}
24+
const int8_t bitsPerCrc = 16;
25+
const int8_t N_symbol_header = this->headerType == RADIOLIB_SX126X_LORA_HEADER_EXPLICIT ? 20 : 0;
26+
27+
// numerator of equation in section 6.1.4 of SX1268 datasheet v1.1 (might not actually be bitcount, but it has len * 8)
28+
int16_t bitCount = (int16_t) 8 * len + this->crcTypeLoRa * bitsPerCrc - 4 * this->spreadingFactor + sfCoeff2 + N_symbol_header;
29+
if(bitCount < 0) {
30+
bitCount = 0;
31+
}
32+
// add (sfDivisor) - 1 to the numerator to give integer CEIL(...)
33+
uint16_t nPreCodedSymbols = (bitCount + (sfDivisor - 1)) / (sfDivisor);
34+
35+
// preamble can be 65k, therefore nSymbol_x4 needs to be 32 bit
36+
uint32_t nSymbol_x4 = (this->preambleLengthLoRa + 8) * 4 + sfCoeff1_x4 + nPreCodedSymbols * (this->codingRate + 4) * 4;
37+
38+
return((symbolLength_us * nSymbol_x4) / 4);
39+
}
40+
1241
bool isReceiving() {
1342
uint16_t irq = getIrqStatus();
1443
bool detected = ((irq & LR1110_IRQ_HEADER_VALID) || (irq & LR1110_IRQ_HAS_PREAMBLE));

0 commit comments

Comments
 (0)