aPacket.h¶
- group aPacket
BrainStem Packet.
aPacket.h Provides and interface for creating and destroying BrainStem Protocol packets.
-
const uint16_t VALIDPACKET¶
Const value used to check packet validity.
-
struct aPacket¶
Struct for BrainStem packets.
the check member is for checking the validity of the packet structure in memory. Current size is used during link stream processing. Address, dataSize and data fulfill the requirements of the BrainStem protocol.
-
bool aVALIDPACKET(const aPacket *packet)¶
Check packet pointer for validity.
Checks to make sure a packet was allocated using aPacket_Create.
- Parameters:
packet – - valid packet pointer.
- Returns:
bool - True for valid false otherwise.
aPacket Functions¶
-
aPacket *aPacket_Create(void)¶
Create a BrainStem packet.
Create a BrainStem packet.
- Returns:
aPacket - Pointer or NULL on error.
-
aPacket *aPacket_CreateWithData(const uint8_t address, const uint8_t dataLength, const uint8_t *data)¶
Create a BrainStem packet, containing the given data.
Create a BrainStem packet with data.
- Parameters:
address – - Module address of the BrainStem module.
dataLength – - The length of the data array.
data – - Pointer to the beginning of the packet data.
- Returns:
aPacket - Pointer or NULL on error.
-
aErr aPacket_Reset(aPacket *packet)¶
Reset an existing packet.
Zero out any data the packet contains.
- Return values:
aErrNone – - If the reset was successful.
aErrParam – - If the packet is not valid.
- Returns:
Function returns aErr values.
-
aErr aPacket_AddByte(aPacket *packet, const uint8_t byte)¶
Accumulate a Byte into a packet.
A packet can be constructed byte by byte. the first byte added will be the BrainStem module address, the second byte the data length, and subsequent bytes will be data payload. This call will fail if more than datalength bytes are added, or if address is an invalid module address (i.e. an odd number).
- Return values:
aErrNone – - Adding the byte was successful.
aErrParam – - The packet was invalid.
aErrPacket – - The byte added violates the BrainStem protocol.
- Returns:
Function returns aErr values.
-
bool aPacket_IsComplete(const aPacket *packet)¶
Determine whether a packet is complete.
A packet can be constructed byte by byte. This call determines whether such a packet has been completed. It checks that dataSize is equal to the currentSize minus the Address and dataSize bytes.
- Returns:
bool - True if complete false if not complete.
-
aErr aPacket_Destroy(aPacket **packet)¶
Destroy a BrainStem packet.
Safely destroy a brainstem packet and deallocate the associated resources.
- Parameters:
packet – - A pointer to a pointer of a valid packet. The packet pointer will be set to NULL on successful destruction of the packet.
- Return values:
aErrNone – - The packet was successfully destoryed.
aErrParam – - The packetRef is invalid.
- Returns:
Function returns aErr values.