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