ADD: added controlmessage
This commit is contained in:
@@ -42,7 +42,9 @@ add_library(SimCore STATIC
|
||||
include/SimCore/Messages/Emission.hpp
|
||||
src/SimCore/Messages/Emission.cpp
|
||||
|
||||
|
||||
include/SimCore/Messages/Control.hpp
|
||||
src/SimCore/Messages/Control.cpp
|
||||
include/SimCore/Messages/Protos/Control.pb.cc
|
||||
|
||||
include/SimCore/Messages/Protos/GeocentricPosition.pb.cc
|
||||
include/SimCore/Messages/Protos/Identifier.pb.cc
|
||||
|
||||
46
include/SimCore/Messages/Control.hpp
Normal file
46
include/SimCore/Messages/Control.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#pragma once
|
||||
|
||||
#include <SimCore/Identifier.hpp>
|
||||
#include <WHISPER/Messages/Message.hpp>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <SimCore/Messages/Protos/Control.pb.h>
|
||||
|
||||
namespace SimCore
|
||||
{
|
||||
class Control
|
||||
{
|
||||
public:
|
||||
Control(const SimCore::Identifier SenderID,ControlType type,std::string data);
|
||||
|
||||
const ControlType Type;
|
||||
|
||||
std::string Data;
|
||||
|
||||
uint64_t Timestamp;
|
||||
|
||||
|
||||
|
||||
|
||||
/// @brief return a WHISPER Message out of a simtrack object
|
||||
/// @param parentID
|
||||
/// @return WHISPER::Message
|
||||
WHISPER::Message buildMessage();
|
||||
|
||||
/// @brief creates a SimTrack out of a whisper message
|
||||
/// @param msg
|
||||
/// @return SimTrack Oject
|
||||
static std::unique_ptr<SimCore::Control> unpack(WHISPER::Message msg);
|
||||
|
||||
/// @brief creates a SimTrack out of a string message
|
||||
/// @param msg
|
||||
/// @return SimTrack Oject
|
||||
static std::unique_ptr<SimCore::Control> unpack(std::string msgString);
|
||||
|
||||
private:
|
||||
const SimCore::Identifier ID_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
9
include/SimCore/Messages/Protos/Control.proto
Normal file
9
include/SimCore/Messages/Protos/Control.proto
Normal file
@@ -0,0 +1,9 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package messages.control;
|
||||
|
||||
message control{
|
||||
uint32 type = 1;
|
||||
string data = 2;
|
||||
optional uint64 timestamp = 3;
|
||||
}
|
||||
@@ -78,6 +78,16 @@ enum TrackKind : std::uint8_t {
|
||||
|
||||
};
|
||||
|
||||
enum ControlType : std::uint32_t
|
||||
{
|
||||
IDENTIFY,
|
||||
START,
|
||||
STOP,
|
||||
CREATE_ENTITY,
|
||||
DELETE_ENTITY,
|
||||
GET_CONTROL
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
71
src/SimCore/Messages/Control.cpp
Normal file
71
src/SimCore/Messages/Control.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include "SimCore/Identifier.hpp"
|
||||
#include "SimCore/Messages/Protos/Control.pb.h"
|
||||
#include "SimCore/SimCore.hpp"
|
||||
#include <SimCore/Messages/Control.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace SimCore
|
||||
{
|
||||
|
||||
Control::Control(const SimCore::Identifier SenderID,ControlType type,std::string data):ID_(SenderID),Type(type),Data(data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
WHISPER::Message Control::buildMessage()
|
||||
{
|
||||
WHISPER::Message msg(ID_.getUUID(),WHISPER::MsgTopics::MANAGEMENT , WHISPER::MsgType::COMMAND);
|
||||
|
||||
|
||||
messages::control::control control;
|
||||
control.set_type(Type);
|
||||
control.set_data(Data);
|
||||
control.set_timestamp(Timestamp);
|
||||
|
||||
auto any = std::make_shared<google::protobuf::Any>();
|
||||
|
||||
any->PackFrom(control);
|
||||
msg.addPayLoad(any);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<SimCore::Control> Control::unpack(WHISPER::Message msg)
|
||||
{
|
||||
auto m = msg.getProtoMessage();
|
||||
|
||||
auto controlMsg = messages::control::control();
|
||||
if(m.payload().Is<messages::control::control>())
|
||||
{
|
||||
m.payload().UnpackTo(&controlMsg);
|
||||
|
||||
SimCore::Identifier id(msg.senderUUID_);
|
||||
|
||||
ControlType kind = (SimCore::ControlType)controlMsg.type();
|
||||
std::string data = controlMsg.data();
|
||||
|
||||
auto control = std::make_unique<Control>(id,kind,data);
|
||||
if (controlMsg.has_timestamp()) control->Timestamp = controlMsg.timestamp();
|
||||
|
||||
// SimCore::Control control(id,kind,data);
|
||||
return control;
|
||||
|
||||
}
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<SimCore::Control> Control::unpack(std::string msgString)
|
||||
{
|
||||
if (std::empty(msgString) == false && msgString != "NULL")
|
||||
{
|
||||
WHISPER::Message whisperMessage(msgString);
|
||||
return std::move(unpack(whisperMessage));
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user