SX1268: add IRQ timeout logic
This commit is contained in:
1 parent
c490abf452
commit
2f19204283
2 files changed
+58
-3
No files matched your search
@@ -3,6 +3,11 @@
|
|||||||
#include <RadioLib.h>
|
#include <RadioLib.h>
|
||||||
|
|
||||||
class CustomSX1268 : public SX1268 {
|
class CustomSX1268 : public SX1268 {
|
||||||
|
uint32_t _preambleMillis = 66;
|
||||||
|
uint32_t _maxPayloadMillis = 3934;
|
||||||
|
uint32_t _activityAt = 0;
|
||||||
|
bool _headerSeen = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CustomSX1268(Module *mod) : SX1268(mod) { }
|
CustomSX1268(Module *mod) : SX1268(mod) { }
|
||||||
|
|
||||||
@@ -81,10 +86,57 @@ class CustomSX1268 : public SX1268 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool isReceiving() {
|
bool isReceiving() {
|
||||||
uint16_t irq = getIrqFlags();
|
uint32_t irq = getIrqFlags();
|
||||||
bool detected = (irq & RADIOLIB_SX126X_IRQ_HEADER_VALID) || (irq & RADIOLIB_SX126X_IRQ_PREAMBLE_DETECTED);
|
bool preamble = irq & RADIOLIB_SX126X_IRQ_PREAMBLE_DETECTED; // bit 2
|
||||||
return detected;
|
bool header = irq & RADIOLIB_SX126X_IRQ_HEADER_VALID; // bit 4
|
||||||
|
bool hdrErr = irq & RADIOLIB_SX126X_IRQ_HEADER_ERR; // bit 5
|
||||||
|
uint32_t now = millis();
|
||||||
|
if (hdrErr) {
|
||||||
|
clearIrqFlags(RADIOLIB_SX126X_IRQ_PREAMBLE_DETECTED | RADIOLIB_SX126X_IRQ_HEADER_VALID | RADIOLIB_SX126X_IRQ_HEADER_ERR | RADIOLIB_SX126X_IRQ_SYNC_WORD_VALID);
|
||||||
|
_activityAt = 0;
|
||||||
|
_headerSeen = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!header && _headerSeen) {
|
||||||
|
// something cleared the header flag, reset our state.
|
||||||
|
_activityAt = 0; _headerSeen = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (header) {
|
||||||
|
if (!_headerSeen) { _headerSeen = true; _activityAt = now; };
|
||||||
|
if (now - _activityAt > _maxPayloadMillis) {
|
||||||
|
MESH_DEBUG_PRINTLN("Clearing header IRQ after %ums", _maxPayloadMillis);
|
||||||
|
clearIrqFlags(RADIOLIB_SX126X_IRQ_PREAMBLE_DETECTED | RADIOLIB_SX126X_IRQ_HEADER_VALID | RADIOLIB_SX126X_IRQ_HEADER_ERR | RADIOLIB_SX126X_IRQ_SYNC_WORD_VALID);
|
||||||
|
_activityAt = 0; _headerSeen = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (preamble) {
|
||||||
|
if (_activityAt == 0) _activityAt = now;
|
||||||
|
if (now - _activityAt > _preambleMillis) {
|
||||||
|
clearIrqFlags(RADIOLIB_SX126X_IRQ_PREAMBLE_DETECTED);
|
||||||
|
_activityAt = 0;
|
||||||
|
MESH_DEBUG_PRINTLN("Clearing preamble IRQ after %ums", _preambleMillis);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
_activityAt = 0; _headerSeen = false;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setPreambleMillis(uint32_t preambleMillis) {
|
||||||
|
_preambleMillis = preambleMillis;
|
||||||
|
MESH_DEBUG_PRINTLN("Set _preambleMillis=%u", _preambleMillis);
|
||||||
|
}
|
||||||
|
void setMaxPayloadMillis(uint32_t payloadMillis) {
|
||||||
|
_maxPayloadMillis = payloadMillis;
|
||||||
|
MESH_DEBUG_PRINTLN("Set _maxPayloadMillis=%u", _maxPayloadMillis);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool getRxBoostedGainMode() {
|
bool getRxBoostedGainMode() {
|
||||||
uint8_t rxGain = 0;
|
uint8_t rxGain = 0;
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ public:
|
|||||||
((CustomSX1268 *)_radio)->setBandwidth(bw);
|
((CustomSX1268 *)_radio)->setBandwidth(bw);
|
||||||
((CustomSX1268 *)_radio)->setCodingRate(cr);
|
((CustomSX1268 *)_radio)->setCodingRate(cr);
|
||||||
updatePreamble(sf);
|
updatePreamble(sf);
|
||||||
|
PacketMillis pm = calcMaxPacketMillis(sf, bw, cr, preambleLengthForSF(sf));
|
||||||
|
((CustomSX1268 *)_radio)->setPreambleMillis(pm.preambleMillis);
|
||||||
|
((CustomSX1268 *)_radio)->setMaxPayloadMillis(pm.payloadMillis);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isReceivingPacket() override {
|
bool isReceivingPacket() override {
|
||||||
|
|||||||
Reference in new issue
Block a user