Class SocketCanSender

Class Documentation

class SocketCanSender

Simple RAII wrapper around a raw CAN sender.

Public Functions

explicit SocketCanSender(const std::string &interface = "can0", const bool enable_fd = false, const CanId &default_id = CanId{})

Constructor.

~SocketCanSender() noexcept

Destructor.

void send(const void *const data, const std::size_t length, const std::chrono::nanoseconds timeout = std::chrono::nanoseconds::zero()) const

Send raw data with the default id

Parameters:
  • data[in] A pointer to the beginning of the data to send

  • timeout[in] Maximum duration to wait for file descriptor to be free for write. Negative durations are treated the same as zero timeout

  • length[in] The amount of data to send starting from the data pointer

Throws:
  • std::domain_error – If length is > 8

  • SocketCanTimeout – On timeout

  • std::runtime_error – on other errors

void send(const void *const data, const std::size_t length, const CanId id, const std::chrono::nanoseconds timeout = std::chrono::nanoseconds::zero()) const

Send raw data with an explicit CAN id

Parameters:
  • data[in] A pointer to the beginning of the data to send

  • timeout[in] Maximum duration to wait for file descriptor to be free for write. Negative durations are treated the same as zero timeout

  • id[in] The id field for the CAN frame

  • length[in] The amount of data to send starting from the data pointer

Throws:
  • std::domain_error – If length is > 8

  • SocketCanTimeout – On timeout

  • std::runtime_error – on other errors

template<typename T, typename = std::enable_if_t<!std::is_pointer<T>::value>>
inline void send(const T &data, const std::chrono::nanoseconds timeout = std::chrono::nanoseconds::zero()) const

Send typed data with the default id

Template Parameters:

Type – of data to send, must be 8 bytes or smaller

Parameters:
  • data[in] The data to send

  • timeout[in] Maximum duration to wait for file descriptor to be free for write. Negative durations are treated the same as zero timeout

Throws:
template<typename T, typename = std::enable_if_t<!std::is_pointer<T>::value>>
inline void send(const T &data, const CanId id, const std::chrono::nanoseconds timeout = std::chrono::nanoseconds::zero()) const

Send typed data with an explicit CAN Id

Template Parameters:

Type – of data to send, must be 8 bytes or smaller

Parameters:
  • data[in] The data to send

  • timeout[in] Maximum duration to wait for file descriptor to be free for write. Negative durations are treated the same as zero timeout

  • id[in] The id field for the CAN frame

Throws:
void send_fd(const void *const data, const std::size_t length, const std::chrono::nanoseconds timeout = std::chrono::nanoseconds::zero()) const

Send raw data with the default id

Parameters:
  • data[in] A pointer to the beginning of the data to send

  • timeout[in] Maximum duration to wait for file descriptor to be free for write. Negative durations are treated the same as zero timeout

  • length[in] The amount of data to send starting from the data pointer

Throws:
  • std::domain_error – If length is > 64

  • SocketCanTimeout – On timeout

  • std::runtime_error – on other errors

void send_fd(const void *const data, const std::size_t length, const CanId id, const std::chrono::nanoseconds timeout = std::chrono::nanoseconds::zero()) const

Send raw data with an explicit CAN id

Parameters:
  • data[in] A pointer to the beginning of the data to send

  • timeout[in] Maximum duration to wait for file descriptor to be free for write. Negative durations are treated the same as zero timeout

  • id[in] The id field for the CAN frame

  • length[in] The amount of data to send starting from the data pointer

Throws:
  • std::domain_error – If length is > 64

  • SocketCanTimeout – On timeout

  • std::runtime_error – on other errors

template<typename T, typename = std::enable_if_t<!std::is_pointer<T>::value>>
inline void send_fd(const T &data, const std::chrono::nanoseconds timeout = std::chrono::nanoseconds::zero()) const

Send typed data with the default id

Template Parameters:

Type – of data to send, must be 8 bytes or smaller

Parameters:
  • data[in] The data to send

  • timeout[in] Maximum duration to wait for file descriptor to be free for write. Negative durations are treated the same as zero timeout

Throws:
template<typename T, typename = std::enable_if_t<!std::is_pointer<T>::value>>
inline void send_fd(const T &data, const CanId id, const std::chrono::nanoseconds timeout = std::chrono::nanoseconds::zero()) const

Send typed data with an explicit CAN Id

Template Parameters:

Type – of data to send, must be 8 bytes or smaller

Parameters:
  • data[in] The data to send

  • timeout[in] Maximum duration to wait for file descriptor to be free for write. Negative durations are treated the same as zero timeout

  • id[in] The id field for the CAN frame

Throws:
CanId default_id() const noexcept

Get the default CAN id.