[SX127x] Sync with LoRaLib v7.1.1
This commit is contained in:
parent
59564a17e2
commit
bd2596efac
15 changed files with 1046 additions and 130 deletions
|
@ -36,9 +36,9 @@ class Module {
|
|||
void SPIwriteRegisterBurst(uint8_t reg, uint8_t* data, uint8_t numBytes);
|
||||
void SPIwriteRegister(uint8_t reg, uint8_t data);
|
||||
|
||||
int cs() const { return(_cs); }
|
||||
int int0() const { return(_int0); }
|
||||
int int1() const { return(_int1); }
|
||||
int getCs() const { return(_cs); }
|
||||
int getInt0() const { return(_int0); }
|
||||
int getInt1() const { return(_int1); }
|
||||
|
||||
private:
|
||||
int _cs;
|
||||
|
|
|
@ -125,7 +125,7 @@ int16_t RF69::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
|||
_mod->SPIsetRegValue(RF69_REG_TEST_PA2, RF69_PA2_20_DBM);
|
||||
|
||||
// wait for transmission end
|
||||
while(!digitalRead(_mod->int0()));
|
||||
while(!digitalRead(_mod->getInt0()));
|
||||
|
||||
// clear interrupt flags
|
||||
clearIRQFlags();
|
||||
|
@ -167,8 +167,8 @@ int16_t RF69::receive(uint8_t* data, size_t len) {
|
|||
_mod->SPIsetRegValue(RF69_REG_TEST_PA2, RF69_PA2_NORMAL);
|
||||
|
||||
// wait for packet reception or timeout
|
||||
while(!digitalRead(_mod->int0())) {
|
||||
if(digitalRead(_mod->int1())) {
|
||||
while(!digitalRead(_mod->getInt0())) {
|
||||
if(digitalRead(_mod->getInt1())) {
|
||||
clearIRQFlags();
|
||||
return(ERR_RX_TIMEOUT);
|
||||
}
|
||||
|
@ -304,11 +304,11 @@ int16_t RF69::startReceive() {
|
|||
}
|
||||
|
||||
void RF69::setDio0Action(void (*func)(void)) {
|
||||
attachInterrupt(digitalPinToInterrupt(_mod->int0()), func, RISING);
|
||||
attachInterrupt(digitalPinToInterrupt(_mod->getInt0()), func, RISING);
|
||||
}
|
||||
|
||||
void RF69::setDio1Action(void (*func)(void)) {
|
||||
attachInterrupt(digitalPinToInterrupt(_mod->int1()), func, RISING);
|
||||
attachInterrupt(digitalPinToInterrupt(_mod->getInt1()), func, RISING);
|
||||
}
|
||||
|
||||
int16_t RF69::startTransmit(String& str, uint8_t addr) {
|
||||
|
@ -416,8 +416,7 @@ int16_t RF69::setFrequency(float freq) {
|
|||
setMode(RF69_STANDBY);
|
||||
|
||||
//set carrier frequency
|
||||
uint32_t base = 1;
|
||||
uint32_t FRF = (freq * (base << 19)) / 32.0;
|
||||
uint32_t FRF = (freq * (uint32_t(1) << RF69_DIV_EXPONENT)) / RF69_CRYSTAL_FREQ;
|
||||
int16_t state = _mod->SPIsetRegValue(RF69_REG_FRF_MSB, (FRF & 0xFF0000) >> 16, 7, 0);
|
||||
state |= _mod->SPIsetRegValue(RF69_REG_FRF_MID, (FRF & 0x00FF00) >> 8, 7, 0);
|
||||
state |= _mod->SPIsetRegValue(RF69_REG_FRF_LSB, FRF & 0x0000FF, 7, 0);
|
||||
|
|
|
@ -9,15 +9,62 @@
|
|||
// SX127X_REG_VERSION
|
||||
#define RFM95_CHIP_VERSION 0x11
|
||||
|
||||
/*!
|
||||
\class RFM95
|
||||
|
||||
\brief Derived class for %RFM95 modules. Overrides some methods from SX1278 due to different parameter ranges.
|
||||
*/
|
||||
class RFM95: public SX1278 {
|
||||
public:
|
||||
|
||||
// constructor
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
RFM95(Module* mod);
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 868.0 MHz to 915.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA.
|
||||
Set to 0 to disable OCP (not recommended).
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 868.0 MHz to 915.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
|
||||
private:
|
||||
|
|
|
@ -9,21 +9,73 @@
|
|||
// SX127X_REG_VERSION
|
||||
#define RFM9X_CHIP_VERSION 0x12 // according to datasheet, this should be 0x11, but all modules seem to have 0x12
|
||||
|
||||
/*!
|
||||
\class RFM96
|
||||
|
||||
\brief Derived class for %RFM96 modules. Overrides some methods from SX1278 due to different parameter ranges.
|
||||
*/
|
||||
class RFM96: public SX1278 {
|
||||
public:
|
||||
|
||||
// constructor
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
RFM96(Module* mod);
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 433.0 MHz to 470.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA.
|
||||
Set to 0 to disable OCP (not recommended).
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 433.0 MHz to 470.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
/*!
|
||||
\class RFM98
|
||||
|
||||
\brief Only exists as alias for RFM96, since there seems to be no difference between %RFM96 and %RFM98 modules.
|
||||
*/
|
||||
using RFM98 = RFM96;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,12 +7,32 @@
|
|||
#include "SX1278.h"
|
||||
#include "RFM95.h"
|
||||
|
||||
/*!
|
||||
\class RFM97
|
||||
|
||||
\brief Derived class for %RFM97 modules. Overrides some methods from RFM95 due to different parameter ranges.
|
||||
*/
|
||||
class RFM97: public RFM95 {
|
||||
public:
|
||||
// contructor
|
||||
|
||||
// constructor
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
RFM97(Module* mod);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 9. Only available in %LoRa mode.
|
||||
|
||||
\param sf %LoRa link spreading factor to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setSpreadingFactor(uint8_t sf);
|
||||
|
||||
private:
|
||||
|
|
|
@ -83,23 +83,149 @@
|
|||
#define SX1272_PLL_LOW_PN_BANDWIDTH_225_KHZ 0b10000000 // 7 6 225 kHz
|
||||
#define SX1272_PLL_LOW_PN_BANDWIDTH_300_KHZ 0b11000000 // 7 6 300 kHz (default)
|
||||
|
||||
/*!
|
||||
\class SX1272
|
||||
|
||||
\brief Derived class for %SX1272 modules. Also used as base class for SX1273.
|
||||
Both modules use the same basic hardware and only differ in parameter ranges.
|
||||
*/
|
||||
class SX1272: public SX127x {
|
||||
public:
|
||||
|
||||
// constructor
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
SX1272(Module* mod);
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA.
|
||||
Set to 0 to disable OCP (not recommended).
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
int16_t beginFSK(float freq = 434.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 13, uint8_t currentLimit = 100, float sh = 0.3);
|
||||
|
||||
/*!
|
||||
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
|
||||
|
||||
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
|
||||
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA.
|
||||
Set to 0 to disable OCP (not recommended).
|
||||
|
||||
\param sh Gaussian shaping bandwidth-time product that will be used for data shaping. Allowed values are 0.3, 0.5 or 1.0. Set to 0 to disable data shaping.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginFSK(float freq = 915.0, float br = 48.0, float rxBw = 125.0, float freqDev = 50.0, int8_t power = 13, uint8_t currentLimit = 100, float sh = 0.3);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 860.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link bandwidth. Allowed values are 125, 250 and 500 kHz. Only available in %LoRa mode.
|
||||
|
||||
\param bw %LoRa link bandwidth to be set in kHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setBandwidth(float bw);
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 12. Only available in %LoRa mode.
|
||||
|
||||
\param sf %LoRa link spreading factor to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setSpreadingFactor(uint8_t sf);
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link coding rate denominator. Allowed values range from 5 to 8. Only available in %LoRa mode.
|
||||
|
||||
\param cr %LoRa link coding rate denominator to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setCodingRate(uint8_t cr);
|
||||
|
||||
/*!
|
||||
\brief Sets transmission output power. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param power Transmission output power in dBm.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power);
|
||||
|
||||
/*!
|
||||
\brief Sets gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended). Only available in %LoRa mode.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier) to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setGain(uint8_t gain);
|
||||
|
||||
/*!
|
||||
\brief Sets gaussian shaping bandwidth-time product that will be used for data shaping.
|
||||
Allowed values are 0.3, 0.5 or 1.0. Set to 0 to disable data shaping. Only available in FSK mode.
|
||||
|
||||
\param sh Gaussian shaping bandwidth-time product that will be used for data shaping
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDataShaping(float sh);
|
||||
|
||||
/*!
|
||||
\brief Gets recorded signal strength indicator of the latest received packet.
|
||||
|
||||
\returns Last packet recorded signal strength indicator (RSSI).
|
||||
*/
|
||||
int8_t getRSSI();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -4,15 +4,62 @@
|
|||
#include "TypeDef.h"
|
||||
#include "SX1272.h"
|
||||
|
||||
/*!
|
||||
\class SX1273
|
||||
|
||||
\brief Derived class for %SX1273 modules. Overrides some methods from SX1272 due to different parameter ranges.
|
||||
*/
|
||||
class SX1273: public SX1272 {
|
||||
public:
|
||||
|
||||
// constructor
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
SX1273(Module* mod);
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 860.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 9.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA.
|
||||
Set to 0 to disable OCP (not recommended).
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 915.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 9. Only available in %LoRa mode.
|
||||
|
||||
\param sf %LoRa link spreading factor to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setSpreadingFactor(uint8_t sf);
|
||||
};
|
||||
|
||||
|
|
|
@ -4,15 +4,62 @@
|
|||
#include "TypeDef.h"
|
||||
#include "SX1278.h"
|
||||
|
||||
/*!
|
||||
\class SX1276
|
||||
|
||||
\brief Derived class for %SX1276 modules. Overrides some methods from SX1278 due to different parameter ranges.
|
||||
*/
|
||||
class SX1276: public SX1278 {
|
||||
public:
|
||||
|
||||
// constructor
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
SX1276(Module* mod);
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA.
|
||||
Set to 0 to disable OCP (not recommended).
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 137.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
};
|
||||
|
||||
|
|
|
@ -4,16 +4,71 @@
|
|||
#include "TypeDef.h"
|
||||
#include "SX1278.h"
|
||||
|
||||
/*!
|
||||
\class SX1277
|
||||
|
||||
\brief Derived class for %SX1277 modules. Overrides some methods from SX1278 due to different parameter ranges.
|
||||
*/
|
||||
class SX1277: public SX1278 {
|
||||
public:
|
||||
|
||||
// constructor
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
SX1277(Module* mod);
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 9.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA.
|
||||
Set to 0 to disable OCP (not recommended).
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 137.0 MHz to 1020.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 9. Only available in %LoRa mode.
|
||||
|
||||
\param sf %LoRa link spreading factor to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setSpreadingFactor(uint8_t sf);
|
||||
};
|
||||
|
||||
|
|
|
@ -92,23 +92,149 @@
|
|||
#define SX1278_AGC_STEP_4 0xC0 // 7 4 4th AGC threshold
|
||||
#define SX1278_AGC_STEP_5 0x0C // 4 0 5th AGC threshold
|
||||
|
||||
/*!
|
||||
\class SX1278
|
||||
|
||||
\brief Derived class for %SX1278 modules. Also used as base class for SX1276, SX1277, SX1279, RFM95 and RFM96.
|
||||
All of these modules use the same basic hardware and only differ in parameter ranges (and names).
|
||||
*/
|
||||
class SX1278: public SX127x {
|
||||
public:
|
||||
|
||||
// constructor
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
SX1278(Module* mod);
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA.
|
||||
Set to 0 to disable OCP (not recommended).
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
|
||||
/*!
|
||||
\brief FSK modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 525.0 MHz.
|
||||
|
||||
\param br Bit rate of the FSK transmission in kbps (kilobits per second). Allowed values range from 1.2 to 300.0 kbps.
|
||||
|
||||
\param freqDev Frequency deviation of the FSK transmission in kHz. Allowed values range from 0.6 to 200.0 kHz.
|
||||
Note that the allowed range changes based on bit rate setting, so that the condition FreqDev + BitRate/2 <= 250 kHz is always met.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz. Allowed values are 2.6, 3.1, 3.9, 5.2, 6.3, 7.8, 10.4, 12.5, 15.6, 20.8, 25, 31.3, 41.7, 50, 62.5, 83.3, 100, 125, 166.7, 200 and 250 kHz.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA.
|
||||
Set to 0 to disable OCP (not recommended).
|
||||
|
||||
\param sh Gaussian shaping bandwidth-time product that will be used for data shaping. Allowed values are 0.3, 0.5 or 1.0. Set to 0 to disable data shaping.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginFSK(float freq = 434.0, float br = 48.0, float freqDev = 50.0, float rxBw = 125.0, int8_t power = 13, uint8_t currentLimit = 100, float sh = 0.3);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 137.0 MHz to 525.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link bandwidth. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz. Only available in %LoRa mode.
|
||||
|
||||
\param bw %LoRa link bandwidth to be set in kHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setBandwidth(float bw);
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link spreading factor. Allowed values range from 6 to 12. Only available in %LoRa mode.
|
||||
|
||||
\param sf %LoRa link spreading factor to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setSpreadingFactor(uint8_t sf);
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa link coding rate denominator. Allowed values range from 5 to 8. Only available in %LoRa mode.
|
||||
|
||||
\param cr %LoRa link coding rate denominator to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setCodingRate(uint8_t cr);
|
||||
|
||||
/*!
|
||||
\brief Sets transmission output power. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param power Transmission output power in dBm.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setOutputPower(int8_t power);
|
||||
|
||||
/*!
|
||||
\brief Sets gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended). Only available in %LoRa mode.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier) to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setGain(uint8_t gain);
|
||||
|
||||
/*!
|
||||
\brief Sets gaussian shaping bandwidth-time product that will be used for data shaping.
|
||||
Allowed values are 0.3, 0.5 or 1.0. Set to 0 to disable data shaping. Only available in FSK mode.
|
||||
|
||||
\param sh Gaussian shaping bandwidth-time product that will be used for data shaping
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setDataShaping(float sh);
|
||||
|
||||
/*!
|
||||
\brief Gets recorded signal strength indicator of the latest received packet.
|
||||
|
||||
\returns Last packet recorded signal strength indicator (RSSI).
|
||||
*/
|
||||
int8_t getRSSI();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -4,15 +4,62 @@
|
|||
#include "TypeDef.h"
|
||||
#include "SX1278.h"
|
||||
|
||||
/*!
|
||||
\class SX1279
|
||||
|
||||
\brief Derived class for %SX1279 modules. Overrides some methods from SX1278 due to different parameter ranges.
|
||||
*/
|
||||
class SX1279: public SX1278 {
|
||||
public:
|
||||
|
||||
// constructor
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called from Arduino sketch when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
SX1279(Module* mod);
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief %LoRa modem initialization method. Must be called at least once from Arduino sketch to initialize the module.
|
||||
|
||||
\param freq Carrier frequency in MHz. Allowed values range from 137.0 MHz to 960.0 MHz.
|
||||
|
||||
\param bw %LoRa link bandwidth in kHz. Allowed values are 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250 and 500 kHz.
|
||||
|
||||
\param sf %LoRa link spreading factor. Allowed values range from 6 to 12.
|
||||
|
||||
\param cr %LoRa link coding rate denominator. Allowed values range from 5 to 8.
|
||||
|
||||
\param syncWord %LoRa sync word. Can be used to distinguish different networks. Note that value 0x34 is reserved for LoRaWAN networks.
|
||||
|
||||
\param power Transmission output power in dBm. Allowed values range from 2 to 17 dBm.
|
||||
|
||||
\param currentLimit Trim value for OCP (over current protection) in mA. Can be set to multiplies of 5 in range 45 to 120 mA and to multiples of 10 in range 120 to 240 mA.
|
||||
Set to 0 to disable OCP (not recommended).
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols. The actual preamble length is 4.25 symbols longer than the set number.
|
||||
Allowed values range from 6 to 65535.
|
||||
|
||||
\param gain Gain of receiver LNA (low-noise amplifier). Can be set to any integer in range 1 to 6 where 1 is the highest gain.
|
||||
Set to 0 to enable automatic gain control (recommended).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(float freq = 434.0, float bw = 125.0, uint8_t sf = 9, uint8_t cr = 7, uint8_t syncWord = SX127X_SYNC_WORD, int8_t power = 17, uint8_t currentLimit = 100, uint16_t preambleLength = 8, uint8_t gain = 0);
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets carrier frequency. Allowed values range from 137.0 MHz to 960.0 MHz.
|
||||
|
||||
\param freq Carrier frequency to be set in MHz.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequency(float freq);
|
||||
};
|
||||
|
||||
|
|
|
@ -108,14 +108,6 @@ int16_t SX127x::beginFSK(uint8_t chipVersion, float br, float freqDev, float rxB
|
|||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX127x::transmit(String& str, uint8_t addr) {
|
||||
return(SX127x::transmit(str.c_str(), addr));
|
||||
}
|
||||
|
||||
int16_t SX127x::transmit(const char* str, uint8_t addr) {
|
||||
return(SX127x::transmit((uint8_t*)str, strlen(str), addr));
|
||||
}
|
||||
|
||||
int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
||||
// set mode to standby
|
||||
int16_t state = setMode(SX127X_STANDBY);
|
||||
|
@ -164,7 +156,7 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
|||
|
||||
// wait for packet transmission or timeout
|
||||
uint32_t start = millis();
|
||||
while(!digitalRead(_mod->int0())) {
|
||||
while(!digitalRead(_mod->getInt0())) {
|
||||
if(millis() - start > timeout) {
|
||||
clearIRQFlags();
|
||||
return(ERR_TX_TIMEOUT);
|
||||
|
@ -213,7 +205,7 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
|||
// wait for transmission end or timeout (150 % of expected time-on-air)
|
||||
uint32_t timeout = (uint32_t)((((float)(len * 8)) / (_br * 1000.0)) * 1500.0);
|
||||
uint32_t start = millis();
|
||||
while(!digitalRead(_mod->int0())) {
|
||||
while(!digitalRead(_mod->getInt0())) {
|
||||
if(millis() - start > timeout) {
|
||||
clearIRQFlags();
|
||||
return(ERR_TX_TIMEOUT);
|
||||
|
@ -229,20 +221,6 @@ int16_t SX127x::transmit(uint8_t* data, size_t len, uint8_t addr) {
|
|||
return(ERR_UNKNOWN);
|
||||
}
|
||||
|
||||
int16_t SX127x::receive(String& str, size_t len) {
|
||||
// create temporary array to store received data
|
||||
char* data = new char[len + 1];
|
||||
int16_t state = SX127x::receive((uint8_t*)data, len);
|
||||
|
||||
// if packet was received successfully, copy data into String
|
||||
if(state == ERR_NONE) {
|
||||
str = String(data);
|
||||
}
|
||||
|
||||
delete[] data;
|
||||
return(state);
|
||||
}
|
||||
|
||||
int16_t SX127x::receive(uint8_t* data, size_t len) {
|
||||
// set mode to standby
|
||||
int16_t state = setMode(SX127X_STANDBY);
|
||||
|
@ -266,8 +244,8 @@ int16_t SX127x::receive(uint8_t* data, size_t len) {
|
|||
}
|
||||
|
||||
// wait for packet reception or timeout
|
||||
while(!digitalRead(_mod->int0())) {
|
||||
if(digitalRead(_mod->int1())) {
|
||||
while(!digitalRead(_mod->getInt0())) {
|
||||
if(digitalRead(_mod->getInt1())) {
|
||||
clearIRQFlags();
|
||||
return(ERR_RX_TIMEOUT);
|
||||
}
|
||||
|
@ -323,7 +301,7 @@ int16_t SX127x::receive(uint8_t* data, size_t len) {
|
|||
}
|
||||
uint32_t timeout = (uint32_t)((((float)(maxLen * 8)) / (_br * 1000.0)) * 1500.0);
|
||||
uint32_t start = millis();
|
||||
while(!digitalRead(_mod->int0())) {
|
||||
while(!digitalRead(_mod->getInt0())) {
|
||||
if(millis() - start > timeout) {
|
||||
clearIRQFlags();
|
||||
return(ERR_RX_TIMEOUT);
|
||||
|
@ -384,8 +362,8 @@ int16_t SX127x::scanChannel() {
|
|||
}
|
||||
|
||||
// wait for channel activity detected or timeout
|
||||
while(!digitalRead(_mod->int0())) {
|
||||
if(digitalRead(_mod->int1())) {
|
||||
while(!digitalRead(_mod->getInt0())) {
|
||||
if(digitalRead(_mod->getInt1())) {
|
||||
clearIRQFlags();
|
||||
return(PREAMBLE_DETECTED);
|
||||
}
|
||||
|
@ -509,11 +487,11 @@ int16_t SX127x::startReceive() {
|
|||
}
|
||||
|
||||
void SX127x::setDio0Action(void (*func)(void)) {
|
||||
attachInterrupt(digitalPinToInterrupt(_mod->int0()), func, RISING);
|
||||
attachInterrupt(digitalPinToInterrupt(_mod->getInt0()), func, RISING);
|
||||
}
|
||||
|
||||
void SX127x::setDio1Action(void (*func)(void)) {
|
||||
attachInterrupt(digitalPinToInterrupt(_mod->int1()), func, RISING);
|
||||
attachInterrupt(digitalPinToInterrupt(_mod->getInt1()), func, RISING);
|
||||
}
|
||||
|
||||
int16_t SX127x::startTransmit(String& str, uint8_t addr) {
|
||||
|
@ -860,71 +838,7 @@ int16_t SX127x::setRxBandwidth(float rxBw) {
|
|||
}
|
||||
|
||||
// check allowed bandwidth values
|
||||
uint8_t bwMant, bwExp;
|
||||
if(abs(rxBw - 2.6) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_24;
|
||||
bwExp = 7;
|
||||
} else if(abs(rxBw - 3.1) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_20;
|
||||
bwExp = 7;
|
||||
} else if(abs(rxBw - 3.9) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_16;
|
||||
bwExp = 7;
|
||||
} else if(abs(rxBw - 5.2) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_24;
|
||||
bwExp = 6;
|
||||
} else if(abs(rxBw - 6.3) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_20;
|
||||
bwExp = 6;
|
||||
} else if(abs(rxBw - 7.8) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_16;
|
||||
bwExp = 6;
|
||||
} else if(abs(rxBw - 10.4) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_24;
|
||||
bwExp = 5;
|
||||
} else if(abs(rxBw - 12.5) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_20;
|
||||
bwExp = 5;
|
||||
} else if(abs(rxBw - 15.6) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_16;
|
||||
bwExp = 5;
|
||||
} else if(abs(rxBw - 20.8) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_24;
|
||||
bwExp = 4;
|
||||
} else if(abs(rxBw - 25.0) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_20;
|
||||
bwExp = 4;
|
||||
} else if(abs(rxBw - 31.3) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_16;
|
||||
bwExp = 4;
|
||||
} else if(abs(rxBw - 41.7) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_24;
|
||||
bwExp = 3;
|
||||
} else if(abs(rxBw - 50.0) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_20;
|
||||
bwExp = 3;
|
||||
} else if(abs(rxBw - 62.5) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_16;
|
||||
bwExp = 3;
|
||||
} else if(abs(rxBw - 83.3) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_24;
|
||||
bwExp = 2;
|
||||
} else if(abs(rxBw - 100.0) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_20;
|
||||
bwExp = 2;
|
||||
} else if(abs(rxBw - 125.0) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_16;
|
||||
bwExp = 2;
|
||||
} else if(abs(rxBw - 166.7) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_24;
|
||||
bwExp = 1;
|
||||
} else if(abs(rxBw - 200.0) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_20;
|
||||
bwExp = 1;
|
||||
} else if(abs(rxBw - 250.0) <= 0.001) {
|
||||
bwMant = SX127X_RX_BW_MANT_16;
|
||||
bwExp = 1;
|
||||
} else {
|
||||
if(!((rxBw >= 2.6) && (rxBw <= 250.0))) {
|
||||
return(ERR_INVALID_RX_BANDWIDTH);
|
||||
}
|
||||
|
||||
|
@ -934,19 +848,29 @@ int16_t SX127x::setRxBandwidth(float rxBw) {
|
|||
return(state);
|
||||
}
|
||||
|
||||
// set Rx bandwidth during AFC
|
||||
state = _mod->SPIsetRegValue(SX127X_REG_AFC_BW, bwMant | bwExp, 4, 0);
|
||||
if(state != ERR_NONE) {
|
||||
return(state);
|
||||
// calculate exponent and mantisa values
|
||||
for(uint8_t e = 7; e >= 1; e--) {
|
||||
for(int8_t m = 2; m >= 0; m--) {
|
||||
float point = (SX127X_CRYSTAL_FREQ * 1000000.0)/(((4 * m) + 16) * ((uint32_t)1 << (e + 2)));
|
||||
if(abs(rxBw - ((point / 1000.0) + 0.05)) <= 0.5) {
|
||||
// set Rx bandwidth during AFC
|
||||
state = _mod->SPIsetRegValue(SX127X_REG_AFC_BW, (m << 3) | e, 4, 0);
|
||||
if(state != ERR_NONE) {
|
||||
return(state);
|
||||
}
|
||||
|
||||
// set Rx bandwidth
|
||||
state = _mod->SPIsetRegValue(SX127X_REG_RX_BW, (m << 3) | e, 4, 0);
|
||||
if(state == ERR_NONE) {
|
||||
SX127x::_rxBw = rxBw;
|
||||
}
|
||||
|
||||
return(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set Rx bandwidth
|
||||
state = _mod->SPIsetRegValue(SX127X_REG_RX_BW, bwMant | bwExp, 4, 0);
|
||||
if(state == ERR_NONE) {
|
||||
SX127x::_rxBw = rxBw;
|
||||
}
|
||||
|
||||
return(state);
|
||||
return(ERR_UNKNOWN);
|
||||
}
|
||||
|
||||
int16_t SX127x::setSyncWord(uint8_t* syncWord, size_t len) {
|
||||
|
@ -1038,8 +962,7 @@ int16_t SX127x::setFrequencyRaw(float newFreq) {
|
|||
int16_t state = setMode(SX127X_STANDBY);
|
||||
|
||||
// calculate register values
|
||||
uint32_t base = 1;
|
||||
uint32_t FRF = (newFreq * (base << 19)) / 32.0;
|
||||
uint32_t FRF = (newFreq * (uint32_t(1) << SX127X_DIV_EXPONENT)) / SX127X_CRYSTAL_FREQ;
|
||||
|
||||
// write registers
|
||||
state |= _mod->SPIsetRegValue(SX127X_REG_FRF_MSB, (FRF & 0xFF0000) >> 16);
|
||||
|
|
|
@ -521,49 +521,331 @@
|
|||
#define SX127X_PLL_BANDWIDTH_225_KHZ 0b10000000 // 7 6 225 kHz
|
||||
#define SX127X_PLL_BANDWIDTH_300_KHZ 0b11000000 // 7 6 300 kHz (default)
|
||||
|
||||
/*!
|
||||
\class SX127x
|
||||
|
||||
\brief Implements all common high-level chip functions. All derived classes (e.g. SX1278 or SX1272) inherit from this base class.
|
||||
This class should not be instantiated directly from Arduino sketch, only from its derived classes.
|
||||
*/
|
||||
class SX127x: public PhysicalLayer {
|
||||
public:
|
||||
// introduce PhysicalLayer overloads
|
||||
using PhysicalLayer::transmit;
|
||||
using PhysicalLayer::receive;
|
||||
|
||||
// constructor
|
||||
|
||||
/*!
|
||||
\brief Default constructor. Called internally when creating new LoRa instance.
|
||||
|
||||
\param mod Instance of Module that will be used to communicate with the %LoRa chip.
|
||||
*/
|
||||
SX127x(Module* mod);
|
||||
|
||||
// basic methods
|
||||
|
||||
/*!
|
||||
\brief Initialization method. Will be called with appropriate parameters when calling initialization method from derived class.
|
||||
|
||||
\param chipVersion Value in SPI version register. Used to verify the connection and hardware version.
|
||||
|
||||
\param syncWord %LoRa sync word.
|
||||
|
||||
\param currentLimit Trim value for OCP (over current protection) in mA.
|
||||
|
||||
\param preambleLength Length of %LoRa transmission preamble in symbols.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t begin(uint8_t chipVersion, uint8_t syncWord, uint8_t currentLimit, uint16_t preambleLength);
|
||||
|
||||
/*!
|
||||
\brief Initialization method for FSK modem. Will be called with appropriate parameters when calling FSK initialization method from derived class.
|
||||
|
||||
\param chipVersion Value in SPI version register. Used to verify the connection and hardware version.
|
||||
|
||||
\param br Bit rate of the FSK transmission in kbps (kilobits per second).
|
||||
|
||||
\param freqDev Frequency deviation of the FSK transmission in kHz.
|
||||
|
||||
\param rxBw Receiver bandwidth in kHz.
|
||||
|
||||
\param currentLimit Trim value for OCP (over current protection) in mA.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t beginFSK(uint8_t chipVersion, float br, float freqDev, float rxBw, uint8_t currentLimit);
|
||||
int16_t transmit(String& str, uint8_t addr = 0);
|
||||
int16_t transmit(const char* str, uint8_t addr = 0);
|
||||
|
||||
/*!
|
||||
\brief Binary transmit method. Will transmit arbitrary binary data up to 255 bytes long using %LoRa or up to 63 bytes using FSK modem.
|
||||
For overloads to transmit Arduino String or C-string, see PhysicalLayer::transmit.
|
||||
|
||||
\param data Binary data that will be transmitted.
|
||||
|
||||
\param len Length of binary data to transmit (in bytes).
|
||||
|
||||
\param addr Node address to transmit the packet to. Only used in FSK mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0);
|
||||
int16_t receive(String& str, size_t len = 0);
|
||||
|
||||
/*!
|
||||
\brief Binary receive method. Will attempt to receive arbitrary binary data up to 255 bytes long using %LoRa or up to 63 bytes using FSK modem.
|
||||
For overloads to receive Arduino String, see PhysicalLayer::receive.
|
||||
|
||||
\param data Pointer to array to save the received binary data.
|
||||
|
||||
\param len Number of bytes that will be received. Must be known in advance for binary transmissions.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t receive(uint8_t* data, size_t len);
|
||||
|
||||
/*!
|
||||
\brief Performs scan for valid %LoRa preamble in the current channel.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t scanChannel();
|
||||
|
||||
/*!
|
||||
\brief Sets the %LoRa module to sleep to save power. %Module will not be able to transmit or receive any data while in sleep mode.
|
||||
%Module will wake up autmatically when methods like transmit or receive are called.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t sleep();
|
||||
|
||||
/*!
|
||||
\brief Sets the %LoRa module to standby.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t standby();
|
||||
|
||||
/*!
|
||||
\brief Enables direct transmission mode on pins DIO1 (clock) and DIO2 (data).
|
||||
While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode.
|
||||
|
||||
\param FRF 24-bit raw frequency value to start transmitting at. Required for quick frequency shifts in RTTY.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmitDirect(uint32_t FRF = 0);
|
||||
|
||||
/*!
|
||||
\brief Enables direct reception mode on pins DIO1 (clock) and DIO2 (data).
|
||||
While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t receiveDirect();
|
||||
|
||||
/*!
|
||||
\brief Disables direct mode and enables packet mode, allowing the module to receive packets. Can only be activated in FSK mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t packetMode();
|
||||
|
||||
|
||||
// interrupt methods
|
||||
|
||||
/*!
|
||||
\brief Set interrupt service routine function to call when DIO0 activates.
|
||||
|
||||
\param func Pointer to interrupt service routine.
|
||||
*/
|
||||
void setDio0Action(void (*func)(void));
|
||||
|
||||
/*!
|
||||
\brief Set interrupt service routine function to call when DIO1 activates.
|
||||
|
||||
\param func Pointer to interrupt service routine.
|
||||
*/
|
||||
void setDio1Action(void (*func)(void));
|
||||
|
||||
/*!
|
||||
\brief Interrupt-driven Arduino String transmit method. Will start transmitting Arduino String up to 255 characters long using %LoRa or up to 63 bytes using FSK modem.
|
||||
Unlike the standard transmit method, this one is non-blocking. DIO0 will be activated when transmission finishes.
|
||||
|
||||
\param str Address of Arduino String that will be transmitted.
|
||||
|
||||
\param addr Node address to transmit the packet to. Only used in FSK mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startTransmit(String& str, uint8_t addr = 0);
|
||||
|
||||
/*!
|
||||
\brief Interrupt-driven Arduino String transmit method. Will start transmitting Arduino String up to 255 characters long using %LoRa or up to 63 bytes using FSK modem.
|
||||
Unlike the standard transmit method, this one is non-blocking. DIO0 will be activated when transmission finishes.
|
||||
|
||||
\param str C-string that will be transmitted.
|
||||
|
||||
\param addr Node address to transmit the packet to. Only used in FSK mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startTransmit(const char* str, uint8_t addr = 0);
|
||||
|
||||
/*!
|
||||
\brief Interrupt-driven binary transmit method. Will start transmitting arbitrary binary data up to 255 bytes long using %LoRa or up to 63 bytes using FSK modem.
|
||||
|
||||
\param data Binary data that will be transmitted.
|
||||
|
||||
\param len Length of binary data to transmit (in bytes).
|
||||
|
||||
\param addr Node address to transmit the packet to. Only used in FSK mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startTransmit(uint8_t* data, size_t len, uint8_t addr = 0);
|
||||
|
||||
/*!
|
||||
\brief Interrupt-driven receive method. DIO0 will be activated when full valid packet is received.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t startReceive();
|
||||
|
||||
/*!
|
||||
\brief Reads data that was received after calling startReceive method.
|
||||
|
||||
\param str Address of Arduino String to save the received data.
|
||||
|
||||
\param len Expected number of characters in the message. Must be known in advance for %LoRa spreading factor 6.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t readData(String& str, size_t len = 0);
|
||||
|
||||
/*!
|
||||
\brief Reads data that was received after calling startReceive method.
|
||||
|
||||
\param data Pointer to array to save the received binary data.
|
||||
|
||||
\param len Number of bytes that will be received. Must be known in advance for binary transmissions.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t readData(uint8_t* data, size_t len);
|
||||
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa sync word. Only available in %LoRa mode.
|
||||
|
||||
\param syncWord Sync word to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setSyncWord(uint8_t syncWord);
|
||||
|
||||
/*!
|
||||
\brief Sets current limit for over current protection at transmitter amplifier. Allowed values range from 45 to 120 mA in 5 mA steps and 120 to 240 mA in 10 mA steps.
|
||||
|
||||
\param currentLimit Current limit to be set (in mA).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setCurrentLimit(uint8_t currentLimit);
|
||||
|
||||
/*!
|
||||
\brief Sets %LoRa preamble length. Allowed values range from 6 to 65535. Only available in %LoRa mode.
|
||||
|
||||
\param preambleLength Preamble length to be set (in symbols).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setPreambleLength(uint16_t preambleLength);
|
||||
|
||||
/*!
|
||||
\brief Gets frequency error of the latest received packet.
|
||||
|
||||
\param autoCorrect When set to true, frequency will be autmatically corrected.
|
||||
|
||||
\returns Frequency error in Hz.
|
||||
*/
|
||||
float getFrequencyError(bool autoCorrect = false);
|
||||
|
||||
/*!
|
||||
\brief Gets signal-to-noise ratio of the latest received packet.
|
||||
|
||||
\returns Last packet signal-to-noise ratio (SNR).
|
||||
*/
|
||||
float getSNR();
|
||||
|
||||
/*!
|
||||
\brief Get data rate of the latest transmitted packet.
|
||||
|
||||
\returns Last packet data rate in bps (bits per second).
|
||||
*/
|
||||
float getDataRate();
|
||||
|
||||
/*!
|
||||
\brief Sets FSK bit rate. Allowed values range from 1.2 to 300 kbps. Only available in FSK mode.
|
||||
|
||||
\param br Bit rate to be set (in kbps).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setBitRate(float br);
|
||||
|
||||
/*!
|
||||
\brief Sets FSK frequency deviation from carrier frequency. Allowed values depend on bit rate setting and must be lower than 200 kHz. Only available in FSK mode.
|
||||
|
||||
\param freqDev Frequency deviation to be set (in kHz).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setFrequencyDeviation(float freqDev);
|
||||
|
||||
/*!
|
||||
\brief Sets FSK receiver bandwidth. Allowed values range from 2.6 to 250 kHz. Only available in FSK mode.
|
||||
|
||||
\param rxBw Receiver bandwidth to be set (in kHz).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setRxBandwidth(float rxBw);
|
||||
|
||||
/*!
|
||||
\brief Sets FSK sync word. Allowed sync words are up to 8 bytes long and can not conatain null bytes. Only available in FSK mode.
|
||||
|
||||
\param syncWord Sync word array.
|
||||
|
||||
\param len Sync word length (in bytes).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setSyncWord(uint8_t* syncWord, size_t len);
|
||||
|
||||
/*!
|
||||
\brief Sets FSK node address. Calling this method will enable address filtering. Only available in FSK mode.
|
||||
|
||||
\param nodeAddr Node address to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setNodeAddress(uint8_t nodeAddr);
|
||||
|
||||
/*!
|
||||
\brief Sets FSK broadcast address. Calling this method will enable address filtering. Only available in FSK mode.
|
||||
|
||||
\param broadAddr Broadcast address to be set.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t setBroadcastAddress(uint8_t broadAddr);
|
||||
|
||||
/*!
|
||||
\brief Disables FSK address filtering.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t disableAddressFiltering();
|
||||
|
||||
#ifdef KITELIB_DEBUG
|
||||
|
|
36
src/protocols/PhysicalLayer.cpp
Normal file
36
src/protocols/PhysicalLayer.cpp
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include "PhysicalLayer.h"
|
||||
|
||||
PhysicalLayer::PhysicalLayer(float crysFreq, uint8_t divExp) {
|
||||
_crystalFreq = crysFreq;
|
||||
_divExponent = divExp;
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::transmit(String& str, uint8_t addr) {
|
||||
return(transmit(str.c_str(), addr));
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::transmit(const char* str, uint8_t addr) {
|
||||
return(transmit((uint8_t*)str, strlen(str), addr));
|
||||
}
|
||||
|
||||
int16_t PhysicalLayer::receive(String& str, size_t len) {
|
||||
// create temporary array to store received data
|
||||
char* data = new char[len + 1];
|
||||
int16_t state = receive((uint8_t*)data, len);
|
||||
|
||||
// if packet was received successfully, copy data into String
|
||||
if(state == ERR_NONE) {
|
||||
str = String(data);
|
||||
}
|
||||
|
||||
delete[] data;
|
||||
return(state);
|
||||
}
|
||||
|
||||
float PhysicalLayer::getCrystalFreq() {
|
||||
return(_crystalFreq);
|
||||
}
|
||||
|
||||
uint8_t PhysicalLayer::getDivExponent() {
|
||||
return(_divExponent);
|
||||
}
|
|
@ -3,22 +3,131 @@
|
|||
|
||||
#include "TypeDef.h"
|
||||
|
||||
/*!
|
||||
\class PhysicalLayer
|
||||
|
||||
\brief Provides common interface for protocols that run on %LoRa/FSK modules, such as RTTY or LoRaWAN. Also provides extracts some common
|
||||
module-independent methods. Using this interface class allows to use the protocols on various modules without much code duplicity.
|
||||
Because this class is used mainly as interface, all of its virtual members must be implemented in the module class.
|
||||
*/
|
||||
class PhysicalLayer {
|
||||
public:
|
||||
|
||||
// constructor
|
||||
PhysicalLayer(float crysFreq, uint8_t divExp) { _crystalFreq = crysFreq; _divExponent = divExp; }
|
||||
|
||||
/*!
|
||||
\brief Default constructor.
|
||||
|
||||
\param crysFreq Frequency of crystal oscillator inside the module in MHz.
|
||||
|
||||
\param divExp Exponent of module frequency divider.
|
||||
*/
|
||||
PhysicalLayer(float crysFreq, uint8_t divExp);
|
||||
|
||||
// basic methods
|
||||
virtual int16_t transmitDirect(uint32_t FRF = 0) = 0;
|
||||
virtual int16_t receiveDirect() = 0;
|
||||
virtual int16_t transmit(const char* data, uint8_t addr = 0) = 0;
|
||||
|
||||
/*!
|
||||
\brief Arduino String transmit method. Will transmit Arduino String up to 255 characters long using %LoRa or up to 63 bytes using FSK modem.
|
||||
|
||||
\param str Address of Arduino string that will be transmitted.
|
||||
|
||||
\param addr Node address to transmit the packet to. Only used in FSK mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmit(String& str, uint8_t addr = 0);
|
||||
|
||||
/*!
|
||||
\brief C-string transmit method. Will transmit C-string up to 255 characters long using %LoRa or up to 63 characters using FSK modem.
|
||||
|
||||
\param str C-string that will be transmitted.
|
||||
|
||||
\param addr Node address to transmit the packet to. Only used in FSK mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t transmit(const char* str, uint8_t addr = 0);
|
||||
|
||||
/*!
|
||||
\brief Binary transmit method. Will transmit arbitrary binary data up to 255 bytes long using %LoRa or up to 63 bytes using FSK modem.
|
||||
Must be implemented in module class.
|
||||
|
||||
\param data Binary data that will be transmitted.
|
||||
|
||||
\param len Length of binary data to transmit (in bytes).
|
||||
|
||||
\param addr Node address to transmit the packet to. Only used in FSK mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t transmit(uint8_t* data, size_t len, uint8_t addr = 0) = 0;
|
||||
|
||||
/*!
|
||||
\brief Arduino String receive method. Will attempt to receive Arduino String up to 255 characters long using %LoRa or up to 63 characters using FSK modem.
|
||||
|
||||
\param str Address of Arduino String to save the received data.
|
||||
|
||||
\param len Expected number of characters in the message. Must be known in advance for %LoRa spreading factor 6.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
int16_t receive(String& str, size_t len = 0);
|
||||
|
||||
/*!
|
||||
\brief Binary receive method. Will attempt to receive arbitrary binary data up to 255 bytes long using %LoRa or up to 63 bytes using FSK modem.
|
||||
Must be implemented in module class.
|
||||
|
||||
\param data Pointer to array to save the received binary data.
|
||||
|
||||
\param len Number of bytes that will be received. Must be known in advance for binary transmissions.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t receive(uint8_t* data, size_t len) = 0;
|
||||
|
||||
/*!
|
||||
\brief Enables direct transmission mode on pins DIO1 (clock) and DIO2 (data). Must be implemented in module class.
|
||||
While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode.
|
||||
|
||||
\param FRF 24-bit raw frequency value to start transmitting at. Required for quick frequency shifts in RTTY.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t transmitDirect(uint32_t FRF = 0) = 0;
|
||||
|
||||
/*!
|
||||
\brief Enables direct reception mode on pins DIO1 (clock) and DIO2 (data). Must be implemented in module class.
|
||||
While in direct mode, the module will not be able to transmit or receive packets. Can only be activated in FSK mode.
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t receiveDirect() = 0;
|
||||
|
||||
// configuration methods
|
||||
|
||||
/*!
|
||||
\brief Sets FSK frequency deviation from carrier frequency. Allowed values depend on bit rate setting and must be lower than 200 kHz.
|
||||
Only available in FSK mode. Must be implemented in module class.
|
||||
|
||||
\param freqDev Frequency deviation to be set (in kHz).
|
||||
|
||||
\returns \ref status_codes
|
||||
*/
|
||||
virtual int16_t setFrequencyDeviation(float freqDev) = 0;
|
||||
float getCrystalFreq() { return(_crystalFreq); }
|
||||
uint8_t getDivExponent() { return(_divExponent); }
|
||||
|
||||
/*!
|
||||
\brief Gets the module crystal oscillator frequency that was set in constructor.
|
||||
|
||||
\returns Crystal oscillator frequency in MHz.
|
||||
*/
|
||||
float getCrystalFreq();
|
||||
|
||||
/*!
|
||||
\brief Gets the module frequency divider exponent that was set in constructor.
|
||||
|
||||
\returns Frequency divider exponent.
|
||||
*/
|
||||
uint8_t getDivExponent();
|
||||
|
||||
private:
|
||||
float _crystalFreq;
|
||||
|
|
Loading…
Add table
Reference in a new issue