Autoware.Auto
socket_can

Purpose / Use cases

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.

Design

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.

Assumptions / Known limits

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.

Inputs / Outputs / API

See the sender API docs. and the receiver API docs.

Inner-workings / Algorithms

These classes have no substantive logic.

Unix's select() function was used to wait for resource availability. On any error, an exception is thrown.

Error detection and handling

Both the receiver and the sender classes throw exceptions in the following cases:

  1. On construction if the specified interface is invalid or cannot be bound
  2. If the file descriptor is unavailable within the timeout period for sending
  3. 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.

Security considerations

This component exposes any security concerns that CAN might have.

References / External links

API inspirations:

  1. python-can
  2. qtcanbus
  3. rust socketcan

Implementation-specific references:

  1. SocketCAN reference
  2. socket
  3. bind
  4. send
  5. ioctl
  6. close

CAN-related references:

  1. KVaser CAN Protocol Tour
  2. Kvaser Higher Level Protocols

Future extensions / Unimplemented parts

  • AutoSAR/PCLint fixes around FDSET and select()

Related issues

  • #223: Export internal implementation