VitroIO SDK
Software development kit for Vitro Shard.
|
Class is a wrapper for mbed::CAN class and provides interface for CanbusFrame type. More...
#include <canbus.h>
Public Types | |
typedef Callback< void(const CanbusFrame &)> | OnFrameReceivedCallback |
Type defines signature of callback function which is to be called when a new frame will be received. More... | |
Public Member Functions | |
Canbus (PinName rd, PinName td, EventQueue *targetQueue, uint32_t eventQueueSize=VITROIO_CANBUS_DEFAULT_EVENT_QUEUE_SIZE, int hz=VITROIO_CANBUS_DEFAULT_FREQUENCY) | |
Constructor initializes CAN bus and chains an internal event queue to the targetQueue . More... | |
Canbus (PinName rd, PinName td, osPriority priority=osPriorityNormal, uint32_t eventQueueSize=VITROIO_CANBUS_DEFAULT_EVENT_QUEUE_SIZE, int hz=VITROIO_CANBUS_DEFAULT_FREQUENCY) | |
Constructor initializes CAN bus and creates internal event loop using thread with priority priority . More... | |
~Canbus () | |
Destructor. More... | |
bool | isValid () const |
Function allows to check whether the bus is in valid state. More... | |
int | sendFrame (const CanbusFrame &frame) |
Functions sends frame over the bus. More... | |
int | setOnFrameReceivedCallback (OnFrameReceivedCallback callback, int handle=-1) |
Function allows to set callbacks which are to be called any time the frame received. More... | |
Class is a wrapper for mbed::CAN class and provides interface for CanbusFrame type.
Read of incoming frames is possible only by callbacks because of thread safety - the frames are read using RX IRQ.
The class uses an event queue for reading incoming frames. The event queue can be managed by external queue specified by user or by internal queue with thread of specified priority.
typedef Callback<void(const CanbusFrame&)> vitroio::sdk::Canbus::OnFrameReceivedCallback |
Type defines signature of callback function which is to be called when a new frame will be received.
|
explicit |
Constructor initializes CAN bus and chains an internal event queue to the targetQueue
.
There is not guarantee that the object is in valid state. User should call isValid() method to determine if the object was initialized successfully. When the object is in invalid state, the behaviour is undefined.
The contructor uses mbed::EventQueue::chain method for connection to targetQueue
.
targetQueue
must be run before usage of this class (construction of the object can be done earlier).rd | RD pin of the CAN interface |
td | TD pin of the CAN interface |
targetQueue | External event queue to which the internal queue is to be chained |
eventQueueSize | Size of internal event queue |
hz | Transmission frequency in hertz |
|
explicit |
Constructor initializes CAN bus and creates internal event loop using thread with priority priority
.
There is not guarantee that the object is in valid state. User should call isValid() method to determine if the object was initialized successfully. When the object is in invalid state, the behaviour is undefined.
rd | RD pin of the CAN interface |
td | TD pin of the CAN interface |
priority | Priority of thread for handling internal event queue |
eventQueueSize | Size of internal event queue |
hz | Transmission frequency in hertz |
vitroio::sdk::Canbus::~Canbus | ( | ) |
Destructor.
bool vitroio::sdk::Canbus::isValid | ( | ) | const |
Function allows to check whether the bus is in valid state.
int vitroio::sdk::Canbus::sendFrame | ( | const CanbusFrame & | frame | ) |
Functions sends frame over the bus.
frame | Frame to send |
int vitroio::sdk::Canbus::setOnFrameReceivedCallback | ( | OnFrameReceivedCallback | callback, |
int | handle = -1 |
||
) |
Function allows to set callbacks which are to be called any time the frame received.
Maximum number of callbacks that can be set is 4. The callback can be unset by passing OnFrameReceivedCallback(NULL) as callback
and providing handle
returned by this method.
handle | Handle of callback returned by this function - it should be used when the specified callback is to be changed |