Skip to content

Commit

Permalink
[SX128x] Added get/set modem
Browse files Browse the repository at this point in the history
  • Loading branch information
jgromes committed Oct 26, 2024
1 parent 301654e commit 641a5b7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/modules/SX128x/SX128x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
15 changes: 15 additions & 0 deletions src/modules/SX128x/SX128x.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 641a5b7

Please sign in to comment.