staubli_driver_ros2 main
ROS2 control driver for Staubli robots
Loading...
Searching...
No Matches
Public Member Functions | List of all members
staubli_robot_driver::TCPSocket Class Reference

Class for handling bidirectional TCP communication. More...

#include <tcp_socket.hpp>

Inheritance diagram for staubli_robot_driver::TCPSocket:
[legend]
Collaboration diagram for staubli_robot_driver::TCPSocket:
[legend]

Public Member Functions

 TCPSocket ()
 
 ~TCPSocket () override
 
bool connect (const std::string &remote_address, uint16_t remote_port, uint16_t local_port) override
 Connect to the remote endpoint.
 
bool connect (const std::string &remote_address, uint16_t remote_port, const std::string &local_address, uint16_t local_port) override
 Connect to the remote endpoint with specific local address.
 
bool connect (const std::string &remote_address, uint16_t remote_port, uint16_t local_port, int timeout_ms)
 
bool disconnect () override
 Disconnect from the remote endpoint.
 
bool is_connected () const override
 Check if the connection is established.
 
bool send (std::vector< uint8_t > &data) override
 Send data to the remote endpoint.
 
bool receive_once (int timeout_ms, std::vector< uint8_t > &data) override
 Receive data from socket (blocking with timeout)
 
bool start_receive_thread (std::function< void(std::vector< uint8_t > &, size_t)> reception_callback) override
 Start a receive thread that calls the provided reception_callback when data is received.
 
bool stop_receive_thread () override
 Stop the receive thread.
 
bool is_receiving () const override
 Check if the receive thread is running.
 
- Public Member Functions inherited from staubli_robot_driver::Socket
 Socket ()=default
 Default constructor.
 
virtual ~Socket ()=default
 Virtual destructor.
 

Detailed Description

Class for handling bidirectional TCP communication.

Constructor & Destructor Documentation

◆ TCPSocket()

staubli_robot_driver::TCPSocket::TCPSocket ( )

◆ ~TCPSocket()

staubli_robot_driver::TCPSocket::~TCPSocket ( )
override

Member Function Documentation

◆ connect() [1/3]

bool staubli_robot_driver::TCPSocket::connect ( const std::string &  remote_address,
uint16_t  remote_port,
uint16_t  local_port 
)
overridevirtual

Connect to the remote endpoint.

Parameters
remote_addressAddress of the remote endpoint (format depends on protocol)
remote_portPort or identifier for the remote endpoint
local_portPort or identifier for the local endpoint
Returns
True if connected successfully, false otherwise

Implements staubli_robot_driver::Socket.

◆ connect() [2/3]

bool staubli_robot_driver::TCPSocket::connect ( const std::string &  remote_address,
uint16_t  remote_port,
const std::string &  local_address,
uint16_t  local_port 
)
overridevirtual

Connect to the remote endpoint with specific local address.

Parameters
remote_addressAddress of the remote endpoint (format depends on protocol)
remote_portPort or identifier for the remote endpoint
local_addressLocal IP address to bind to (e.g., "192.168.1.100", "0.0.0.0" for any)
local_portPort or identifier for the local endpoint
Returns
True if connected successfully, false otherwise

Implements staubli_robot_driver::Socket.

◆ connect() [3/3]

bool staubli_robot_driver::TCPSocket::connect ( const std::string &  remote_address,
uint16_t  remote_port,
uint16_t  local_port,
int  timeout_ms 
)

◆ disconnect()

bool staubli_robot_driver::TCPSocket::disconnect ( )
overridevirtual

Disconnect from the remote endpoint.

Returns
True if disconnected successfully, false otherwise

Implements staubli_robot_driver::Socket.

◆ is_connected()

bool staubli_robot_driver::TCPSocket::is_connected ( ) const
overridevirtual

Check if the connection is established.

Returns
True if connected, false otherwise

Implements staubli_robot_driver::Socket.

◆ send()

bool staubli_robot_driver::TCPSocket::send ( std::vector< uint8_t > &  data)
overridevirtual

Send data to the remote endpoint.

Parameters
dataData to send
Returns
True if data was sent successfully, false otherwise

Implements staubli_robot_driver::Socket.

◆ receive_once()

bool staubli_robot_driver::TCPSocket::receive_once ( int  timeout_ms,
std::vector< uint8_t > &  data 
)
overridevirtual

Receive data from socket (blocking with timeout)

Parameters
timeout_msTimeout in milliseconds
dataWill be filled with received data
Returns
Number of bytes received, 0 on timeout, -1 on error
Warning
The data vector must be preallocated with the max buffer size. The function will resize it to the max buffer size otherwise...

Implements staubli_robot_driver::Socket.

◆ start_receive_thread()

bool staubli_robot_driver::TCPSocket::start_receive_thread ( std::function< void(std::vector< uint8_t > &, size_t)>  reception_callback)
overridevirtual

Start a receive thread that calls the provided reception_callback when data is received.

Parameters
reception_callbackFunction to call when data is received
Returns
True if the receive thread was started successfully, false otherwise

Implements staubli_robot_driver::Socket.

◆ stop_receive_thread()

bool staubli_robot_driver::TCPSocket::stop_receive_thread ( )
overridevirtual

Stop the receive thread.

Returns
True if the receive thread was stopped successfully, false otherwise

Implements staubli_robot_driver::Socket.

◆ is_receiving()

bool staubli_robot_driver::TCPSocket::is_receiving ( ) const
overridevirtual

Check if the receive thread is running.

Returns
True if the receive thread is running, false otherwise

Implements staubli_robot_driver::Socket.


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