staubli_driver_ros2 main
ROS2 control driver for Staubli robots
Loading...
Searching...
No Matches
udp_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__UDP_SOCKET_HPP_
18#define STAUBLI_ROBOT_DRIVER__COMMUNICATION__UDP_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 UDPSocketImpl;
35
39class UDPSocket : public Socket {
40public:
42
43 ~UDPSocket() 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 disconnect() override;
57
58 bool is_connected() const override;
59
60 bool send(std::vector<uint8_t>& data) override;
61
62 bool receive_once(int timeout_ms, std::vector<uint8_t>& data) override;
63
65 std::function<void(
66 std::vector<uint8_t>& /*reception buffer*/,
67 size_t /*bytes_transferred*/)> reception_callback) override;
68
69 bool stop_receive_thread() override;
70
71 bool is_receiving() const override;
72
73private:
74 std::unique_ptr<UDPSocketImpl> impl_; // Implementation
75};
76
81public:
86 static std::shared_ptr<Socket> create();
87};
88
89} // namespace staubli_robot_driver
90
91#endif // STAUBLI_ROBOT_DRIVER__COMMUNICATION__UDP_SOCKET_HPP_
Abstract interface for communication with the robot.
Definition socket.hpp:38
Factory implementation for UDP communication.
Definition udp_socket.hpp:80
static std::shared_ptr< Socket > create()
Create a UDP communication interface.
Class for handling bidirectional UDP communication.
Definition udp_socket.hpp:39
bool send(std::vector< uint8_t > &data) override
Send data to the remote endpoint.
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 receive_once(int timeout_ms, std::vector< uint8_t > &data) override
Receive data from socket (blocking with timeout)
bool stop_receive_thread() override
Stop the receive thread.
bool is_receiving() const override
Check if the receive thread is running.
bool connect(const std::string &remote_address, uint16_t remote_port, uint16_t local_port) override
Connect to the remote endpoint.
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 is_connected() const override
Check if the connection is established.
Definition messages.hpp:23