From 1cf89064709ccab6dbf741838b56e3a468e7b947 Mon Sep 17 00:00:00 2001 From: Henry Winkel Date: Fri, 27 Oct 2023 14:23:29 +0200 Subject: [PATCH] ADD: added build and push script and added the possibility to order contacts --- CMakeLists.txt | 1 + Dockerfile | 6 +-- build/libs/SimCore/libs/whisper-comm | 1 - buildDocker.sh | 6 +++ include/SimControl/SimControl.hpp | 10 +++-- include/SimControl/Tracklist.hpp | 4 ++ libs/KubeControl | 2 +- libs/SimCore | 2 +- src/SimControl/SimControl.cpp | 65 +++++++++++++++++++++++++--- src/SimControl/Tracklist.cpp | 11 +++++ 10 files changed, 94 insertions(+), 14 deletions(-) delete mode 160000 build/libs/SimCore/libs/whisper-comm create mode 100755 buildDocker.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index c152405..40d2302 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ IF(NOT TARGET SimCore) ENDIF() IF(NOT TARGET KubeControl) + set(TEST_KUBECONTROL_LIBRARY OFF CACHE BOOL "disable testing") add_subdirectory(libs/KubeControl EXCLUDE_FROM_ALL) ENDIF() diff --git a/Dockerfile b/Dockerfile index 62033fc..d2eb0ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,17 +21,17 @@ RUN apt-get -y install tcpdump nano netcat-openbsd # install all used libs -RUN apt-get -y install libsodium23 libuuid1 libstdc++5 libcurl4 +RUN apt-get -y install libsodium23 libuuid1 libstdc++5 libcurl4 libcurl4-gnutls-dev # copy all custom buld libs COPY build/libs/SimCore/libs/whisper-com/libs/libzmq/lib/libzmq.so.5 /usr/lib/ # COPY build/libs/EntityLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/libprotobuf.so.32 /usr/lib/ -COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/libprotobufd.so.32 /usr/lib/ +COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/libprotobuf.so.32 /usr/lib/ COPY build/libs/SimCore/libs/geographiclib/src/libGeographicLib.so.23 /usr/lib/ COPY build/libs/KubeControl/libs/yaml-cpp/libyaml-cpp.so.0.8 /usr/lib/ COPY build/libs/KubeControl/libs/curlpp/libcurlpp.so.1 /usr/lib/ # COPY build/libs/EntityLibrary/libs/SimCore/libs/crossguid/libcrossguid.so.0 /usr/lib/ -COPY build/libs/SimCore/libs/crossguid/libcrossguid-dgb.so.0 /usr/lib/ +COPY build/libs/SimCore/libs/crossguid/libcrossguid.so.0 /usr/lib/ COPY build/libs/ixwebsocket/libixwebsocket.so.0.1.0 /usr/lib/ diff --git a/build/libs/SimCore/libs/whisper-comm b/build/libs/SimCore/libs/whisper-comm deleted file mode 160000 index f17566c..0000000 --- a/build/libs/SimCore/libs/whisper-comm +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f17566cba09db26b745600249fd449e1fac7bb2d diff --git a/buildDocker.sh b/buildDocker.sh new file mode 100755 index 0000000..fb7ab92 --- /dev/null +++ b/buildDocker.sh @@ -0,0 +1,6 @@ +cd build/ +make -j8 +cd .. +TAG="kmaster.ti.unibw-hamburg.de:30808/simcontrol:latest" +docker build --pull --rm -f "Dockerfile" -t ${TAG} "." +docker image push ${TAG} diff --git a/include/SimControl/SimControl.hpp b/include/SimControl/SimControl.hpp index d524b60..bbb00b5 100644 --- a/include/SimControl/SimControl.hpp +++ b/include/SimControl/SimControl.hpp @@ -55,8 +55,15 @@ class SimControl{ void startShip(std::string name); + void updateShip(nlohmann::json request); + void deleteShip(nlohmann::json request); + void startWebApp(); + void startWebsocketServer(); + void HandleWebsocketMessages(std::shared_ptr connectionState, ix::WebSocket &websocket, const ix::WebSocketMessagePtr &msg); + void HandleBroadcastMessage(std::string msg); + std::unique_ptr PodController_; std::unique_ptr Tracklist_; @@ -73,11 +80,8 @@ class SimControl{ int port = 9999; std::string host = "0.0.0.0"; std::shared_ptr WebsocketServer_ = nullptr; - void startWebsocketServer(); - void HandleWebsocketMessages(std::shared_ptr connectionState, ix::WebSocket &websocket, const ix::WebSocketMessagePtr &msg); std::shared_ptr BroadcastListener_; - void HandleBroadcastMessage(std::string msg); diff --git a/include/SimControl/Tracklist.hpp b/include/SimControl/Tracklist.hpp index 8219a71..fee72dd 100644 --- a/include/SimControl/Tracklist.hpp +++ b/include/SimControl/Tracklist.hpp @@ -19,6 +19,10 @@ namespace SimControl TrackList(); void addTrack(std::shared_ptr Track); std::shared_ptr getTrack(SimCore::Identifier); + + + std::shared_ptr getTrackBySringID(std::string ID); + void getJsonTRackList(nlohmann::json &message); diff --git a/libs/KubeControl b/libs/KubeControl index 49b3605..d40cc7a 160000 --- a/libs/KubeControl +++ b/libs/KubeControl @@ -1 +1 @@ -Subproject commit 49b36053d7dc6f08c05d10d80928597367788046 +Subproject commit d40cc7a8c08ed159c9c10bf0a9257c724a92e317 diff --git a/libs/SimCore b/libs/SimCore index d060f9f..edbea7e 160000 --- a/libs/SimCore +++ b/libs/SimCore @@ -1 +1 @@ -Subproject commit d060f9f2d4dcebc8fb26c07cb63307ba5ea0a757 +Subproject commit edbea7e374bc0772c0666bd0f5d231bf1642710f diff --git a/src/SimControl/SimControl.cpp b/src/SimControl/SimControl.cpp index f2750d5..1f6e95d 100644 --- a/src/SimControl/SimControl.cpp +++ b/src/SimControl/SimControl.cpp @@ -137,7 +137,7 @@ namespace SimControl { auto track = SimCore::SimTrack::unpack(msg); if (track != nullptr) { - LOG_S(INFO)<<"Track received"; + // LOG_S(INFO)<<"Track received"; Tracklist_->addTrack(std::move(track)); } @@ -165,7 +165,7 @@ namespace SimControl { } void SimControl::HandleWebsocketMessages(std::shared_ptr connectionState, ix::WebSocket &websocket, const ix::WebSocketMessagePtr &msg) { - LOG_S(INFO) << "Remote ip: " << connectionState->getRemoteIp(); + // LOG_S(INFO) << "Remote ip: " << connectionState->getRemoteIp(); if (msg->type == ix::WebSocketMessageType::Open) { @@ -195,7 +195,7 @@ namespace SimControl { // LOG_S(INFO)<< "Received: " << msg->str << std::endl; try { nlohmann::json j = nlohmann::json::parse(msg->str); - LOG_S(INFO)<< "Received: " << j["Data"].get() << std::endl; + // LOG_S(INFO)<< "Received: " << j["Data"].get() << std::endl; if (j["Data"] == "COP") { @@ -204,12 +204,17 @@ namespace SimControl { response["Data"] = "COP"; Tracklist_->getJsonTRackList(response); // response.merge_patch(Tracklist_->getJsonTRackList()); - LOG_S(INFO)<startPod(ShipPod1); } + + void SimControl::updateShip(nlohmann::json request) + { + // if (j["Type"] == ) { + // statements + // } + LOG_S(INFO)<< "Entity values:" << request; + auto track = Tracklist_->getTrackBySringID(request["ID"].get()); + Orders::MoveOrder moveOrder(track->getIdentifier()); + if(track != nullptr) + { + LOG_S(INFO)<(); + LOG_S(INFO)<(); + + moveOrder.Speed.setValue(std::stod(request["Speed"].get())); + moveOrder.Course.setValue(std::stod(request["Course"].get())); + } + + if(request["SetPosition"].get() == true) + { + LOG_S(INFO)<<"setting new position"; + SimCore::Position pos; + LOG_S(INFO)<<"LAT: "<(); + LOG_S(INFO)<<"LON: "<(); + + pos.setGeodesicPos(request["Position"][0].get(),request["Position"][1].get(), request["Height"].get()); + moveOrder.setPosition(pos); + + } + + auto info = PodController_->getPodsInfo(request["ID"].get()); + if(info != nullptr) + { + LOG_S(INFO)<<"PODS Info: " <ToJson(); + DirectCommunication::DirectCommunicationClient client(std::stoi(CommandPort_),info->Ip); + client.sendMessage(moveOrder.buildMessage().serialize()); + // client.disconnect(); + } + + } + + void SimControl::deleteShip(nlohmann::json request) + { + + } + void SimControl::startWebApp() { diff --git a/src/SimControl/Tracklist.cpp b/src/SimControl/Tracklist.cpp index fbedf2d..d8c4b09 100644 --- a/src/SimControl/Tracklist.cpp +++ b/src/SimControl/Tracklist.cpp @@ -31,6 +31,15 @@ namespace SimControl return it->second; } + std::shared_ptr TrackList::getTrackBySringID(std::string ID) + { + std::lock_guard lock(mx_); + + auto it = TrackStore_.find(ID); + return it->second; + } + + void TrackList::getJsonTRackList(nlohmann::json &message) { std::lock_guard lock(mx_); @@ -42,7 +51,9 @@ namespace SimControl j["Name"] = it->second->Name.getValue(); j["Course"] = it->second->Course.getValue(); j["Speed"] = it->second->Speed.getValue(); + j["External"] = false; j["Position"] = {it->second->getPosition().getGeodesicPos()[SimCore::LATITUDE], it->second->getPosition().getGeodesicPos()[SimCore::LONGITUDE]}; + j["Height"] = it->second->getPosition().getGeodesicPos()[SimCore::HEIGHT]; j["Type"] = SimCore::Kind::EntityKindMap[it->second->EntityKind.getValue()]; j["Side"] = SimCore::Side::EntitySideMap[it->second->EntitySide.getValue()];