SAE Teensy ECU
IIT SAE Microcontroller programming
Loading...
Searching...
No Matches
CAN::Buffer Struct Reference

An incoming canbus message, allows the message data to be interpreted through a simple wrapper class. More...

#include <CanBuffer.h>

Public Member Functions

 Buffer (volatile uint8_t *buffer, bool outgoing=false)
 Construct a new Buffer as a wrapper.
 
 Buffer (const uint32_t address, volatile uint8_t *buffer, bool outgoing=false)
 Construct a new internal Buffer.
 
void init ()
 Initialize a buffer if not done so already by constructor.
 
void dump (uint8_t *dest)
 Dump the current buffer onto an external one.
 
void set (const uint8_t *src)
 Replace the current buffer.
 
void clear (void)
 Clear the buffer.
 
void Buffer::setDouble (double val)
 
void Buffer::setULong (uint64_t val)
 
void Buffer::setLong (int64_t val)
 
void Buffer::setFloat (float val, size_t pos)
 
void Buffer::setUInt (uint32_t val, size_t pos)
 
void Buffer::setInt (int32_t val, size_t pos)
 
void Buffer::setUShort (uint16_t val, size_t pos)
 
void Buffer::setShort (int16_t val, size_t pos)
 
void Buffer::setUByte (uint8_t val, size_t pos)
 
void Buffer::setByte (int8_t val, size_t pos)
 
void Buffer::setBit (bool val, size_t pos)
 
double Buffer::getDouble ()
 
float Buffer::getFloat (size_t pos)
 
uint64_t getULong ()
 Interpret the buffer as an unsigned long.
 
int64_t getLong ()
 Interpret the buffer as a long.
 
uint32_t getUInt (size_t pos)
 Interpret the buffer as an unsigned Integer at byte position pos
 
int32_t getInt (size_t pos)
 Interpret the buffer as an Integer at byte position pos
 
uint16_t getUShort (size_t pos)
 Interpret the buffer as an unsigned Short at byte position pos
 
int16_t getShort (size_t pos)
 Interpret the buffer as an Short at byte position pos
 
uint8_t getUByte (size_t pos)
 Interpret the buffer as an unsigned Byte at byte position pos
 
int8_t getByte (size_t pos)
 Interpret the buffer as a Byte at byte position pos
 
bool getBit (size_t pos)
 Get the bit at position pos of this buffer.
 
bool lock ()
 Locks this buffer to be used, returns false if it was unable todo so.
 
void lock_wait ()
 locks this buffer to be used, waits indefinitely for it to unlock if it is locked
 
void unlock ()
 Unlocks this buffer if it is locked.
 

Public Attributes

const uint32_t address
 Address this buffer represents.
 
volatile uint8_tbuffer
 The buffer.
 
volatile canCallback callback
 Optional callback function associated with this buffer.
 
const bool outgoing
 Whether this buffer is meant to be an outgoing message.
 
bool modified = false
 Whether this buffer has been set in anyway.
 

Detailed Description

An incoming canbus message, allows the message data to be interpreted through a simple wrapper class.

Note
Buffers are persistent, when a message is received it stays in the buffer unless cleared

Definition at line 23 of file CanBuffer.h.

Constructor & Destructor Documentation

◆ Buffer() [1/2]

CAN::Buffer::Buffer ( volatile uint8_t buffer,
bool  outgoing = false 
)
inline

Construct a new Buffer as a wrapper.

Parameters
bufferthe array to wrap around

Definition at line 57 of file CanBuffer.h.

◆ Buffer() [2/2]

CAN::Buffer::Buffer ( const uint32_t  address,
volatile uint8_t buffer,
bool  outgoing = false 
)
inline

Construct a new internal Buffer.

Parameters
addressthe address this buffer should represent
bufferbeginning of the array of 8 byte buffers to select from

Definition at line 64 of file CanBuffer.h.

Member Function Documentation

◆ clear()

void CAN::Buffer::clear ( void  )

Clear the buffer.

Warning
Must externally lock the buffer to ensure atomic operation

Definition at line 109 of file CanBuffer.cpp.

◆ dump()

void CAN::Buffer::dump ( uint8_t dest)

Dump the current buffer onto an external one.

