ADD: added new server for external comms but it is just in a experimental phase
This commit is contained in:
@@ -58,7 +58,8 @@ namespace Entities {
|
|||||||
SimCore::Identifier ParentID,
|
SimCore::Identifier ParentID,
|
||||||
SimCore::EntityKind EntityKind,
|
SimCore::EntityKind EntityKind,
|
||||||
std::uint32_t GroundTruthPort,
|
std::uint32_t GroundTruthPort,
|
||||||
ushort CommandPort);
|
ushort CommandPort,
|
||||||
|
bool online);
|
||||||
~Entity();
|
~Entity();
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
@@ -91,6 +92,7 @@ namespace Entities {
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool online_;
|
||||||
|
|
||||||
std::vector<std::thread> threads;
|
std::vector<std::thread> threads;
|
||||||
|
|
||||||
@@ -104,8 +106,9 @@ namespace Entities {
|
|||||||
void handleMovement();
|
void handleMovement();
|
||||||
|
|
||||||
|
|
||||||
|
std::shared_ptr<DirectCommunication::DirectCommunicationServer> ExternalCommsServer_ = nullptr;
|
||||||
|
|
||||||
|
void handleExternalComms(std::string msg);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Submodule libs/KubeControl updated: 96495f44ea...681338d945
Submodule libs/SimCore updated: 0123a22aac...5e8b1b84e8
Submodule libs/json updated: a0c1318830...5d2754306d
@@ -17,12 +17,17 @@
|
|||||||
#include <Entities/Entity.hpp>
|
#include <Entities/Entity.hpp>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define __MOVEMENT_SERVER_PORT__ 5556
|
#define __MOVEMENT_SERVER_PORT__ 5556
|
||||||
|
#define __EXTERNAL_SERVER_PORT__ 5557
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace Entities
|
namespace Entities
|
||||||
{
|
{
|
||||||
@@ -33,10 +38,12 @@ namespace Entities
|
|||||||
SimCore::Identifier ParentID,
|
SimCore::Identifier ParentID,
|
||||||
SimCore::EntityKind EntityKind,
|
SimCore::EntityKind EntityKind,
|
||||||
std::uint32_t GroundTruthPort,
|
std::uint32_t GroundTruthPort,
|
||||||
ushort CommandPort):
|
ushort CommandPort,
|
||||||
|
bool online):
|
||||||
EntityName_(EnttityName),
|
EntityName_(EnttityName),
|
||||||
ParentID_(ParentID),
|
ParentID_(ParentID),
|
||||||
EntityKind_(EntityKind)
|
EntityKind_(EntityKind),
|
||||||
|
online_(online)
|
||||||
|
|
||||||
{
|
{
|
||||||
PodController_ = std::make_unique<kubecontrol::PodController>("docs/config");
|
PodController_ = std::make_unique<kubecontrol::PodController>("docs/config");
|
||||||
@@ -45,8 +52,9 @@ namespace Entities
|
|||||||
|
|
||||||
MovemtServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(__MOVEMENT_SERVER_PORT__);
|
MovemtServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(__MOVEMENT_SERVER_PORT__);
|
||||||
|
|
||||||
|
// ExternalCommsServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(8000);
|
||||||
|
|
||||||
|
// ExternalCommsServer_->registerMessageCallback(std::bind(&Entity::handleExternalComms,this,std::placeholders::_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -135,15 +143,20 @@ namespace Entities
|
|||||||
|
|
||||||
void Entity::startMovementWorker()
|
void Entity::startMovementWorker()
|
||||||
{
|
{
|
||||||
|
if (online_ == true) {
|
||||||
|
LOG_S(INFO)<<"__ONLINE__";
|
||||||
auto MovementPod = kubecontrol::KubePod("movmentpod-"+EntityName_,xg::newGuid().str(),"movementimage:latest");
|
auto MovementPod = kubecontrol::KubePod("movmentpod-"+EntityName_,xg::newGuid().str(),"movementimage:latest");
|
||||||
|
|
||||||
MovementPod.setEnvironmentVar("SERVER_IP", SimCore::UtilFunctions::getOwnIP());
|
MovementPod.setEnvironmentVar("SERVER_IP", SimCore::UtilFunctions::getOwnIP());
|
||||||
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();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
||||||
|
}else {
|
||||||
|
|
||||||
|
LOG_S(INFO)<< "Wait for MomentApp";
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
|
||||||
|
}
|
||||||
|
|
||||||
LOG_S(INFO)<< "TODO: starting the movement app from here";
|
|
||||||
|
|
||||||
if (MovemtServer_->countClients() > 0 )
|
if (MovemtServer_->countClients() > 0 )
|
||||||
{
|
{
|
||||||
@@ -171,22 +184,32 @@ namespace Entities
|
|||||||
if (newTrack != nullptr)
|
if (newTrack != nullptr)
|
||||||
{
|
{
|
||||||
OwnShipTrack->setPosition(newTrack->getPosition());
|
OwnShipTrack->setPosition(newTrack->getPosition());
|
||||||
LOG_S(INFO)<< "new POS: LAT: "<< OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LATITUDE) << " LON: " << OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LONGITUDE);
|
// LOG_S(INFO)<< "new POS: LAT: "<< OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LATITUDE) << " LON: " << OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LONGITUDE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Entity::handleExternalComms(std::string msg)
|
||||||
|
{
|
||||||
|
LOG_S(INFO)<<msg;
|
||||||
|
|
||||||
|
LOG_S(INFO)<<this->ExternalCommsServer_->countClients();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Entity::MainLoop()
|
void Entity::MainLoop()
|
||||||
{
|
{
|
||||||
|
auto server = DirectCommunication::DirectCommunicationServer(35000);
|
||||||
LOG_S(INFO)<< "main loop started";
|
LOG_S(INFO)<< "main loop started";
|
||||||
while (!stopMainLoop)
|
while (!stopMainLoop)
|
||||||
{
|
{
|
||||||
handleMovement();
|
handleMovement();
|
||||||
|
LOG_S(INFO)<<server.countClients();
|
||||||
|
server.sendMessage("hello client");
|
||||||
|
LOG_S(INFO)<<"hello";
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user