ark::canbus::SocketCanDevice
Defined in header “ark/canbus/socket_can_device.hh”.
A class that allows interacting with CAN devices (on Linux) via the socketcan interface. This abstracts away some of the C-level socket (and netlink) details.
Methods
-
SocketCanDevice()
Constructor. Initializes a SocketCAN device. -
~SocketCanDevice()
Destructor. Closes the CAN device. -
native_handle_type native_handle()
Returns the underlying native handle for this object. -
void bind(const std::string & device_name)
Binds to the given CAN device; throws if there is a problem doing so. -
void set_nonblocking(bool value)
Sets if this socket is non-blocking or not. -
void enable_canfd_frames(bool enabled)
Sets if this socket supports CANFD frames or not. Enabling this means that you may get back CAN data that is larger than 8 bytes. -
std::optional< CanPacket > read()
Reads a single CAN packet off the bus. -
bool read(CanPacket & packet)
Reads a single CAN packet off this bus. Returns true if a packet was read, or false otherwise. -
bool read(CanPacket & packet, std::chrono::system_clock::time_point & receive_time)
Reads a CAN packet off the bus, and then retrieves the kernel timestamp that the CAN packet was received. Otherwise, equivalent to read(). -
bool write(const CanPacket & packet)
Writes a CAN packet onto this bus. Returns true if a packet was written, or false if the underlying buffer is full and a packet could not be written out. Throws on any other error. -
SocketCanLinkStatus link_status()
Returns the link status of this CAN device.