1
0
mirror of https://github.com/sandeepmistry/arduino-LoRa.git synced 2025-04-19 13:02:14 +03:00

better handling of packet SNR, which can be a negative number and is stored in the register as twos complement

This commit is contained in:
Morgan 'ARR\!' Allen 2023-10-26 13:13:16 -07:00
parent 71d4c2998f
commit c84edc3bf1
2 changed files with 14 additions and 3 deletions

View File

@ -270,9 +270,20 @@ int LoRaClass::packetRssi()
return (readRegister(REG_PKT_RSSI_VALUE) - (_frequency < RF_MID_BAND_THRESHOLD ? RSSI_OFFSET_LF_PORT : RSSI_OFFSET_HF_PORT)); return (readRegister(REG_PKT_RSSI_VALUE) - (_frequency < RF_MID_BAND_THRESHOLD ? RSSI_OFFSET_LF_PORT : RSSI_OFFSET_HF_PORT));
} }
float LoRaClass::packetSnr() int LoRaClass::packetSnr()
{ {
return ((int8_t)readRegister(REG_PKT_SNR_VALUE)) * 0.25; int8_t snr = readRegister(REG_PKT_SNR_VALUE);
// check for two's complement negetive value
if(snr & 0x80) {
// invert value, increment by 1 and divide by 4 with >> 2 to avoid float
snr = ((~snr + 1) & 0xFF) >> 2;
} else {
// positive value only needs to be divided by 4
snr = snr >> 2;
}
return snr;
} }
long LoRaClass::packetFrequencyError() long LoRaClass::packetFrequencyError()

View File

@ -42,7 +42,7 @@ public:
int parsePacket(int size = 0); int parsePacket(int size = 0);
int packetRssi(); int packetRssi();
float packetSnr(); int packetSnr();
long packetFrequencyError(); long packetFrequencyError();
int rssi(); int rssi();