diff --git a/src/Dispatcher.h b/src/Dispatcher.h index 7d4e2abf..0abfa9ab 100644 --- a/src/Dispatcher.h +++ b/src/Dispatcher.h @@ -38,9 +38,7 @@ public: virtual float packetScore(float snr, int packet_len) = 0; -#ifdef JP_STRICT - virtual int getMaxTextLen() const { return 1 * 16; } // default: CR4/8 -#endif + virtual int getMaxTextLen() const { return 10 * 16; } // default: non-JP /** * \brief starts the raw packet send. (no wait) diff --git a/src/helpers/BaseChatMesh.cpp b/src/helpers/BaseChatMesh.cpp index d414c7b7..2003db44 100644 --- a/src/helpers/BaseChatMesh.cpp +++ b/src/helpers/BaseChatMesh.cpp @@ -395,16 +395,9 @@ void BaseChatMesh::onGroupDataRecv(mesh::Packet* packet, uint8_t type, const mes mesh::Packet* BaseChatMesh::composeMsgPacket(const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char *text, uint32_t& expected_ack) { int text_len = strlen(text); - -#ifdef JP_STRICT int max_len = _radio->getMaxTextLen(); if (text_len > max_len) return NULL; if (attempt > 3 && text_len > max_len - 2) return NULL; -#else - if (text_len > MAX_TEXT_LEN) return NULL; - if (attempt > 3 && text_len > MAX_TEXT_LEN-2) return NULL; -#endif - uint8_t temp[5+MAX_TEXT_LEN+1]; memcpy(temp, ×tamp, 4); // mostly an extra blob to help make packet_hash unique temp[4] = (attempt & 3); diff --git a/src/helpers/radiolib/CustomLR1110Wrapper.h b/src/helpers/radiolib/CustomLR1110Wrapper.h index 68db703d..ad05bfca 100644 --- a/src/helpers/radiolib/CustomLR1110Wrapper.h +++ b/src/helpers/radiolib/CustomLR1110Wrapper.h @@ -35,4 +35,7 @@ public: uint8_t getCodingRate() const override { return ((CustomLR1110 *)_radio)->getCodingRate(); } + float getFreqMHz() const override { + return ((CustomLR1110 *)_radio)->getFreqMHz(); + } }; diff --git a/src/helpers/radiolib/CustomSX1262Wrapper.h b/src/helpers/radiolib/CustomSX1262Wrapper.h index 5edaa25e..e9c02554 100644 --- a/src/helpers/radiolib/CustomSX1262Wrapper.h +++ b/src/helpers/radiolib/CustomSX1262Wrapper.h @@ -40,4 +40,7 @@ public: uint8_t getCodingRate() const override { return ((CustomSX1262 *)_radio)->codingRate + 4; // RadioLib stores 1-4, return 5-8 } + float getFreqMHz() const override { + return ((CustomSX1262 *)_radio)->freqMHz; + } }; diff --git a/src/helpers/radiolib/RadioLibWrappers.cpp b/src/helpers/radiolib/RadioLibWrappers.cpp index 70c163c8..d0a0a94c 100644 --- a/src/helpers/radiolib/RadioLibWrappers.cpp +++ b/src/helpers/radiolib/RadioLibWrappers.cpp @@ -169,10 +169,10 @@ bool RadioLibWrapper::isSendComplete() { void RadioLibWrapper::onSendFinished() { _radio->finishTransmit(); _board->onAfterTransmit(); -#ifdef JP_STRICT - // ARIB STD-T108: wait >= 50ms after TX before next transmission - delay(50); -#endif + if (isJapanMode()) { + // ARIB STD-T108: wait >= 50ms after TX before next transmission + delay(50); + } state = STATE_IDLE; } @@ -183,40 +183,39 @@ int16_t RadioLibWrapper::performChannelScan() { bool RadioLibWrapper::isChannelActive() { if (_threshold == 0) return false; // interference check is disabled -#ifdef JP_STRICT - // ARIB STD-T108 compliant LBT: continuous RSSI sensing for >= 5ms - // Energy-based sensing required; LoRa CAD not used here — - // CAD detects only LoRa preambles and is not required by ARIB STD-T108 - uint32_t sense_start = millis(); - while (millis() - sense_start < 5) { - if (getCurrentRSSI() > -80.0f) { - // Channel busy: exponential backoff (tuned for JP 4s airtime) - _busy_count++; - uint32_t base_ms = 2000; - uint32_t max_backoff = min(base_ms * (1u << _busy_count), (uint32_t)16000); - uint32_t backoff_until = millis() + random(max_backoff / 2, max_backoff); - while (millis() < backoff_until) { - vTaskDelay(1); // yield CPU to FreeRTOS tasks including BLE + // Activate JP_STRICT LBT on Japan 920MHz band 3 channels only + // CH25=920.800MHz, CH26=921.000MHz, CH27=921.200MHz (ARIB STD-T108) + if (isJapanMode()) { + // ARIB STD-T108 compliant LBT: continuous RSSI sensing for >= 5ms + // Energy-based sensing required; LoRa CAD not used + uint32_t sense_start = millis(); + while (millis() - sense_start < 5) { + if (getCurrentRSSI() > -80.0f) { + // Channel busy: exponential backoff (tuned for JP 4s airtime) + _busy_count++; + uint32_t base_ms = 2000; + uint32_t max_backoff = min(base_ms * (1u << _busy_count), (uint32_t)16000); + uint32_t backoff_until = millis() + random(max_backoff / 2, max_backoff); + while (millis() < backoff_until) { + vTaskDelay(1); + } + return true; } - return true; + vTaskDelay(1); } - vTaskDelay(1); // yield CPU between RSSI samples + // Channel free: reset busy counter and add small jitter + _busy_count = 0; + uint32_t jitter_until = millis() + random(0, 500); + while (millis() < jitter_until) { + vTaskDelay(1); + } + return false; } - // Channel free: reset busy counter and add small jitter - _busy_count = 0; - uint32_t jitter_until = millis() + random(0, 500); - while (millis() < jitter_until) { - vTaskDelay(1); // yield CPU to FreeRTOS tasks including BLE - } - return false; -#else // Non-JP: original behavior (RSSI threshold only) return getCurrentRSSI() > _noise_floor + _threshold; -#endif } - float RadioLibWrapper::getLastRSSI() const { return _radio->getRSSI(); } diff --git a/src/helpers/radiolib/RadioLibWrappers.h b/src/helpers/radiolib/RadioLibWrappers.h index 66ad2525..2ca2f59a 100644 --- a/src/helpers/radiolib/RadioLibWrappers.h +++ b/src/helpers/radiolib/RadioLibWrappers.h @@ -40,16 +40,23 @@ public: virtual float getCurrentRSSI() =0; virtual uint8_t getCodingRate() const = 0; + virtual float getFreqMHz() const = 0; -#ifdef JP_STRICT - int getMaxTextLen() const { - uint8_t cr = getCodingRate(); - if (cr <= 5) return 3 * 16; // 48 bytes ~16 JP chars - if (cr == 6) return 2 * 16; // 32 bytes ~10 JP chars - if (cr == 7) return 1 * 16 + 8; // 24 bytes ~8 JP chars - return 1 * 16; // 16 bytes ~5 JP chars + bool isJapanMode() const { + float freq = getFreqMHz(); + return (fabsf(freq - 920.800f) < 0.05f || + fabsf(freq - 921.000f) < 0.05f || + fabsf(freq - 921.200f) < 0.05f); + } + + int getMaxTextLen() const { + if (!isJapanMode()) return 10 * 16; // default + uint8_t cr = getCodingRate(); + if (cr <= 5) return 3 * 16; // 48 bytes ~16 JP chars + if (cr == 6) return 2 * 16; // 32 bytes ~10 JP chars + if (cr == 7) return 1 * 16 + 8; // 24 bytes ~8 JP chars + return 1 * 16; // 16 bytes ~5 JP chars } -#endif virtual int16_t performChannelScan(); diff --git a/variants/rak_wismesh_tag/platformio.ini b/variants/rak_wismesh_tag/platformio.ini index 447bd469..79de2096 100644 --- a/variants/rak_wismesh_tag/platformio.ini +++ b/variants/rak_wismesh_tag/platformio.ini @@ -25,8 +25,6 @@ build_flags = ${nrf52_base.build_flags} -D PIN_BUZZER=21 -D PIN_BOARD_SDA=PIN_WIRE_SDA -D PIN_BOARD_SCL=PIN_WIRE_SCL - -D JP_STRICT - -D LORA_CR=5 build_src_filter = ${nrf52_base.build_src_filter} +<../variants/rak_wismesh_tag> + diff --git a/variants/wio-tracker-l1/platformio.ini b/variants/wio-tracker-l1/platformio.ini index 962a392d..6c1e8f63 100644 --- a/variants/wio-tracker-l1/platformio.ini +++ b/variants/wio-tracker-l1/platformio.ini @@ -16,8 +16,6 @@ build_flags = ${nrf52_base.build_flags} -D SX126X_RX_BOOSTED_GAIN=1 -D PIN_OLED_RESET=-1 -D GPS_BAUD_RATE=9600 - -D JP_STRICT - -D LORA_CR=5 build_src_filter = ${nrf52_base.build_src_filter} + +<../variants/wio-tracker-l1>