Class Node

Inheritance Relationships

Derived Types

  • protected myactuator_rmd::Node< AddressOffset::request, AddressOffset::response > (Template Class Node)

  • protected myactuator_rmd::Node< SEND_ID_OFFSET, RECEIVE_ID_OFFSET > (Template Class Node)

Class Documentation

class Node

Base class for sending and receiving CAN frames over SocketCAN with a default 8*uint8 length in a blocking manner.

Subclassed by myactuator_rmd::Node< AddressOffset::request, AddressOffset::response >, myactuator_rmd::Node< SEND_ID_OFFSET, RECEIVE_ID_OFFSET >

Public Functions

Node(std::string const &ifname, std::chrono::microseconds const &send_timeout = std::chrono::seconds(1), std::chrono::microseconds const &receive_timeout = std::chrono::seconds(1), bool const is_signal_errors = true)
Node() = delete

Class constructor, initialises the socket that should be used for communication and sets up debugging.

Parameters:
  • ifname[in] The name of the network interface that should communicated over

  • send_timeout[in] The send timeout for the underlying socket

  • receive_timeout[in] The receive timeout for the underlying socket

  • is_signal_errors[in] Boolean flags indicating whether error frames should be received or not

Node(Node const&) = delete
Node &operator=(Node const&) = default
Node(Node&&) = default
Node &operator=(Node&&) = default
~Node()
void setLoopback(bool const is_loopback)

Set the socket to also receive its own messages, this can be desirable for debugging.

Parameters:

is_loopback[in] If set to true the node will also receive its own messages

void setRecvFilter(std::uint32_t const &can_id, bool const is_invert = false)

Set a filter for receiving CAN frames only for specific IDs.

Parameters:
  • can_id[in] The CAN id that should be accepted (discarded if is_invert set to true)

  • is_invert[in] Invert the CAN id filter: If set to true all messages of the given ID are discarded

void setSendTimeout(std::chrono::microseconds const &timeout)

Set socket timeout for sending frames.

Parameters:

timeout[in] Timeout that the socket should be set to for sending frames

void setRecvTimeout(std::chrono::microseconds const &timeout)

Set socket timeout for receiving frames.

Parameters:

timeout[in] Timeout that the socket should be set to for receiving frames

void setErrorFilters(bool const is_signal_errors)

Set error filters for the socket. We will only receive error frames if we explicitly activate it!

Parameters:

is_signal_errors[in] Boolean flags indicating whether errors should be received or not

Frame read() const

Read a CAN frame in a blocking manner Only CAN frames that a receive filter was set for can be read.

Returns:

The read CAN frame

void write(Frame const &frame)
void write(std::uint32_t const can_id, std::array<std::uint8_t, 8> const &data)

Protected Functions

void initSocket(std::string const &ifname)

Initialise a socket for the given network interface.

Parameters:

ifname[in] The name of the network interface that should communicated over

void closeSocket() noexcept

Close the underlying socket.

Protected Attributes

std::string ifname_
int socket_