From 9c8ffad475f077a9f8daac90f5592687fed2373b Mon Sep 17 00:00:00 2001 From: Henry Winkel Date: Wed, 9 Aug 2023 17:07:31 +0200 Subject: [PATCH] ADD: added new server for external comms but it is just in a experimental phase --- include/Entities/Entity.hpp | 7 +++-- libs/KubeControl | 2 +- libs/SimCore | 2 +- libs/json | 2 +- src/Entities/Entity.cpp | 53 ++++++++++++++++++++++++++----------- 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/include/Entities/Entity.hpp b/include/Entities/Entity.hpp index af45058..b3bb54c 100644 --- a/include/Entities/Entity.hpp +++ b/include/Entities/Entity.hpp @@ -58,7 +58,8 @@ namespace Entities { SimCore::Identifier ParentID, SimCore::EntityKind EntityKind, std::uint32_t GroundTruthPort, - ushort CommandPort); + ushort CommandPort, + bool online); ~Entity(); void start(); @@ -91,6 +92,7 @@ namespace Entities { private: + bool online_; std::vector threads; @@ -104,8 +106,9 @@ namespace Entities { void handleMovement(); - + std::shared_ptr ExternalCommsServer_ = nullptr; + void handleExternalComms(std::string msg); diff --git a/libs/KubeControl b/libs/KubeControl index 96495f4..681338d 160000 --- a/libs/KubeControl +++ b/libs/KubeControl @@ -1 +1 @@ -Subproject commit 96495f44eadb56f5e8115c2a171310304527a227 +Subproject commit 681338d945ee514755a13536fbae1156145edc12 diff --git a/libs/SimCore b/libs/SimCore index 0123a22..5e8b1b8 160000 --- a/libs/SimCore +++ b/libs/SimCore @@ -1 +1 @@ -Subproject commit 0123a22aacae6973146bada32d966fcaa58dbddc +Subproject commit 5e8b1b84e893946c62fab79783c13c5fe2ee3949 diff --git a/libs/json b/libs/json index a0c1318..5d27543 160000 --- a/libs/json +++ b/libs/json @@ -1 +1 @@ -Subproject commit a0c1318830519eac027a31edec1a99ce1ae5670e +Subproject commit 5d2754306d67d1e654a1a34e1d2e74439a9d53b3 diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index aa59ba0..d99330d 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -17,12 +17,17 @@ #include #include +#include #include +#include #include #define __MOVEMENT_SERVER_PORT__ 5556 +#define __EXTERNAL_SERVER_PORT__ 5557 + + namespace Entities { @@ -33,20 +38,23 @@ namespace Entities SimCore::Identifier ParentID, SimCore::EntityKind EntityKind, std::uint32_t GroundTruthPort, - ushort CommandPort): + ushort CommandPort, + bool online): EntityName_(EnttityName), ParentID_(ParentID), - EntityKind_(EntityKind) + EntityKind_(EntityKind), + online_(online) { PodController_ = std::make_unique("docs/config"); OwnShipTrack = std::make_shared(OwnID, OwnType, EntityKind); OwnShipTrack->setPosition(SimCore::Position()); - MovemtServer_ = std::make_shared(__MOVEMENT_SERVER_PORT__); - + MovemtServer_ = std::make_shared(__MOVEMENT_SERVER_PORT__); + // ExternalCommsServer_ = std::make_shared(8000); + // ExternalCommsServer_->registerMessageCallback(std::bind(&Entity::handleExternalComms,this,std::placeholders::_1)); } @@ -135,15 +143,20 @@ namespace Entities void Entity::startMovementWorker() { - auto MovementPod = kubecontrol::KubePod("movmentpod-"+EntityName_,xg::newGuid().str(),"movementimage:latest"); + if (online_ == true) { + LOG_S(INFO)<<"__ONLINE__"; + auto MovementPod = kubecontrol::KubePod("movmentpod-"+EntityName_,xg::newGuid().str(),"movementimage:latest"); + MovementPod.setEnvironmentVar("SERVER_IP", SimCore::UtilFunctions::getOwnIP()); + LOG_S(INFO)<< MovementPod.createYAML(); + PodController_->startPod(MovementPod); + LOG_S(INFO)<getServerAddress(); + 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)); + } - MovementPod.setEnvironmentVar("SERVER_IP", SimCore::UtilFunctions::getOwnIP()); - LOG_S(INFO)<< MovementPod.createYAML(); - PodController_->startPod(MovementPod); - LOG_S(INFO)<getServerAddress(); - std::this_thread::sleep_for(std::chrono::milliseconds(5000)); - - LOG_S(INFO)<< "TODO: starting the movement app from here"; if (MovemtServer_->countClients() > 0 ) { @@ -171,22 +184,32 @@ namespace Entities if (newTrack != nullptr) { 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)<ExternalCommsServer_->countClients(); } + void Entity::MainLoop() { - + auto server = DirectCommunication::DirectCommunicationServer(35000); LOG_S(INFO)<< "main loop started"; while (!stopMainLoop) { handleMovement(); - + LOG_S(INFO)<