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

@@ -17,12 +17,17 @@
#include <Entities/Entity.hpp>
#include <chrono>
#include <functional>
#include <memory>
#include <string>
#include <thread>
#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<kubecontrol::PodController>("docs/config");
OwnShipTrack = std::make_shared<SimCore::SimTrack>(OwnID, OwnType, EntityKind);
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()
{
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 )
{
@@ -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)<<msg;
LOG_S(INFO)<<this->ExternalCommsServer_->countClients();
}
void Entity::MainLoop()
{
auto server = DirectCommunication::DirectCommunicationServer(35000);
LOG_S(INFO)<< "main loop started";
while (!stopMainLoop)
{
handleMovement();
LOG_S(INFO)<<server.countClients();
server.sendMessage("hello client");
LOG_S(INFO)<<"hello";
std::this_thread::sleep_for(std::chrono::milliseconds(500));