staubli_driver_ros2 main
ROS2 control driver for Staubli robots
Loading...
Searching...
No Matches
tcp_socket.hpp
Go to the documentation of this file.
1// Copyright 2025 ICUBE Laboratory, University of Strasbourg
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Author: Thibault Poignonec (thibault.poignonec@gmail.fr)
16
17#ifndef STAUBLI_ROBOT_DRIVER__COMMUNICATION__TCP_SOCKET_HPP_
18#define STAUBLI_ROBOT_DRIVER__COMMUNICATION__TCP_SOCKET_HPP_
19
20
21#include <string>
22#include <vector>
23#include <functional>
24#include <memory>
25#include <mutex>
26#include <atomic>
27#include <condition_variable>
28
30
31namespace staubli_robot_driver {
32
33// Forward declaration of implementation class
34class TCPSocketImpl;
35
39class TCPSocket : public Socket {
40public:
42
43 ~TCPSocket() override;
44
45 bool connect(
46 const std::string& remote_address,
47 uint16_t remote_port,
48 uint16_t local_port) override;
49
50 bool connect(
51 const std::string& remote_address,
52 uint16_t remote_port,
53 const std::string& local_address,
54 uint16_t local_port) override;
55
56 bool connect(
57 const std::string& remote_address,
58 uint16_t remote_port,
59 uint16_t local_port,
60 int timeout_ms);
61
62 bool disconnect() override;
63
64 bool is_connected() const override;
65
66 bool send(std::vector<uint8_t>& data) override;
67
68 bool receive_once(int timeout_ms, std::vector<uint8_t>& data) override;
69
71 std::function<void(
72 std::vector<uint8_t>& /*reception buffer*/,
73 size_t /*bytes_transferred*/)> reception_callback) override;
74
75 bool stop_receive_thread() override;
76
77 bool is_receiving() const override;
78
79private:
80 std::unique_ptr<TCPSocketImpl> impl_; // Implementation
81};
82
87public:
92 static std::shared_ptr<Socket> create();
93};
94
95} // namespace staubli_robot_driver
96
97#endif // STAUBLI_ROBOT_DRIVER__COMMUNICATION__TCP_SOCKET_HPP_
Abstract interface for communication with the robot.
Definition socket.hpp:38
Factory implementation for TCP communication.
Definition tcp_socket.hpp:86
static std::shared_ptr< Socket > create()
Create a TCP communication interface.
Class for handling bidirectional TCP communication.
Definition tcp_socket.hpp:39
bool send(std::vector< uint8_t > &data) override
Send data to the remote endpoint.
bool connect(const std::string &remote_address, uint16_t remote_port, uint16_t local_port, int timeout_ms)
bool is_receiving() const override
Check if the receive thread is running.
bool is_connected() const override
Check if the connection is established.
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 disconnect() override
Disconnect from 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) override
Connect to the remote endpoint.
bool receive_once(int timeout_ms, std::vector< uint8_t > &data) override
Receive data from socket (blocking with timeout)
Definition messages.hpp:23