Autoware.Auto
autoware::drivers::socketcan::SocketCanSender Class Reference

Simple RAII wrapper around a raw CAN sender. More...

#include <socket_can_sender.hpp>

Public Member Functions

 SocketCanSender (const std::string &interface="can0", const CanId &default_id=CanId{})
 Constructor. More...
 
 ~SocketCanSender () noexcept
 Destructor. More...
 
void send (const void *const data, const std::size_t length, const std::chrono::nanoseconds timeout=std::chrono::nanoseconds::zero()) const
 
void send (const void *const data, const std::size_t length, const CanId id, const std::chrono::nanoseconds timeout=std::chrono::nanoseconds::zero()) const
 
template<typename T , typename = std::enable_if_t<!std::is_pointer<T>::value>>
void send (const T &data, const std::chrono::nanoseconds timeout=std::chrono::nanoseconds::zero()) const
 
template<typename T , typename = std::enable_if_t<!std::is_pointer<T>::value>>
void send (const T &data, const CanId id, const std::chrono::nanoseconds timeout=std::chrono::nanoseconds::zero()) const
 
CanId default_id () const noexcept
 Get the default CAN id. More...
 

Detailed Description

Simple RAII wrapper around a raw CAN sender.

Constructor & Destructor Documentation

◆ SocketCanSender()

autoware::drivers::socketcan::SocketCanSender::SocketCanSender ( const std::string &  interface = "can0",
const CanId default_id = CanId{} 
)
explicit

Constructor.

◆ ~SocketCanSender()

autoware::drivers::socketcan::SocketCanSender::~SocketCanSender ( )
noexcept

Destructor.

Member Function Documentation

◆ default_id()

CanId autoware::drivers::socketcan::SocketCanSender::default_id ( ) const
noexcept

Get the default CAN id.

◆ send() [1/4]

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

Send typed data with an explicit CAN Id

Template Parameters
Typeof data to send, must be 8 bytes or smaller
Parameters
[in]dataThe data to send
[in]timeoutMaximum duration to wait for file descriptor to be free for write. Negative durations are treated the same as zero timeout
[in]idThe id field for the CAN frame
Exceptions
SocketCanTimeoutOn timeout
std::runtime_erroron other errors

◆ send() [2/4]

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

Send typed data with the default id

Template Parameters
Typeof data to send, must be 8 bytes or smaller
Parameters
[in]dataThe data to send
[in]timeoutMaximum duration to wait for file descriptor to be free for write. Negative durations are treated the same as zero timeout
Exceptions
SocketCanTimeoutOn timeout
std::runtime_erroron other errors

◆ send() [3/4]

void autoware::drivers::socketcan::SocketCanSender::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
[in]dataA pointer to the beginning of the data to send
[in]timeoutMaximum duration to wait for file descriptor to be free for write. Negative durations are treated the same as zero timeout
[in]idThe id field for the CAN frame
[in]lengthThe amount of data to send starting from the data pointer
Exceptions
std::domain_errorIf length is > 8
SocketCanTimeoutOn timeout
std::runtime_erroron other errors

◆ send() [4/4]

void autoware::drivers::socketcan::SocketCanSender::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
[in]dataA pointer to the beginning of the data to send
[in]timeoutMaximum duration to wait for file descriptor to be free for write. Negative durations are treated the same as zero timeout
[in]lengthThe amount of data to send starting from the data pointer
Exceptions
std::domain_errorIf length is > 8
SocketCanTimeoutOn timeout
std::runtime_erroron other errors

The documentation for this class was generated from the following files: