Driver to nRF24L01 radio transceiver.
Encapsule RF24 class (J. Coliz lib) and implement a basic message format to communication.
Take care of communication details.
Public declarations:
typedef struct{ union{ struct{ byte msgID; byte paySize; uint serialN; }; long l; }; } THeader; #define PAYLOAD_MAX_LEN (32-sizeof(THeader)) typedef struct { THeader head; byte buff[PAYLOAD_MAX_LEN]; } TRadioMsg; class RadioMessage: protected RF24{ public: RadioMessage(int cePin, int csPin); void begin(byte *pipeIn, byte *pipeOut, TDatarate rate); TRadioMsg* makeMessage(TRadioMsg* msg, byte msgID, byte payloadSize=0, void* payload= NULL); int sendMessage(TRadioMsg* msg); int readMessage(TRadioMsg* msg); boolean messageWaiting(); byte getMsgID(TRadioMsg* msg); byte getMsgPaySize(TRadioMsg* msg); void* getMsgPayload(TRadioMsg* msg); byte copyMsgPayload(TRadioMsg* msg, void* destination); void run(); protected: virtual void onIncommingMsg(TRadioMsg* msg){} };
Inform CE pin and CS pin on constructor.
Call begin() before any method informing comunication params.
Call makeMessage() to mount a message pack. Messages with 1 byte dont need payload, use msgID param.
Send message packs calling sendMessage().
Call messageWaiting() to check if there are incomming messages to read. If yes, call readMessage() to read the message.
If you prefer to work with events, derive RadioMessage class and rewrite onIncommingMsg() event. In this case, dont forget to call run() method once per loop.