Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHY] Get/Set modem #1294

Merged
merged 15 commits into from
Oct 26, 2024
Prev Previous commit
Next Next commit
[SX128x] Added get/set modem
  • Loading branch information
jgromes committed Oct 26, 2024
commit 641a5b7985c83265bd3c62ef84f3b04328f77f45
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
Loading