Class AxiomaticAdapter

Inheritance Relationships

Base Type

  • public std::enable_shared_from_this< AxiomaticAdapter >

Class Documentation

class AxiomaticAdapter : public std::enable_shared_from_this<AxiomaticAdapter>

Creates and manages a tcp connection and simplifies the interface. Generally does not throw, but returns booleans to tell you success.

Public Types

using socket_error_string_t = std::string

Mapped to std lib, but should be remapped to Polymath Safety compatible versions.

Public Functions

AxiomaticAdapter(const std::string &ip_address, const std::string &port, const std::function<void(std::unique_ptr<const polymath::socketcan::CanFrame> frame)> &&receive_callback_function = [](std::unique_ptr< const polymath::socketcan::CanFrame >) { }, const std::function<void(socket_error_string_t error)> &&error_callback_function = [](socket_error_string_t) { }, const std::chrono::milliseconds &receive_timeout_ms = AxiomaticAdapter::DEFAULT_SOCKET_RECEIVE_TIMEOUT_MS)

AxiomaticAdapter Class Init.

Parameters:
  • ip_address – Axiomatic Device IP address to connect

  • port – Axiomatic Device Port to connect to

  • receive_timeout_ms – receive timeout in milliseconds

virtual ~AxiomaticAdapter()

Destructor for AxiomaticAdapter.

bool openSocket()

Open TCP Socket.

Returns:

bool success for opening socket

bool closeSocket()

Close TCP Socket.

Returns:

bool success for closing socket

std::optional<socket_error_string_t> receive(polymath::socketcan::CanFrame &can_frame)

Receive with a reference to a CanFrame to fill.

Parameters:

frame – OUTPUT CanFrame to fill

Returns:

optional error string filled with an error message if any

std::optional<const polymath::socketcan::CanFrame> receive()

Receive returns the received CanFrame.

Returns:

optional CanFrame nullopt is returned if no frame received, acts like null

bool startReceptionThread()

Start a reception thread (calls callback)

Returns:

success on started

bool joinReceptionThread(const std::chrono::milliseconds &timeout_s = AxiomaticAdapter::JOIN_RECEPTION_TIMEOUT_MS)

Stop and join reception thread.

Parameters:

timeout_s – INPUT timeout in seconds, <=0 means no timeout

Returns:

success on closed and joined thread

std::optional<socket_error_string_t> send(const polymath::socketcan::CanFrame &frame)

Transmit a can frame via socket.

Parameters:

frame – INPUT const reference to the frame

Returns:

optional error string filled with an error message if any

std::optional<socket_error_string_t> send(const can_frame &frame)

Transmit a can frame via socket.

Parameters:

frame – Linux CAN frame to send

Returns:

optional error string filled with an error message if any

TCPSocketState get_socket_state()

Get state of socket.

Returns:

TCPSocketState data type detailing OPEN or CLOSED

bool is_thread_running()

Checks if the receive thread is running.

Returns:

True if the thread is running, false otherwise

Public Static Attributes

static constexpr std::chrono::milliseconds DEFAULT_SOCKET_RECEIVE_TIMEOUT_MS = {100}
static constexpr std::chrono::milliseconds JOIN_RECEPTION_TIMEOUT_MS = {100}