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

Parse unknown states to default RobotStates

This commit is contained in:
Felix Mauch
2019-04-10 10:01:17 +02:00
parent 4dc4cc0fb0
commit fcc1e62ab5
5 changed files with 37 additions and 12 deletions

View File

@@ -172,6 +172,14 @@ public:
parse(val.rotation); parse(val.rotation);
} }
void rawData(std::unique_ptr<uint8_t>& buffer, size_t& buffer_length)
{
buffer_length = buf_end_ - buf_pos_;
buffer.reset(new uint8_t[buffer_length]);
memcpy(buffer.get(), buf_pos_, buffer_length);
consume();
}
void parseRemainder(std::string& val) void parseRemainder(std::string& val)
{ {
parse(val, size_t(buf_end_ - buf_pos_)); parse(val, size_t(buf_end_ - buf_pos_));

View File

@@ -46,14 +46,17 @@ public:
/*! /*!
* \brief Creates a new PrimaryPackage object. * \brief Creates a new PrimaryPackage object.
*/ */
PrimaryPackage() = default; PrimaryPackage() : buffer_length_(0)
{
}
virtual ~PrimaryPackage() = default; virtual ~PrimaryPackage() = default;
virtual bool parseWith(comm::BinParser& bp); virtual bool parseWith(comm::BinParser& bp);
virtual std::string toString() const; virtual std::string toString() const;
private: protected:
std::string buffer_; std::unique_ptr<uint8_t> buffer_;
size_t buffer_length_;
}; };
} // namespace primary_interface } // namespace primary_interface

View File

@@ -144,9 +144,9 @@ private:
case robot_state_type::MASTERBOARD_DATA: case robot_state_type::MASTERBOARD_DATA:
return new MBD;*/ return new MBD;*/
case RobotStateType::KINEMATICS_INFO: case RobotStateType::KINEMATICS_INFO:
return new KinematicsInfo; return new KinematicsInfo(type);
default: default:
return nullptr; return new RobotState(type);
} }
} }

View File

@@ -53,25 +53,31 @@ enum class RobotStateType : uint8_t
}; };
/*! /*!
* \brief Abstract class for a RobotState msg. This will never be instanciated, but the underlying * \brief Base class for a RobotState data packages will be used directly.
* data packages will be used directly.
*/ */
class RobotState : public PrimaryPackage class RobotState : public PrimaryPackage
{ {
public: public:
RobotState() = default; RobotState() = delete;
RobotState(const RobotStateType type) : state_type_(type)
{
}
virtual ~RobotState() = default; virtual ~RobotState() = default;
virtual bool parseWith(comm::BinParser& bp) virtual bool parseWith(comm::BinParser& bp)
{ {
return true; return PrimaryPackage::parseWith(bp);
} }
virtual std::string toString() const virtual std::string toString() const
{ {
return std::string(); std::stringstream ss;
ss << "Type: " << static_cast<int>(state_type_) << std::endl;
ss << PrimaryPackage::toString();
return ss.str();
} }
private: private:
RobotStateType state_type_;
}; };
} // namespace primary_interface } // namespace primary_interface

View File

@@ -33,13 +33,21 @@ namespace primary_interface
{ {
bool PrimaryPackage::parseWith(comm::BinParser& bp) bool PrimaryPackage::parseWith(comm::BinParser& bp)
{ {
bp.parseRemainder(buffer_); bp.rawData(buffer_, buffer_length_);
return true; return true;
} }
std::string PrimaryPackage::toString() const std::string PrimaryPackage::toString() const
{ {
return buffer_; std::stringstream ss;
ss << "Raw byte stream: ";
for (size_t i = 0; i < buffer_length_; ++i)
{
uint8_t* buf = buffer_.get();
ss << std::hex << static_cast<int>(buf[i]) << " ";
}
ss << std::endl;
return ss.str();
} }
} // namespace primary_interface } // namespace primary_interface