mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
Merge pull request #953 from Woodie-07/dev
LR1110 packet shift issue workaround
This commit is contained in:
commit
15ecf186fa
2 changed files with 70 additions and 1 deletions
|
|
@ -18,7 +18,7 @@ monitor_speed = 115200
|
|||
lib_deps =
|
||||
SPI
|
||||
Wire
|
||||
jgromes/RadioLib @ ^7.1.2
|
||||
jgromes/RadioLib @ ^7.3.0
|
||||
rweather/Crypto @ ^0.4.0
|
||||
adafruit/RTClib @ ^2.1.3
|
||||
melopero/Melopero RV3028 @ ^1.1.0
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <RadioLib.h>
|
||||
#include "MeshCore.h"
|
||||
|
||||
#define LR1110_IRQ_HAS_PREAMBLE 0b0000000100 // 4 4 valid LoRa header received
|
||||
#define LR1110_IRQ_HEADER_VALID 0b0000010000 // 4 4 valid LoRa header received
|
||||
|
|
@ -9,6 +10,74 @@ class CustomLR1110 : public LR1110 {
|
|||
public:
|
||||
CustomLR1110(Module *mod) : LR1110(mod) { }
|
||||
|
||||
uint8_t shiftCount = 0;
|
||||
|
||||
int16_t standby() override {
|
||||
// tx resets the shift, standby is called on tx completion
|
||||
// this might not actually be what resets it, but it seems to work
|
||||
// more investigation needed
|
||||
this->shiftCount = 0;
|
||||
return LR1110::standby();
|
||||
}
|
||||
|
||||
size_t getPacketLength(bool update) override {
|
||||
size_t len = LR1110::getPacketLength(update);
|
||||
if (len == 0) {
|
||||
uint32_t irq = getIrqStatus();
|
||||
if (irq & RADIOLIB_LR11X0_IRQ_HEADER_ERR) {
|
||||
MESH_DEBUG_PRINTLN("LR1110: got header err, assuming shift");
|
||||
this->shiftCount += 4; // uint8 will loop around to 0 at 256, perfect as rx buffer is 256 bytes
|
||||
} else {
|
||||
MESH_DEBUG_PRINTLN("LR1110: got zero-length packet without header err irq");
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int16_t readData(uint8_t *data, size_t len) override {
|
||||
// check active modem
|
||||
uint8_t modem = RADIOLIB_LR11X0_PACKET_TYPE_NONE;
|
||||
int16_t state = getPacketType(&modem);
|
||||
RADIOLIB_ASSERT(state);
|
||||
if((modem != RADIOLIB_LR11X0_PACKET_TYPE_LORA) &&
|
||||
(modem != RADIOLIB_LR11X0_PACKET_TYPE_GFSK)) {
|
||||
return(RADIOLIB_ERR_WRONG_MODEM);
|
||||
}
|
||||
|
||||
// check integrity CRC
|
||||
uint32_t irq = getIrqStatus();
|
||||
int16_t crcState = RADIOLIB_ERR_NONE;
|
||||
// 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)
|
||||
if((irq & RADIOLIB_LR11X0_IRQ_CRC_ERR) || ((irq & RADIOLIB_LR11X0_IRQ_HEADER_ERR) && !(irq & RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID))) {
|
||||
crcState = RADIOLIB_ERR_CRC_MISMATCH;
|
||||
}
|
||||
|
||||
// get packet length
|
||||
// the offset is needed since LR11x0 seems to move the buffer base by 4 bytes on every packet
|
||||
uint8_t offset = 0;
|
||||
size_t length = LR1110::getPacketLength(true, &offset);
|
||||
if((len != 0) && (len < length)) {
|
||||
// user requested less data than we got, only return what was requested
|
||||
length = len;
|
||||
}
|
||||
|
||||
// read packet data
|
||||
state = readBuffer8(data, length, (uint8_t)(offset + this->shiftCount)); // add shiftCount to offset - only change from radiolib
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// clear the Rx buffer
|
||||
state = clearRxBuffer();
|
||||
RADIOLIB_ASSERT(state);
|
||||
|
||||
// clear interrupt flags
|
||||
state = clearIrqState(RADIOLIB_LR11X0_IRQ_ALL);
|
||||
|
||||
// check if CRC failed - this is done after reading data to give user the option to keep them
|
||||
RADIOLIB_ASSERT(crcState);
|
||||
|
||||
return(state);
|
||||
}
|
||||
|
||||
RadioLibTime_t getTimeOnAir(size_t len) override {
|
||||
// calculate number of symbols
|
||||
float N_symbol = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue