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

Major refactor

This commit is contained in:
Simon Rasmussen
2017-04-27 06:40:03 +02:00
parent 46f4e493cf
commit c59bfc78cc
22 changed files with 825 additions and 423 deletions

View File

@@ -1,4 +1,5 @@
#pragma once
#include <chrono>
#include "ur_modern_driver/pipeline.h"
#include "ur_modern_driver/ur/parser.h"
#include "ur_modern_driver/ur/stream.h"
@@ -9,9 +10,10 @@ class URProducer : public IProducer<T>
private:
URStream& stream_;
URParser<T>& parser_;
std::chrono::seconds timeout_;
public:
URProducer(URStream& stream, URParser<T>& parser) : stream_(stream), parser_(parser)
URProducer(URStream& stream, URParser<T>& parser) : stream_(stream), parser_(parser), timeout_(1)
{
}
@@ -32,24 +34,29 @@ public:
{
// 4KB should be enough to hold any packet received from UR
uint8_t buf[4096];
// blocking call
ssize_t len = stream_.receive(buf, sizeof(buf));
// LOG_DEBUG("Read %d bytes from stream", len);
if (len == 0)
size_t read = 0;
//expoential backoff reconnects
while(true)
{
LOG_WARN("Read nothing from stream");
return false;
}
else if (len < 0)
{
LOG_WARN("Stream closed");
return false;
if(stream_.read(buf, sizeof(buf), read))
{
//reset sleep amount
timeout_ = std::chrono::seconds(1);
break;
}
if(stream_.closed())
return false;
LOG_WARN("Failed to read from stream, reconnecting in %ld seconds...", timeout_.count());
std::this_thread::sleep_for(timeout_);
auto next = timeout_ * 2;
if(next <= std::chrono::seconds(120))
timeout_ = next;
}
BinParser bp(buf, static_cast<size_t>(len));
BinParser bp(buf, read);
return parser_.parse(bp, products);
}
};