From c68f4581788a7d6fc50740c1f153b756782ab186 Mon Sep 17 00:00:00 2001 From: Henry Winkel Date: Mon, 6 Nov 2023 17:48:55 +0100 Subject: [PATCH] ADD: default grid scenario --- Dockerfile | 2 +- include/SimControl/SimControl.hpp | 7 +++ src/SimControl/SimControl.cpp | 91 ++++++++++++++++++++++++++++--- 3 files changed, 92 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index d2eb0ac..2f11b8e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ RUN apt-get upgrade ####### DEBUG packete -RUN apt-get -y install tcpdump nano netcat-openbsd +RUN apt-get -y install tcpdump nano netcat-openbsd htop ######## diff --git a/include/SimControl/SimControl.hpp b/include/SimControl/SimControl.hpp index cf7a1e6..3f37048 100644 --- a/include/SimControl/SimControl.hpp +++ b/include/SimControl/SimControl.hpp @@ -60,6 +60,13 @@ class SimControl{ void updateShip(nlohmann::json request); void deleteShip(nlohmann::json request); + + void saveScenario(); + void loadScenario(std::string ID); + void deleteScenario(std::string ID); + void generateSampleScneario(); + + void startWebApp(); void startWebsocketServer(); diff --git a/src/SimControl/SimControl.cpp b/src/SimControl/SimControl.cpp index 57acd36..b33a5e2 100644 --- a/src/SimControl/SimControl.cpp +++ b/src/SimControl/SimControl.cpp @@ -1,6 +1,7 @@ #include #include #include "DirectCommunicationServer.hpp" +#include "GeographicLib/Geodesic.hpp" #include "SimControl/Tracklist.hpp" #include "SimCore/Messages/Control.hpp" #include "SimCore/Messages/SimTrack.hpp" @@ -180,11 +181,11 @@ namespace SimControl { // The uri the client did connect to. LOG_S(INFO) << "Uri: " << msg->openInfo.uri ; - LOG_S(INFO) << "Headers:" ; - for (auto it : msg->openInfo.headers) - { - LOG_S(INFO)<< "\t" << it.first << ": " << it.second; - } + // LOG_S(INFO) << "Headers:" ; + // for (auto it : msg->openInfo.headers) + // { + // LOG_S(INFO)<< "\t" << it.first << ": " << it.second; + // } } else if (msg->type == ix::WebSocketMessageType::Message) { @@ -225,13 +226,36 @@ namespace SimControl { + }else if (j["Data"] == "Scenario") + { + if(j["Type"] == "Save") + { + + }else if(j["Type"] == "Load") + { + + }else if(j["Type"] == "Delete") + { + + }else if(j["Type"] == "AutoRaster") + { + this->generateSampleScneario(); + } + + + }else if (j["Data"] == "TEST") + { + nlohmann::json response; + response["Message"] = "Hello world"; + websocket.send(response.dump()); + } } catch (const std::exception e) { - LOG_S(ERROR)<< e.what(); + LOG_S(ERROR)<< e.what(); } @@ -267,7 +291,7 @@ namespace SimControl { void SimControl::startNewShip(std::string Name, std::string lat, std::string lon, std::string height , std::string course, std::string speed) { - + LOG_S(INFO)<< "start New Ship"; std::string uuid = xg::newGuid().str(); kubecontrol::KubePod ShipPod1("controller",uuid,"ship","ship:latest",Namespace_); @@ -303,6 +327,8 @@ namespace SimControl { void SimControl::updateShip(nlohmann::json request) { + LOG_S(INFO)<< "Update Ship: "<< request["ID"]; + // if (j["Type"] == ) { // statements // } @@ -375,6 +401,57 @@ namespace SimControl { } + void SimControl::saveScenario() + { + + } + + void SimControl::loadScenario(std::string ID) + { + + } + + void SimControl::deleteScenario(std::string ID) + { + + } + + void SimControl::generateSampleScneario() + { + GeographicLib::Geodesic geod(GeographicLib::Constants::WGS84_a(), GeographicLib::Constants::WGS84_f()); + double lat = 54, lon = 1; + int counter = 0; + double distance = 10000; + + int rasterSize = 10; + + for (int i = 0; i < rasterSize; i++ ) + { + double lonTmp = lon; + for (int a = 0; a < rasterSize; a++) + { + + std::string name = "test"; + name += std::to_string(counter); + double lat2, lon2; + geod.Direct(lat, lonTmp, 90, distance, lat2, lon2); + + SimControl::startNewShip(name, std::to_string(lat2), std::to_string(lon2), "0", "0", "0"); + lonTmp = lon2; + counter ++; + } + double lat2, lon2; + + geod.Direct(lat, lon, 0, distance, lat2, lon2); + + lat = lat2; + + } + + + } + + void SimControl::MainFunction_()