From 32e13eb7f9c1549b3d12c9f9359c2f974c961076 Mon Sep 17 00:00:00 2001 From: Rainer Fritz Date: Sun, 29 Dec 2024 19:18:20 +0100 Subject: [PATCH 1/2] added set custom syncword function --- src/radio/radio.h | 8 ++++++++ src/radio/sx126x/radio.cpp | 33 +++++++++++++++++++++++++++++---- 2 files changed, 37 insertions(+), 4 deletions(-) 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..3d5117e 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 SetCustomSyncWord(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, + SetCustomSyncWord, 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 SetCustomSyncWord(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) From ca35a64e52e5e4e309bf503eacb8b4a575f555a0 Mon Sep 17 00:00:00 2001 From: Rainer Fritz Date: Tue, 31 Dec 2024 15:44:52 +0100 Subject: [PATCH 2/2] corrected Function name RadioSetCustomSyncWord --- src/radio/sx126x/radio.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/radio/sx126x/radio.cpp b/src/radio/sx126x/radio.cpp index 3d5117e..53a2962 100644 --- a/src/radio/sx126x/radio.cpp +++ b/src/radio/sx126x/radio.cpp @@ -326,7 +326,7 @@ void RadioSetPublicNetwork(bool enable); * * \param syncword 2 byte custom Sync-Word to be used */ -void SetCustomSyncWord(uint16_t syncword); +void RadioSetCustomSyncWord(uint16_t syncword); /*! * @brief Gets the time required for the board plus radio to get out of sleep.[ms] @@ -395,7 +395,7 @@ const struct Radio_s Radio = RadioReadBuffer, RadioSetMaxPayloadLength, RadioSetPublicNetwork, - SetCustomSyncWord, + RadioSetCustomSyncWord, RadioGetWakeupTime, RadioBgIrqProcess, RadioIrqProcess, @@ -1230,7 +1230,7 @@ void RadioSetPublicNetwork(bool enable) } } -void SetCustomSyncWord(uint16_t syncword){ +void RadioSetCustomSyncWord(uint16_t syncword){ hasCustomSyncWord = true; RadioSetModem(MODEM_LORA); SX126xWriteRegister(REG_LR_SYNCWORD, (syncword >> 8) & 0xFF);