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::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<std::thread> threads;
|
||||
|
||||
@@ -104,8 +106,9 @@ namespace Entities {
|
||||
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 <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));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user