From 173d8cc202e6a6d94efbe3be28cf5a61ff93ce82 Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 26 Oct 2024 09:03:02 +0100 Subject: [PATCH] [LR11x0] Added get/set modem --- src/modules/LR11x0/LR1110.cpp | 15 +++++++++++++++ src/modules/LR11x0/LR1110.h | 8 ++++++++ src/modules/LR11x0/LR1120.cpp | 15 +++++++++++++++ src/modules/LR11x0/LR1120.h | 8 ++++++++ src/modules/LR11x0/LR11x0.cpp | 24 ++++++++++++++++++++++++ src/modules/LR11x0/LR11x0.h | 7 +++++++ 6 files changed, 77 insertions(+) diff --git a/src/modules/LR11x0/LR1110.cpp b/src/modules/LR11x0/LR1110.cpp index 7ebf5a7b..0950a3a3 100644 --- a/src/modules/LR11x0/LR1110.cpp +++ b/src/modules/LR11x0/LR1110.cpp @@ -105,4 +105,19 @@ int16_t LR1110::checkOutputPower(int8_t power, int8_t* clipped, bool forceHighPo return(RADIOLIB_ERR_NONE); } +int16_t LR1110::setModem(ModemType_t modem) { + switch(modem) { + case(ModemType_t::LoRa): { + return(this->begin()); + } break; + case(ModemType_t::FSK): { + return(this->beginGFSK()); + } break; + case(ModemType_t::LRFHSS): { + return(this->beginLRFHSS()); + } break; + } + return(RADIOLIB_ERR_WRONG_MODEM); +} + #endif \ No newline at end of file diff --git a/src/modules/LR11x0/LR1110.h b/src/modules/LR11x0/LR1110.h index 3e1bc5fc..bd7818f8 100644 --- a/src/modules/LR11x0/LR1110.h +++ b/src/modules/LR11x0/LR1110.h @@ -123,6 +123,14 @@ class LR1110: public LR11x0 { */ int16_t checkOutputPower(int8_t power, int8_t* clipped, bool forceHighPower); + /*! + \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; + #if !RADIOLIB_GODMODE private: #endif diff --git a/src/modules/LR11x0/LR1120.cpp b/src/modules/LR11x0/LR1120.cpp index 9afa8dfb..ae4dc4a1 100644 --- a/src/modules/LR11x0/LR1120.cpp +++ b/src/modules/LR11x0/LR1120.cpp @@ -128,4 +128,19 @@ int16_t LR1120::checkOutputPower(int8_t power, int8_t* clipped, bool forceHighPo return(RADIOLIB_ERR_NONE); } +int16_t LR1120::setModem(ModemType_t modem) { + switch(modem) { + case(ModemType_t::LoRa): { + return(this->begin()); + } break; + case(ModemType_t::FSK): { + return(this->beginGFSK()); + } break; + case(ModemType_t::LRFHSS): { + return(this->beginLRFHSS()); + } break; + } + return(RADIOLIB_ERR_WRONG_MODEM); +} + #endif \ No newline at end of file diff --git a/src/modules/LR11x0/LR1120.h b/src/modules/LR11x0/LR1120.h index 4abae5a9..dde24208 100644 --- a/src/modules/LR11x0/LR1120.h +++ b/src/modules/LR11x0/LR1120.h @@ -132,6 +132,14 @@ class LR1120: public LR11x0 { */ int16_t checkOutputPower(int8_t power, int8_t* clipped, bool forceHighPower); + /*! + \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; + #if !RADIOLIB_GODMODE private: #endif diff --git a/src/modules/LR11x0/LR11x0.cpp b/src/modules/LR11x0/LR11x0.cpp index 6bb4e227..03d32d04 100644 --- a/src/modules/LR11x0/LR11x0.cpp +++ b/src/modules/LR11x0/LR11x0.cpp @@ -2009,6 +2009,30 @@ int16_t LR11x0::getGnssSatellites(LR11x0GnssSatellite_t* sats, uint8_t numSats) return(state); } +int16_t LR11x0::getModem(ModemType_t* modem) { + if(!modem) { + return(RADIOLIB_ERR_MEMORY_ALLOCATION_FAILED); + } + + uint8_t packetType = RADIOLIB_LR11X0_PACKET_TYPE_NONE; + int16_t state = getPacketType(&packetType); + RADIOLIB_ASSERT(state); + + switch(packetType) { + case(RADIOLIB_LR11X0_PACKET_TYPE_LORA): + *modem = ModemType_t::LoRa; + return(RADIOLIB_ERR_NONE); + case(RADIOLIB_LR11X0_PACKET_TYPE_GFSK): + *modem = ModemType_t::FSK; + return(RADIOLIB_ERR_NONE); + case(RADIOLIB_LR11X0_PACKET_TYPE_LR_FHSS): + *modem = ModemType_t::LRFHSS; + return(RADIOLIB_ERR_NONE); + } + + return(RADIOLIB_ERR_WRONG_MODEM); +} + int16_t LR11x0::modSetup(float tcxoVoltage, uint8_t modem) { this->mod->init(); this->mod->hal->pinMode(this->mod->getIrq(), this->mod->hal->GpioModeInput); diff --git a/src/modules/LR11x0/LR11x0.h b/src/modules/LR11x0/LR11x0.h index 3f1939a5..490c1203 100644 --- a/src/modules/LR11x0/LR11x0.h +++ b/src/modules/LR11x0/LR11x0.h @@ -1602,6 +1602,13 @@ class LR11x0: public PhysicalLayer { \returns \ref status_codes */ int16_t getGnssSatellites(LR11x0GnssSatellite_t* sats, uint8_t numSats); + + /*! + \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; #if !RADIOLIB_GODMODE && !RADIOLIB_LOW_LEVEL protected: