Skip to content

Commit 15ecf18

Browse files
authored
Merge pull request #953 from Woodie-07/dev
LR1110 packet shift issue workaround
2 parents cd92069 + 02351ab commit 15ecf18

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

platformio.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ monitor_speed = 115200
1818
lib_deps =
1919
SPI
2020
Wire
21-
jgromes/RadioLib @ ^7.1.2
21+
jgromes/RadioLib @ ^7.3.0
2222
rweather/Crypto @ ^0.4.0
2323
adafruit/RTClib @ ^2.1.3
2424
melopero/Melopero RV3028 @ ^1.1.0

src/helpers/radiolib/CustomLR1110.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <RadioLib.h>
4+
#include "MeshCore.h"
45

56
#define LR1110_IRQ_HAS_PREAMBLE 0b0000000100 // 4 4 valid LoRa header received
67
#define LR1110_IRQ_HEADER_VALID 0b0000010000 // 4 4 valid LoRa header received
@@ -9,6 +10,74 @@ class CustomLR1110 : public LR1110 {
910
public:
1011
CustomLR1110(Module *mod) : LR1110(mod) { }
1112

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+
23+
size_t getPacketLength(bool update) override {
24+
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+
}
33+
}
34+
return len;
35+
}
36+
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+
1281
RadioLibTime_t getTimeOnAir(size_t len) override {
1382
// calculate number of symbols
1483
float N_symbol = 0;

0 commit comments

Comments
 (0)