diff --git a/src/radio/radio.h b/src/radio/radio.h index 1cb69d7..38cd7e6 100644 --- a/src/radio/radio.h +++ b/src/radio/radio.h @@ -351,6 +351,14 @@ struct Radio_s * \param enable if true, it enables a public network */ void (*SetPublicNetwork)(bool enable); + /*! + * \brief Sets a custom Sync-Word. Updates the sync byte. + * + * \remark Applies to LoRa modem only + * + * \param syncword 2 byte custom Sync-Word to be used + */ + void (*SetCustomSyncWord)(uint16_t syncword); /*! * \brief Gets the time required for the board plus radio to get out of sleep.[ms] * diff --git a/src/radio/sx126x/radio.cpp b/src/radio/sx126x/radio.cpp index 0dea0f5..53a2962 100644 --- a/src/radio/sx126x/radio.cpp +++ b/src/radio/sx126x/radio.cpp @@ -319,6 +319,15 @@ void RadioSetMaxPayloadLength(RadioModems_t modem, uint8_t max); */ void RadioSetPublicNetwork(bool enable); +/*! + * \brief Sets a custom Sync-Word. Updates the sync byte. + * + * \remark Applies to LoRa modem only + * + * \param syncword 2 byte custom Sync-Word to be used + */ +void RadioSetCustomSyncWord(uint16_t syncword); + /*! * @brief Gets the time required for the board plus radio to get out of sleep.[ms] * @@ -386,6 +395,7 @@ const struct Radio_s Radio = RadioReadBuffer, RadioSetMaxPayloadLength, RadioSetPublicNetwork, + RadioSetCustomSyncWord, RadioGetWakeupTime, RadioBgIrqProcess, RadioIrqProcess, @@ -465,6 +475,8 @@ bool TimerTxTimeout = false; RadioModems_t _modem; +bool hasCustomSyncWord = false; + /* * SX126x DIO IRQ callback functions prototype */ @@ -612,12 +624,17 @@ void RadioSetModem(RadioModems_t modem) break; case MODEM_LORA: SX126xSetPacketType(PACKET_TYPE_LORA); - // Public/Private network register is reset when switching modems - if (RadioPublicNetwork.Current != RadioPublicNetwork.Previous) + // check first if a custom SyncWord is set + if (!hasCustomSyncWord) { - RadioPublicNetwork.Current = RadioPublicNetwork.Previous; - RadioSetPublicNetwork(RadioPublicNetwork.Current); + // Public/Private network register is reset when switching modems + if (RadioPublicNetwork.Current != RadioPublicNetwork.Previous) + { + RadioPublicNetwork.Current = RadioPublicNetwork.Previous; + RadioSetPublicNetwork(RadioPublicNetwork.Current); + } } + _modem = modem; break; } @@ -1195,6 +1212,7 @@ void RadioSetMaxPayloadLength(RadioModems_t modem, uint8_t max) void RadioSetPublicNetwork(bool enable) { + hasCustomSyncWord = false; RadioPublicNetwork.Current = RadioPublicNetwork.Previous = enable; RadioSetModem(MODEM_LORA); @@ -1212,6 +1230,13 @@ void RadioSetPublicNetwork(bool enable) } } +void RadioSetCustomSyncWord(uint16_t syncword){ + hasCustomSyncWord = true; + RadioSetModem(MODEM_LORA); + SX126xWriteRegister(REG_LR_SYNCWORD, (syncword >> 8) & 0xFF); + SX126xWriteRegister(REG_LR_SYNCWORD + 1, syncword & 0xFF); +} + uint32_t RadioGetWakeupTime(void) { if (_hwConfig.USE_DIO3_TCXO)