28 #ifndef UR_CLIENT_LIBRARY_REVERSE_INTERFACE_H_INCLUDED 29 #define UR_CLIENT_LIBRARY_REVERSE_INTERFACE_H_INCLUDED 36 #include <condition_variable> 69 : client_fd_(-1), server_(port), handle_program_state_(handle_program_state), keepalive_count_(1)
71 handle_program_state_(
false);
72 server_.setMessageCallback(
76 server_.setMaxClientsAllowed(1);
101 uint8_t buffer[
sizeof(int32_t) * 8];
102 uint8_t* b_pos = buffer;
105 int32_t val = htobe32(keepalive_count_);
106 b_pos += append(b_pos, val);
108 if (positions !=
nullptr)
110 for (
auto const& pos : *positions)
114 b_pos += append(b_pos, val);
119 b_pos += 6 *
sizeof(int32_t);
123 b_pos += append(b_pos, val);
127 return server_.write(client_fd_, buffer,
sizeof(buffer), written);
137 keepalive_count_ = count;
145 URCL_LOG_INFO(
"Robot connected to reverse interface. Ready to receive control commands.");
146 client_fd_ = filedescriptor;
147 handle_program_state_(
true);
151 URCL_LOG_ERROR(
"Connection request to ReverseInterface received while connection already established. Only one " 152 "connection is allowed at a time. Ignoring this request.");
158 URCL_LOG_INFO(
"Connection to reverse interface dropped.", filedescriptor);
160 handle_program_state_(
false);
165 URCL_LOG_WARN(
"Messge on ReverseInterface received. The reverse interface currently does not support any message " 166 "handling. This message will be ignored.");
174 template <
typename T>
177 size_t s =
sizeof(T);
178 std::memcpy(buffer, &val, s);
189 #endif // UR_CLIENT_LIBRARY_REVERSE_INTERFACE_H_INCLUDED #define URCL_LOG_ERROR(...)
void setKeepaliveCount(const uint32_t &count)
Set the Keepalive count. This will set the number of allowed timeout reads on the robot...
Set when speedj control is active.
void disconnectionCallback(const int filedescriptor)
bool write(const vector6d_t *positions, const ControlMode control_mode=ControlMode::MODE_IDLE)
Writes needed information to the robot to be read by the URCaps program.
uint32_t keepalive_count_
~ReverseInterface()
Disconnects possible clients so the reverse interface object can be safely destroyed.
Wrapper class for a TCP socket server.
static const int32_t MULT_JOINTSTATE
Set when no controller is currently active controlling the robot.
Set when servoj control is active.
size_t append(uint8_t *buffer, T &val)
void messageCallback(const int filedescriptor, char *buffer)
std::function< void(bool)> handle_program_state_
ControlMode
Control modes as interpreted from the script runnning on the robot.
When this is set, the program is expected to stop and exit.
Startup default until another mode is sent to the script.
#define URCL_LOG_WARN(...)
constexpr std::underlying_type< E >::type toUnderlying(const E e) noexcept
Converts an enum type to its underlying type.
void connectionCallback(const int filedescriptor)
The ReverseInterface class handles communication to the robot. It starts a server and waits for the r...
std::array< double, 6 > vector6d_t
ReverseInterface(uint32_t port, std::function< void(bool)> handle_program_state)
Creates a ReverseInterface object including a TCPServer.
#define URCL_LOG_INFO(...)