LoRaWANCH341 Library
|
Class for handling RFM95 LoRa module. More...
#include <RFM95.hpp>
Public Member Functions | |
RFM95 (int device_index=0) | |
Constructor. | |
RFM95 (std::unique_ptr< SPIInterface > spi_interface) | |
Constructor. | |
~RFM95 () | |
Destructor. | |
bool | begin () |
Initialize RFM95 module. | |
void | end () |
Close the connection. | |
void | setFrequency (float freq_mhz) |
Set frequency in MHz. | |
float | getFrequency () |
Get current frequency in MHz. | |
void | setTxPower (int level, bool use_pa_boost=true) |
Set transmit power level. | |
int | getTxPower () |
Get current transmit power level. | |
void | setSpreadingFactor (int sf) |
Set spreading factor (6-12) | |
int | getSpreadingFactor () |
Get current spreading factor. | |
void | setBandwidth (float bw_khz) |
Set bandwidth in kHz (7.8, 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250, 500) | |
float | getBandwidth () |
Get current bandwidth in kHz. | |
void | setCodingRate (int denominator) |
Set coding rate denominator (5-8, giving rates of 4/5, 4/6, 4/7, 4/8) | |
int | getCodingRate () |
Get current coding rate denominator. | |
void | setPreambleLength (int length) |
Set preamble length (6-65535) | |
int | getPreambleLength () |
Get current preamble length. | |
void | setInvertIQ (bool invert=false) |
Set IQ inversion (used for LoRaWAN downlinks) | |
bool | getInvertIQ () |
Check if IQ inversion is enabled. | |
void | setSyncWord (uint8_t sync_word) |
Set sync word. | |
uint8_t | getSyncWord () |
Get current sync word. | |
void | setLNA (int lna_gain=-1, bool lna_boost=true) |
Set LNA gain and boost. | |
uint8_t | getLNA () |
Get current LNA settings. | |
void | setAutoAGC (bool enable) |
Enable or disable automatic gain control. | |
bool | getAutoAGC () |
Check if automatic gain control is enabled. | |
void | clearIRQFlags () |
Clear all IRQ flags. | |
uint8_t | getIRQFlags () |
Get current IRQ flags. | |
void | clearIRQFlagTxDone () |
Clear TX done flag. | |
void | clearIRQFlagRxDone () |
Clear RX done flag. | |
bool | getRxDone () |
Check if RX done flag is set. | |
bool | getTxDone () |
Check if TX done flag is set. | |
bool | getRxError () |
Check if RX error flag is set. | |
bool | getValidHeader () |
Check if valid header flag is set. | |
bool | getCADDone () |
Check if CAD done flag is set. | |
bool | getCADDetected () |
Check if CAD detected flag is set. | |
bool | getPayloadCRCError () |
Check if payload CRC error flag is set. | |
void | setLoRaMode (bool enable=true) |
Enable or disable LoRa mode. | |
bool | send (const std::vector< uint8_t > &data, bool invert_iq=false) |
Send data packet. | |
std::vector< uint8_t > | receive (float timeout=5.0, bool invert_iq=false) |
Receive data packet. | |
void | setContinuousReceive () |
Set continuous receive mode. | |
void | standbyMode () |
Set standby mode. | |
void | sleepMode () |
Set sleep mode. | |
void | resetPtrRx () |
Reset RX pointer. | |
uint8_t | getFifoRxCurrentAddr () |
Get current RX FIFO address. | |
uint8_t | getRxNbBytes () |
Get number of received bytes. | |
std::vector< uint8_t > | readPayload () |
Read received data packet. | |
float | getRSSI () |
Get current RSSI in dBm. | |
float | getSNR () |
Get last packet SNR in dB. | |
uint8_t | readRegister (uint8_t address) |
Read a register value. | |
void | writeRegister (uint8_t address, uint8_t value) |
Write a register value. | |
void | receiveMode () |
Put the module in continuous receive mode. | |
void | setDIOMapping (uint8_t _dio3=0x40, uint8_t _dio4=0x00) |
Configure DIO pins for TX/RX indication. | |
bool | calibrateTemperature (float actual_temp) |
Calibrate temperature sensor with a reference temperature. | |
float | readTemperature () |
Read calibrated temperature. | |
bool | setBeaconMode (int interval_ms, const std::vector< uint8_t > &payload) |
Configure beacon mode with automatic periodic transmission. | |
void | stopBeaconMode () |
Stop beacon mode. | |
void | checkOperatingMode () |
Check and print current operating mode. | |
void | checkIRQFlags () |
Check and print IRQ flags. | |
void | printRegisters () |
Print key registers for debugging. | |
bool | testCommunication () |
Test basic SPI communication. | |
uint8_t | readVersionRegister () |
Read VERSION register (0x42) directly. | |
Static Public Attributes | |
static constexpr uint8_t | REG_FIFO = 0x00 |
static constexpr uint8_t | REG_OP_MODE = 0x01 |
static constexpr uint8_t | REG_FRF_MSB = 0x06 |
static constexpr uint8_t | REG_FRF_MID = 0x07 |
static constexpr uint8_t | REG_FRF_LSB = 0x08 |
static constexpr uint8_t | REG_PA_CONFIG = 0x09 |
static constexpr uint8_t | REG_PA_RAMP = 0x0A |
static constexpr uint8_t | REG_OCP = 0x0B |
static constexpr uint8_t | REG_LNA = 0x0C |
static constexpr uint8_t | REG_FIFO_ADDR_PTR = 0x0D |
static constexpr uint8_t | REG_FIFO_TX_BASE_ADDR = 0x0E |
static constexpr uint8_t | REG_FIFO_RX_BASE_ADDR = 0x0F |
static constexpr uint8_t | REG_FIFO_RX_CURRENT_ADDR = 0x10 |
static constexpr uint8_t | REG_IRQ_FLAGS_MASK = 0x11 |
static constexpr uint8_t | REG_IRQ_FLAGS = 0x12 |
static constexpr uint8_t | REG_RX_NB_BYTES = 0x13 |
static constexpr uint8_t | REG_PKT_SNR_VALUE = 0x19 |
static constexpr uint8_t | REG_PKT_RSSI_VALUE = 0x1A |
static constexpr uint8_t | REG_MODEM_CONFIG_1 = 0x1D |
static constexpr uint8_t | REG_MODEM_CONFIG_2 = 0x1E |
static constexpr uint8_t | REG_PREAMBLE_MSB = 0x20 |
static constexpr uint8_t | REG_PREAMBLE_LSB = 0x21 |
static constexpr uint8_t | REG_PAYLOAD_LENGTH = 0x22 |
static constexpr uint8_t | REG_MODEM_CONFIG_3 = 0x26 |
static constexpr uint8_t | REG_FREQ_ERROR_MSB = 0x28 |
static constexpr uint8_t | REG_FREQ_ERROR_MID = 0x29 |
static constexpr uint8_t | REG_FREQ_ERROR_LSB = 0x2A |
static constexpr uint8_t | REG_RSSI_WIDEBAND = 0x2C |
static constexpr uint8_t | REG_DETECTION_OPTIMIZE = 0x31 |
static constexpr uint8_t | REG_INVERTIQ = 0x33 |
static constexpr uint8_t | REG_DETECTION_THRESHOLD = 0x37 |
static constexpr uint8_t | REG_SYNC_WORD = 0x39 |
static constexpr uint8_t | REG_INVERTIQ2 = 0x3B |
static constexpr uint8_t | REG_DIO_MAPPING_1 = 0x40 |
static constexpr uint8_t | REG_DIO_MAPPING_2 = 0x41 |
static constexpr uint8_t | REG_VERSION = 0x42 |
static constexpr uint8_t | REG_PA_DAC = 0x4D |
static constexpr uint8_t | MODE_SLEEP = 0x00 |
static constexpr uint8_t | MODE_STDBY = 0x01 |
static constexpr uint8_t | MODE_TX = 0x03 |
static constexpr uint8_t | MODE_RX_CONTINUOUS = 0x05 |
static constexpr uint8_t | MODE_RX_SINGLE = 0x06 |
static constexpr uint8_t | PA_BOOST = 0x80 |
static constexpr uint8_t | IRQ_CAD_DONE_MASK = 0x01 |
static constexpr uint8_t | IRQ_CAD_DETECTED_MASK = 0x02 |
static constexpr uint8_t | IRQ_RX_TIMEOUT_MASK = 0x04 |
static constexpr uint8_t | IRQ_TX_DONE_MASK = 0x08 |
static constexpr uint8_t | IRQ_VALID_HEADER_MASK = 0x10 |
static constexpr uint8_t | IRQ_PAYLOAD_CRC_ERROR_MASK = 0x20 |
static constexpr uint8_t | IRQ_RX_DONE_MASK = 0x40 |
static constexpr uint8_t | IRQ_TX_TIMEOUT_MASK = 0x80 |
static constexpr uint8_t | DIO0_RX_DONE = 0x00 |
static constexpr uint8_t | DIO0_TX_DONE = 0x40 |
static constexpr uint8_t | DIO1_RX_TIMEOUT = 0x00 |
static constexpr uint8_t | DIO3_TX_DONE = 0x40 |
static constexpr uint8_t | DIO4_RX_DONE = 0x00 |
static constexpr uint8_t | DIO_TX_PIN = 0x03 |
static constexpr uint8_t | DIO_RX_PIN = 0x04 |
Private Attributes | |
std::unique_ptr< SPIInterface > | spi |
Unique pointer to SPI interface implementation. | |
Class for handling RFM95 LoRa module.
This class provides methods to configure and use the RFM95 LoRa module. It includes methods for setting frequency, transmit power, spreading factor, bandwidth, coding rate, preamble length, and other parameters. It also provides methods for sending and receiving data packets, as well as handling IRQ flags.
RFM95::RFM95 | ( | int | device_index = 0 | ) |
Constructor.
device_index | Index of CH341 device to use (default: 0) |
RFM95::RFM95 | ( | std::unique_ptr< SPIInterface > | spi_interface | ) |
Constructor.
spi_interface | Unique pointer to SPI interface implementation |
RFM95::~RFM95 | ( | ) |
Destructor.
bool RFM95::begin | ( | ) |
Initialize RFM95 module.
bool RFM95::calibrateTemperature | ( | float | actual_temp | ) |
Calibrate temperature sensor with a reference temperature.
actual_temp | Actual temperature measured with external sensor in Celsius |
void RFM95::checkIRQFlags | ( | ) |
Check and print IRQ flags.
void RFM95::checkOperatingMode | ( | ) |
Check and print current operating mode.
void RFM95::clearIRQFlagRxDone | ( | ) |
Clear RX done flag.
void RFM95::clearIRQFlags | ( | ) |
Clear all IRQ flags.
void RFM95::clearIRQFlagTxDone | ( | ) |
Clear TX done flag.
void RFM95::end | ( | ) |
Close the connection.
bool RFM95::getAutoAGC | ( | ) |
Check if automatic gain control is enabled.
float RFM95::getBandwidth | ( | ) |
Get current bandwidth in kHz.
bool RFM95::getCADDetected | ( | ) |
Check if CAD detected flag is set.
bool RFM95::getCADDone | ( | ) |
Check if CAD done flag is set.
int RFM95::getCodingRate | ( | ) |
Get current coding rate denominator.
uint8_t RFM95::getFifoRxCurrentAddr | ( | ) |
Get current RX FIFO address.
float RFM95::getFrequency | ( | ) |
Get current frequency in MHz.
bool RFM95::getInvertIQ | ( | ) |
Check if IQ inversion is enabled.
uint8_t RFM95::getIRQFlags | ( | ) |
Get current IRQ flags.
uint8_t RFM95::getLNA | ( | ) |
Get current LNA settings.
bool RFM95::getPayloadCRCError | ( | ) |
Check if payload CRC error flag is set.
int RFM95::getPreambleLength | ( | ) |
Get current preamble length.
float RFM95::getRSSI | ( | ) |
Get current RSSI in dBm.
bool RFM95::getRxDone | ( | ) |
Check if RX done flag is set.
bool RFM95::getRxError | ( | ) |
Check if RX error flag is set.
uint8_t RFM95::getRxNbBytes | ( | ) |
Get number of received bytes.
float RFM95::getSNR | ( | ) |
Get last packet SNR in dB.
int RFM95::getSpreadingFactor | ( | ) |
Get current spreading factor.
uint8_t RFM95::getSyncWord | ( | ) |
Get current sync word.
bool RFM95::getTxDone | ( | ) |
Check if TX done flag is set.
int RFM95::getTxPower | ( | ) |
Get current transmit power level.
bool RFM95::getValidHeader | ( | ) |
Check if valid header flag is set.
void RFM95::printRegisters | ( | ) |
Print key registers for debugging.
std::vector< uint8_t > RFM95::readPayload | ( | ) |
Read received data packet.
uint8_t RFM95::readRegister | ( | uint8_t | address | ) |
Read a register value.
address | Register address |
float RFM95::readTemperature | ( | ) |
Read calibrated temperature.
uint8_t RFM95::readVersionRegister | ( | ) |
Read VERSION register (0x42) directly.
std::vector< uint8_t > RFM95::receive | ( | float | timeout = 5.0 , |
bool | invert_iq = false |
||
) |
Receive data packet.
timeout | Maximum time to wait for packet in seconds |
invert_iq | True to receive with inverted IQ |
void RFM95::receiveMode | ( | ) |
Put the module in continuous receive mode.
void RFM95::resetPtrRx | ( | ) |
Reset RX pointer.
bool RFM95::send | ( | const std::vector< uint8_t > & | data, |
bool | invert_iq = false |
||
) |
Send data packet.
data | Data to send (max 255 bytes) |
invert_iq | True to send with inverted IQ (LoRaWAN downlinks) |
void RFM95::setAutoAGC | ( | bool | enable | ) |
Enable or disable automatic gain control.
enable | True to enable, False to disable |
void RFM95::setBandwidth | ( | float | bw_khz | ) |
Set bandwidth in kHz (7.8, 10.4, 15.6, 20.8, 31.25, 41.7, 62.5, 125, 250, 500)
bw_khz | Bandwidth in kHz |
bool RFM95::setBeaconMode | ( | int | interval_ms, |
const std::vector< uint8_t > & | payload | ||
) |
Configure beacon mode with automatic periodic transmission.
interval_ms | Interval between transmissions in milliseconds |
payload | Data to transmit in each beacon |
void RFM95::setCodingRate | ( | int | denominator | ) |
Set coding rate denominator (5-8, giving rates of 4/5, 4/6, 4/7, 4/8)
denominator | Coding rate denominator |
void RFM95::setContinuousReceive | ( | ) |
Set continuous receive mode.
void RFM95::setDIOMapping | ( | uint8_t | _dio3 = 0x40 , |
uint8_t | _dio4 = 0x00 |
||
) |
Configure DIO pins for TX/RX indication.
_dio3 | DIO3 mapping |
_dio4 | DIO4 mapping |
void RFM95::setFrequency | ( | float | freq_mhz | ) |
Set frequency in MHz.
freq_mhz | Frequency in MHz |
void RFM95::setInvertIQ | ( | bool | invert = false | ) |
Set IQ inversion (used for LoRaWAN downlinks)
invert | True to invert IQ, False for normal operation |
void RFM95::setLNA | ( | int | lna_gain = -1 , |
bool | lna_boost = true |
||
) |
Set LNA gain and boost.
lna_gain | LNA gain |
lna_boost | LNA boost |
void RFM95::setLoRaMode | ( | bool | enable = true | ) |
Enable or disable LoRa mode.
enable | True to enable, False to disable |
void RFM95::setPreambleLength | ( | int | length | ) |
Set preamble length (6-65535)
length | Preamble length |
void RFM95::setSpreadingFactor | ( | int | sf | ) |
Set spreading factor (6-12)
sf | Spreading factor |
void RFM95::setSyncWord | ( | uint8_t | sync_word | ) |
Set sync word.
sync_word | Sync word |
void RFM95::setTxPower | ( | int | level, |
bool | use_pa_boost = true |
||
) |
Set transmit power level.
level | Power level in dBm (2-20 for PA_BOOST, 0-15 for RFO) |
use_pa_boost | Use PA_BOOST output pin |
void RFM95::sleepMode | ( | ) |
Set sleep mode.
void RFM95::standbyMode | ( | ) |
Set standby mode.
void RFM95::stopBeaconMode | ( | ) |
Stop beacon mode.
bool RFM95::testCommunication | ( | ) |
Test basic SPI communication.
void RFM95::writeRegister | ( | uint8_t | address, |
uint8_t | value | ||
) |
Write a register value.
address | Register address |
value | Value to write |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
private |
Unique pointer to SPI interface implementation.