[SX127x] & [SX126x] read current RSSI for getRSSI
This commit is contained in:
parent
04e24ab9d1
commit
09ab5f8073
4 changed files with 42 additions and 55 deletions
src/modules
|
@ -1222,10 +1222,20 @@ float SX126x::getDataRate() const {
|
|||
}
|
||||
|
||||
float SX126x::getRSSI() {
|
||||
|
||||
if (packet) {
|
||||
// get last packet RSSI from packet status
|
||||
uint32_t packetStatus = getPacketStatus();
|
||||
uint8_t rssiPkt = packetStatus & 0xFF;
|
||||
return(-1.0 * rssiPkt/2.0);
|
||||
uint32_t packetStatus = getPacketStatus();
|
||||
uint8_t rssiPkt = packetStatus & 0xFF;
|
||||
return(-1.0 * rssiPkt/2.0);
|
||||
} else {
|
||||
// get instantaneous RSSI value
|
||||
uint8_t data[3] = {0, 0, 0}; // RssiInst, Status, RFU
|
||||
_mod->SPIreadStream(RADIOLIB_SX126X_CMD_GET_RSSI_INST, data, 3);
|
||||
|
||||
return (float)data[0] / (-2.0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float SX126x::getSNR() {
|
||||
|
|
|
@ -917,9 +917,11 @@ class SX126x: public PhysicalLayer {
|
|||
/*!
|
||||
\brief Gets RSSI (Recorded Signal Strength Indicator) of the last received packet.
|
||||
|
||||
\param packet Set to false to gets current RSSI measurement in LoRa mode.
|
||||
|
||||
\returns RSSI of the last received packet in dBm.
|
||||
*/
|
||||
float getRSSI();
|
||||
float getRSSI(bool packet = true);
|
||||
|
||||
/*!
|
||||
\brief Gets SNR (Signal to Noise Ratio) of the last received packet. Only available for LoRa modem.
|
||||
|
|
|
@ -381,60 +381,42 @@ int16_t SX1278::setDataShapingOOK(uint8_t sh) {
|
|||
return(state);
|
||||
}
|
||||
|
||||
float SX1278::getRSSI(bool skipReceive) {
|
||||
float SX1278::getRSSI(bool packet, bool skipReceive) {
|
||||
if(getActiveModem() == RADIOLIB_SX127X_LORA) {
|
||||
// for LoRa, get RSSI of the last packet
|
||||
float lastPacketRSSI;
|
||||
|
||||
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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
float lastPacketSNR = SX127x::getSNR();
|
||||
if(lastPacketSNR < 0.0) {
|
||||
lastPacketRSSI += lastPacketSNR;
|
||||
}
|
||||
return(lastPacketRSSI);
|
||||
|
||||
return(lastPacketRSSI);
|
||||
} else {
|
||||
|
||||
} 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 SX1278::getInstRSSI(bool skipReceive) {
|
||||
if(getActiveModem() == RADIOLIB_SX127X_LORA) {
|
||||
// for LoRa, get current RSSI
|
||||
float currentRSSI;
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
return(currentRSSI);
|
||||
|
||||
|
||||
} else {
|
||||
// enable listen mode
|
||||
if(!skipReceive) {
|
||||
|
|
|
@ -251,20 +251,13 @@ class SX1278: public SX127x {
|
|||
/*!
|
||||
\brief Gets recorded signal strength indicator of the latest received packet for LoRa modem, or current RSSI level for FSK modem.
|
||||
|
||||
\param packet Set to false to gets current RSSI measurement in LoRa mode.
|
||||
|
||||
\param skipReceive Set to true to skip putting radio in receive mode for the RSSI measurement in FKS/OOK mode.
|
||||
|
||||
\returns Last packet RSSI for LoRa modem, or current RSSI level for FSK modem.
|
||||
*/
|
||||
float getRSSI(bool skipReceive = false);
|
||||
|
||||
/*!
|
||||
\brief Gets current signal strength indicator of 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 FKS/OOK mode.
|
||||
|
||||
\returns Current packet RSSI for LoRa modem, or FSK modem.
|
||||
*/
|
||||
float getInstRSSI(bool skipReceive = false);
|
||||
float getRSSI(bool packet = true, bool skipReceive = false);
|
||||
|
||||
/*!
|
||||
\brief Enables/disables CRC check of received packets.
|
||||
|
|
Loading…
Add table
Reference in a new issue