ADD: added new way of handling command messages
This commit is contained in:
@@ -82,6 +82,7 @@ namespace Entities {
|
||||
|
||||
ushort MovemntWorkerPort_;
|
||||
|
||||
std::unique_ptr<kubecontrol::PodController> PodController_;
|
||||
|
||||
|
||||
|
||||
@@ -111,7 +112,6 @@ namespace Entities {
|
||||
void startSensor();
|
||||
|
||||
|
||||
std::unique_ptr<kubecontrol::PodController> PodController_;
|
||||
|
||||
|
||||
std::shared_ptr<std::list<Entities::SensorClientData>> SensorStore_;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "DirectCommunicationServer.hpp"
|
||||
#include "Entities/Movement.hpp"
|
||||
#include "Orders/MoveOrder.hpp"
|
||||
#include "SimCore/Messages/Control.hpp"
|
||||
#include "SimCore/Messages/SimTrack.hpp"
|
||||
#include "SimCore/UtilFunctions.hpp"
|
||||
#include "WHISPER/InternalUDPListener.hpp"
|
||||
@@ -17,6 +18,8 @@
|
||||
#include <Entities/Entity.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -58,9 +61,8 @@ namespace Entities
|
||||
|
||||
Entity::~Entity()
|
||||
{
|
||||
PodController_->stopAllPods();
|
||||
stop();
|
||||
MovemtServer_.reset();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -121,6 +123,12 @@ namespace Entities
|
||||
|
||||
void Entity::stop()
|
||||
{
|
||||
|
||||
|
||||
PodController_->stopAllPods();
|
||||
|
||||
MovemtServer_.reset();
|
||||
|
||||
stopMainLoop = true;
|
||||
|
||||
|
||||
@@ -136,8 +144,9 @@ namespace Entities
|
||||
}
|
||||
|
||||
LOG_S(ERROR)<< threads.size();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(30000));
|
||||
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void Entity::startMovementWorker()
|
||||
@@ -145,8 +154,10 @@ namespace Entities
|
||||
if (online_ == true) {
|
||||
LOG_S(INFO)<<"__ONLINE__";
|
||||
MovementPodUUID_ = xg::newGuid().str();
|
||||
auto MovementPod = kubecontrol::KubePod(MovementPodUUID_,MovementPodUUID_,"movementimage:latest");
|
||||
LOG_S(INFO)<<this->OwnShipTrack->getIdentifier().getUUID();
|
||||
auto MovementPod = kubecontrol::KubePod(this->OwnShipTrack->getIdentifier().getUUID(),MovementPodUUID_,"movementimage:latest");
|
||||
MovementPod.setEnvironmentVar("SERVER_IP", SimCore::UtilFunctions::getOwnIP());
|
||||
MovementPod.setComponent("MovementCalculation");
|
||||
LOG_S(INFO)<< MovementPod.createYAML();
|
||||
PodController_->startPod(MovementPod);
|
||||
LOG_S(INFO)<<PodController_->getServerAddress();
|
||||
@@ -190,6 +201,7 @@ namespace Entities
|
||||
if (MovemtServer_->countClients() == 0)
|
||||
{
|
||||
MovementWorkerStarted = false;
|
||||
LOG_S(WARNING)<<"Movementclient lost";
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
|
||||
@@ -197,23 +209,68 @@ namespace Entities
|
||||
|
||||
void Entity::handleExternalComms(std::string msg)
|
||||
{
|
||||
// LOG_S(INFO)<<msg;
|
||||
auto MoveOrder = Orders::MoveOrder::unpack(msg);
|
||||
try {
|
||||
|
||||
if (MoveOrder != nullptr)
|
||||
{
|
||||
if(MoveOrder->Speed.isValid()) this->setSpeed(MoveOrder->Speed.getValue());
|
||||
if(MoveOrder->Course.isValid()) this->setCourse(MoveOrder->Course.getValue());
|
||||
if(MoveOrder->getPosition().isValid())
|
||||
|
||||
WHISPER::Message whisperMsg(msg);
|
||||
|
||||
switch (whisperMsg.msgType_)
|
||||
{
|
||||
case WHISPER::MsgType::ORDER:
|
||||
{
|
||||
|
||||
auto MoveOrder = Orders::MoveOrder::unpack(whisperMsg);
|
||||
if (MoveOrder != nullptr)
|
||||
{
|
||||
LOG_S(INFO)<<"New Position received";
|
||||
if(MoveOrder->Speed.isValid()) this->setSpeed(MoveOrder->Speed.getValue());
|
||||
if(MoveOrder->Course.isValid()) this->setCourse(MoveOrder->Course.getValue());
|
||||
if(MoveOrder->getPosition().isValid())
|
||||
{
|
||||
LOG_S(INFO)<<"New Position received";
|
||||
|
||||
this->setPosition(MoveOrder->getPosition());
|
||||
this->setPosition(MoveOrder->getPosition());
|
||||
}
|
||||
}
|
||||
// CommandCommsServer_->sendMessage("Hello Client");
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
case WHISPER::MsgType::COMMAND:
|
||||
{
|
||||
std::unique_ptr<SimCore::Control> control = std::move(SimCore::Control::unpack(whisperMsg));
|
||||
switch (control->Type)
|
||||
{
|
||||
case SimCore::IDENTIFY :
|
||||
case SimCore::START:
|
||||
case SimCore::STOP :
|
||||
case SimCore::SHUT_DOWN :
|
||||
{
|
||||
LOG_S(INFO)<<"shutdown received";
|
||||
this->stop();
|
||||
}
|
||||
case SimCore::CREATE_ENTITY:
|
||||
case SimCore::DELETE_ENTITY :
|
||||
case SimCore::GET_CONTROL:
|
||||
|
||||
break;
|
||||
};
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} catch (std::exception &e) {
|
||||
LOG_S(ERROR)<<e.what();
|
||||
}
|
||||
|
||||
|
||||
|
||||
LOG_S(INFO)<<"sending";
|
||||
CommandCommsServer_->sendMessage(this->OwnShipTrack->buildMessage().serialize());
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user