VitroIO SDK
Software development kit for Vitro Shard.
Loading...
Searching...
No Matches
canbus.h
Go to the documentation of this file.
1#ifndef VITROIO_SDK_CANBUS_H
2#define VITROIO_SDK_CANBUS_H
3
4#include <mbed.h>
5
7
9
10namespace vitroio
11{
12
13namespace sdk
14{
15
27#define VITROIO_CANBUS_DEFAULT_FREQUENCY 500000
28
35#define VITROIO_CANBUS_DEFAULT_EVENT_QUEUE_SIZE 32
36
49class Canbus : private NonCopyable<Canbus>
50{
51public:
56 typedef Callback<void(const CanbusFrame&)> OnFrameReceivedCallback;
57
83 explicit Canbus(
84 PinName rd, PinName td,
85 EventQueue* targetQueue,
86 uint32_t eventQueueSize = VITROIO_CANBUS_DEFAULT_EVENT_QUEUE_SIZE,
88
105 explicit Canbus(
106 PinName rd, PinName td,
107 osPriority priority = osPriorityNormal,
108 uint32_t eventQueueSize = VITROIO_CANBUS_DEFAULT_EVENT_QUEUE_SIZE,
110
115
123 bool isValid() const;
124
133 int sendFrame(const CanbusFrame& frame);
134
154
155private:
156 static const uint32_t onFramesReceivedCallbacksCnt_ = 4;
157
158 bool valid_;
159
160 impl::_CAN can_;
161 EventQueue evQueue_;
162 Thread* evQueueThread_;
163 OnFrameReceivedCallback onFrameReceivedUserCallbacks_[onFramesReceivedCallbacksCnt_];
164
165 void rxIrqHandler();
166 void onFrameReceivedCallback(CanbusFrame frame);
167};
168
173} // namespace sdk
174
175} // namespace vitroio
176
177#endif // VITROIO_SDK_CANBUS_H
Class is a wrapper for mbed::CANMessage. It provides interface allowing creation of frames complied w...
Definition: canbus_frame.h:24
Class is a wrapper for mbed::CAN class and provides interface for CanbusFrame type.
Definition: canbus.h:50
bool isValid() const
Function allows to check whether the bus is in valid state.
~Canbus()
Destructor.
int setOnFrameReceivedCallback(OnFrameReceivedCallback callback, int handle=-1)
Function allows to set callbacks which are to be called any time the frame received.
Callback< void(const CanbusFrame &)> OnFrameReceivedCallback
Type defines signature of callback function which is to be called when a new frame will be received.
Definition: canbus.h:56
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.
int sendFrame(const CanbusFrame &frame)
Functions sends frame over the bus.
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.
The _CAN class is a simple extension of mbed::CAN class.
Definition: _CAN.h:37
#define VITROIO_CANBUS_DEFAULT_FREQUENCY
Defines default communication frequency for Canbus .
Definition: canbus.h:27
#define VITROIO_CANBUS_DEFAULT_EVENT_QUEUE_SIZE
Defines default size of internal event queue for Canbus .
Definition: canbus.h:35
The namespace contains all of components of vitro-shard-sdk and components based on the sdk....
Definition: can_layer.h:9