mirror of
https://github.com/sandeepmistry/arduino-LoRa.git
synced 2025-04-20 23:47:47 +03:00
Update for review comments
This commit is contained in:
parent
abff435bd6
commit
1356f736a3
@ -49,7 +49,6 @@ random KEYWORD2
|
|||||||
setPins KEYWORD2
|
setPins KEYWORD2
|
||||||
setSPIFrequency KEYWORD2
|
setSPIFrequency KEYWORD2
|
||||||
dumpRegisters KEYWORD2
|
dumpRegisters KEYWORD2
|
||||||
getSignalBandwidth KEYWORD2
|
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
# Constants (LITERAL1)
|
# Constants (LITERAL1)
|
||||||
|
28
src/LoRa.cpp
28
src/LoRa.cpp
@ -25,7 +25,9 @@
|
|||||||
#define REG_PREAMBLE_LSB 0x21
|
#define REG_PREAMBLE_LSB 0x21
|
||||||
#define REG_PAYLOAD_LENGTH 0x22
|
#define REG_PAYLOAD_LENGTH 0x22
|
||||||
#define REG_MODEM_CONFIG_3 0x26
|
#define REG_MODEM_CONFIG_3 0x26
|
||||||
#define REG_FREQ_ERROR 0x28
|
#define REG_FREQ_ERROR_MSB 0x28
|
||||||
|
#define REG_FREQ_ERROR_MID 0x29
|
||||||
|
#define REG_FREQ_ERROR_LSB 0x2a
|
||||||
#define REG_RSSI_WIDEBAND 0x2c
|
#define REG_RSSI_WIDEBAND 0x2c
|
||||||
#define REG_DETECTION_OPTIMIZE 0x31
|
#define REG_DETECTION_OPTIMIZE 0x31
|
||||||
#define REG_DETECTION_THRESHOLD 0x37
|
#define REG_DETECTION_THRESHOLD 0x37
|
||||||
@ -212,23 +214,23 @@ float LoRaClass::packetSnr()
|
|||||||
return ((int8_t)readRegister(REG_PKT_SNR_VALUE)) * 0.25;
|
return ((int8_t)readRegister(REG_PKT_SNR_VALUE)) * 0.25;
|
||||||
}
|
}
|
||||||
|
|
||||||
double LoRaClass::packetFrequencyError()
|
long LoRaClass::packetFrequencyError()
|
||||||
{
|
{
|
||||||
int32_t fe = (int32_t)readRegister(REG_FREQ_ERROR) & 7;
|
int32_t freqError = 0;
|
||||||
fe <<= 8L;
|
freqError = static_cast<int32_t>(readRegister(REG_FREQ_ERROR_MSB) & B111);
|
||||||
fe += (int32_t)readRegister(REG_FREQ_ERROR+1);
|
freqError <<= 8L;
|
||||||
fe <<= 8L;
|
freqError += static_cast<int32_t>(readRegister(REG_FREQ_ERROR_MID));
|
||||||
fe += (int32_t)readRegister(REG_FREQ_ERROR+2);
|
freqError <<= 8L;
|
||||||
|
freqError += static_cast<int32_t>(readRegister(REG_FREQ_ERROR_LSB));
|
||||||
|
|
||||||
if (readRegister(REG_FREQ_ERROR) & 8) {
|
if (readRegister(REG_FREQ_ERROR_MSB) & B1000) { // Sign bit is on
|
||||||
fe = fe - 524288;
|
freqError -= 524288; // B1000'0000'0000'0000'0000
|
||||||
}
|
}
|
||||||
|
|
||||||
double freqError = (double)fe;
|
const float fXtal = 32E6; // FXOSC: crystal oscillator (XTAL) frequency (2.5. Chip Specification, p. 14)
|
||||||
freqError *= (16777216.0 / 32000000.0);
|
const float fError = ((static_cast<float>(freqError) * (1L << 24)) / fXtal) * (getSignalBandwidth() / 500000.0f); // p. 37
|
||||||
freqError *= (getSignalBandwidth() / 500000.0);
|
|
||||||
|
|
||||||
return freqError;
|
return static_cast<long>(fError);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t LoRaClass::write(uint8_t byte)
|
size_t LoRaClass::write(uint8_t byte)
|
||||||
|
@ -27,7 +27,7 @@ public:
|
|||||||
int parsePacket(int size = 0);
|
int parsePacket(int size = 0);
|
||||||
int packetRssi();
|
int packetRssi();
|
||||||
float packetSnr();
|
float packetSnr();
|
||||||
double packetFrequencyError();
|
long packetFrequencyError();
|
||||||
|
|
||||||
// from Print
|
// from Print
|
||||||
virtual size_t write(uint8_t byte);
|
virtual size_t write(uint8_t byte);
|
||||||
@ -66,14 +66,14 @@ public:
|
|||||||
|
|
||||||
void dumpRegisters(Stream& out);
|
void dumpRegisters(Stream& out);
|
||||||
|
|
||||||
long getSignalBandwidth();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void explicitHeaderMode();
|
void explicitHeaderMode();
|
||||||
void implicitHeaderMode();
|
void implicitHeaderMode();
|
||||||
|
|
||||||
void handleDio0Rise();
|
void handleDio0Rise();
|
||||||
|
|
||||||
|
long getSignalBandwidth();
|
||||||
|
|
||||||
uint8_t readRegister(uint8_t address);
|
uint8_t readRegister(uint8_t address);
|
||||||
void writeRegister(uint8_t address, uint8_t value);
|
void writeRegister(uint8_t address, uint8_t value);
|
||||||
uint8_t singleTransfer(uint8_t address, uint8_t value);
|
uint8_t singleTransfer(uint8_t address, uint8_t value);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user