From bbf4be8108a415d04d82a27802f5cdacb174b265 Mon Sep 17 00:00:00 2001 From: Henry Winkel Date: Thu, 10 Aug 2023 17:18:10 +0200 Subject: [PATCH] ADD: added functionality to show the position in a simtrack of a connected ship --- CMakeLists.txt | 7 ++- include/SimControl/SimControl.hpp | 16 +++++- src/SimControl/SimControl.cpp | 96 ++++++++++++++++++++++++++----- src/main.cpp | 34 +++++++---- 4 files changed, 125 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b92a0d..f45352c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required (VERSION 3.1 FATAL_ERROR) -project (EntitiyManager VERSION 0.1.0 LANGUAGES CXX C) +project (SimControlApplication VERSION 0.1.0 LANGUAGES CXX C) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) include(defaultOptions) @@ -58,6 +58,11 @@ target_link_libraries(SimControlApplication SimControl ) + +add_custom_command(TARGET SimControlApplication POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + ${CMAKE_CURRENT_SOURCE_DIR}/libs/EntityLibrary/libs/KubeControl/docs $/docs) + # target_include_directories(EntitiyManagerApplication # PRIVATE # src) diff --git a/include/SimControl/SimControl.hpp b/include/SimControl/SimControl.hpp index ae01a48..652a618 100644 --- a/include/SimControl/SimControl.hpp +++ b/include/SimControl/SimControl.hpp @@ -2,6 +2,9 @@ #define __SIMCONTROL__ #include "DirectCommunicationClient.hpp" +#include "SimCore/Identifier.hpp" +#include "crossguid/guid.hpp" +#include "kubecontrol/PodController.hpp" #include @@ -9,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -22,15 +26,23 @@ namespace SimControl { class SimControl{ public: - SimControl( std::string addr, ushort port); + SimControl(ushort CommandPort); ~SimControl(); + void stop(); private: - + const SimCore::Identifier ID_; + ushort CommandPort_; void MainFunction_(); void HandleMessage(std::string msg); + std::unique_ptr PodController_; + + + std::thread MainThread_; + std::atomic stopMainThread_ = false; + std::unique_ptr TCPClient_; diff --git a/src/SimControl/SimControl.cpp b/src/SimControl/SimControl.cpp index 97a2775..653e43b 100644 --- a/src/SimControl/SimControl.cpp +++ b/src/SimControl/SimControl.cpp @@ -1,3 +1,10 @@ +#include "Orders/MoveOrder.hpp" +#include "SimCore/Identifier.hpp" +#include "SimCore/Messages/SimTrack.hpp" +#include "WHISPER/Messages/Message.hpp" +#include "crossguid/guid.hpp" +#include "kubecontrol/KubePod.hpp" +#include "kubecontrol/PodController.hpp" #include @@ -5,32 +12,93 @@ #include #include #include +#include namespace SimControl { - SimControl::SimControl( std::string addr, ushort port) - { + SimControl::SimControl( ushort CommandPort):CommandPort_(CommandPort),ID_(SimCore::Identifier(xg::newGuid())) + { + PodController_ = std::make_unique("docs/config"); - TCPClient_ = std::make_unique(port,addr); - TCPClient_->registerMessageCallback(std::bind(&SimControl::HandleMessage,this,std::placeholders::_1)); - TCPClient_->sendMessage("Hello Server"); + TCPClient_ = std::make_unique(30200,"192.168.252.6"); + TCPClient_->registerMessageCallback(std::bind(&SimControl::HandleMessage,this,std::placeholders::_1)); + TCPClient_->sendMessage("Hello Server"); - } + this->stopMainThread_ = false; + MainThread_ = std::thread(&SimControl::MainFunction_,this); - SimControl::~SimControl() - { - TCPClient_ = nullptr; + } - } + SimControl::~SimControl() + { + this->stopMainThread_ = true; - void SimControl::HandleMessage(std::string msg) - { + TCPClient_ = nullptr; - LOG_S(INFO)<stopMainThread_ = true; + TCPClient_.reset(); + + + } + + void SimControl::HandleMessage(std::string msg) + { + TCPClient_->sendMessage("Hello Server") ; + // LOG_S(INFO)<(simtrack->getPosition()); + LOG_S(INFO)<< " pos: Lat= "<< OwnShipPos->getGeodesicPos().x() << "Lon= "<< OwnShipPos->getGeodesicPos().y(); + } + std::this_thread::sleep_for(std::chrono::milliseconds(500)); + + + } + + + + void SimControl::MainFunction_() + { + + kubecontrol::KubePod ShipPod1("hamburg","ship1","ship:latest"); + ShipPod1.setEnvironmentVar("ENTITY_ID", "ship1"); + ShipPod1.setEnvironmentVar("ENTITY_NAME", "hamburg"); + ShipPod1.setEnvironmentVar("POS_LAT", "\"55\""); + ShipPod1.setEnvironmentVar("POS_LONG", "\"8\""); + ShipPod1.setEnvironmentVar("POS_HEIGHT", "\"0\""); + ShipPod1.setEnvironmentVar("GROUNDTRUTH_PORT", "\"8000\""); + ShipPod1.setEnvironmentVar("COMMAND_PORT", "\"5555\""); + + ShipPod1.createYAML(); + + + Orders::MoveOrder order(this->ID_,WHISPER::SourceType::SIMCOMTROLER); + order.Speed.setValue(5.14444); + TCPClient_->sendMessage(order.buildMessage().serialize()); + + + // std::this_thread::sleep_for(std::chrono::milliseconds(3000)); + // TCPClient_->disconnect(); + // TCPClient_.reset(); + + while (!stopMainThread_) + { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + + + } + // std::this_thread::sleep_for(std::chrono::milliseconds(3000)); + TCPClient_->disconnect(); + LOG_S(INFO)<<"main func stopped"; + } diff --git a/src/main.cpp b/src/main.cpp index 972c89d..124d569 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,4 @@ +#include "Orders/MoveOrder.hpp" #include #include #include @@ -32,26 +33,37 @@ int main() sigIntHandler.sa_flags = 0; sigaction(SIGINT, &sigIntHandler, NULL); - ushort port = 3500; - // SimControl::SimControl sc("127.0.0.1",5557); + const char* CommandPortChar = "31371"; + if (std::getenv("COMMAND_PORT") != nullptr) { + CommandPortChar = std::getenv("COMMAND_PORT"); + } + ushort commandPort_ = (unsigned short)strtol(CommandPortChar,NULL,0); - DirectCommunication::DirectCommunicationClient client(port,"127.0.0.1"); + const char *ServerAddress = nullptr; + + ServerAddress = std::getenv("SERVER_IP"); + if (ServerAddress == nullptr) { + ServerAddress = "127.0.0.1"; + } + + LOG_S(INFO)<