The magic numbers for the high frequency(HF) vs. low frequency(LF) adjustment bugged me
int rssi = this.RegisterManager.ReadByte((byte)Registers.RegRssiValue); if (Frequency < 868E6) rssi = -164 + rssi; // LF output port else rssi = -157 + rssi; // HF output port int packetRssi = this.RegisterManager.ReadByte((byte)Registers.RegPktRssiValue); if (Frequency < 868E6) packetRssi = -164 + rssi; // LF output port else packetRssi = -157 + rssi; // HF output port
After some searching I ended up at the Semetch LoRaMac node github repository. In that code they had a number of constants which looked like a better approach.
if( SX1276.Settings.Channel > RF_MID_BAND_THRESH ) { rssi = RSSI_OFFSET_HF + SX1276Read( REG_LR_RSSIVALUE ); } else { rssi = RSSI_OFFSET_LF + SX1276Read( REG_LR_RSSIVALUE ); }
I also fixed a couple of bugs I noticed with the maths and the code now looks like this
int rssi = this.RegisterManager.ReadByte((byte)Registers.RegRssiValue); if (Frequency > RFMidBandThreshold) rssi = RssiAdjustmentHF + rssi; else rssi = RssiAdjustmentLF + rssi; int packetRssi = this.RegisterManager.ReadByte((byte)Registers.RegPktRssiValue); if (Frequency > RFMidBandThreshold) packetRssi = RssiAdjustmentHF + packetRssi; else packetRssi = RssiAdjustmentLF + packetRssi;
This has also got me thing about how RegLna – LnaBoostLf/LnaBoostHf should be handled as well.