|
4 | 4 | #include "MeshCore.h" |
5 | 5 |
|
6 | 6 | class CustomLR1110 : public LR1110 { |
| 7 | + uint32_t _preambleMillis = 66; |
| 8 | + uint32_t _maxPayloadMillis = 3934; |
| 9 | + uint32_t _activityAt = 0; |
| 10 | + bool _headerSeen = false; |
7 | 11 | bool _rx_boosted = false; |
8 | 12 |
|
9 | 13 | public: |
@@ -32,9 +36,46 @@ class CustomLR1110 : public LR1110 { |
32 | 36 | bool getRxBoostedGainMode() const { return _rx_boosted; } |
33 | 37 |
|
34 | 38 | bool isReceiving() { |
35 | | - uint16_t irq = getIrqStatus(); |
36 | | - bool detected = ((irq & RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID) || (irq & RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED)); |
37 | | - return detected; |
| 39 | + uint32_t irq = getIrqStatus(); |
| 40 | + bool preamble = irq & RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED; // bit 4 |
| 41 | + bool header = irq & RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID; // bit 5 |
| 42 | + bool hdrErr = irq & RADIOLIB_LR11X0_IRQ_HEADER_ERR; // bit 6 |
| 43 | + uint32_t now = millis(); |
| 44 | + if (hdrErr) { |
| 45 | + clearIrqState(RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED | RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID | RADIOLIB_LR11X0_IRQ_HEADER_ERR); |
| 46 | + _activityAt = 0; |
| 47 | + _headerSeen = false; |
| 48 | + return false; |
| 49 | + } |
| 50 | + if (header) { |
| 51 | + if (!_headerSeen) { _headerSeen = true; _activityAt = now; }; |
| 52 | + if (now - _activityAt > _maxPayloadMillis) { |
| 53 | + MESH_DEBUG_PRINTLN("Clearing header IRQ after %ums", _maxPayloadMillis); |
| 54 | + clearIrqState(RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED | RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID | RADIOLIB_LR11X0_IRQ_HEADER_ERR); |
| 55 | + _activityAt = 0; _headerSeen = false; |
| 56 | + return false; |
| 57 | + } |
| 58 | + return true; |
| 59 | + } |
| 60 | + if (preamble) { |
| 61 | + if (_activityAt == 0) _activityAt = now; |
| 62 | + if (now - _activityAt > _preambleMillis) { |
| 63 | + clearIrqState(RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED); |
| 64 | + _activityAt = 0; |
| 65 | + MESH_DEBUG_PRINTLN("Clearing preamble IRQ after %ums", _preambleMillis); |
| 66 | + |
| 67 | + return false; |
| 68 | + } |
| 69 | + return true; |
| 70 | + } |
| 71 | + _activityAt = 0; _headerSeen = false; |
| 72 | + return false; |
| 73 | + } |
| 74 | + |
| 75 | + PacketMillis setMaxPacketMillis(PacketMillis maxPacketMillis) { |
| 76 | + MESH_DEBUG_PRINTLN("Setting _preambleMillis=%u, _maxPacketMillis=%u", maxPacketMillis.preambleMillis, maxPacketMillis.payloadMillis); |
| 77 | + _preambleMillis = maxPacketMillis.preambleMillis; |
| 78 | + _maxPayloadMillis = maxPacketMillis.payloadMillis; |
38 | 79 | } |
39 | 80 |
|
40 | 81 | uint8_t getSpreadingFactor() const { return spreadingFactor; } |
|
0 commit comments