diff --git a/src/modules/SX128x/SX128x.cpp b/src/modules/SX128x/SX128x.cpp index a7fe165b5..5847f3d6c 100644 --- a/src/modules/SX128x/SX128x.cpp +++ b/src/modules/SX128x/SX128x.cpp @@ -856,6 +856,37 @@ int16_t SX128x::checkOutputPower(int8_t pwr, int8_t* clipped) { return(RADIOLIB_ERR_NONE); } +int16_t SX128x::setModem(ModemType_t modem) { + switch(modem) { + case(ModemType_t::LoRa): { + return(this->begin()); + } break; + case(ModemType_t::FSK): { + return(this->beginGFSK()); + } break; + default: + return(RADIOLIB_ERR_WRONG_MODEM); + } +} + +int16_t SX128x::getModem(ModemType_t* modem) { + if(!modem) { + return(RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED); + } + + uint8_t packetType = getPacketType(); + switch(packetType) { + case(RADIOLIB_SX128X_PACKET_TYPE_LORA): + *modem = ModemType_t::LoRa; + return(RADIOLIB_ERR_NONE); + case(RADIOLIB_SX128X_PACKET_TYPE_GFSK): + *modem = ModemType_t::FSK; + return(RADIOLIB_ERR_NONE); + } + + return(RADIOLIB_ERR_WRONG_MODEM); +} + int16_t SX128x::setPreambleLength(uint32_t preambleLength) { uint8_t modem = getPacketType(); if((modem == RADIOLIB_SX128X_PACKET_TYPE_LORA) || (modem == RADIOLIB_SX128X_PACKET_TYPE_RANGING)) { diff --git a/src/modules/SX128x/SX128x.h b/src/modules/SX128x/SX128x.h index 6f584ead8..ae1d46876 100644 --- a/src/modules/SX128x/SX128x.h +++ b/src/modules/SX128x/SX128x.h @@ -671,6 +671,21 @@ class SX128x: public PhysicalLayer { \returns \ref status_codes */ int16_t checkOutputPower(int8_t pwr, int8_t* clipped) override; + + /*! + \brief Set modem for the radio to use. Will perform full reset and reconfigure the radio + using its default parameters. + \param modem Modem type to set - FSK, LoRa or LR-FHSS. + \returns \ref status_codes + */ + int16_t setModem(ModemType_t modem) override; + + /*! + \brief Get modem currently in use by the radio. + \param modem Pointer to a variable to save the retrieved configuration into. + \returns \ref status_codes + */ + int16_t getModem(ModemType_t* modem) override; /*! \brief Sets preamble length for currently active modem. Allowed values range from 1 to 65535.