RF24G 0.9
Simple Abstraction Layer for the nRF24L01
Loading...
Searching...
No Matches
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.

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

Detailed Description

Examples
rf24g_receive.cpp, and rf24g_send.cpp.

Member Function Documentation

◆ 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.

Examples
rf24g_send.cpp.

◆ getAddress()

uint8_t packet::getAddress ( ) const

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.
Examples
rf24g_receive.cpp.

◆ getCnt()

uint8_t packet::getCnt ( ) const

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.
Examples
rf24g_receive.cpp.

◆ 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 30 bytes to the packet.

Note
There is no way to determine what kind of datatype is in this packet without prior knowledge.
If you want to send different types of payloads, use a struct or class similar to this packet within the payload that contains metadata on what type of data it is.

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!")
}
Definition rf24g.h:36
bool addPayload(const void *data, const uint8_t size)
Definition rf24g.cpp:36
Returns
True if the size is within 30 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.
Examples
rf24g_send.cpp.

◆ readPayload()

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

Retrieves any datatype smaller than 30 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!")
}
bool readPayload(void *data, const uint8_t size)
Definition rf24g.cpp:48
Note
The variable var will have a new value from the packet.
Returns
True if the size is within 30 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.
Examples
rf24g_receive.cpp, and rf24g_send.cpp.

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