From 157a00a65c7ba26f5dc2d6b70040af3af1e7c33f Mon Sep 17 00:00:00 2001 From: "jacob.eva" Date: Wed, 2 Oct 2024 15:12:44 +0100 Subject: [PATCH] [SX128x] Add setDataRate method for LoRa modem --- src/modules/SX128x/SX128x.cpp | 16 ++++++++++++++++ src/modules/SX128x/SX128x.h | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index b1f47c7e8..05d5af519 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -902,6 +902,22 @@ int16_t SX128x::setPreambleLength(uint32_t preambleLength) { return(RADIOLIB_ERR_WRONG_MODEM); } +int16_t SX128x::setDataRate(DataRate_t dr) { + // check active modem + uint8_t modem = getPacketType(); + int16_t state = RADIOLIB_ERR_NONE; + if (modem == RADIOLIB_SX128X_PACKET_TYPE_LORA) { + state = this->setBandwidth(dr.lora.bandwidth); + RADIOLIB_ASSERT(state); + state = this->setSpreadingFactor(dr.lora.spreadingFactor); + RADIOLIB_ASSERT(state); + state = this->setCodingRate(dr.lora.codingRate); + } else { + return(RADIOLIB_ERR_WRONG_MODEM); + } + return(state); +} + int16_t SX128x::setBitRate(float br) { // check active modem uint8_t modem = getPacketType(); diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index cea6b7ade..2fa16093b 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -678,6 +678,13 @@ class SX128x: public PhysicalLayer { */ int16_t setPreambleLength(uint32_t preambleLength); + /*! + \brief Set data rate. + \param dr Data rate struct. Interpretation depends on currently active modem (FSK or LoRa). + \returns \ref status_codes + */ + int16_t setDataRate(DataRate_t dr) override; + /*! \brief Sets FSK or FLRC bit rate. Allowed values are 125, 250, 400, 500, 800, 1000, 1600 and 2000 kbps (for FSK modem) or 260, 325, 520, 650, 1000 and 1300 (for FLRC modem).