mirror of
https://gitlab.com/obbart/universal_robots_ros_driver.git
synced 2026-04-10 18:10:47 +02:00
Added clang formatting
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
#include "ur_modern_driver/ur/master_board.h"
|
||||
#include "ur_modern_driver/ur/consumer.h"
|
||||
|
||||
bool SharedMasterBoardData::parse_with(BinParser &bp) {
|
||||
bool SharedMasterBoardData::parse_with(BinParser& bp)
|
||||
{
|
||||
bp.parse(analog_input_range0);
|
||||
bp.parse(analog_input_range1);
|
||||
bp.parse(analog_input0);
|
||||
bp.parse(analog_input1);
|
||||
bp.parse(analog_input1);
|
||||
bp.parse(analog_output_domain0);
|
||||
bp.parse(analog_output_domain1);
|
||||
bp.parse(analog_output0);
|
||||
@@ -17,8 +18,9 @@ bool SharedMasterBoardData::parse_with(BinParser &bp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MasterBoardData_V1_X::parse_with(BinParser &bp) {
|
||||
if(!bp.check_size<MasterBoardData_V1_X>())
|
||||
bool MasterBoardData_V1_X::parse_with(BinParser& bp)
|
||||
{
|
||||
if (!bp.check_size<MasterBoardData_V1_X>())
|
||||
return false;
|
||||
|
||||
bp.parse(digital_input_bits);
|
||||
@@ -30,8 +32,8 @@ bool MasterBoardData_V1_X::parse_with(BinParser &bp) {
|
||||
bp.parse(master_on_off_state);
|
||||
bp.parse(euromap67_interface_installed);
|
||||
|
||||
if(euromap67_interface_installed) {
|
||||
if(!bp.check_size(MasterBoardData_V1_X::EURO_SIZE))
|
||||
if (euromap67_interface_installed) {
|
||||
if (!bp.check_size(MasterBoardData_V1_X::EURO_SIZE))
|
||||
return false;
|
||||
|
||||
bp.parse(euromap_voltage);
|
||||
@@ -41,23 +43,24 @@ bool MasterBoardData_V1_X::parse_with(BinParser &bp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MasterBoardData_V3_0__1::parse_with(BinParser &bp) {
|
||||
if(!bp.check_size<MasterBoardData_V3_0__1>())
|
||||
bool MasterBoardData_V3_0__1::parse_with(BinParser& bp)
|
||||
{
|
||||
if (!bp.check_size<MasterBoardData_V3_0__1>())
|
||||
return false;
|
||||
|
||||
bp.parse(digital_input_bits);
|
||||
bp.parse(digital_output_bits);
|
||||
|
||||
|
||||
SharedMasterBoardData::parse_with(bp);
|
||||
|
||||
bp.parse(safety_mode);
|
||||
bp.parse(in_reduced_mode);
|
||||
bp.parse(euromap67_interface_installed);
|
||||
|
||||
if(euromap67_interface_installed) {
|
||||
if(!bp.check_size(MasterBoardData_V3_0__1::EURO_SIZE))
|
||||
if (euromap67_interface_installed) {
|
||||
if (!bp.check_size(MasterBoardData_V3_0__1::EURO_SIZE))
|
||||
return false;
|
||||
|
||||
|
||||
bp.parse(euromap_voltage);
|
||||
bp.parse(euromap_current);
|
||||
}
|
||||
@@ -67,10 +70,9 @@ bool MasterBoardData_V3_0__1::parse_with(BinParser &bp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool MasterBoardData_V3_2::parse_with(BinParser &bp) {
|
||||
if(!bp.check_size<MasterBoardData_V3_2>())
|
||||
bool MasterBoardData_V3_2::parse_with(BinParser& bp)
|
||||
{
|
||||
if (!bp.check_size<MasterBoardData_V3_2>())
|
||||
return false;
|
||||
|
||||
MasterBoardData_V3_0__1::parse_with(bp);
|
||||
@@ -81,16 +83,15 @@ bool MasterBoardData_V3_2::parse_with(BinParser &bp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool MasterBoardData_V1_X::consume_with(URStatePacketConsumer &consumer) {
|
||||
bool MasterBoardData_V1_X::consume_with(URStatePacketConsumer& consumer)
|
||||
{
|
||||
return consumer.consume(*this);
|
||||
}
|
||||
bool MasterBoardData_V3_0__1::consume_with(URStatePacketConsumer &consumer) {
|
||||
bool MasterBoardData_V3_0__1::consume_with(URStatePacketConsumer& consumer)
|
||||
{
|
||||
return consumer.consume(*this);
|
||||
}
|
||||
bool MasterBoardData_V3_2::consume_with(URStatePacketConsumer &consumer) {
|
||||
bool MasterBoardData_V3_2::consume_with(URStatePacketConsumer& consumer)
|
||||
{
|
||||
return consumer.consume(*this);
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "ur_modern_driver/ur/messages.h"
|
||||
#include "ur_modern_driver/ur/consumer.h"
|
||||
|
||||
bool VersionMessage::parse_with(BinParser& bp)
|
||||
{
|
||||
|
||||
bool VersionMessage::parse_with(BinParser &bp) {
|
||||
|
||||
bp.parse(project_name);
|
||||
bp.parse(major_version);
|
||||
bp.parse(minor_version);
|
||||
@@ -11,10 +11,10 @@ bool VersionMessage::parse_with(BinParser &bp) {
|
||||
bp.consume(sizeof(uint32_t)); //undocumented field??
|
||||
bp.parse_remainder(build_date);
|
||||
|
||||
return true; //not really possible to check dynamic size packets
|
||||
return true; //not really possible to check dynamic size packets
|
||||
}
|
||||
|
||||
|
||||
bool VersionMessage::consume_with(URMessagePacketConsumer &consumer) {
|
||||
bool VersionMessage::consume_with(URMessagePacketConsumer& consumer)
|
||||
{
|
||||
return consumer.consume(*this);
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "ur_modern_driver/ur/robot_mode.h"
|
||||
#include "ur_modern_driver/ur/consumer.h"
|
||||
|
||||
|
||||
bool SharedRobotModeData::parse_with(BinParser &bp) {
|
||||
bool SharedRobotModeData::parse_with(BinParser& bp)
|
||||
{
|
||||
bp.parse(timestamp);
|
||||
bp.parse(physical_robot_connected);
|
||||
bp.parse(real_robot_enabled);
|
||||
@@ -11,9 +11,9 @@ bool SharedRobotModeData::parse_with(BinParser &bp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool RobotModeData_V1_X::parse_with(BinParser &bp) {
|
||||
if(!bp.check_size<RobotModeData_V1_X>())
|
||||
bool RobotModeData_V1_X::parse_with(BinParser& bp)
|
||||
{
|
||||
if (!bp.check_size<RobotModeData_V1_X>())
|
||||
return false;
|
||||
|
||||
SharedRobotModeData::parse_with(bp);
|
||||
@@ -27,13 +27,13 @@ bool RobotModeData_V1_X::parse_with(BinParser &bp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool RobotModeData_V3_0__1::parse_with(BinParser &bp) {
|
||||
if(!bp.check_size<RobotModeData_V3_0__1>())
|
||||
bool RobotModeData_V3_0__1::parse_with(BinParser& bp)
|
||||
{
|
||||
if (!bp.check_size<RobotModeData_V3_0__1>())
|
||||
return false;
|
||||
|
||||
SharedRobotModeData::parse_with(bp);
|
||||
|
||||
|
||||
bp.parse(protective_stopped);
|
||||
bp.parse(program_running);
|
||||
bp.parse(program_paused);
|
||||
@@ -45,8 +45,9 @@ bool RobotModeData_V3_0__1::parse_with(BinParser &bp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RobotModeData_V3_2::parse_with(BinParser &bp) {
|
||||
if(!bp.check_size<RobotModeData_V3_2>())
|
||||
bool RobotModeData_V3_2::parse_with(BinParser& bp)
|
||||
{
|
||||
if (!bp.check_size<RobotModeData_V3_2>())
|
||||
return false;
|
||||
|
||||
RobotModeData_V3_0__1::parse_with(bp);
|
||||
@@ -56,15 +57,15 @@ bool RobotModeData_V3_2::parse_with(BinParser &bp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool RobotModeData_V1_X::consume_with(URStatePacketConsumer &consumer) {
|
||||
bool RobotModeData_V1_X::consume_with(URStatePacketConsumer& consumer)
|
||||
{
|
||||
return consumer.consume(*this);
|
||||
}
|
||||
bool RobotModeData_V3_0__1::consume_with(URStatePacketConsumer &consumer) {
|
||||
bool RobotModeData_V3_0__1::consume_with(URStatePacketConsumer& consumer)
|
||||
{
|
||||
return consumer.consume(*this);
|
||||
}
|
||||
bool RobotModeData_V3_2::consume_with(URStatePacketConsumer &consumer) {
|
||||
bool RobotModeData_V3_2::consume_with(URStatePacketConsumer& consumer)
|
||||
{
|
||||
return consumer.consume(*this);
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "ur_modern_driver/ur/rt_state.h"
|
||||
#include "ur_modern_driver/ur/consumer.h"
|
||||
|
||||
|
||||
bool RTShared::parse_shared1(BinParser &bp) {
|
||||
bool RTShared::parse_shared1(BinParser& bp)
|
||||
{
|
||||
bp.parse(time);
|
||||
bp.parse(q_target);
|
||||
bp.parse(qd_target);
|
||||
@@ -15,7 +15,8 @@ bool RTShared::parse_shared1(BinParser &bp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RTShared::parse_shared2(BinParser &bp) {
|
||||
bool RTShared::parse_shared2(BinParser& bp)
|
||||
{
|
||||
bp.parse(digital_input);
|
||||
bp.parse(motor_temperatures);
|
||||
bp.parse(controller_time);
|
||||
@@ -23,13 +24,13 @@ bool RTShared::parse_shared2(BinParser &bp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool RTState_V1_6__7::parse_with(BinParser &bp) {
|
||||
if(!bp.check_size<RTState_V1_6__7>())
|
||||
bool RTState_V1_6__7::parse_with(BinParser& bp)
|
||||
{
|
||||
if (!bp.check_size<RTState_V1_6__7>())
|
||||
return false;
|
||||
|
||||
parse_shared1(bp);
|
||||
|
||||
|
||||
bp.parse(tool_accelerometer_values);
|
||||
bp.parse(tcp_force);
|
||||
bp.parse(tool_vector_actual);
|
||||
@@ -40,8 +41,9 @@ bool RTState_V1_6__7::parse_with(BinParser &bp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RTState_V1_8::parse_with(BinParser &bp) {
|
||||
if(!bp.check_size<RTState_V1_8>())
|
||||
bool RTState_V1_8::parse_with(BinParser& bp)
|
||||
{
|
||||
if (!bp.check_size<RTState_V1_8>())
|
||||
return false;
|
||||
|
||||
RTState_V1_6__7::parse_with(bp);
|
||||
@@ -51,8 +53,9 @@ bool RTState_V1_8::parse_with(BinParser &bp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RTState_V3_0__1::parse_with(BinParser &bp) {
|
||||
if(!bp.check_size<RTState_V3_0__1>())
|
||||
bool RTState_V3_0__1::parse_with(BinParser& bp)
|
||||
{
|
||||
if (!bp.check_size<RTState_V3_0__1>())
|
||||
return false;
|
||||
|
||||
parse_shared1(bp);
|
||||
@@ -74,7 +77,7 @@ bool RTState_V3_0__1::parse_with(BinParser &bp) {
|
||||
bp.parse(speed_scaling);
|
||||
bp.parse(linear_momentum_norm);
|
||||
bp.consume(sizeof(double)); //skip undocumented
|
||||
bp.consume(sizeof(double)); //skip undocumented
|
||||
bp.consume(sizeof(double)); //skip undocumented
|
||||
bp.parse(v_main);
|
||||
bp.parse(v_robot);
|
||||
bp.parse(i_robot);
|
||||
@@ -83,8 +86,9 @@ bool RTState_V3_0__1::parse_with(BinParser &bp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RTState_V3_2__3::parse_with(BinParser &bp) {
|
||||
if(!bp.check_size<RTState_V3_2__3>())
|
||||
bool RTState_V3_2__3::parse_with(BinParser& bp)
|
||||
{
|
||||
if (!bp.check_size<RTState_V3_2__3>())
|
||||
return false;
|
||||
|
||||
RTState_V3_0__1::parse_with(bp);
|
||||
@@ -95,15 +99,19 @@ bool RTState_V3_2__3::parse_with(BinParser &bp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RTState_V1_6__7::consume_with(URRTPacketConsumer &consumer) {
|
||||
bool RTState_V1_6__7::consume_with(URRTPacketConsumer& consumer)
|
||||
{
|
||||
return consumer.consume(*this);
|
||||
}
|
||||
bool RTState_V1_8::consume_with(URRTPacketConsumer &consumer) {
|
||||
bool RTState_V1_8::consume_with(URRTPacketConsumer& consumer)
|
||||
{
|
||||
return consumer.consume(*this);
|
||||
}
|
||||
bool RTState_V3_0__1::consume_with(URRTPacketConsumer &consumer) {
|
||||
bool RTState_V3_0__1::consume_with(URRTPacketConsumer& consumer)
|
||||
{
|
||||
return consumer.consume(*this);
|
||||
}
|
||||
bool RTState_V3_2__3::consume_with(URRTPacketConsumer &consumer) {
|
||||
bool RTState_V3_2__3::consume_with(URRTPacketConsumer& consumer)
|
||||
{
|
||||
return consumer.consume(*this);
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "ur_modern_driver/log.h"
|
||||
#include "ur_modern_driver/ur/state.h"
|
||||
|
||||
|
||||
#include "ur_modern_driver/log.h"
|
||||
|
||||
//StatePacket::~StatePacket() { }
|
||||
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#include <cstring>
|
||||
#include <unistd.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <endian.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "ur_modern_driver/ur/stream.h"
|
||||
#include "ur_modern_driver/log.h"
|
||||
#include "ur_modern_driver/ur/stream.h"
|
||||
|
||||
bool URStream::connect() {
|
||||
if(_initialized)
|
||||
bool URStream::connect()
|
||||
{
|
||||
if (_initialized)
|
||||
return false;
|
||||
|
||||
LOG_INFO("Connecting to UR @ %s:%d", _host.c_str(), _port);
|
||||
@@ -23,20 +24,20 @@ bool URStream::connect() {
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
hints.ai_flags = AI_PASSIVE;
|
||||
|
||||
if(getaddrinfo(_host.c_str(), service.c_str(), &hints, &result) != 0) {
|
||||
LOG_ERROR("Failed to get host name");
|
||||
if (getaddrinfo(_host.c_str(), service.c_str(), &hints, &result) != 0) {
|
||||
LOG_ERROR("Failed to get host name");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//loop through the list of addresses untill we find one that's connectable
|
||||
for(struct addrinfo *p = result; p != nullptr; p = p->ai_next) {
|
||||
for (struct addrinfo* p = result; p != nullptr; p = p->ai_next) {
|
||||
_socket_fd = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
|
||||
|
||||
if(_socket_fd == -1) //socket error?
|
||||
if (_socket_fd == -1) //socket error?
|
||||
continue;
|
||||
|
||||
if(::connect(_socket_fd, p->ai_addr, p->ai_addrlen) != 0) {
|
||||
if(_stopping)
|
||||
if (::connect(_socket_fd, p->ai_addr, p->ai_addrlen) != 0) {
|
||||
if (_stopping)
|
||||
break;
|
||||
else
|
||||
continue; //try next addrinfo if connect fails
|
||||
@@ -51,14 +52,15 @@ bool URStream::connect() {
|
||||
}
|
||||
|
||||
freeaddrinfo(result);
|
||||
if(!_initialized)
|
||||
if (!_initialized)
|
||||
LOG_ERROR("Connection failed");
|
||||
|
||||
return _initialized;
|
||||
}
|
||||
|
||||
void URStream::disconnect() {
|
||||
if(!_initialized || _stopping)
|
||||
void URStream::disconnect()
|
||||
{
|
||||
if (!_initialized || _stopping)
|
||||
return;
|
||||
|
||||
_stopping = true;
|
||||
@@ -66,10 +68,11 @@ void URStream::disconnect() {
|
||||
_initialized = false;
|
||||
}
|
||||
|
||||
ssize_t URStream::send(uint8_t *buf, size_t buf_len) {
|
||||
if(!_initialized)
|
||||
ssize_t URStream::send(uint8_t* buf, size_t buf_len)
|
||||
{
|
||||
if (!_initialized)
|
||||
return -1;
|
||||
if(_stopping)
|
||||
if (_stopping)
|
||||
return 0;
|
||||
|
||||
size_t total = 0;
|
||||
@@ -77,9 +80,9 @@ ssize_t URStream::send(uint8_t *buf, size_t buf_len) {
|
||||
|
||||
//TODO: handle reconnect?
|
||||
//handle partial sends
|
||||
while(total < buf_len) {
|
||||
ssize_t sent = ::send(_socket_fd, buf+total, remaining, 0);
|
||||
if(sent <= 0)
|
||||
while (total < buf_len) {
|
||||
ssize_t sent = ::send(_socket_fd, buf + total, remaining, 0);
|
||||
if (sent <= 0)
|
||||
return _stopping ? 0 : sent;
|
||||
total += sent;
|
||||
remaining -= sent;
|
||||
@@ -88,24 +91,25 @@ ssize_t URStream::send(uint8_t *buf, size_t buf_len) {
|
||||
return total;
|
||||
}
|
||||
|
||||
ssize_t URStream::receive(uint8_t *buf, size_t buf_len) {
|
||||
if(!_initialized)
|
||||
ssize_t URStream::receive(uint8_t* buf, size_t buf_len)
|
||||
{
|
||||
if (!_initialized)
|
||||
return -1;
|
||||
if(_stopping)
|
||||
if (_stopping)
|
||||
return 0;
|
||||
|
||||
size_t remainder = sizeof(int32_t);
|
||||
uint8_t *buf_pos = buf;
|
||||
uint8_t* buf_pos = buf;
|
||||
bool initial = true;
|
||||
|
||||
do {
|
||||
ssize_t read = recv(_socket_fd, buf_pos, remainder, 0);
|
||||
if(read <= 0) //failed reading from socket
|
||||
return _stopping ? 0 : read;
|
||||
|
||||
if(initial) {
|
||||
if (read <= 0) //failed reading from socket
|
||||
return _stopping ? 0 : read;
|
||||
|
||||
if (initial) {
|
||||
remainder = be32toh(*(reinterpret_cast<int32_t*>(buf)));
|
||||
if(remainder >= (buf_len - sizeof(int32_t))) {
|
||||
if (remainder >= (buf_len - sizeof(int32_t))) {
|
||||
LOG_ERROR("Packet size %d is larger than buffer %d, discarding.", remainder, buf_len);
|
||||
return -1;
|
||||
}
|
||||
@@ -113,8 +117,8 @@ ssize_t URStream::receive(uint8_t *buf, size_t buf_len) {
|
||||
}
|
||||
|
||||
buf_pos += read;
|
||||
remainder -= read;
|
||||
} while(remainder > 0);
|
||||
remainder -= read;
|
||||
} while (remainder > 0);
|
||||
|
||||
return buf_pos - buf;
|
||||
}
|
||||
Reference in New Issue
Block a user