mirror of
https://gitlab.com/obbart/universal_robots_ros_driver.git
synced 2026-04-10 10:00:48 +02:00
Added bitset parsing and setter for random data
This commit is contained in:
@@ -5,31 +5,32 @@
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <bitset>
|
||||||
#include "ur_modern_driver/bin_parser.h"
|
#include "ur_modern_driver/bin_parser.h"
|
||||||
|
|
||||||
class RandomDataTest
|
class RandomDataTest
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
using random_bytes_engine = std::independent_bits_engine<std::default_random_engine, CHAR_BIT, uint8_t>;
|
using random_bytes_engine = std::independent_bits_engine<std::default_random_engine, CHAR_BIT, uint8_t>;
|
||||||
uint8_t* _buf;
|
uint8_t* buf_;
|
||||||
BinParser bp_;
|
BinParser bp_;
|
||||||
size_t n_;
|
size_t n_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RandomDataTest(size_t n) : _buf(new uint8_t[n]), bp_(_buf, n), n_(n)
|
RandomDataTest(size_t n) : buf_(new uint8_t[n]), bp_(buf_, n), n_(n)
|
||||||
{
|
{
|
||||||
random_bytes_engine rbe;
|
random_bytes_engine rbe;
|
||||||
std::generate(_buf, _buf + n, std::ref(rbe));
|
std::generate(buf_, buf_ + n, std::ref(rbe));
|
||||||
}
|
}
|
||||||
|
|
||||||
~RandomDataTest()
|
~RandomDataTest()
|
||||||
{
|
{
|
||||||
delete _buf;
|
delete buf_;
|
||||||
}
|
}
|
||||||
|
|
||||||
BinParser getParser(bool skip = false)
|
BinParser getParser(bool skip = false)
|
||||||
{
|
{
|
||||||
return BinParser(_buf, n_ - (skip ? sizeof(int32_t) : 0));
|
return BinParser(buf_, n_ - (skip ? sizeof(int32_t) : 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@@ -39,6 +40,21 @@ public:
|
|||||||
bp_.parse(actual);
|
bp_.parse(actual);
|
||||||
return actual;
|
return actual;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T, size_t N>
|
||||||
|
std::bitset<N> getNext()
|
||||||
|
{
|
||||||
|
T actual;
|
||||||
|
bp_.parse(actual);
|
||||||
|
return std::bitset<N>(actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void set(T data, size_t pos)
|
||||||
|
{
|
||||||
|
std::memcpy(&data, buf_+pos, sizeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
void skip(size_t n)
|
void skip(size_t n)
|
||||||
{
|
{
|
||||||
bp_.consume(n);
|
bp_.consume(n);
|
||||||
|
|||||||
Reference in New Issue
Block a user