Eddystone test using modified DAL

Dependencies:   BLE_API mbed-dev-bin nRF51822

Dependents:   microbit-eddystone

Fork of microbit-dal by Lancaster University

Embed: (wiki syntax)

« Back to documentation index

PacketBuffer Class Reference

PacketBuffer Class Reference

Class definition for a PacketBuffer. More...

#include <PacketBuffer.h>

Public Member Functions

uint8_t * getBytes ()
 Provide a pointer to a memory location containing the packet data.
 PacketBuffer ()
 Default Constructor.
 PacketBuffer (int length)
 Constructor.
 PacketBuffer (uint8_t *data, int length, int rssi=0)
 Constructor.
 PacketBuffer (const PacketBuffer &buffer)
 Copy Constructor.
void init (uint8_t *data, int length, int rssi)
 Internal constructor-initialiser.
 ~PacketBuffer ()
 Destructor.
PacketBufferoperator= (const PacketBuffer &p)
 Copy assign operation.
uint8_t operator[] (int i) const
 Array access operation (read).
uint8_t & operator[] (int i)
 Array access operation (modify).
bool operator== (const PacketBuffer &p)
 Equality operation.
int setByte (int position, uint8_t value)
 Sets the byte at the given index to value provided.
int getByte (int position)
 Determines the value of the given byte in the packet.
int length ()
 Gets number of bytes in this buffer.
int getRSSI ()
 Retrieves the received signal strength of this packet.
void setRSSI (uint8_t rssi)
 Sets the received signal strength of this packet.

Detailed Description

Class definition for a PacketBuffer.

A PacketBuffer holds a series of bytes that can be sent or received from the MicroBitRadio channel.

Note:
This is a mutable, managed type.

Definition at line 46 of file PacketBuffer.h.


Constructor & Destructor Documentation

PacketBuffer (  )

Default Constructor.

Creates an empty Packet Buffer.

Definition at line 41 of file PacketBuffer.cpp.

PacketBuffer ( int  length )

Constructor.

Creates a new PacketBuffer of the given size.

Parameters:
lengthThe length of the buffer to create.
 PacketBuffer p(16);         // Creates a PacketBuffer 16 bytes long.

Definition at line 56 of file PacketBuffer.cpp.

PacketBuffer ( uint8_t *  data,
int  length,
int  rssi = 0 
)

Constructor.

Creates an empty Packet Buffer of the given size, and fills it with the data provided.

Parameters:
dataThe data with which to fill the buffer.
lengthThe length of the buffer to create.
rssiThe radio signal strength at the time this packet was recieved. Defaults to 0.
 uint8_t buf = {13,5,2};
 PacketBuffer p(buf, 3);         // Creates a PacketBuffer 3 bytes long.

Definition at line 77 of file PacketBuffer.cpp.

PacketBuffer ( const PacketBuffer buffer )

Copy Constructor.

Add ourselves as a reference to an existing PacketBuffer.

Parameters:
bufferThe PacketBuffer to reference.
 PacketBuffer p();
 PacketBuffer p2(p); // Refers to the same packet as p.

Definition at line 93 of file PacketBuffer.cpp.

~PacketBuffer (  )

Destructor.

Removes buffer resources held by the instance.

Definition at line 129 of file PacketBuffer.cpp.


Member Function Documentation

int getByte ( int  position )

Determines the value of the given byte in the packet.

Parameters:
positionThe index of the byte to read.
Returns:
The value of the byte at the given position, or MICROBIT_INVALID_PARAMETER.
 PacketBuffer p1(16);
 p1.setByte(0,255);              // Sets the first byte in the buffer to the value 255.
 p1.getByte(0);                  // Returns 255.

Definition at line 267 of file PacketBuffer.cpp.

uint8_t * getBytes (  )

Provide a pointer to a memory location containing the packet data.

Returns:
The contents of this packet, as an array of bytes.

Definition at line 280 of file PacketBuffer.cpp.

int getRSSI (  )

Retrieves the received signal strength of this packet.

Returns:
The signal strength of the radio when this packet was received, in -dbM.
 PacketBuffer p1(16);
 p1.getRSSI();                 // Returns the received signal strength.

Definition at line 310 of file PacketBuffer.cpp.

void init ( uint8_t *  data,
int  length,
int  rssi 
)

Internal constructor-initialiser.

Parameters:
dataThe data with which to fill the buffer.
lengthThe length of the buffer to create.
rssiThe radio signal strength at the time this packet was recieved.

Definition at line 108 of file PacketBuffer.cpp.

int length (  )

Gets number of bytes in this buffer.

Returns:
The size of the buffer in bytes.
 PacketBuffer p1(16);
 p1.length(); // Returns 16.

Definition at line 295 of file PacketBuffer.cpp.

PacketBuffer & operator= ( const PacketBuffer p )

Copy assign operation.

Called when one PacketBuffer is assigned the value of another using the '=' operator.

Decrements our reference count and free up the buffer as necessary.

Then, update our buffer to refer to that of the supplied PacketBuffer, and increase its reference count.

Parameters:
pThe PacketBuffer to reference.
 uint8_t buf = {13,5,2};
 PacketBuffer p1(16);
 PacketBuffer p2(buf, 3);

 p1 = p2;

Definition at line 154 of file PacketBuffer.cpp.

bool operator== ( const PacketBuffer p )

Equality operation.

Called when one PacketBuffer is tested to be equal to another using the '==' operator.

Parameters:
pThe PacketBuffer to test ourselves against.
Returns:
true if this PacketBuffer is identical to the one supplied, false otherwise.
 MicroBitDisplay display;
 uint8_t buf = {13,5,2};
 PacketBuffer p1();
 PacketBuffer p2();

 if(p1 == p2)                    // will be true
     display.scroll("same!");

Definition at line 219 of file PacketBuffer.cpp.

uint8_t & operator[] ( int  i )

Array access operation (modify).

Called when a PacketBuffer is dereferenced with a [] operation.

Transparently map this through to the underlying payload for elegance of programming.

 PacketBuffer p1(16);
 p1[0] = 42;

Definition at line 195 of file PacketBuffer.cpp.

uint8_t operator[] ( int  i ) const

Array access operation (read).

Called when a PacketBuffer is dereferenced with a [] operation.

Transparently map this through to the underlying payload for elegance of programming.

 PacketBuffer p1(16);
 uint8_t data = p1[0];

Definition at line 178 of file PacketBuffer.cpp.

int setByte ( int  position,
uint8_t  value 
)

Sets the byte at the given index to value provided.

Parameters:
positionThe index of the byte to change.
valueThe new value of the byte (0-255).
Returns:
MICROBIT_OK, or MICROBIT_INVALID_PARAMETER.
 PacketBuffer p1(16);
 p1.setByte(0,255);              // Sets the first byte in the buffer to the value 255.

Definition at line 241 of file PacketBuffer.cpp.

void setRSSI ( uint8_t  rssi )

Sets the received signal strength of this packet.

 PacketBuffer p1(16);
 p1.setRSSI(37);

Definition at line 323 of file PacketBuffer.cpp.