MeshNet  1.0.0
Public Member Functions | Data Fields | Protected Attributes | Static Protected Attributes
NRF24L01_RFI Class Reference

#include <NRF24L01_interface.h>

Inheritance diagram for NRF24L01_RFI:
Inheritance graph
[legend]
Collaboration diagram for NRF24L01_RFI:
Collaboration graph
[legend]

Public Member Functions

 NRF24L01_RFI (RF24 &Radio, HardwareSPI &_spi, uint8_t IRQ_pin=255, ThreadLock *_lock=NULL)
 Constructor. More...
 
 ~NRF24L01_RFI () override
 
bool init () override
 Override this method to initialize radio and communication with it. More...
 
bool deInit () override
 Override this method to de-initialize radio and communication with it. More...
 
bool hasError () override
 Override this method to check if radio has some error or is not connected to MCU. If this method returns true, deInit() method in meshNet will be called. More...
 
bool send (uint8_t *data, uint8_t dataSize) override
 Override this method to send data through radio. More...
 
bool recv (uint8_t *data, uint8_t &dataSize, int8_t &rssi) override
 Override this method to read data from radio buffer. More...
 
uint8_t available () override
 Override this method to get raw size of received frame in bytes. More...
 
bool sleep () override
 Override this method to temporary power off the radio. If the radio cannot sleep, just return true. More...
 
bool wakeUp () override
 Override this method to temporary power on (wake up) the radio from sleep. If the radio cannot sleep, just return true. More...
 
bool checkInterference () override
 Override this method to check, if there is currently an interference in the air. If interference check cannot be done on selected radio, just return false. This method is used to check, if radio can send data or has to wait on another radio. More...
 
bool setChannel (uint8_t channel) override
 Override this method to set radio channel. If channels cannot be set on selected radio, just return false. More...
 
bool setPower (uint8_t power) override
 Override this method to set radio output power. If radio output power cannot be set, just return true. More...
 
bool setFullSpeed (bool enableFullSpeed) override
 Override this method to set full or slow speed (data rate). If speed cannot be set, just return true. More...
 
bool setReceiveInterruptCallback (void(*InterruptCallback)(void)) override
 Override this method to set receive message interrupt method. If interrupt cannot be set or is not supported, return false. More...
 
bool interruptHandle () override
 This method has to be done, when ReceiveInterrupt happened. More...
 
void handle () override
 This method is included in meshNet::handle() method and it is included in main loop. More...
 
void printDetails (OSTREAM *stream) override
 This method is used to print radio details to stream (usually to Serial port). Method is also called, when "mesh radio info" command has been called in SerialConsole. More...
 
uint8_t scanChannels (uint8_t startChannel, uint8_t endChannel, uint8_t retries=50, OSTREAM *stream=NULL) override
 This method has to scan all free channels and returns channel with minimum interferences. Method is also called, when "mesh radio scan channels <int:retries>" command has been called in SerialConsole. More...
 
uint8_t scanChannels (uint8_t startChannel, uint8_t endChannel, OSTREAM *stream=NULL) override
 This method has to scan all free channels and returns channel with minimum interferences. Method is also called, when "mesh radio scan channels <int:retries>" command has been called in SerialConsole. Retries count is set to best value. More...
 
bool scanChannelsWorking () override
 Checks if channel scan is processed now. More...
 
uint32_t getChannelsWidth () override
 Gets width of each channels in kHz. More...
 
uint8_t * getInternalTemporaryBuffer () override
 Gets pointer to internal temporary buffer with size of MaxFrameLength. This buffer can be used for temporary storing of received data. More...
 
- Public Member Functions inherited from RFInterface
 RFInterface (const uint8_t maxFrameLength, const RFIType interfaceType, const bool canCheckInterference, const uint8_t maxChannelNumber, const uint8_t minChannelNumber, const uint8_t maxPowerValue, const uint8_t minPowerValue, const bool canSetSpeed, const uint32_t baseFrequency, ThreadLock *_lock)
 Constructor - has to be overridden and parameters have to be set in overridden constructor. More...
 
virtual ~RFInterface ()=0
 

Data Fields

uint8_t internalTmpBuffer [NRF24L01_RFI_MAX_MSG_SIZE]
 
- Data Fields inherited from RFInterface
const uint8_t MaxFrameLength
 RF_NO_INTERNAL_TMP_BUFFER. More...
 
