From 1046db24e464b28d880f6d6c40fb9e10f73c671f Mon Sep 17 00:00:00 2001 From: mmrein <55082189+mmrein@users.noreply.github.com> Date: Thu, 12 Sep 2019 10:16:36 +0200 Subject: [PATCH 1/6] Add setSyncBits for SX126x Add setSyncBits for possibility to set the sync word length in bits --- src/modules/SX126x.cpp | 27 +++++++++++++++++++++++++++ src/modules/SX126x.h | 11 +++++++++++ 2 files changed, 38 insertions(+) diff --git a/src/modules/SX126x.cpp b/src/modules/SX126x.cpp index dd920d0f..e76b05e2 100644 --- a/src/modules/SX126x.cpp +++ b/src/modules/SX126x.cpp @@ -721,6 +721,33 @@ int16_t SX126x::setSyncWord(uint8_t* syncWord, uint8_t len) { return(state); } +int16_t SX126x::setSyncBits(uint8_t *syncWord, uint8_t bitsLen) { + // check active modem + if(getPacketType() != SX126X_PACKET_TYPE_GFSK) { + return(ERR_WRONG_MODEM); + } + + // check sync word Length + if(bitsLen > 0x40) { + return(ERR_INVALID_SYNC_WORD); + } + + uint8_t bytesLen = bitsLen / 8; + if ((bitsLen % 8) != 0) bytesLen++; + + // write sync word + int16_t state = writeRegister(SX126X_REG_SYNC_WORD_0, syncWord, bytesLen); + if(state != ERR_NONE) { + return(state); + } + + // update packet parameters + _syncWordLength = bitsLen; + state = setPacketParamsFSK(_preambleLengthFSK, _crcTypeFSK, _syncWordLength, _addrComp); + + return(state); +} + int16_t SX126x::setNodeAddress(uint8_t nodeAddr) { // check active modem if(getPacketType() != SX126X_PACKET_TYPE_GFSK) { diff --git a/src/modules/SX126x.h b/src/modules/SX126x.h index 134325bd..df43c497 100644 --- a/src/modules/SX126x.h +++ b/src/modules/SX126x.h @@ -604,6 +604,17 @@ class SX126x: public PhysicalLayer { */ int16_t setSyncWord(uint8_t* syncWord, uint8_t len); + /*! + \brief Sets FSK sync word in the form of array of up to 8 bytes. + + \param syncWord FSK sync word to be set. + + \param len FSK sync word length in bits. + + \returns \ref status_codes + */ + int16_t setSyncBits(uint8_t *sync, uint8_t bitsLen); + /*! \brief Sets node address. Calling this method will also enable address filtering for node address only. From 86ca0290235fdbca48950b35780cbeecb7b3e6a2 Mon Sep 17 00:00:00 2001 From: mmrein <55082189+mmrein@users.noreply.github.com> Date: Mon, 16 Sep 2019 19:25:35 +0200 Subject: [PATCH 2/6] Update SX126x.cpp --- src/modules/SX126x.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/modules/SX126x.cpp b/src/modules/SX126x.cpp index e76b05e2..99996ea8 100644 --- a/src/modules/SX126x.cpp +++ b/src/modules/SX126x.cpp @@ -733,7 +733,9 @@ int16_t SX126x::setSyncBits(uint8_t *syncWord, uint8_t bitsLen) { } uint8_t bytesLen = bitsLen / 8; - if ((bitsLen % 8) != 0) bytesLen++; + if ((bitsLen % 8) != 0) { + bytesLen++; + } // write sync word int16_t state = writeRegister(SX126X_REG_SYNC_WORD_0, syncWord, bytesLen); From dbbb12610ce748b36802fb50d1aeff1a8575ae6f Mon Sep 17 00:00:00 2001 From: mmrein <55082189+mmrein@users.noreply.github.com> Date: Mon, 16 Sep 2019 19:32:41 +0200 Subject: [PATCH 3/6] Add setSyncBits to # SX126x-specific --- keywords.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/keywords.txt b/keywords.txt index 1e47e76e..d0846298 100644 --- a/keywords.txt +++ b/keywords.txt @@ -106,6 +106,7 @@ setDio2Action KEYWORD2 setTCXO KEYWORD2 setDio2AsRfSwitch KEYWORD2 getTimeOnAir KEYWORD2 +setSyncBits KEYWORD2 # ESP8266 join KEYWORD2 From c543a42124b15d43b1922acf3f8854bd5942617c Mon Sep 17 00:00:00 2001 From: mmrein <55082189+mmrein@users.noreply.github.com> Date: Mon, 16 Sep 2019 19:51:39 +0200 Subject: [PATCH 4/6] Add examle use for setSyncBits method --- examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino b/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino index 61b6a1e8..5a924b6d 100644 --- a/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino +++ b/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino @@ -73,6 +73,13 @@ void setup() { Serial.println(state); while (true); } + + // FSK modem on SX126x can handle the sync word setting in bits, not just + // whole bytes. The value used is LSB first. + // This makes same result as fsk.setSyncWord(syncWord, 8): + state = fsk.setSyncBits(syncWord, 64); + // This will use 0x012 as sync word (12 bits only): + state = fsk.setSyncBits(syncWord, 12); // FSK modem allows advanced CRC configuration // Default is CCIT CRC16 (2 bytes, initial 0x1D0F, polynomial 0x1021, inverted) From 9bb8586beb61c38d206f0ab6737dd3a4fa1f58bb Mon Sep 17 00:00:00 2001 From: mmrein <55082189+mmrein@users.noreply.github.com> Date: Mon, 16 Sep 2019 19:54:49 +0200 Subject: [PATCH 5/6] Updated note for setSyncBits example --- examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino b/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino index 5a924b6d..18050269 100644 --- a/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino +++ b/examples/SX126x/SX126x_FSK_Modem/SX126x_FSK_Modem.ino @@ -75,7 +75,7 @@ void setup() { } // FSK modem on SX126x can handle the sync word setting in bits, not just - // whole bytes. The value used is LSB first. + // whole bytes. The value used is left-justified. // This makes same result as fsk.setSyncWord(syncWord, 8): state = fsk.setSyncBits(syncWord, 64); // This will use 0x012 as sync word (12 bits only): From a810a31c5f8a9125a7e787ac731804a25c35687a Mon Sep 17 00:00:00 2001 From: mmrein <55082189+mmrein@users.noreply.github.com> Date: Mon, 16 Sep 2019 20:10:59 +0200 Subject: [PATCH 6/6] setSyncBits: *sync changed to *syncWord, added note setSyncBits: Update *sync to *syncWord, add note about bits of syncWord being used if less than 64 bits. --- src/modules/SX126x.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/SX126x.h b/src/modules/SX126x.h index df43c497..b56c879d 100644 --- a/src/modules/SX126x.h +++ b/src/modules/SX126x.h @@ -607,13 +607,13 @@ class SX126x: public PhysicalLayer { /*! \brief Sets FSK sync word in the form of array of up to 8 bytes. - \param syncWord FSK sync word to be set. + \param syncWord FSK sync word to be set. - \param len FSK sync word length in bits. + \param len FSK sync word length in bits. If less than 64 bits the LSB's of syncWord will be ignored. \returns \ref status_codes */ - int16_t setSyncBits(uint8_t *sync, uint8_t bitsLen); + int16_t setSyncBits(uint8_t *syncWord, uint8_t bitsLen); /*! \brief Sets node address. Calling this method will also enable address filtering for node address only.