@@ -10,34 +10,58 @@ class CustomLR1110 : public LR1110 {
1010 CustomLR1110 (Module *mod) : LR1110(mod) { }
1111
1212 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 );
13+ // calculate number of symbols
14+ float N_symbol = 0 ;
15+ if (this ->codingRate <= RADIOLIB_LR11X0_LORA_CR_4_8_SHORT) {
16+ // legacy coding rate - nice and simple
17+ // get SF coefficients
18+ float coeff1 = 0 ;
19+ int16_t coeff2 = 0 ;
20+ int16_t coeff3 = 0 ;
21+ if (this ->spreadingFactor < 7 ) {
22+ // SF5, SF6
23+ coeff1 = 6.25 ;
24+ coeff2 = 4 *this ->spreadingFactor ;
25+ coeff3 = 4 *this ->spreadingFactor ;
26+ } else if (this ->spreadingFactor < 11 ) {
27+ // SF7. SF8, SF9, SF10
28+ coeff1 = 4.25 ;
29+ coeff2 = 4 *this ->spreadingFactor + 8 ;
30+ coeff3 = 4 *this ->spreadingFactor ;
31+ } else {
32+ // SF11, SF12
33+ coeff1 = 4.25 ;
34+ coeff2 = 4 *this ->spreadingFactor + 8 ;
35+ coeff3 = 4 *(this ->spreadingFactor - 2 );
3936 }
4037
38+ // get CRC length
39+ int16_t N_bitCRC = 16 ;
40+ if (this ->crcTypeLoRa == RADIOLIB_LR11X0_LORA_CRC_DISABLED) {
41+ N_bitCRC = 0 ;
42+ }
43+
44+ // get header length
45+ int16_t N_symbolHeader = 20 ;
46+ if (this ->headerType == RADIOLIB_LR11X0_LORA_HEADER_IMPLICIT) {
47+ N_symbolHeader = 0 ;
48+ }
49+
50+ // calculate number of LoRa preamble symbols - NO! Lora preamble is already in symbols
51+ // uint32_t N_symbolPreamble = (this->preambleLengthLoRa & 0x0F) * (uint32_t(1) << ((this->preambleLengthLoRa & 0xF0) >> 4));
52+
53+ // calculate the number of symbols - nope
54+ // 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);
55+ // calculate the number of symbols - using only preamblelora because it's already in symbols
56+ 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 );
57+ } else {
58+ // long interleaving - not needed for this modem
59+ }
60+
61+ // get time-on-air in us
62+ return (((uint32_t (1 ) << this ->spreadingFactor ) / this ->bandwidthKhz ) * N_symbol * 1000 .0f );
63+ }
64+
4165 bool isReceiving () {
4266 uint16_t irq = getIrqStatus ();
4367 bool detected = ((irq & LR1110_IRQ_HEADER_VALID) || (irq & LR1110_IRQ_HAS_PREAMBLE));
0 commit comments