Skip to content

Commit fa481e8

Browse files
committed
LR's corrected calculation override (instead of SX) and minor changes according to radiolib's wiki
1 parent ff9699c commit fa481e8

File tree

2 files changed

+52
-27
lines changed

2 files changed

+52
-27
lines changed

src/helpers/CustomLR1110.h

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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));

variants/t1000-e/target.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ bool radio_init() {
6161
return false; // fail
6262
}
6363

64-
radio.setCRC(1);
64+
radio.setCRC(2);
65+
radio.explicitHeader();
6566

6667
#ifdef RF_SWITCH_TABLE
6768
radio.setRfSwitchTable(rfswitch_dios, rfswitch_table);

0 commit comments

Comments
 (0)