ADD: added new server for external comms but it is just in a experimental phase

This commit is contained in:
Henry Winkel
2023-08-09 17:07:31 +02:00
parent 14cc61d8c7
commit 9c8ffad475
5 changed files with 46 additions and 20 deletions

View File

@@ -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);

View File

@@ -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,20 +38,23 @@ 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");
OwnShipTrack = std::make_shared<SimCore::SimTrack>(OwnID, OwnType, EntityKind); OwnShipTrack = std::make_shared<SimCore::SimTrack>(OwnID, OwnType, EntityKind);
OwnShipTrack->setPosition(SimCore::Position()); OwnShipTrack->setPosition(SimCore::Position());
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()
{ {
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)<<PodController_->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)<<PodController_->getServerAddress();
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));