RF24G  0.9
Simple Abstraction Layer for the nRF24L01
List of all members
packet Class Reference

Public Member Functions

Packet public interface

These are the main methods you need to set, modify, and retrieve data from packets.

 RF24_G ()
 
void setAddress (uint8_t _address)
 
uint8_t getAddress ()
 
uint8_t getCnt ()
 
void setCnt (uint8_t _cnt)
 
bool addPayload (const void *data, const uint8_t size)
 
bool readPayload (void *data, const uint8_t size)
 

Member Function Documentation

§ RF24_G()

packet::RF24_G ( )

Default Constructor

Creates a new instance of the packet object. The packet is blank and will need to be modified with the methods below.

§ setAddress()

void packet::setAddress ( uint8_t  _address)

Sets the address of a packet.

If you are sending a packet, set this to set the destination of the packet.

§ getAddress()

uint8_t packet::getAddress ( )

Gets the address of a packet.

If you receive a packet, call this on the packet to get what address the packet came from.

Returns
Current packet address.

§ getCnt()

uint8_t packet::getCnt ( )

Gets the counter of a packet.

This is used internally by the library to set the packet counter. This is used to detect duplicate packets.

The user does not need to use this method.

Returns
Current packet counter.

§ setCnt()

void packet::setCnt ( uint8_t  _cnt)

Sets the counter of a packet.

This is used internally by the library to set the packet counter. This is used to detect duplicate packets.

The user does not need to use this method.

§ addPayload()

bool packet::addPayload ( const void *  data,
const uint8_t  size 
)

Adds any datatype smaller than 31 bytes to the packet.

Note
There is no way to determine what kind of datatype is in this packet.
If you want to send multiple values, use a struct or class similar to this packet within the payload.

This needs the address of an object and it's size to work correctly.

//addPayload() example:
int var = 23;
if (packet.addPayload( &value, sizeof(var)) == false) {
Serial.println("Datatype is too large!")
}
Returns
True if the size is within 31 bytes, false if it is not.
Warning
This does not allow for you to overwrite the packet. But it is possible to overread from locations in memory that are adjacent to an object! Always use sizeof(yourObject) to prevent this.

§ readPayload()

bool packet::readPayload ( void *  data,
const uint8_t  size 
)

Retrieves any datatype smaller than 31 bytes from the packet.

Note
There is no way to determine what kind of datatype is in this packet.
If you want to send multiple values, use a struct or class similar to this packet within the payload.

This needs the address of an object and it's size to work correctly.

//readPayload() example:
int var;
if (packet.readPayload( &var, sizeof(var)) == false) {
Serial.println("Datatype is too large!")
}
Note
The variable var will have a new value from the packet.
Returns
True if the size is within 31 bytes, false if it is not.
Warning
If you specify a size that is larger than the object you wish to write to, you can write into adjacent memory!
This probably will crash your program and/or give you junk data in other parts of your code! Always use sizeof(yourObject) to prevent this.

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