50 using MsgHandler = std::function<void(
const CanMessage& data)>;
59 miosix::Priority threadPriority);
86 bool addFilter(uint8_t src, uint64_t dst);
101 bool enqueueEvent(uint8_t priority, uint8_t primaryType, uint8_t source,
102 uint8_t destination, uint8_t secondaryType);
110 uint8_t source, uint8_t destination,
111 uint8_t secondaryType, uint64_t payload);
121 template <
typename T>
122 bool enqueueData(uint8_t priority, uint8_t primaryType, uint8_t source,
123 uint8_t destination, uint8_t secondaryType,
const T& t);
160 static void rcvLauncher(
void* arg);
167 static void sndLauncher(
void* arg);
172 uint8_t byteForUint64(uint64_t number);
175 MsgHandler onReceive;
178 bool stopFlag =
false;
179 bool sndStarted =
false;
180 bool rcvStarted =
false;
182 miosix::Thread* sndThread =
nullptr;
183 miosix::Thread* rcvThread =
nullptr;
184 miosix::Priority threadPriority;
186 SyncCircularBuffer<CanMessage, 10> outQueue;
193 uint8_t source, uint8_t destination,
194 uint8_t secondaryType,
const T& t)
196 if (priority > 0xF || primaryType > 0x3F || source > 0xF ||
197 destination > 0xF || secondaryType > 0xF)
Canbus protocol implementation.
CanProtocol(CanbusDriver *can, MsgHandler onReceive, miosix::Priority threadPriority)
Construct a new CanProtocol object.
bool enqueueMsg(const CanMessage &msg)
Non-blocking send function, puts the messages in a queue. Message is discarded if the queue is full.
bool start()
Start the receiving and sending threads.
bool enqueueData(uint8_t priority, uint8_t primaryType, uint8_t source, uint8_t destination, uint8_t secondaryType, const T &t)
Non-blocking send function for a generic data type.
bool isStarted()
Tells whether the driver was started.
bool enqueueSimplePacket(uint8_t priority, uint8_t primaryType, uint8_t source, uint8_t destination, uint8_t secondaryType, uint64_t payload)
Non-blocking send function for a simple packet with a payload of 1 can packet, useful to send generic...
bool addFilter(uint8_t src, uint64_t dst)
Adds a filter to the can peripheral to receive only messages from the given source and targeted to th...
void stop()
Stops sender and receiver threads.
bool enqueueEvent(uint8_t priority, uint8_t primaryType, uint8_t source, uint8_t destination, uint8_t secondaryType)
Non-blocking send function for an event (a message without payload).
Low level CanBus driver, with support for both peripherals (CAN1 and CAN2) on stm32f4 microcontroller...
static PrintLogger getLogger(const string &name)
This file includes all the types the logdecoder script will decode.
Canbus::CanMessage toCanMessage(const PitotData &data)
Generic struct that contains a can protocol message.