Warning
Must externally lock the buffer to ensure atomic operation
Parameters
destthe array to dump to

Definition at line 87 of file CanBuffer.cpp.

◆ getBit()

bool CAN::Buffer::getBit ( size_t  pos)

Get the bit at position pos of this buffer.

Parameters
posthe bit to check on the buffer
Returns
bit as boolean

Definition at line 84 of file CanBuffer.cpp.

◆ getByte()

int8_t CAN::Buffer::getByte ( size_t  pos)

Interpret the buffer as a Byte at byte position pos

Parameters
posthe byte to start interpreting at
Returns
int8_t The interpreted value

Definition at line 81 of file CanBuffer.cpp.

◆ getInt()

int32_t CAN::Buffer::getInt ( size_t  pos)

Interpret the buffer as an Integer at byte position pos

Parameters
posthe byte to start interpreting at
Returns
int32_t The interpreted value

Definition at line 69 of file CanBuffer.cpp.

◆ getLong()

int64_t CAN::Buffer::getLong ( )

Interpret the buffer as a long.

Parameters
posthe byte to start interpreting at
Returns
int64_t The interpreted value

Definition at line 60 of file CanBuffer.cpp.

◆ getShort()

int16_t CAN::Buffer::getShort ( size_t  pos)

Interpret the buffer as an Short at byte position pos

Parameters
posthe byte to start interpreting at
Returns
int16_t The interpreted value

Definition at line 75 of file CanBuffer.cpp.

◆ getUByte()

uint8_t CAN::Buffer::getUByte ( size_t  pos)

Interpret the buffer as an unsigned Byte at byte position pos

Parameters
posthe byte to start interpreting at
Returns
uint8_t The interpreted value

Definition at line 78 of file CanBuffer.cpp.

◆ getUInt()

uint32_t CAN::Buffer::getUInt ( size_t  pos)

Interpret the buffer as an unsigned Integer at byte position pos

Parameters
posthe byte to start interpreting at
Returns
uint32_t The interpreted value

Definition at line 66 of file CanBuffer.cpp.

◆ getULong()

uint64_t CAN::Buffer::getULong ( )

Interpret the buffer as an unsigned long.

Parameters
posthe byte to start interpreting at
Returns
uint64_t The interpreted value

Definition at line 57 of file CanBuffer.cpp.

◆ getUShort()

uint16_t CAN::Buffer::getUShort ( size_t  pos)

Interpret the buffer as an unsigned Short at byte position pos

Parameters
posthe byte to start interpreting at
Returns
uint16_t The interpreted value

Definition at line 72 of file CanBuffer.cpp.

◆ lock()

bool CAN::Buffer::lock ( )

Locks this buffer to be used, returns false if it was unable todo so.

Returns
true Locked
false Unable to lock, in use

Definition at line 120 of file CanBuffer.cpp.

◆ lock_wait()

void CAN::Buffer::lock_wait ( )

locks this buffer to be used, waits indefinitely for it to unlock if it is locked

Definition at line 124 of file CanBuffer.cpp.

◆ set()

void CAN::Buffer::set ( const uint8_t *  src)

Replace the current buffer.

Warning
Must externally lock the buffer to ensure atomic operation
Parameters
srcthe array to be used

Definition at line 98 of file CanBuffer.cpp.

◆ unlock()

void CAN::Buffer::unlock ( )

Unlocks this buffer if it is locked.

Definition at line 128 of file CanBuffer.cpp.

Member Data Documentation

◆ address

const uint32_t CAN::Buffer::address

Address this buffer represents.

Definition at line 27 of file CanBuffer.h.

◆ buffer

volatile uint8_t* CAN::Buffer::buffer

The buffer.

Warning
Not recommended to access directly

Definition at line 34 of file CanBuffer.h.

◆ callback

volatile canCallback CAN::Buffer::callback

Optional callback function associated with this buffer.

Definition at line 39 of file CanBuffer.h.

◆ modified

bool CAN::Buffer::modified = false

Whether this buffer has been set in anyway.

Note
Must be manually reset

Definition at line 50 of file CanBuffer.h.

◆ outgoing

const bool CAN::Buffer::outgoing

Whether this buffer is meant to be an outgoing message.

Definition at line 44 of file CanBuffer.h.


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