mirror of
https://github.com/sandeepmistry/arduino-LoRa.git
synced 2025-04-19 13:02:14 +03:00
Add getting the frequency error of a packet
This commit is contained in:
parent
b4558aa8f5
commit
abff435bd6
@ -21,6 +21,7 @@ endPacket KEYWORD2
|
||||
parsePacket KEYWORD2
|
||||
packetRssi KEYWORD2
|
||||
packetSnr KEYWORD2
|
||||
packetFrequencyError KEYWORD2
|
||||
|
||||
write KEYWORD2
|
||||
|
||||
@ -48,6 +49,7 @@ random KEYWORD2
|
||||
setPins KEYWORD2
|
||||
setSPIFrequency KEYWORD2
|
||||
dumpRegisters KEYWORD2
|
||||
getSignalBandwidth KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
|
37
src/LoRa.cpp
37
src/LoRa.cpp
@ -25,6 +25,7 @@
|
||||
#define REG_PREAMBLE_LSB 0x21
|
||||
#define REG_PAYLOAD_LENGTH 0x22
|
||||
#define REG_MODEM_CONFIG_3 0x26
|
||||
#define REG_FREQ_ERROR 0x28
|
||||
#define REG_RSSI_WIDEBAND 0x2c
|
||||
#define REG_DETECTION_OPTIMIZE 0x31
|
||||
#define REG_DETECTION_THRESHOLD 0x37
|
||||
@ -211,6 +212,25 @@ float LoRaClass::packetSnr()
|
||||
return ((int8_t)readRegister(REG_PKT_SNR_VALUE)) * 0.25;
|
||||
}
|
||||
|
||||
double LoRaClass::packetFrequencyError()
|
||||
{
|
||||
int32_t fe = (int32_t)readRegister(REG_FREQ_ERROR) & 7;
|
||||
fe <<= 8L;
|
||||
fe += (int32_t)readRegister(REG_FREQ_ERROR+1);
|
||||
fe <<= 8L;
|
||||
fe += (int32_t)readRegister(REG_FREQ_ERROR+2);
|
||||
|
||||
if (readRegister(REG_FREQ_ERROR) & 8) {
|
||||
fe = fe - 524288;
|
||||
}
|
||||
|
||||
double freqError = (double)fe;
|
||||
freqError *= (16777216.0 / 32000000.0);
|
||||
freqError *= (getSignalBandwidth() / 500000.0);
|
||||
|
||||
return freqError;
|
||||
}
|
||||
|
||||
size_t LoRaClass::write(uint8_t byte)
|
||||
{
|
||||
return write(&byte, sizeof(byte));
|
||||
@ -365,6 +385,23 @@ void LoRaClass::setSpreadingFactor(int sf)
|
||||
writeRegister(REG_MODEM_CONFIG_2, (readRegister(REG_MODEM_CONFIG_2) & 0x0f) | ((sf << 4) & 0xf0));
|
||||
}
|
||||
|
||||
long LoRaClass::getSignalBandwidth()
|
||||
{
|
||||
byte bw = (readRegister(REG_MODEM_CONFIG_1) >> 4);
|
||||
switch (bw) {
|
||||
case 0: return 7.8E3;
|
||||
case 1: return 10.4E3;
|
||||
case 2: return 15.6E3;
|
||||
case 3: return 20.8E3;
|
||||
case 4: return 31.25E3;
|
||||
case 5: return 41.7E3;
|
||||
case 6: return 62.5E3;
|
||||
case 7: return 125E3;
|
||||
case 8: return 250E3;
|
||||
case 9: return 500E3;
|
||||
}
|
||||
}
|
||||
|
||||
void LoRaClass::setSignalBandwidth(long sbw)
|
||||
{
|
||||
int bw;
|
||||
|
@ -27,6 +27,7 @@ public:
|
||||
int parsePacket(int size = 0);
|
||||
int packetRssi();
|
||||
float packetSnr();
|
||||
double packetFrequencyError();
|
||||
|
||||
// from Print
|
||||
virtual size_t write(uint8_t byte);
|
||||
@ -65,6 +66,8 @@ public:
|
||||
|
||||
void dumpRegisters(Stream& out);
|
||||
|
||||
long getSignalBandwidth();
|
||||
|
||||
private:
|
||||
void explicitHeaderMode();
|
||||
void implicitHeaderMode();
|
||||
|
Loading…
x
Reference in New Issue
Block a user