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.
Dependents: UAVCAN UAVCAN_Subscriber
SocketCanDriver Class Reference
Multiplexing container for multiple SocketCAN sockets. More...
#include <socketcan.hpp>
Inherits uavcan::ICanDriver.
Public Member Functions | |
| SocketCanDriver (const SystemClock &clock) | |
| Reference to the clock object shall remain valid. | |
| std::int16_t | select (uavcan::CanSelectMasks &inout_masks, const uavcan::CanFrame *(&)[uavcan::MaxCanIfaces], uavcan::MonotonicTime blocking_deadline) override |
| This function may return before deadline expiration even if no requested IO operations become possible. | |
| std::uint8_t | getNumIfaces () const override |
| Total number of available CAN interfaces. | |
| int | addIface (const std::string &iface_name) |
| Adds one iface by name. | |
| bool | isIfaceDown (std::uint8_t iface_index) const |
| Returns false if the specified interface is functioning, true if it became unavailable. | |
| virtual ICanIface * | getIface (uint8_t iface_index)=0 |
| Returns an interface by index, or null pointer if the index is out of range. | |
| virtual const ICanIface * | getIface (uint8_t iface_index) const |
| Default implementation of this method calls the non-const overload of getIface(). | |
| virtual int16_t | select (CanSelectMasks &inout_masks, const CanFrame *(&pending_tx)[MaxCanIfaces], MonotonicTime blocking_deadline)=0 |
| Block until the deadline, or one of the specified interfaces becomes available for read or write. | |
Detailed Description
Multiplexing container for multiple SocketCAN sockets.
Uses ppoll() for multiplexing.
When an interface becomes down/disconnected while the node is running, the driver will silently exclude it from the IO loop and continue to run on the remaining interfaces. When all interfaces become down/disconnected, the driver will throw AllIfacesDownException from SocketCanDriver::select(). Whether a certain interface is down can be checked with SocketCanDriver::isIfaceDown().
Definition at line 618 of file socketcan.hpp.
Constructor & Destructor Documentation
| SocketCanDriver | ( | const SystemClock & | clock ) | [explicit] |
Reference to the clock object shall remain valid.
Definition at line 652 of file socketcan.hpp.
Member Function Documentation
| int addIface | ( | const std::string & | iface_name ) |
Adds one iface by name.
Will fail if there are MaxIfaces ifaces registered already.
- Parameters:
-
iface_name E.g. "can0", "vcan1"
- Returns:
- Negative on error, interface index on success.
- Exceptions:
-
uavcan_linux::Exception.
Definition at line 765 of file socketcan.hpp.
| virtual const ICanIface* getIface | ( | uint8_t | iface_index ) | const [virtual, inherited] |
Default implementation of this method calls the non-const overload of getIface().
Can be overriden by the application if necessary.
Definition at line 211 of file include/uavcan/driver/can.hpp.
| virtual ICanIface* getIface | ( | uint8_t | iface_index ) | [pure virtual, inherited] |
| std::uint8_t getNumIfaces | ( | ) | const [override, virtual] |
Total number of available CAN interfaces.
This value shall not change after initialization.
Implements ICanDriver.
Definition at line 757 of file socketcan.hpp.
| bool isIfaceDown | ( | std::uint8_t | iface_index ) | const |
Returns false if the specified interface is functioning, true if it became unavailable.
Definition at line 798 of file socketcan.hpp.
| virtual int16_t select | ( | CanSelectMasks & | inout_masks, |
| const CanFrame *(&) | pending_tx[MaxCanIfaces], | ||
| MonotonicTime | blocking_deadline | ||
| ) | [pure virtual, inherited] |
Block until the deadline, or one of the specified interfaces becomes available for read or write.
Iface masks will be modified by the driver to indicate which exactly interfaces are available for IO.
Bit position in the masks defines interface index.
Note that it is allowed to return from this method even if no requested events actually happened, or if there are events that were not requested by the library.
The pending TX argument contains an array of pointers to CAN frames that the library wants to transmit next, per interface. This is intended to allow the driver to properly prioritize transmissions; many drivers will not need to use it. If a write flag for the given interface is set to one in the select mask structure, then the corresponding pointer is guaranteed to be valid (not UAVCAN_NULLPTR).
- Parameters:
-
[in,out] inout_masks Masks indicating which interfaces are needed/available for IO. [in] pending_tx Array of frames, per interface, that are likely to be transmitted next. [in] blocking_deadline Zero means non-blocking operation.
- Returns:
- Positive number of ready interfaces or negative error code.
| std::int16_t select | ( | uavcan::CanSelectMasks & | inout_masks, |
| const uavcan::CanFrame * | (&)[uavcan::MaxCanIfaces], | ||
| uavcan::MonotonicTime | blocking_deadline | ||
| ) | [override] |
This function may return before deadline expiration even if no requested IO operations become possible.
This behavior makes implementation way simpler, and it is OK since libuavcan can properly handle such early returns. Also it can return more events than were originally requested by uavcan, which is also acceptable.
Definition at line 664 of file socketcan.hpp.
Generated on Tue Jul 12 2022 17:17:38 by
1.7.2