This code was developed initially for the Autoware.Auto project. It is now available for ROS2 in the ros2_socketcan as ROS2 nodes. The purpose of this package is to make this C++ wrapper available as a stand-alone library.
CAN is the de-facto standard for communication between components on a vehicle.
As such, to send commands to the vehicle, a mechanism to send messages via CAN is required.
Similarly a mechanism to receive messages via CAN is required to receive data from the vehicle platform.
These classes are a thin wrapper around C functions to manage some extra book-keeping.
A typed interface for sending is also provided for compile-time checking of data sizes.
A helper class following the named parameter idiom is provided to wrap the CAN ID.
Sending and receiving are separate concerns and thus contained in separate classes.
Finally, care is taken to avoid exposing C/POSIX headers.
The concern for sender is only simple book-keeping and sending of data.
The same is true for the receiver.
Any complex error handling which would require receiving data is outside the concern of this class, and should be a part of a higher level class which contains an instance of this class.
See the [sender API docs](@ref socketcan::SocketCanSender). and the [receiver API docs](@ref socketcan::SocketCanReceiver).
These classes have no substantive logic.
Unix's select() function was used to wait for resource availability. On any error, an exception is thrown.
Both the receiver and the sender classes throw exceptions in the following cases:
- On construction if the specified interface is invalid or cannot be bound
- If the file descriptor is unavailable within the timeout period for sending
- Any other Unix error is raised during the sending process
Message-level error checking mechanisms a part of the CAN standard are outside the scope of this class.
This component exposes any security concerns that CAN might have.
API inspirations:
Implementation-specific references:
CAN-related references:
- AutoSAR/PCLint fixes around FDSET and select()