MeshNet  1.0.0
NRF24L01_interface.h
Go to the documentation of this file.
1 /*
2  * NRF24L01_interface.h
3  *
4  * Created on: 11. 8. 2021
5  * Author: ASUS
6  */
7 
8 #ifndef NRF24L01_INTERFACE_H_
9 #define NRF24L01_INTERFACE_H_
10 
11 #include <RF24.h>
12 #include <RFInterface.h>
13 
14 #define NRF24L01_RFI_MAX_MSG_SIZE (32)
15 #define NRF24L01_RFI_SCAN_TYPE (0) //Channel scanning type.
16  //0 - Channel is incremented after one test. Cycle is repeated when last channel was reached. Retries count is cycles count.
17  //1 - Channel is incremented after all tests.
18 
19 //This file have to be modified by user
20 
21 #define MRF_NRF24L01 //Mesh RF interface of this file is NRF24L01
22 
23 class NRF24L01_RFI: public RFInterface{
24 public:
25 
33  NRF24L01_RFI(RF24 &Radio, HardwareSPI& _spi, uint8_t IRQ_pin = 255, ThreadLock* _lock = NULL);
34 
35  ~NRF24L01_RFI() override;
36 
37  bool init() override;
38 
39  bool deInit() override;
40 
41  bool hasError() override;
42 
43  bool send(uint8_t* data, uint8_t dataSize) override;
44 
45  bool recv(uint8_t* data, uint8_t& dataSize, int8_t& rssi) override;
46 
47  uint8_t available() override;
48 
49  bool sleep() override;
50 
51  bool wakeUp() override;
52 
53  bool checkInterference() override;
54 
55  bool setChannel(uint8_t channel) override;
56 
57  bool setPower(uint8_t power) override;
58 
59  bool setFullSpeed(bool enableFullSpeed) override;
60 
61  bool setReceiveInterruptCallback(void(*InterruptCallback)(void)) override;
62 
63  bool interruptHandle() override;
64 
65  void handle() override;
66 
67  void printDetails(OSTREAM *stream) override;
68 
69  uint8_t scanChannels(uint8_t startChannel, uint8_t endChannel, uint8_t retries = 50, OSTREAM *stream = NULL) override;
70 
71  uint8_t scanChannels(uint8_t startChannel, uint8_t endChannel, OSTREAM *stream = NULL) override {
72  return scanChannels(startChannel, endChannel, 50, stream);
73  }
74 
75  bool scanChannelsWorking() override;
76 
77  uint32_t getChannelsWidth() override;
78 
79 #ifndef RF_NO_INTERNAL_TMP_BUFFER
80  uint8_t* getInternalTemporaryBuffer() override;
82 #endif
83 
84 protected:
85  RF24* radio = NULL;
86  HardwareSPI* spi = NULL;
87  uint8_t IRQ_Pin = 255;
88 
90  rf24_datarate_e lastSpeed = RF24_250KBPS;
91  bool scanWorking = false;
92 
93  const static uint32_t dummy_address = 0xE7E7E7UL; //Default NRF address
94 };
95 
96 
97 #endif /* NRF24L01_INTERFACE_H_ */
RFInterface.h
This file contains interface (pattern) class, that has to be overridden to create driver for radio wh...
NRF24L01_RFI
Definition: NRF24L01_interface.h:23
RFInterface
Radio frequency interface, that helps to use meshNet with different radios or communication types....
Definition: RFInterface.h:48
NRF24L01_RFI::wakeUp
bool wakeUp() override
Override this method to temporary power on (wake up) the radio from sleep. If the radio cannot sleep,...
Definition: NRF24L01_interface.cpp:175
NRF24L01_RFI::send
bool send(uint8_t *data, uint8_t dataSize) override
Override this method to send data through radio.
Definition: NRF24L01_interface.cpp:107
NRF24L01_RFI::available
uint8_t available() override
Override this method to get raw size of received frame in bytes.
Definition: NRF24L01_interface.cpp:138
NRF24L01_RFI::lastChannel
uint8_t lastChannel
Definition: NRF24L01_interface.h:89
NRF24L01_RFI::handle
void handle() override
This method is included in meshNet::handle() method and it is included in main loop.
Definition: NRF24L01_interface.cpp:299
NRF24L01_RFI::hasError
bool hasError() override
Override this method to check if radio has some error or is not connected to MCU. If this method retu...
Definition: NRF24L01_interface.cpp:103
NRF24L01_RFI::printDetails
void printDetails(OSTREAM *stream) override
This method is used to print radio details to stream (usually to Serial port). Method is also called,...
Definition: NRF24L01_interface.cpp:303
NRF24L01_RFI::dummy_address
const static uint32_t dummy_address
Definition: NRF24L01_interface.h:93
NRF24L01_RFI::scanChannels
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....
Definition: NRF24L01_interface.h:71
NRF24L01_RFI::scanChannels
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....
Definition: NRF24L01_interface.cpp:316
NRF24L01_RFI::checkInterference
bool checkInterference() override
Override this method to check, if there is currently an interference in the air. If interference chec...
Definition: NRF24L01_interface.cpp:201
RFInterface::MinChannelNumber
const uint8_t MinChannelNumber
Minimum channel number. When this value is equal or higher than MaxChannelNumber, radio channel canno...
Definition: RFInterface.h:272
NRF24L01_RFI::sleep
bool sleep() override
Override this method to temporary power off the radio. If the radio cannot sleep, just return true.
Definition: NRF24L01_interface.cpp:149
NRF24L01_RFI::radio
RF24 * radio
RF_NO_INTERNAL_TMP_BUFFER.
Definition: NRF24L01_interface.h:85
NRF24L01_RFI::init
bool init() override
Override this method to initialize radio and communication with it.
Definition: NRF24L01_interface.cpp:30
NRF24L01_RFI::setChannel
bool setChannel(uint8_t channel) override
Override this method to set radio channel. If channels cannot be set on selected radio,...
Definition: NRF24L01_interface.cpp:205
NRF24L01_RFI::IRQ_Pin
uint8_t IRQ_Pin
Definition: NRF24L01_interface.h:87
NRF24L01_RFI::lastSpeed
rf24_datarate_e lastSpeed
Definition: NRF24L01_interface.h:90
NRF24L01_RFI::internalTmpBuffer
uint8_t internalTmpBuffer[NRF24L01_RFI_MAX_MSG_SIZE]
Definition: NRF24L01_interface.h:81
OSTREAM
#define OSTREAM
Definition: meshConfig.h:41
NRF24L01_RFI::setReceiveInterruptCallback
bool setReceiveInterruptCallback(void(*InterruptCallback)(void)) override
Override this method to set receive message interrupt method. If interrupt cannot be set or is not su...
Definition: NRF24L01_interface.cpp:281
NRF24L01_RFI::setFullSpeed
bool setFullSpeed(bool enableFullSpeed) override
Override this method to set full or slow speed (data rate). If speed cannot be set,...
Definition: NRF24L01_interface.cpp:255
NRF24L01_RFI_MAX_MSG_SIZE
#define NRF24L01_RFI_MAX_MSG_SIZE
Definition: NRF24L01_interface.h:14
NRF24L01_RFI::recv
bool recv(uint8_t *data, uint8_t &dataSize, int8_t &rssi) override
Override this method to read data from radio buffer.
Definition: NRF24L01_interface.cpp:117
NRF24L01_RFI::NRF24L01_RFI
NRF24L01_RFI(RF24 &Radio, HardwareSPI &_spi, uint8_t IRQ_pin=255, ThreadLock *_lock=NULL)
Constructor.
Definition: NRF24L01_interface.cpp:7
NRF24L01_RFI::deInit
bool deInit() override
Override this method to de-initialize radio and communication with it.
Definition: NRF24L01_interface.cpp:98
NRF24L01_RFI::interruptHandle
bool interruptHandle() override
This method has to be done, when ReceiveInterrupt happened.
Definition: NRF24L01_interface.cpp:293
NRF24L01_RFI::scanChannelsWorking
bool scanChannelsWorking() override
Checks if channel scan is processed now.
Definition: NRF24L01_interface.cpp:533
NRF24L01_RFI::scanWorking
bool scanWorking
Definition: NRF24L01_interface.h:91
NRF24L01_RFI::getInternalTemporaryBuffer
uint8_t * getInternalTemporaryBuffer() override
Gets pointer to internal temporary buffer with size of MaxFrameLength. This buffer can be used for te...
Definition: NRF24L01_interface.cpp:551
NRF24L01_RFI::spi
HardwareSPI * spi
Definition: NRF24L01_interface.h:86
NRF24L01_RFI::getChannelsWidth
uint32_t getChannelsWidth() override
Gets width of each channels in kHz.
Definition: NRF24L01_interface.cpp:537
NRF24L01_RFI::~NRF24L01_RFI
~NRF24L01_RFI() override
Definition: NRF24L01_interface.cpp:25
NRF24L01_RFI::setPower
bool setPower(uint8_t power) override
Override this method to set radio output power. If radio output power cannot be set,...
Definition: NRF24L01_interface.cpp:232