Skip to content

Commit

Permalink
Merge pull request #137 from rainerfritz/master
Browse files Browse the repository at this point in the history
[Feature] set custom syncword function
  • Loading branch information
beegee-tokyo authored Jan 1, 2025
2 parents fdf4456 + ca35a64 commit b8ee298
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/radio/radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]
*
Expand Down
33 changes: 29 additions & 4 deletions src/radio/sx126x/radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]
*
Expand Down Expand Up @@ -386,6 +395,7 @@ const struct Radio_s Radio =
RadioReadBuffer,
RadioSetMaxPayloadLength,
RadioSetPublicNetwork,
RadioSetCustomSyncWord,
RadioGetWakeupTime,
RadioBgIrqProcess,
RadioIrqProcess,
Expand Down Expand Up @@ -465,6 +475,8 @@ bool TimerTxTimeout = false;

RadioModems_t _modem;

bool hasCustomSyncWord = false;

/*
* SX126x DIO IRQ callback functions prototype
*/
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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)
Expand Down

0 comments on commit b8ee298

Please sign in to comment.