const RFIType InterfaceType
 Interface type, see RFIType. More...
 
const bool CanCheckInterference:1
 True when interference can be checked. More...
 
const uint8_t MaxChannelNumber
 Maximum channel number. When this value is equal or lower than MinChannelNumber, radio channel cannot be set. More...
 
const uint8_t MinChannelNumber
 Minimum channel number. When this value is equal or higher than MaxChannelNumber, radio channel cannot be set. More...
 
const uint8_t MaxPowerValue
 Maximum power level value. When this value is equal or lower than MinPowerValue, radio output power cannot be set. More...
 
const uint8_t MinPowerValue
 Minimum power level value. When this value is equal or higher than MaxPowerValue, radio output power cannot be set. More...
 
const bool CanSetSpeed:1
 True when speed (data rate) can be set. More...
 
const uint32_t BaseFrequency
 Frequency of channel 0 in kHz. More...
 
ThreadLock * lock
 Thread lock, that is used to lock current methods. More...
 

Protected Attributes

RF24 * radio = NULL
 RF_NO_INTERNAL_TMP_BUFFER. More...
 
HardwareSPI * spi = NULL
 
uint8_t IRQ_Pin = 255
 
uint8_t lastChannel = MinChannelNumber
 
rf24_datarate_e lastSpeed = RF24_250KBPS
 
bool scanWorking = false
 

Static Protected Attributes

const static uint32_t dummy_address = 0xE7E7E7UL
 

Constructor & Destructor Documentation

◆ NRF24L01_RFI()

NRF24L01_RFI::NRF24L01_RFI ( RF24 &  Radio,
HardwareSPI &  _spi,
uint8_t  IRQ_pin = 255,
ThreadLock *  _lock = NULL 
)

Constructor.

Parameters
RadioInstance of RF24 radio class, that can communicate with NRF24L01.
_spiHardwareSPI instance, where Radio is connected.
IRQ_pinPin number on MCU, where NRF's IRQ pin is connected. If set to 255, interrupt is disabled.
_lockPointer to lock instance, which is used to lock SPI. If set to NULL, lock will not be used.

◆ ~NRF24L01_RFI()

NRF24L01_RFI::~NRF24L01_RFI ( )
override

Member Function Documentation

◆ available()

uint8_t NRF24L01_RFI::available ( )
overridevirtual

Override this method to get raw size of received frame in bytes.

Note
This method should not be locked, because it returns value and can be called in interrupt. Lock has to be provided there, where this method is used.
Returns
Returns size of received packet in bytes.

Implements RFInterface.

◆ checkInterference()

bool NRF24L01_RFI::checkInterference ( )
overridevirtual

Override this method to check, if there is currently an interference in the air. If interference check cannot be done on selected radio, just return false. This method is used to check, if radio can send data or has to wait on another radio.

Note
This method should not be locked, because it returns value and can be called in interrupt. Lock has to be provided there, where this method is used.
Returns
Returns true when interference is present in the air.

Implements RFInterface.

◆ deInit()

bool NRF24L01_RFI::deInit ( )
overridevirtual

Override this method to de-initialize radio and communication with it.

Note
This method should be called in main thread, that's why thread locking TLWhenUnlocked is recommended to use.
Returns
Returns true when de-initialization was done correctly.

Implements RFInterface.

◆ getChannelsWidth()

uint32_t NRF24L01_RFI::getChannelsWidth ( )
overridevirtual

Gets width of each channels in kHz.

Returns
Returns width of each channels in kHz.

Implements RFInterface.

◆ getInternalTemporaryBuffer()

uint8_t * NRF24L01_RFI::getInternalTemporaryBuffer ( )
overridevirtual

Gets pointer to internal temporary buffer with size of MaxFrameLength. This buffer can be used for temporary storing of received data.

Implements RFInterface.

◆ handle()

void NRF24L01_RFI::handle ( )
overridevirtual

This method is included in meshNet::handle() method and it is included in main loop.

Note
This method should be called in main thread, that's why thread locking TLWhenUnlocked is recommended to use.

Implements RFInterface.

◆ hasError()

bool NRF24L01_RFI::hasError ( )
overridevirtual

Override this method to check if radio has some error or is not connected to MCU. If this method returns true, deInit() method in meshNet will be called.

