[SX126x] Implemented new common PHY methods
This commit is contained in:
parent
91787eb269
commit
d561d41e95
2 changed files with 61 additions and 21 deletions
|
@ -879,7 +879,7 @@ float SX126x::getCurrentLimit() {
|
||||||
return((float)ocp * 2.5);
|
return((float)ocp * 2.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t SX126x::setPreambleLength(uint16_t preambleLength) {
|
int16_t SX126x::setPreambleLength(size_t preambleLength) {
|
||||||
uint8_t modem = getPacketType();
|
uint8_t modem = getPacketType();
|
||||||
if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) {
|
if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) {
|
||||||
this->preambleLengthLoRa = preambleLength;
|
this->preambleLengthLoRa = preambleLength;
|
||||||
|
@ -937,6 +937,31 @@ int16_t SX126x::setBitRate(float br) {
|
||||||
return(setModulationParamsFSK(this->bitRate, this->pulseShape, this->rxBandwidth, this->frequencyDev));
|
return(setModulationParamsFSK(this->bitRate, this->pulseShape, this->rxBandwidth, this->frequencyDev));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int16_t SX126x::setDataRate(DataRate_t dr) {
|
||||||
|
int16_t state = RADIOLIB_ERR_UNKNOWN;
|
||||||
|
|
||||||
|
// select interpretation based on active modem
|
||||||
|
uint8_t modem = this->getPacketType();
|
||||||
|
if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
|
||||||
|
// set the bit rate
|
||||||
|
state = this->setBitRate(dr.fsk.bitRate);
|
||||||
|
RADIOLIB_ASSERT(state);
|
||||||
|
|
||||||
|
// set the frequency deviation
|
||||||
|
state = this->setFrequencyDeviation(dr.fsk.freqDev);
|
||||||
|
|
||||||
|
} else if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) {
|
||||||
|
// set the spreading factor
|
||||||
|
state = this->setSpreadingFactor(dr.lora.spreadingFactor);
|
||||||
|
RADIOLIB_ASSERT(state);
|
||||||
|
|
||||||
|
// set the bandwidth
|
||||||
|
state = this->setBandwidth(dr.lora.bandwidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(state);
|
||||||
|
}
|
||||||
|
|
||||||
int16_t SX126x::setRxBandwidth(float rxBw) {
|
int16_t SX126x::setRxBandwidth(float rxBw) {
|
||||||
// check active modem
|
// check active modem
|
||||||
if(getPacketType() != RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
|
if(getPacketType() != RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
|
||||||
|
@ -1068,26 +1093,34 @@ int16_t SX126x::setDataShaping(uint8_t sh) {
|
||||||
return(setModulationParamsFSK(this->bitRate, this->pulseShape, this->rxBandwidth, this->frequencyDev));
|
return(setModulationParamsFSK(this->bitRate, this->pulseShape, this->rxBandwidth, this->frequencyDev));
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t SX126x::setSyncWord(uint8_t* syncWord, uint8_t len) {
|
int16_t SX126x::setSyncWord(uint8_t* syncWord, size_t len) {
|
||||||
// check active modem
|
// check active modem
|
||||||
if(getPacketType() != RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
|
uint8_t modem = getPacketType();
|
||||||
return(RADIOLIB_ERR_WRONG_MODEM);
|
if(modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
|
||||||
|
// check sync word Length
|
||||||
|
if(len > 8) {
|
||||||
|
return(RADIOLIB_ERR_INVALID_SYNC_WORD);
|
||||||
|
}
|
||||||
|
|
||||||
|
// write sync word
|
||||||
|
int16_t state = writeRegister(RADIOLIB_SX126X_REG_SYNC_WORD_0, syncWord, len);
|
||||||
|
RADIOLIB_ASSERT(state);
|
||||||
|
|
||||||
|
// update packet parameters
|
||||||
|
this->syncWordLength = len * 8;
|
||||||
|
state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType);
|
||||||
|
|
||||||
|
return(state);
|
||||||
|
|
||||||
|
} else if(modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) {
|
||||||
|
// with length set to 1 and LoRa modem active, assume it is the LoRa sync word
|
||||||
|
if(len > 1) {
|
||||||
|
return(RADIOLIB_ERR_INVALID_SYNC_WORD);
|
||||||
|
}
|
||||||
|
return(setSyncWord(syncWord[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// check sync word Length
|
return(RADIOLIB_ERR_WRONG_MODEM);
|
||||||
if(len > 8) {
|
|
||||||
return(RADIOLIB_ERR_INVALID_SYNC_WORD);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write sync word
|
|
||||||
int16_t state = writeRegister(RADIOLIB_SX126X_REG_SYNC_WORD_0, syncWord, len);
|
|
||||||
RADIOLIB_ASSERT(state);
|
|
||||||
|
|
||||||
// update packet parameters
|
|
||||||
this->syncWordLength = len * 8;
|
|
||||||
state = setPacketParamsFSK(this->preambleLengthFSK, this->crcTypeFSK, this->syncWordLength, this->addrComp, this->whitening, this->packetType);
|
|
||||||
|
|
||||||
return(state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t SX126x::setSyncBits(uint8_t *syncWord, uint8_t bitsLen) {
|
int16_t SX126x::setSyncBits(uint8_t *syncWord, uint8_t bitsLen) {
|
||||||
|
|
|
@ -744,7 +744,7 @@ class SX126x: public PhysicalLayer {
|
||||||
\param preambleLength Preamble length to be set in symbols (LoRa) or bits (FSK).
|
\param preambleLength Preamble length to be set in symbols (LoRa) or bits (FSK).
|
||||||
\returns \ref status_codes
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
int16_t setPreambleLength(uint16_t preambleLength);
|
int16_t setPreambleLength(size_t preambleLength) override;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Sets FSK frequency deviation. Allowed values range from 0.0 to 200.0 kHz.
|
\brief Sets FSK frequency deviation. Allowed values range from 0.0 to 200.0 kHz.
|
||||||
|
@ -760,6 +760,13 @@ class SX126x: public PhysicalLayer {
|
||||||
*/
|
*/
|
||||||
int16_t setBitRate(float br);
|
int16_t setBitRate(float br);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Set data.
|
||||||
|
\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 receiver bandwidth. Allowed values are 4.8, 5.8, 7.3, 9.7, 11.7, 14.6, 19.5,
|
\brief Sets FSK receiver bandwidth. Allowed values are 4.8, 5.8, 7.3, 9.7, 11.7, 14.6, 19.5,
|
||||||
23.4, 29.3, 39.0, 46.9, 58.6, 78.2, 93.8, 117.3, 156.2, 187.2, 234.3, 312.0, 373.6 and 467.0 kHz.
|
23.4, 29.3, 39.0, 46.9, 58.6, 78.2, 93.8, 117.3, 156.2, 187.2, 234.3, 312.0, 373.6 and 467.0 kHz.
|
||||||
|
@ -793,7 +800,7 @@ class SX126x: public PhysicalLayer {
|
||||||
\param len FSK sync word length in bytes.
|
\param len FSK sync word length in bytes.
|
||||||
\returns \ref status_codes
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
int16_t setSyncWord(uint8_t* syncWord, uint8_t len);
|
int16_t setSyncWord(uint8_t* syncWord, size_t len) override;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Sets FSK sync word in the form of array of up to 8 bytes.
|
\brief Sets FSK sync word in the form of array of up to 8 bytes.
|
||||||
|
@ -984,7 +991,7 @@ class SX126x: public PhysicalLayer {
|
||||||
\param enable QI inversion enabled (true) or disabled (false);
|
\param enable QI inversion enabled (true) or disabled (false);
|
||||||
\returns \ref status_codes
|
\returns \ref status_codes
|
||||||
*/
|
*/
|
||||||
int16_t invertIQ(bool enable);
|
int16_t invertIQ(bool enable) override;
|
||||||
|
|
||||||
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
|
#if !defined(RADIOLIB_EXCLUDE_DIRECT_RECEIVE)
|
||||||
/*!
|
/*!
|
||||||
|
|
Loading…
Add table
Reference in a new issue