36 : client_fd_(-1), server_(port), handle_program_state_(handle_program_state), keepalive_count_(1)
40 std::placeholders::_2, std::placeholders::_3));
49 const int message_length = 7;
55 uint8_t* b_pos = buffer;
59 b_pos +=
append(b_pos, val);
61 if (positions !=
nullptr)
63 for (
auto const& pos : *positions)
67 b_pos +=
append(b_pos, val);
72 b_pos += 6 *
sizeof(int32_t);
79 b_pos +=
append(b_pos, val);
83 b_pos +=
append(b_pos, val);
91 const int point_number)
93 const int message_length = 3;
99 uint8_t* b_pos = buffer;
103 b_pos +=
append(b_pos, val);
106 b_pos +=
append(b_pos, val);
108 val = htobe32(point_number);
109 b_pos +=
append(b_pos, val);
115 b_pos +=
append(b_pos, val);
119 b_pos +=
append(b_pos, val);
128 const int message_length = 2;
134 uint8_t* b_pos = buffer;
138 b_pos +=
append(b_pos, val);
141 b_pos +=
append(b_pos, val);
147 b_pos +=
append(b_pos, val);
151 b_pos +=
append(b_pos, val);
162 URCL_LOG_INFO(
"Robot connected to reverse interface. Ready to receive control commands.");
168 URCL_LOG_ERROR(
"Connection request to ReverseInterface received while connection already established. Only one " 169 "connection is allowed at a time. Ignoring this request.");
175 URCL_LOG_INFO(
"Connection to reverse interface dropped.", filedescriptor);
182 URCL_LOG_WARN(
"Message on ReverseInterface received. The reverse interface currently does not support any message " 183 "handling. This message will be ignored.");
void setDisconnectCallback(std::function< void(const int)> func)
This callback will be triggered on clients disconnecting from the server.
#define URCL_LOG_ERROR(...)
void setMaxClientsAllowed(const uint32_t &max_clients_allowed)
Set the maximum number of clients allowed to connect to this server.
static const int32_t MULT_JOINTSTATE
bool writeFreedriveControlMessage(const FreedriveControlMessage freedrive_action)
Writes needed information to the robot to be read by the URScript program.
void setConnectCallback(std::function< void(const int)> func)
This callback will be triggered on clients connecting to the server.
Set when trajectory forwarding is active.
virtual void connectionCallback(const int filedescriptor)
FreedriveControlMessage
Control messages for starting and stopping freedrive mode.
size_t append(uint8_t *buffer, T &val)
bool writeTrajectoryControlMessage(const TrajectoryControlMessage trajectory_action, const int point_number=0)
Writes needed information to the robot to be read by the URScript program.
virtual bool write(const vector6d_t *positions, const comm::ControlMode control_mode=comm::ControlMode::MODE_IDLE)
Writes needed information to the robot to be read by the URCaps program.
void start()
Start event handling.
uint32_t keepalive_count_
virtual void messageCallback(const int filedescriptor, char *buffer, int nbytesrecv)
Set when freedrive mode is active.
virtual void disconnectionCallback(const int filedescriptor)
bool write(const int fd, const uint8_t *buf, const size_t buf_len, size_t &written)
Writes to a client.
void setMessageCallback(std::function< void(const int, char *, int)> func)
This callback will be triggered on messages received on the socket.
static const int MAX_MESSAGE_LENGTH
ControlMode
Control modes as interpreted from the script runnning on the robot.
#define URCL_LOG_WARN(...)
constexpr std::underlying_type< E >::type toUnderlying(const E e) noexcept
Converts an enum type to its underlying type.
ReverseInterface()=delete
TrajectoryControlMessage
Control messages for forwarding and aborting trajectories.
std::function< void(bool)> handle_program_state_
std::array< double, 6 > vector6d_t
#define URCL_LOG_INFO(...)