Note
This method should not be locked, because it returns value and can be called in interrupt. Lock has to be provided there, where this method is used.
Returns
Returns true when there is some error.

Implements RFInterface.

◆ init()

bool NRF24L01_RFI::init ( )
overridevirtual

Override this method to initialize radio and communication with it.

Note
This method should be called in main thread, that's why thread locking TLWhenUnlocked is recommended to use.
Returns
Returns true when initialization was done correctly.

Implements RFInterface.

◆ interruptHandle()

bool NRF24L01_RFI::interruptHandle ( )
overridevirtual

This method has to be done, when ReceiveInterrupt happened.

Note
This method should not be locked, because it returns value and can be called in interrupt. Lock has to be provided there, where this method is used.
Returns
Returns true, when new message has been received and it should be read in interrupt.
See also
setReceiveInterruptCallback

Implements RFInterface.

◆ printDetails()

void NRF24L01_RFI::printDetails ( OSTREAM stream)
overridevirtual

This method is used to print radio details to stream (usually to Serial port). Method is also called, when "mesh radio info" command has been called in SerialConsole.

Note
This method should be called in main thread, that's why thread locking TLWhenUnlocked is recommended to use.
Parameters
streamStream, where to print details.

Implements RFInterface.

◆ recv()

bool NRF24L01_RFI::recv ( uint8_t *  data,
uint8_t &  dataSize,
int8_t &  rssi 
)
overridevirtual

Override this method to read data from radio buffer.

Parameters
[out]dataBuffer reserved for data to be recived. The size of buffer has to at least MaxFrameLength value. Internal temporary buffer can be used here, see getInternalTemporaryBuffer().
[in,out]dataSizeInsert size of buffer. After calling, size of received data is assigned to this variable.
[out]rssiRSSI value of current frame in dBm. If RSSI is unknown, set it to 0.
Note
This method should not be locked, because it returns value and can be called in interrupt. Lock has to be provided there, where this method is used.
Returns
Returns true when data was read correctly. Returns false, when some error happened, or data are not available.

Implements RFInterface.

◆ scanChannels() [1/2]

uint8_t NRF24L01_RFI::scanChannels ( uint8_t  startChannel,
uint8_t  endChannel,
OSTREAM stream = NULL 
)
inlineoverridevirtual

This method has to scan all free channels and returns channel with minimum interferences. Method is also called, when "mesh radio scan channels <int:retries>" command has been called in SerialConsole. Retries count is set to best value.

Parameters
streamStream, where to print details about scanning. If stream is NULL, no data will be printed. First line has to contain: "Retries: X" where the X is the number of retries for each channel. Second line has to contain: "Channel span: X" where the X is the number of skipped channels (those skipped channels has same interference count as previous channel). Value has to be greater than 0. Third line has to contain: "Base frequency: X" where the X is the frequency of channel 0 in kHz. Fourth line has to contain: "Channel width: X" where the X is the width of each channel in kHz. Each line has to contain this text: "C: I" where C is channel number and I is the number of retries, where interference has been found.
startChannelChannel, from which to start scanning.
endChannelLast scanned channel.
Note
This method can take some time, do not call it often.
This method should be called in main thread, that's why thread locking TLWhenUnlocked is recommended to use.
Returns
Returns channel with lowest interference count or 255 on error.

Implements RFInterface.

◆ scanChannels() [2/2]

uint8_t NRF24L01_RFI::scanChannels ( uint8_t  startChannel,
uint8_t  endChannel,
uint8_t  retries = 50,
OSTREAM stream = NULL 
)
overridevirtual

This method has to scan all free channels and returns channel with minimum interferences. Method is also called, when "mesh radio scan channels <int:retries>" command has been called in SerialConsole.

Parameters
streamStream, where to print details about scanning. If stream is NULL, no data will be printed. First line has to contain: "Retries: X" where the X is number of retries for each channel. Each line has to contain this text: "C: I" where C is channel number and I is the number of retries, where interference has been found.
retriesNumber of retries for each channel.
startChannelChannel, from which to start scanning.
endChannelLast scanned channel.
Note
This method can take some time, do not call it often.
Returns
Returns channel with lowest interference count.
Note
This method should be called in main thread, that's why thread locking TLWhenUnlocked is recommended to use.

Implements RFInterface.

◆ scanChannelsWorking()

