Skip to content

Commit

Permalink
[LR11x0] Use array as LR-FHSS sync word
Browse files Browse the repository at this point in the history
  • Loading branch information
jgromes committed Oct 28, 2024
1 parent 15a751a commit 8f3a5c7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ void setup() {
3, // header count
0x13A); // hopping sequence seed
state = radio.setOutputPower(10.0);
state = radio.setSyncWord(0x12345678);
uint8_t syncWord[] = {0x01, 0x23, 0x45, 0x67};
state = radio.setSyncWord(syncWord, 4);
if (state != RADIOLIB_ERR_NONE) {
Serial.print(F("Unable to set configuration, code "));
Serial.println(state);
Expand Down
48 changes: 27 additions & 21 deletions src/modules/LR11x0/LR11x0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ int16_t LR11x0::beginLRFHSS(uint8_t bw, uint8_t cr, bool narrowGrid, float tcxoV
state = setLrFhssConfig(bw, cr);
RADIOLIB_ASSERT(state);

state = setSyncWord(0x12AD101B);
uint8_t syncWord[] = { 0x12, 0xAD, 0x10, 0x1B };
state = setSyncWord(syncWord, 4);
RADIOLIB_ASSERT(state);

state = setRegulatorLDO();
Expand Down Expand Up @@ -758,20 +759,16 @@ int16_t LR11x0::setCodingRate(uint8_t cr, bool longInterleave) {
return(setModulationParamsLoRa(this->spreadingFactor, this->bandwidth, this->codingRate, this->ldrOptimize));
}

int16_t LR11x0::setSyncWord(uint32_t syncWord) {
int16_t LR11x0::setSyncWord(uint8_t syncWord) {
// check active modem
uint8_t type = RADIOLIB_LR11X0_PACKET_TYPE_NONE;
int16_t state = getPacketType(&type);
RADIOLIB_ASSERT(state);
if(type == RADIOLIB_LR11X0_PACKET_TYPE_LORA) {
return(setLoRaSyncWord(syncWord & 0xFF));

} else if(type == RADIOLIB_LR11X0_PACKET_TYPE_LR_FHSS) {
return(lrFhssSetSyncWord(syncWord));

if(type != RADIOLIB_LR11X0_PACKET_TYPE_LORA) {
return(RADIOLIB_ERR_WRONG_MODEM);
}

return(RADIOLIB_ERR_WRONG_MODEM);
return(setLoRaSyncWord(syncWord));
}

int16_t LR11x0::setBitRate(float br) {
Expand Down Expand Up @@ -885,27 +882,36 @@ int16_t LR11x0::setSyncWord(uint8_t* syncWord, size_t len) {
uint8_t type = RADIOLIB_LR11X0_PACKET_TYPE_NONE;
int16_t state = getPacketType(&type);
RADIOLIB_ASSERT(state);
if(type == RADIOLIB_LR11X0_PACKET_TYPE_LORA) {
if(type == RADIOLIB_LR11X0_PACKET_TYPE_GFSK) {
// update sync word length
this->syncWordLength = len*8;
state = setPacketParamsGFSK(this->preambleLengthGFSK, this->preambleDetLength, this->syncWordLength, this->addrComp, this->packetType, RADIOLIB_LR11X0_MAX_PACKET_LENGTH, this->crcTypeGFSK, this->whitening);
RADIOLIB_ASSERT(state);

// sync word is passed most-significant byte first
uint8_t fullSyncWord[RADIOLIB_LR11X0_GFSK_SYNC_WORD_LEN] = { 0 };
memcpy(fullSyncWord, syncWord, len);
return(setGfskSyncWord(fullSyncWord));

} else if(type == RADIOLIB_LR11X0_PACKET_TYPE_LORA) {
// with length set to 1 and LoRa modem active, assume it is the LoRa sync word
if(len > 1) {
return(RADIOLIB_ERR_INVALID_SYNC_WORD);
}
return(setSyncWord(syncWord[0]));

} else if(type != RADIOLIB_LR11X0_PACKET_TYPE_GFSK) {
return(RADIOLIB_ERR_WRONG_MODEM);
} else if(type == RADIOLIB_LR11X0_PACKET_TYPE_LR_FHSS) {
// with length set to 4 and LR-FHSS modem active, assume it is the LR-FHSS sync word
if(len != sizeof(uint32_t)) {
return(RADIOLIB_ERR_INVALID_SYNC_WORD);
}
uint32_t sync = 0;
memcpy(&sync, syncWord, sizeof(uint32_t));
return(lrFhssSetSyncWord(sync));

}

// update sync word length
this->syncWordLength = len*8;
state = setPacketParamsGFSK(this->preambleLengthGFSK, this->preambleDetLength, this->syncWordLength, this->addrComp, this->packetType, RADIOLIB_LR11X0_MAX_PACKET_LENGTH, this->crcTypeGFSK, this->whitening);
RADIOLIB_ASSERT(state);

// sync word is passed most-significant byte first
uint8_t fullSyncWord[RADIOLIB_LR11X0_GFSK_SYNC_WORD_LEN] = { 0 };
memcpy(fullSyncWord, syncWord, len);
return(setGfskSyncWord(fullSyncWord));
return(RADIOLIB_ERR_WRONG_MODEM);
}

int16_t LR11x0::setSyncBits(uint8_t *syncWord, uint8_t bitsLen) {
Expand Down
6 changes: 3 additions & 3 deletions src/modules/LR11x0/LR11x0.h
Original file line number Diff line number Diff line change
Expand Up @@ -1176,11 +1176,11 @@ class LR11x0: public PhysicalLayer {
int16_t setCodingRate(uint8_t cr, bool longInterleave = false);

/*!
\brief Sets LoRa or LR-FHSS sync word.
\param syncWord LoRa or LR-FHSS sync word to be set. For LoRa, only 8 least significant bits will be used
\brief Sets LoRa sync word.
\param syncWord LoRa sync word to be set.
\returns \ref status_codes
*/
int16_t setSyncWord(uint32_t syncWord);
int16_t setSyncWord(uint8_t syncWord);

/*!
\brief Sets GFSK bit rate. Allowed values range from 0.6 to 300.0 kbps.
Expand Down

0 comments on commit 8f3a5c7

Please sign in to comment.