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

Implemented URStateParser, URRTStateParser and URProducer

This commit is contained in:
Simon Rasmussen
2017-02-06 14:27:34 +01:00
parent ffe2bbe96a
commit b6eb109cd3
4 changed files with 135 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
#pragma once
#include "ur_modern_driver/log.h"
#include "ur_modern_driver/parser.h"
#include "ur_modern_driver/ur/state.h"
template <typename T>
class URStateParser : public Parser {
std::unique_ptr<Packet> parse(BinParser &bp) {
int32_t packet_size = bp.peek<int32_t>();
message_type type;
if(!bp.check_size(packet_size)) {
LOG_ERROR("Buffer len shorter than expected packet length\n");
return std::unique_ptr<Packet>(nullptr);
}
bp.parse(packet_size); //consumes the peeked data
bp.parse(type);
if(type != message_type::ROBOT_STATE) {
LOG_ERROR("Invalid message type recieved: %u\n", static_cast<uint8_t>(type));
return std::unique_ptr<Packet>(nullptr);
}
std::unique_ptr<Packet> obj(new T);
if(obj->parse_with(bp))
return obj;
return std::unique_ptr<Packet>(nullptr);
}
};
template <typename T>
class URRTStateParser : public Parser {
std::unique_ptr<Packet> parse(BinParser &bp) {
int32_t packet_size = bp.peek<int32_t>();
if(!bp.check_size(packet_size)) {
LOG_ERROR("Buffer len shorter than expected packet length\n");
return std::unique_ptr<Packet>(nullptr);
}
bp.parse(packet_size); //consumes the peeked data
std::unique_ptr<Packet> obj(new T);
if(obj->parse_with(bp))
return obj;
return std::unique_ptr<Packet>(nullptr);
}
};

View File

@@ -0,0 +1,21 @@
#pragma once
#include "ur_modern_driver/pipeline.h"
#include "ur_modern_driver/ur/stream.h"
#include "ur_modern_driver/packet.h"
#include "ur_modern_driver/parser.h"
class URProducer : public IProducer<Packet> {
private:
URStream &_stream;
Parser &_parser;
public:
URProducer(URStream &stream, Parser &parser)
: _stream(stream),
_parser(parser) { }
void setup_producer();
void teardown_producer();
void stop_producer();
std::unique_ptr<Packet> try_get();
};