diff --git a/Dockerfile b/Dockerfile index bdb9c66..49782f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,7 +46,7 @@ COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_p COPY build/libs/OrderLibrary/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/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.so.0 /usr/lib/ diff --git a/include/SimControl/Tracklist.hpp b/include/SimControl/Tracklist.hpp index 9d083ae..6bff837 100644 --- a/include/SimControl/Tracklist.hpp +++ b/include/SimControl/Tracklist.hpp @@ -45,7 +45,7 @@ namespace SimControl void checkTracksTimeout(); - const int TrackTimeoutTime = 12; + const int TrackTimeoutTime = 6; }; diff --git a/libs/ixwebsocket b/libs/ixwebsocket index c5a02f1..f29906c 160000 --- a/libs/ixwebsocket +++ b/libs/ixwebsocket @@ -1 +1 @@ -Subproject commit c5a02f1066fb0fde48f80f51178429a27f689a39 +Subproject commit f29906c72f1739e0c373495cde068923a88c2cc2 diff --git a/src/SimControl/SimControl.cpp b/src/SimControl/SimControl.cpp index 781e17d..c0d5bed 100644 --- a/src/SimControl/SimControl.cpp +++ b/src/SimControl/SimControl.cpp @@ -54,18 +54,7 @@ namespace SimControl { PodController_ = std::make_unique("docs/config"); } - // ExternalTCPServer_ = std::make_shared(5000,ID_.getUUID()); - // ExternalTCPServer_->registerMessageCallback(std::bind(&SimControl::HandleTCPMessage,this,std::placeholders::_1)); - - - // TCPClient_ = std::make_unique(30200,"192.168.252.6"); - // TCPClient_ = std::make_unique(5555,"127.0.0.1"); - - // TCPClient_->registerMessageCallback(std::bind(&SimControl::HandleMessage,this,std::placeholders::_1)); - // TCPClient_->sendMessage("Hello Server"); - - - + WebsocketServer_ = std::make_shared(port,host); WebsocketServer_->setOnClientMessageCallback( [this](std::shared_ptr connectionState, ix::WebSocket &websocket, const ix::WebSocketMessagePtr &msg) { @@ -146,7 +135,7 @@ namespace SimControl { void SimControl::HandleBroadcastMessage(std::string msg) { - // LOG_S(INFO)<addTrack(item); + LOG_S(INFO)<getTracklistSize(); } @@ -185,7 +175,7 @@ namespace SimControl { if (msg->type == ix::WebSocketMessageType::Open) { - // LOG_S(INFO)<< "New connection" ; + LOG_S(INFO)<< "New connection" ; // A connection state object is available, and has a default id // You can subclass ConnectionState and pass an alternate factory @@ -206,15 +196,14 @@ namespace SimControl { { try { nlohmann::json j = nlohmann::json::parse(msg->str); + if (j["Data"] == "COP") { if (j["Type"] == "Request") { nlohmann::json response; response["Data"] = "COP"; Tracklist_->getJsonTRackList(response); - LOG_S(INFO)<<"Tracklist size: " << Tracklist_->getTracklistSize(); - - // LOG_S(INFO)<getTrackListForEntity(j["ID"].get(),response); - websocket.send(response.dump()); } @@ -399,9 +387,7 @@ namespace SimControl { { LOG_S(INFO)<< "Update Ship: "<< request["ID"]; - // if (j["Type"] == ) { - // statements - // } + LOG_S(INFO)<< "Entity values:" << request; auto track = Tracklist_->getTrackBySringID(request["ID"].get()); Orders::MoveOrder moveOrder(track->getIdentifier()); @@ -494,6 +480,7 @@ namespace SimControl { auto update = SimCore::TracklistUpdate::unpack(WHISPER::Message(response)); if(update == nullptr) { + LOG_S(INFO)<<"no update received"; return; } try diff --git a/src/SimControl/Tracklist.cpp b/src/SimControl/Tracklist.cpp index 0e0c697..fe7d2dd 100644 --- a/src/SimControl/Tracklist.cpp +++ b/src/SimControl/Tracklist.cpp @@ -20,19 +20,9 @@ namespace SimControl void TrackList::addTrack(std::shared_ptr Track) { + std::lock_guard lock(mx_); - // LOG_S(INFO)<getIdentifier().getUUID()); - // if (it == markedAsDeletedTracks_.end() ) - // { - // auto [iterator, inserted] = TrackStore_.try_emplace(Track->getIdentifier().getUUID(),Track); - // if (!inserted) { iterator->second = Track; } - - // } - auto [iterator, inserted] = TrackStore_.try_emplace(Track->getIdentifier().getUUID(),Track); if (!inserted) @@ -41,10 +31,11 @@ namespace SimControl { iterator->second = Track; } + }else { + mx_.unlock(); + LOG_S(INFO)<< "Track added new Size:" << this->getTracklistSize(); } - - } @@ -55,7 +46,7 @@ namespace SimControl for (std::map>::iterator it=TrackStore_.begin(); it != TrackStore_.end();) { - if ((time(0) - it->second->getLastUpdateTimestamp())>= 6 ) + if ((time(0) - it->second->getLastUpdateTimestamp())>= TrackTimeoutTime ) { it = TrackStore_.erase(it); }else { @@ -141,8 +132,9 @@ namespace SimControl size_t TrackList::getTracklistSize() { std::lock_guard lock(mx_); + size_t size = this->TrackStore_.size(); + return size; - return this->TrackStore_.size(); } diff --git a/tests/test_Simcontrol.cpp b/tests/test_Simcontrol.cpp index 709a6f0..de4ea24 100644 --- a/tests/test_Simcontrol.cpp +++ b/tests/test_Simcontrol.cpp @@ -2,6 +2,7 @@ #include "SimControl/SimControl.hpp" +#include "SimCore/Messages/SensorTrack.hpp" #include "nlohmann/json_fwd.hpp" #include #include @@ -95,7 +96,7 @@ void addTracksToTracklistUpdate(SimCore::TracklistUpdate *update, int amount) for(int i = 0; i < amount; i++) { std::string name = "test1-" + std::to_string(i); - auto track = std::make_shared(name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL); + auto track = std::make_shared(name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL); SimCore::Position pos; double lat = fRand(-90, 90); double lon = fRand(-180, 180); diff --git a/tests/test_tracklist.cpp b/tests/test_tracklist.cpp index fcc3157..0aa25bb 100644 --- a/tests/test_tracklist.cpp +++ b/tests/test_tracklist.cpp @@ -96,7 +96,9 @@ auto track = list.getTrackBySringID(ids[3]); list.addTrack(std::make_shared(*track)); // REQUIRE(list.getTracklistSize() == 24); + LOG_S(INFO)<<"wait for 7500ms"; std::this_thread::sleep_for(std::chrono::milliseconds(7500)); + LOG_S(INFO)<<"continue"; LOG_S(INFO)<<"add saved track"; list.addTrack(std::make_shared(*track)); LOG_S(INFO)<<"added saved track";