Skip to content

Commit 2981fc7

Browse files
committed
new workaround
1 parent 02351ab commit 2981fc7

File tree

1 file changed

+7
-62
lines changed

1 file changed

+7
-62
lines changed

src/helpers/radiolib/CustomLR1110.h

Lines changed: 7 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,74 +10,19 @@ class CustomLR1110 : public LR1110 {
1010
public:
1111
CustomLR1110(Module *mod) : LR1110(mod) { }
1212

13-
uint8_t shiftCount = 0;
14-
15-
int16_t standby() override {
16-
// tx resets the shift, standby is called on tx completion
17-
// this might not actually be what resets it, but it seems to work
18-
// more investigation needed
19-
this->shiftCount = 0;
20-
return LR1110::standby();
21-
}
22-
2313
size_t getPacketLength(bool update) override {
2414
size_t len = LR1110::getPacketLength(update);
25-
if (len == 0) {
26-
uint32_t irq = getIrqStatus();
27-
if (irq & RADIOLIB_LR11X0_IRQ_HEADER_ERR) {
28-
MESH_DEBUG_PRINTLN("LR1110: got header err, assuming shift");
29-
this->shiftCount += 4; // uint8 will loop around to 0 at 256, perfect as rx buffer is 256 bytes
30-
} else {
31-
MESH_DEBUG_PRINTLN("LR1110: got zero-length packet without header err irq");
32-
}
15+
if (len == 0 && getIrqStatus() & RADIOLIB_LR11X0_IRQ_HEADER_ERR) {
16+
// we've just recieved a corrupted packet
17+
// this may have triggered a bug causing subsequent packets to be shifted
18+
// call standby() to return radio to known-good state
19+
// recvRaw will call startReceive() to restart rx
20+
MESH_DEBUG_PRINTLN("LR1110: got header err, calling standby()");
21+
standby();
3322
}
3423
return len;
3524
}
3625

37-
int16_t readData(uint8_t *data, size_t len) override {
38-
// check active modem
39-
uint8_t modem = RADIOLIB_LR11X0_PACKET_TYPE_NONE;
40-
int16_t state = getPacketType(&modem);
41-
RADIOLIB_ASSERT(state);
42-
if((modem != RADIOLIB_LR11X0_PACKET_TYPE_LORA) &&
43-
(modem != RADIOLIB_LR11X0_PACKET_TYPE_GFSK)) {
44-
return(RADIOLIB_ERR_WRONG_MODEM);
45-
}
46-
47-
// check integrity CRC
48-
uint32_t irq = getIrqStatus();
49-
int16_t crcState = RADIOLIB_ERR_NONE;
50-
// Report CRC mismatch when there's a payload CRC error, or a header error and no valid header (to avoid false alarm from previous packet)
51-
if((irq & RADIOLIB_LR11X0_IRQ_CRC_ERR) || ((irq & RADIOLIB_LR11X0_IRQ_HEADER_ERR) && !(irq & RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID))) {
52-
crcState = RADIOLIB_ERR_CRC_MISMATCH;
53-
}
54-
55-
// get packet length
56-
// the offset is needed since LR11x0 seems to move the buffer base by 4 bytes on every packet
57-
uint8_t offset = 0;
58-
size_t length = LR1110::getPacketLength(true, &offset);
59-
if((len != 0) && (len < length)) {
60-
// user requested less data than we got, only return what was requested
61-
length = len;
62-
}
63-
64-
// read packet data
65-
state = readBuffer8(data, length, (uint8_t)(offset + this->shiftCount)); // add shiftCount to offset - only change from radiolib
66-
RADIOLIB_ASSERT(state);
67-
68-
// clear the Rx buffer
69-
state = clearRxBuffer();
70-
RADIOLIB_ASSERT(state);
71-
72-
// clear interrupt flags
73-
state = clearIrqState(RADIOLIB_LR11X0_IRQ_ALL);
74-
75-
// check if CRC failed - this is done after reading data to give user the option to keep them
76-
RADIOLIB_ASSERT(crcState);
77-
78-
return(state);
79-
}
80-
8126
RadioLibTime_t getTimeOnAir(size_t len) override {
8227
// calculate number of symbols
8328
float N_symbol = 0;

0 commit comments

Comments
 (0)