bool NRF24L01_RFI::scanChannelsWorking ( )
overridevirtual

Checks if channel scan is processed now.

Returns
Returns true when channel scan is processed now.

Implements RFInterface.

◆ send()

bool NRF24L01_RFI::send ( uint8_t *  data,
uint8_t  dataSize 
)
overridevirtual

Override this method to send data through radio.

Parameters
[in]dataRaw frame data to be sent.
[in]dataSizeSize of sending data. The size cannot exceed MaxFrameLength value.
Warning
The raw length of (use GetRawLength() method) MeshFrame has to be lower or equal than MaxFrameLength, else false will be returned.
Note
This method should not be locked, because it returns value and can be called in interrupt. Lock has to be provided there, where this method is used.
Returns
Returns true when data was sent correctly. True is returned also, when data were transmitted, but not received by any radio.

Implements RFInterface.

◆ setChannel()

bool NRF24L01_RFI::setChannel ( uint8_t  channel)
overridevirtual

Override this method to set radio channel. If channels cannot be set on selected radio, just return false.

Parameters
channelChannel number to set. This value have to be between MaxChannelNumber (included) and MinChannelNumber (included).
Note
This method should be called in main thread, that's why thread locking TLWhenUnlocked is recommended to use.
Returns
Returns true when channel was set.

Implements RFInterface.

◆ setFullSpeed()

bool NRF24L01_RFI::setFullSpeed ( bool  enableFullSpeed)
overridevirtual

Override this method to set full or slow speed (data rate). If speed cannot be set, just return true.

Parameters
enableFullSpeedTrue to send data at full speed or false to send data at slow speed.
Note
This method should be called in main thread, that's why thread locking TLWhenUnlocked is recommended to use.
Returns
Returns false when error happened.

Implements RFInterface.

◆ setPower()

bool NRF24L01_RFI::setPower ( uint8_t  power)
overridevirtual

Override this method to set radio output power. If radio output power cannot be set, just return true.

Note
This method should be called in main thread, that's why thread locking TLWhenUnlocked is recommended to use.
Returns
Returns false when error happened.

Implements RFInterface.

◆ setReceiveInterruptCallback()

bool NRF24L01_RFI::setReceiveInterruptCallback ( void(*)(void)  InterruptCallback)
overridevirtual

Override this method to set receive message interrupt method. If interrupt cannot be set or is not supported, return false.

Parameters
InterruptCallbackCallback function, that is called when radio has received new packet. When InterruptCallback is nullptr, interrupt has to be detached.
Note
This method should be called in main thread, that's why thread locking TLWhenUnlocked is recommended to use.
Returns
Returns true when interrupt function was set.

Implements RFInterface.

◆ sleep()

bool NRF24L01_RFI::sleep ( )
overridevirtual

Override this method to temporary power off the radio. If the radio cannot sleep, just return true.

Note
This method should be called in main thread, that's why thread locking TLWhenUnlocked is recommended to use.
Returns
Returns false when some error happened.

Implements RFInterface.

◆ wakeUp()

bool NRF24L01_RFI::wakeUp ( )
overridevirtual

Override this method to temporary power on (wake up) the radio from sleep. If the radio cannot sleep, just return true.

Note
This method should be called in main thread, that's why thread locking TLWhenUnlocked is recommended to use.
Returns
Returns false when some error happened.

Implements RFInterface.

Field Documentation

◆ dummy_address

const static uint32_t NRF24L01_RFI::dummy_address = 0xE7E7E7UL
staticprotected

◆ internalTmpBuffer

uint8_t NRF24L01_RFI::internalTmpBuffer[NRF24L01_RFI_MAX_MSG_SIZE]

◆ IRQ_Pin

uint8_t NRF24L01_RFI::IRQ_Pin = 255
protected

◆ lastChannel

uint8_t NRF24L01_RFI::lastChannel = MinChannelNumber
protected

◆ lastSpeed

rf24_datarate_e NRF24L01_RFI::lastSpeed = RF24_250KBPS
protected

◆ radio

RF24* NRF24L01_RFI::radio = NULL
protected

RF_NO_INTERNAL_TMP_BUFFER.

◆ scanWorking

bool NRF24L01_RFI::scanWorking = false
protected

◆ spi

HardwareSPI* NRF24L01_RFI::spi = NULL
protected

The documentation for this class was generated from the following files: