Skip to content

Commit 73ec376

Browse files
committed
Add getCodingRate() to CustomLR1110 and CustomLR1110Wrapper
LR1110 has codingRate as protected field in LR_common.h, so getCodingRate() is implemented in CustomLR1110 class directly, and exposed via CustomLR1110Wrapper override. This enables dynamic MAX_TEXT_LEN calculation for T1000-E under JP_STRICT mode.
1 parent d7045a1 commit 73ec376

3 files changed

Lines changed: 24 additions & 30 deletions

File tree

src/helpers/radiolib/CustomLR1110.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,8 @@ class CustomLR1110 : public LR1110 {
3636
bool detected = ((irq & RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID) || (irq & RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED));
3737
return detected;
3838
}
39-
};
39+
40+
uint8_t getCodingRate() const {
41+
return this->codingRate + 4; // RadioLib stores 1-4, return 5-8
42+
}
43+
};

src/helpers/radiolib/CustomLR1110Wrapper.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ class CustomLR1110Wrapper : public RadioLibWrapper {
3131
bool getRxBoostedGainMode() const override {
3232
return ((CustomLR1110 *)_radio)->getRxBoostedGainMode();
3333
}
34+
35+
uint8_t getCodingRate() const override {
36+
return ((CustomLR1110 *)_radio)->getCodingRate();
37+
}
3438
};

src/helpers/radiolib/RadioLibWrappers.cpp

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -184,53 +184,39 @@ bool RadioLibWrapper::isChannelActive() {
184184
if (_threshold == 0) return false; // interference check is disabled
185185

186186
#ifdef JP_STRICT
187-
// 5ms continuous RSSI sensing
187+
// ARIB STD-T108 compliant LBT: continuous RSSI sensing for >= 5ms
188+
// Energy-based sensing required; LoRa CAD not used here —
189+
// CAD detects only LoRa preambles and is not required by ARIB STD-T108
188190
uint32_t sense_start = millis();
189191
while (millis() - sense_start < 5) {
190192
if (getCurrentRSSI() > -80.0f) {
191-
// RSSI busy: backoff and return without CAD
193+
// Channel busy: exponential backoff (tuned for JP 4s airtime)
192194
_busy_count++;
193-
uint32_t base_ms = 3000;
194-
uint32_t max_backoff = min(base_ms * (1u << _busy_count), (uint32_t)20000);
195+
uint32_t base_ms = 2000;
196+
uint32_t max_backoff = min(base_ms * (1u << _busy_count), (uint32_t)16000);
195197
uint32_t backoff_until = millis() + random(max_backoff / 2, max_backoff);
196198
while (millis() < backoff_until) {
197-
vTaskDelay(1);
199+
vTaskDelay(1); // yield CPU to FreeRTOS tasks including BLE
198200
}
199201
return true;
200202
}
201-
vTaskDelay(1);
203+
vTaskDelay(1); // yield CPU between RSSI samples
202204
}
203-
#endif
204-
205-
// CAD
206-
int16_t result = performChannelScan();
207-
state = STATE_IDLE;
208-
startRecv();
209-
210-
if (result != RADIOLIB_CHANNEL_FREE) {
211-
// CAD busy: backoff
212-
_busy_count++;
213-
uint32_t base_ms = 3000;
214-
uint32_t max_backoff = min(base_ms * (1u << _busy_count), (uint32_t)20000);
215-
uint32_t backoff_until = millis() + random(max_backoff / 2, max_backoff);
216-
while (millis() < backoff_until) {
217-
vTaskDelay(1);
218-
}
219-
return true;
220-
}
221-
205+
// Channel free: reset busy counter and add small jitter
222206
_busy_count = 0;
223-
224-
// Small jitter even when channel is free to prevent simultaneous TX
225-
// from two nodes that both detect a free channel at the same time
226207
uint32_t jitter_until = millis() + random(0, 500);
227208
while (millis() < jitter_until) {
228209
vTaskDelay(1); // yield CPU to FreeRTOS tasks including BLE
229210
}
230-
231211
return false;
212+
213+
#else
214+
// Non-JP: original behavior (RSSI threshold only)
215+
return getCurrentRSSI() > _noise_floor + _threshold;
216+
#endif
232217
}
233218

219+
234220
float RadioLibWrapper::getLastRSSI() const {
235221
return _radio->getRSSI();
236222
}

0 commit comments

Comments
 (0)