Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
CanPipe Class Reference
A stack on top of mbed CAN class to handle complex filtered callbacks. More...
#include <CanPipe.h>
Public Types | |
| enum | CanPipeResult |
Enumeration for method return values. More... | |
| enum | FilterMode |
Enumeration for how filters should be handled. More... | |
Public Member Functions | |
| CanPipe (CAN *p_can, FilterMode filter_mode=kFilterAuto) | |
| Creates message handler linked with the CAN device. | |
| int | RegisterFilter (unsigned int id, unsigned int mask, CANFormat format=CANAny, int handle=0) |
| Assigns a filter to apply to CAN messages. | |
| int | RegisterCallback (CanMessageCallback callback, int handle) |
| Assigns a callback to apply to CAN messages associated with a given filter. | |
| void | PostMessage (CANMessage msg) |
| Stage a message to be written to the bus. | |
| int | HandleMessages () |
| Passes all received messages through the software-filters, if any, and writes any messages that have been posted. | |
Detailed Description
A stack on top of mbed CAN class to handle complex filtered callbacks.
Definition at line 15 of file CanPipe.h.
Member Enumeration Documentation
| enum CanPipeResult |
| enum FilterMode |
Constructor & Destructor Documentation
| CanPipe | ( | CAN * | p_can, |
| FilterMode | filter_mode = kFilterAuto |
||
| ) |
Creates message handler linked with the CAN device.
- Parameters:
-
p_can reference to CAN device filter_mode hardware or software filtering only (Optional)
Example:
#include "mbed.h" #include "CanPipe.h" Ticker ticker; DigitalOut led1(LED1); CAN m_can(P0_11, P0_31); CanPipe m_can_pipe(&m_can); char counter = 0; void send() { led1 = !led1; m_can_pipe.PostMessage(CANMessage(1337, &counter, 1)); } int callback1(CANMessage &msg) { return CanPipe::kOkay; } int callback2(CANMessage &msg) { return CanPipe::kOkay; } int callback3(CANMessage &msg) { return CanPipe::kOkay; } int main() { int handle; handle = m_can_pipe.RegisterFilter(0x200, 0x780); m_can_pipe.RegisterCallback(callback1, handle); handle = m_can_pipe.RegisterFilter(0x281, 0); m_can_pipe.RegisterCallback(callback2, handle); m_can_pipe.RegisterCallback(callback3, handle); ticker.attach(send, 1); while (1) { __WFI(); //sleep(); m_can_pipe.HandleMessages(); } }
Definition at line 4 of file CanPipe.cpp.
Member Function Documentation
| int HandleMessages | ( | void | ) |
Passes all received messages through the software-filters, if any, and writes any messages that have been posted.
- Returns:
- Boolean 1 if a message was handled (post or receive). 0 otherwise.
Definition at line 89 of file CanPipe.cpp.
| void PostMessage | ( | CANMessage | msg ) |
Stage a message to be written to the bus.
- Parameters:
-
msg message to write
Definition at line 85 of file CanPipe.cpp.
| int RegisterCallback | ( | CanMessageCallback | callback, |
| int | handle | ||
| ) |
Assigns a callback to apply to CAN messages associated with a given filter.
- Parameters:
-
callback 29 bit identifier to base filter on handle Filter handle to associate with this callback (Optional)
Member functions can be added using the right callback Constructor
canopen_class.RegisterCallback(
CanMessageCallback(&object_instance, &ObjectClass::HandleMessage),
handle);
Definition at line 53 of file CanPipe.cpp.
| int RegisterFilter | ( | unsigned int | id, |
| unsigned int | mask, | ||
| CANFormat | format = CANAny, |
||
| int | handle = 0 |
||
| ) |
Assigns a filter to apply to CAN messages.
- Parameters:
-
id 29 bit identifier to base filter on mask Bit mask applied to the id format CAN message format (Default CANAny) handle Number to associate with message when passing this filter (Optional)
Can create software filters if device fails to create filters in hardware
Definition at line 12 of file CanPipe.cpp.
Generated on Tue Jul 12 2022 15:05:39 by
1.7.2