1
0
mirror of https://gitlab.com/obbart/universal_robots_ros_driver.git synced 2026-04-10 10:00:48 +02:00

Fixed strict alisasing warnings and double/float big endian issues

This commit is contained in:
Simon Rasmussen
2017-03-01 00:00:55 +01:00
parent ff36a13aea
commit 7d5e149102

View File

@@ -66,20 +66,14 @@ public:
{ {
return be64toh(val); return be64toh(val);
} }
float decode(float val)
{
return be32toh(val);
}
double decode(double val)
{
return be64toh(val);
}
template <typename T> template <typename T>
T peek() T peek()
{ {
assert(_buf_pos <= _buf_end); assert(_buf_pos <= _buf_end);
return decode(*(reinterpret_cast<T*>(_buf_pos))); T val;
std::memcpy(&val, _buf_pos, sizeof(T));
return decode(val);
} }
template <typename T> template <typename T>
@@ -89,6 +83,19 @@ public:
_buf_pos += sizeof(T); _buf_pos += sizeof(T);
} }
void parse(double& val)
{
uint64_t inner;
parse<uint64_t>(inner);
std::memcpy(&val, &inner, sizeof(double));
}
void parse(float& val)
{
uint32_t inner;
parse<uint32_t>(inner);
std::memcpy(&val, &inner, sizeof(float));
}
// UR uses 1 byte for boolean values but sizeof(bool) is implementation // UR uses 1 byte for boolean values but sizeof(bool) is implementation
// defined so we must ensure they're parsed as uint8_t on all compilers // defined so we must ensure they're parsed as uint8_t on all compilers
void parse(bool& val) void parse(bool& val)