[SX127x] Unified getRSSI interface

This commit is contained in:
jgromes 2023-03-27 23:22:03 +02:00
parent ab9cf0d528
commit f62f912c87
6 changed files with 68 additions and 90 deletions

View file

@ -352,37 +352,8 @@ int16_t SX1272::setDataShapingOOK(uint8_t sh) {
return(state);
}
float SX1272::getRSSI(bool skipReceive) {
if(getActiveModem() == RADIOLIB_SX127X_LORA) {
// RSSI calculation uses different constant for low-frequency and high-frequency ports
float lastPacketRSSI = -139 + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PKT_RSSI_VALUE);
// spread-spectrum modulation signal can be received below noise floor
// check last packet SNR and if it's less than 0, add it to reported RSSI to get the correct value
float lastPacketSNR = SX127x::getSNR();
if(lastPacketSNR < 0.0) {
lastPacketRSSI += lastPacketSNR;
}
return(lastPacketRSSI);
} else {
// enable listen mode
if(!skipReceive) {
startReceive();
}
// read the value for FSK
float rssi = (float)_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE_FSK) / -2.0;
// set mode back to standby
if(!skipReceive) {
standby();
}
// return the value
return(rssi);
}
float SX1272::getRSSI(bool packet, bool skipReceive) {
return(SX127x::getRSSI(packet, skipReceive, -139));
}
int16_t SX1272::setCRC(bool enable, bool mode) {

View file

@ -240,13 +240,15 @@ class SX1272: public SX127x {
int16_t setDataShapingOOK(uint8_t sh);
/*!
\brief Gets recorded signal strength indicator of the latest received packet for LoRa modem, or current RSSI level for FSK modem.
\brief Gets recorded signal strength indicator.
\param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FKS/OOK mode.
\param packet Whether to read last packet RSSI, or the current value. LoRa mode only, ignored for FSK.
\returns Last packet RSSI for LoRa modem, or current RSSI level for FSK modem.
\param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FSK/OOK mode.
\returns RSSI value in dBm.
*/
float getRSSI(bool skipReceive = false);
float getRSSI(bool packet = true, bool skipReceive = false);
/*!
\brief Enables/disables CRC check of received packets.

View file

@ -382,58 +382,11 @@ int16_t SX1278::setDataShapingOOK(uint8_t sh) {
}
float SX1278::getRSSI(bool packet, bool skipReceive) {
if(getActiveModem() == RADIOLIB_SX127X_LORA) {
if (packet) {
// for LoRa, get RSSI of the last packet
float lastPacketRSSI;
// RSSI calculation uses different constant for low-frequency and high-frequency ports
if(_freq < 868.0) {
lastPacketRSSI = -164 + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PKT_RSSI_VALUE);
} else {
lastPacketRSSI = -157 + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PKT_RSSI_VALUE);
}
// spread-spectrum modulation signal can be received below noise floor
// check last packet SNR and if it's less than 0, add it to reported RSSI to get the correct value
float lastPacketSNR = SX127x::getSNR();
if(lastPacketSNR < 0.0) {
lastPacketRSSI += lastPacketSNR;
}
return(lastPacketRSSI);
} else {
// for LoRa, get current RSSI
float currentRSSI;
// RSSI calculation uses different constant for low-frequency and high-frequency ports
if(_freq < 868.0) {
currentRSSI = -164 + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE);
} else {
currentRSSI = -157 + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE);
}
return(currentRSSI);
}
} else {
// enable listen mode
if(!skipReceive) {
startReceive();
}
// read the value for FSK
float rssi = (float)_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE_FSK) / -2.0;
// set mode back to standby
if(!skipReceive) {
standby();
}
// return the value
return(rssi);
int16_t offset = -157;
if(_freq < 868.0) {
offset = -164;
}
return(SX127x::getRSSI(packet, skipReceive, offset));
}
int16_t SX1278::setCRC(bool enable, bool mode) {

View file

@ -249,13 +249,13 @@ class SX1278: public SX127x {
int16_t setDataShapingOOK(uint8_t sh);
/*!
\brief Gets recorded signal strength indicator of the latest received packet for LoRa modem, or current RSSI level for FSK modem.
\brief Gets recorded signal strength indicator.
\param packet Set to false to gets current RSSI measurement in LoRa mode.
\param packet Whether to read last packet RSSI, or the current value. LoRa mode only, ignored for FSK.
\param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FKS/OOK mode.
\param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FSK/OOK mode.
\returns Last packet RSSI for LoRa modem, or current RSSI level for FSK modem.
\returns RSSI value in dBm.
*/
float getRSSI(bool packet = true, bool skipReceive = false);

View file

@ -1552,4 +1552,45 @@ int16_t SX127x::setDIOPreambleDetect(bool usePreambleDetect) {
return _mod->SPIsetRegValue(RADIOLIB_SX127X_REG_DIO_MAPPING_2, (usePreambleDetect) ? RADIOLIB_SX127X_DIO_MAP_PREAMBLE_DETECT : RADIOLIB_SX127X_DIO_MAP_RSSI, 0, 0);
}
float SX127x::getRSSI(bool packet, bool skipReceive, int16_t offset) {
if(getActiveModem() == RADIOLIB_SX127X_LORA) {
if(packet) {
// LoRa packet mode, get RSSI of the last packet
float lastPacketRSSI = offset + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_PKT_RSSI_VALUE);
// spread-spectrum modulation signal can be received below noise floor
// check last packet SNR and if it's less than 0, add it to reported RSSI to get the correct value
float lastPacketSNR = SX127x::getSNR();
if(lastPacketSNR < 0.0) {
lastPacketRSSI += lastPacketSNR;
}
return(lastPacketRSSI);
} else {
// LoRa instant, get current RSSI
float currentRSSI = offset + _mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE);
return(currentRSSI);
}
} else {
// for FSK, there is no packet RSSI
// enable listen mode
if(!skipReceive) {
startReceive();
}
// read the value for FSK
float rssi = (float)_mod->SPIgetRegValue(RADIOLIB_SX127X_REG_RSSI_VALUE_FSK) / -2.0;
// set mode back to standby
if(!skipReceive) {
standby();
}
// return the value
return(rssi);
}
}
#endif

View file

@ -1243,6 +1243,17 @@ class SX127x: public PhysicalLayer {
*/
int16_t setDIOPreambleDetect(bool usePreambleDetect);
/*!
\brief Gets recorded signal strength indicator.
\param packet Whether to read last packet RSSI, or the current value. LoRa mode only, ignored for FSK.
\param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FSK/OOK mode.
\returns RSSI value in dBm.
*/
float getRSSI(bool packet, bool skipReceive, int16_t offset);
/*!
\brief Sets the RSSI value above which the RSSI interrupt is signaled