ADD: updated tracklist for simcontroll
This commit is contained in:
@@ -47,7 +47,10 @@ add_library(SimControl STATIC
|
|||||||
|
|
||||||
include/SimControl/Tracklist.hpp
|
include/SimControl/Tracklist.hpp
|
||||||
src/SimControl/Tracklist.cpp
|
src/SimControl/Tracklist.cpp
|
||||||
)
|
|
||||||
|
include/SimControl/TrackItem.hpp
|
||||||
|
src/SimControl/TrackItem.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(SimControl
|
target_link_libraries(SimControl
|
||||||
|
|||||||
39
Dockerfile
39
Dockerfile
@@ -24,32 +24,33 @@ RUN apt-get -y install tcpdump nano netcat-openbsd htop
|
|||||||
RUN apt-get -y install libsodium23 libuuid1 libstdc++5 libcurl4 libcurl4-gnutls-dev
|
RUN apt-get -y install libsodium23 libuuid1 libstdc++5 libcurl4 libcurl4-gnutls-dev
|
||||||
|
|
||||||
# copy all custom buld libs
|
# copy all custom buld libs
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/libzmq/lib/libzmq.so.5 /usr/lib/
|
|
||||||
|
COPY build/libs/OrderLibrary/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/EntityLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/libprotobuf.so.32 /usr/lib/
|
||||||
# COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/libprotobuf.so.32 /usr/lib/
|
# COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/libprotobuf.so.32 /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/libprotobufd.so.25.0.0 /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/libprotobuf*.so.25.0.0 /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/crc/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/crc/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/base/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/base/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/log/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/log/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/debugging/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/debugging/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/flags/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/flags/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/container/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/container/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/hash/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/hash/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/numeric/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/numeric/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/profiling/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/profiling/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/status/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/status/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/strings/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/strings/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/synchronization/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/synchronization/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/time/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/time/*.so.* /usr/lib/
|
||||||
COPY build/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/types/*.so.* /usr/lib/
|
COPY build/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/third_party/abseil-cpp/absl/types/*.so.* /usr/lib/
|
||||||
|
|
||||||
|
|
||||||
COPY build/libs/SimCore/libs/geographiclib/src/libGeographicLib.so.23 /usr/lib/
|
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/KubeControl/libs/curlpp/libcurlpp.so.1 /usr/lib/
|
||||||
# COPY build/libs/EntityLibrary/libs/SimCore/libs/crossguid/libcrossguid.so.0 /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/
|
# COPY build/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-dgb.so.0 /usr/lib/
|
||||||
|
|
||||||
COPY build/libs/ixwebsocket/libixwebsocket.so.0.1.0 /usr/lib/
|
COPY build/libs/ixwebsocket/libixwebsocket.so.0.1.0 /usr/lib/
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class SimControl{
|
|||||||
|
|
||||||
|
|
||||||
void startShip(std::string name);
|
void startShip(std::string name);
|
||||||
void startNewShip(std::string Name, std::string lat, std::string lon, std::string height , std::string course, std::string speed);
|
void startNewShip(std::string Name, std::string lat, std::string lon, std::string height , std::string course, std::string speed, bool WaitTillRunning = true);
|
||||||
void updateShip(nlohmann::json request);
|
void updateShip(nlohmann::json request);
|
||||||
void deleteShip(nlohmann::json request);
|
void deleteShip(nlohmann::json request);
|
||||||
|
|
||||||
|
|||||||
65
include/SimControl/TrackItem.hpp
Normal file
65
include/SimControl/TrackItem.hpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "SimCore/Messages/SimTrack.hpp"
|
||||||
|
#include "nlohmann/json_fwd.hpp"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace SimControl
|
||||||
|
{
|
||||||
|
|
||||||
|
class TrackItem : public SimCore::SimTrack
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Construct a new Track Item object
|
||||||
|
*
|
||||||
|
* @param track
|
||||||
|
*/
|
||||||
|
TrackItem(SimCore::SimTrack track);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief mark track as deleteed
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void markAsDelete();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @return true if is marked as deleted
|
||||||
|
* @return false if not
|
||||||
|
*/
|
||||||
|
bool isMarkedAsDelete();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get the Last Update Timestamp object
|
||||||
|
*
|
||||||
|
* @return std::chrono::time_point<std::chrono::system_clock>
|
||||||
|
*/
|
||||||
|
std::time_t getLastUpdateTimestamp();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @return nlohmann::json
|
||||||
|
*/
|
||||||
|
nlohmann::json toJSON();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* @return std::string
|
||||||
|
*/
|
||||||
|
std::string toString();
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool markedAsDeleted;
|
||||||
|
std::time_t lastReceiveTimestamp_;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
#include "nlohmann/json_fwd.hpp"
|
#include "nlohmann/json_fwd.hpp"
|
||||||
#include <SimCore/Identifier.hpp>
|
#include <SimCore/Identifier.hpp>
|
||||||
#include <SimCore/Messages/SimTrack.hpp>
|
#include <SimControl/TrackItem.hpp>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -13,17 +13,20 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace SimControl
|
namespace SimControl
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TrackList
|
class TrackList
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TrackList();
|
TrackList();
|
||||||
void addTrack(std::shared_ptr<SimCore::SimTrack> Track);
|
void addTrack(std::shared_ptr<SimControl::TrackItem> Track);
|
||||||
std::shared_ptr<SimCore::SimTrack> getTrack(SimCore::Identifier);
|
std::shared_ptr<SimControl::TrackItem> getTrack(SimCore::Identifier);
|
||||||
|
|
||||||
void deleteTrack(std::string ID);
|
void deleteTrack(std::string ID);
|
||||||
void deleteTrack(SimCore::Identifier);
|
void deleteTrack(SimCore::Identifier);
|
||||||
@@ -36,13 +39,13 @@ namespace SimControl
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
mutable std::mutex mx_;
|
mutable std::mutex mx_;
|
||||||
std::map<std::string, std::shared_ptr<SimCore::SimTrack>> TrackStore_;
|
std::map<std::string, std::shared_ptr<SimControl::TrackItem>> TrackStore_;
|
||||||
|
|
||||||
std::map<std::string, std::time_t> markedAsDeletedTracks_;
|
// std::map<std::string, std::time_t> markedAsDeletedTracks_;
|
||||||
|
|
||||||
void checkTracksTimeout();
|
void checkTracksTimeout();
|
||||||
|
|
||||||
const int TrackTimeoutTime = 6;
|
const int TrackTimeoutTime = 12;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Submodule libs/KubeControl updated: f11742ce64...a413b412df
Submodule libs/OrderLibrary updated: 9d892fdcb6...13f3c07dbc
@@ -2,9 +2,11 @@
|
|||||||
#include <SimCore/Identifier.hpp>
|
#include <SimCore/Identifier.hpp>
|
||||||
#include "DirectCommunicationServer.hpp"
|
#include "DirectCommunicationServer.hpp"
|
||||||
#include "GeographicLib/Geodesic.hpp"
|
#include "GeographicLib/Geodesic.hpp"
|
||||||
|
#include "Orders/TracklistRequest.hpp"
|
||||||
#include "SimControl/Tracklist.hpp"
|
#include "SimControl/Tracklist.hpp"
|
||||||
#include "SimCore/Messages/Control.hpp"
|
#include "SimCore/Messages/Control.hpp"
|
||||||
#include "SimCore/Messages/SimTrack.hpp"
|
#include "SimCore/Messages/SimTrack.hpp"
|
||||||
|
#include "SimCore/Messages/TracklistUpdate.hpp"
|
||||||
#include "SimCore/SimCore.hpp"
|
#include "SimCore/SimCore.hpp"
|
||||||
#include "SimCore/UtilFunctions.hpp"
|
#include "SimCore/UtilFunctions.hpp"
|
||||||
#include "WHISPER/InternalUDPListener.hpp"
|
#include "WHISPER/InternalUDPListener.hpp"
|
||||||
@@ -17,12 +19,15 @@
|
|||||||
#include "nlohmann/json_fwd.hpp"
|
#include "nlohmann/json_fwd.hpp"
|
||||||
#include <SimControl/SimControl.hpp>
|
#include <SimControl/SimControl.hpp>
|
||||||
|
|
||||||
|
#include <SimControl/TrackItem.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <future>
|
#include <future>
|
||||||
|
#include <iterator>
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -45,7 +50,7 @@ namespace SimControl {
|
|||||||
BroadcastListener_->subscribe(WHISPER::MsgTopics::TRACK);
|
BroadcastListener_->subscribe(WHISPER::MsgTopics::TRACK);
|
||||||
|
|
||||||
PodController_ = std::make_unique<kubecontrol::PodController>("docs/config");
|
PodController_ = std::make_unique<kubecontrol::PodController>("docs/config");
|
||||||
ExternalTCPServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(5000);
|
ExternalTCPServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(5000,ID_.getUUID());
|
||||||
ExternalTCPServer_->registerMessageCallback(std::bind(&SimControl::HandleTCPMessage,this,std::placeholders::_1));
|
ExternalTCPServer_->registerMessageCallback(std::bind(&SimControl::HandleTCPMessage,this,std::placeholders::_1));
|
||||||
// TCPClient_ = std::make_unique<DirectCommunication::DirectCommunicationClient>(30200,"192.168.252.6");
|
// TCPClient_ = std::make_unique<DirectCommunication::DirectCommunicationClient>(30200,"192.168.252.6");
|
||||||
// TCPClient_ = std::make_unique<DirectCommunication::DirectCommunicationClient>(5555,"127.0.0.1");
|
// TCPClient_ = std::make_unique<DirectCommunication::DirectCommunicationClient>(5555,"127.0.0.1");
|
||||||
@@ -138,8 +143,10 @@ namespace SimControl {
|
|||||||
auto track = SimCore::SimTrack::unpack(msg);
|
auto track = SimCore::SimTrack::unpack(msg);
|
||||||
if (track != nullptr)
|
if (track != nullptr)
|
||||||
{
|
{
|
||||||
|
auto item = std::make_shared<TrackItem>(*track);
|
||||||
|
|
||||||
// LOG_S(INFO)<<"Track received";
|
// LOG_S(INFO)<<"Track received";
|
||||||
Tracklist_->addTrack(std::move(track));
|
Tracklist_->addTrack(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -227,6 +234,7 @@ namespace SimControl {
|
|||||||
|
|
||||||
}else if(j["Type"] == "Delete")
|
}else if(j["Type"] == "Delete")
|
||||||
{
|
{
|
||||||
|
LOG_S(INFO)<< j;
|
||||||
deleteShip(j);
|
deleteShip(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,13 +316,12 @@ namespace SimControl {
|
|||||||
// ShipPod1.setEnvironmentVar("GROUNDTRUTH_ADDR", "\""+this->GroundTruthAddr_+"\"");
|
// ShipPod1.setEnvironmentVar("GROUNDTRUTH_ADDR", "\""+this->GroundTruthAddr_+"\"");
|
||||||
// ShipPod1.setEnvironmentVar("COMMAND_PORT", "\""+CommandPort_+"\"");
|
// ShipPod1.setEnvironmentVar("COMMAND_PORT", "\""+CommandPort_+"\"");
|
||||||
|
|
||||||
ShipPod1.createYAML();
|
|
||||||
PodController_->startPod(ShipPod1);
|
PodController_->startPod(ShipPod1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SimControl::startNewShip(std::string Name, std::string lat, std::string lon, std::string height , std::string course, std::string speed)
|
void SimControl::startNewShip(std::string Name, std::string lat, std::string lon, std::string height , std::string course, std::string speed,bool WaitTillRunning )
|
||||||
{
|
{
|
||||||
LOG_S(INFO)<< "start New Ship";
|
LOG_S(INFO)<< "start New Ship";
|
||||||
|
|
||||||
@@ -347,8 +354,7 @@ namespace SimControl {
|
|||||||
ShipPod1.setEnvironmentVar("COMMAND_PORT", "\""+CommandPort_+"\"");
|
ShipPod1.setEnvironmentVar("COMMAND_PORT", "\""+CommandPort_+"\"");
|
||||||
ShipPod1.setEnvironmentVar("CONFIG", vars.dump());
|
ShipPod1.setEnvironmentVar("CONFIG", vars.dump());
|
||||||
|
|
||||||
ShipPod1.createYAML();
|
PodController_->startPod(ShipPod1,WaitTillRunning);
|
||||||
PodController_->startPod(ShipPod1);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -370,6 +376,7 @@ namespace SimControl {
|
|||||||
LOG_S(INFO)<<request["Course"].get<std::string>();
|
LOG_S(INFO)<<request["Course"].get<std::string>();
|
||||||
|
|
||||||
moveOrder.Speed.setValue(std::stod(request["Speed"].get<std::string>()));
|
moveOrder.Speed.setValue(std::stod(request["Speed"].get<std::string>()));
|
||||||
|
LOG_S(INFO)<<"Course as double"<< std::stod(request["Course"].get<std::string>());
|
||||||
moveOrder.Course.setValue(std::stod(request["Course"].get<std::string>()));
|
moveOrder.Course.setValue(std::stod(request["Course"].get<std::string>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,32 +392,32 @@ namespace SimControl {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto info = PodController_->getPodsInfo(request["ID"].get<std::string>());
|
auto info = PodController_->getInfoForPod(request["ID"].get<std::string>());
|
||||||
if(info != nullptr)
|
|
||||||
{
|
|
||||||
LOG_S(INFO)<<"PODS Info: " <<info->ToJson();
|
LOG_S(INFO)<<"PODS Info: " <<info.Component;
|
||||||
DirectCommunication::DirectCommunicationClient client(std::stoi(CommandPort_),info->Ip);
|
DirectCommunication::DirectCommunicationClient client(std::stoi(CommandPort_),info.IP,ID_.getUUID());
|
||||||
client.sendMessage(moveOrder.buildMessage().serialize());
|
client.sendMessage(moveOrder.buildMessage());
|
||||||
// client.disconnect();
|
// client.disconnect();
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimControl::deleteShip(nlohmann::json request)
|
void SimControl::deleteShip(nlohmann::json request)
|
||||||
{
|
{
|
||||||
LOG_S(INFO)<<"REQUEST: "<<request;
|
LOG_S(INFO)<<"REQUEST: "<<request;
|
||||||
PodController_->checkPodsHierarchy();
|
|
||||||
|
|
||||||
auto info = PodController_->getPodsInfo(request["ID"].get<std::string>());
|
|
||||||
if(info != nullptr)
|
|
||||||
{
|
|
||||||
LOG_S(INFO)<<"PODS Info: " <<info->ToJson();
|
|
||||||
DirectCommunication::DirectCommunicationClient client(std::stoi(CommandPort_),info->Ip);
|
|
||||||
SimCore::Control control(this->ID_,SimCore::ControlType::SHUT_DOWN,"Bye");
|
|
||||||
client.sendMessage(control.buildMessage().serialize());
|
|
||||||
client.disconnect();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
auto info = PodController_->getInfoForPod(request["ID"].get<std::string>());
|
||||||
|
|
||||||
|
LOG_S(INFO)<<"PODS Info: " <<info.Component;
|
||||||
|
if(!std::empty(info.IP))
|
||||||
|
{
|
||||||
|
DirectCommunication::DirectCommunicationClient client(std::stoi(CommandPort_),info.IP,ID_.getUUID());
|
||||||
|
SimCore::Control control(this->ID_,SimCore::ControlType::SHUT_DOWN,"Bye");
|
||||||
|
client.sendMessage(control.buildMessage());
|
||||||
|
client.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
// std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
// std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
|
|
||||||
PodController_->stopPod(request["ID"]);
|
PodController_->stopPod(request["ID"]);
|
||||||
@@ -425,25 +432,29 @@ namespace SimControl {
|
|||||||
{
|
{
|
||||||
|
|
||||||
// LOG_S(INFO)<<"REQUEST: "<<request;
|
// LOG_S(INFO)<<"REQUEST: "<<request;
|
||||||
PodController_->checkPodsHierarchy();
|
|
||||||
std::string response;
|
std::string response;
|
||||||
auto info = PodController_->getPodsInfo(id);
|
auto info = PodController_->getInfoForPod(id);
|
||||||
if(info != nullptr)
|
|
||||||
{
|
LOG_S(INFO)<<"PODS Info: " <<info.Component;
|
||||||
LOG_S(INFO)<<"PODS Info: " <<info->ToJson();
|
DirectCommunication::DirectCommunicationClient client(std::stoi(CommandPort_),info.IP,ID_.getUUID());
|
||||||
DirectCommunication::DirectCommunicationClient client(std::stoi(CommandPort_),info->Ip);
|
Orders::TracklistRequest TrackListRequest(ID_,SimCore::Identifier(id));
|
||||||
SimCore::Control control(this->ID_,SimCore::ControlType::GET_TRACKLIST,"Tracklist");
|
// SimCore::Control control(this->ID_,SimCore::ControlType::GET_TRACKLIST,"Tracklist");
|
||||||
client.sendMessage(control.buildMessage().serialize());
|
client.sendMessage(TrackListRequest.buildMessage());
|
||||||
response = client.getLatestMessage();
|
response = client.getLatestMessage();
|
||||||
|
|
||||||
client.disconnect();
|
client.disconnect();
|
||||||
}
|
auto update = SimCore::TracklistUpdate::unpack(WHISPER::Message(response));
|
||||||
if (response != "NULL")
|
if (response != "NULL")
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
nlohmann::json tracks = nlohmann::json::parse(response);
|
nlohmann::json Jsontracks = nlohmann::json::parse(response);
|
||||||
j["Tracks"] = tracks;
|
auto tracks = update->getTracks();
|
||||||
|
for(auto item : tracks)
|
||||||
|
{
|
||||||
|
Jsontracks.push_back(item.getsTrackListItemAsJSON());
|
||||||
|
}
|
||||||
|
// j["Tracks"] = ;
|
||||||
|
|
||||||
}catch (const std::exception e) {
|
}catch (const std::exception e) {
|
||||||
LOG_S(ERROR)<< e.what();
|
LOG_S(ERROR)<< e.what();
|
||||||
@@ -459,8 +470,6 @@ namespace SimControl {
|
|||||||
kubecontrol::KubePod Webapp("controller","webapp","webapp","webapp:latest",Namespace_);
|
kubecontrol::KubePod Webapp("controller","webapp","webapp","webapp:latest",Namespace_);
|
||||||
Webapp.setEnvironmentVar("REACT_APP_WEBAPP_WS_URL", SimCore::UtilFunctions::getOwnIP());
|
Webapp.setEnvironmentVar("REACT_APP_WEBAPP_WS_URL", SimCore::UtilFunctions::getOwnIP());
|
||||||
|
|
||||||
Webapp.createYAML();
|
|
||||||
|
|
||||||
PodController_->startPod(Webapp);
|
PodController_->startPod(Webapp);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -501,7 +510,7 @@ namespace SimControl {
|
|||||||
double lat2, lon2;
|
double lat2, lon2;
|
||||||
geod.Direct(lat, lonTmp, 90, distance, lat2, lon2);
|
geod.Direct(lat, lonTmp, 90, distance, lat2, lon2);
|
||||||
|
|
||||||
SimControl::startNewShip(name, std::to_string(lat2), std::to_string(lon2), "0", "0", "0");
|
SimControl::startNewShip(name, std::to_string(lat2), std::to_string(lon2), "0", "0", "0",false);
|
||||||
lonTmp = lon2;
|
lonTmp = lon2;
|
||||||
counter ++;
|
counter ++;
|
||||||
}
|
}
|
||||||
|
|||||||
54
src/SimControl/TrackItem.cpp
Normal file
54
src/SimControl/TrackItem.cpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#include "SimCore/Messages/SimTrack.hpp"
|
||||||
|
#include "nlohmann/json.hpp"
|
||||||
|
#include <SimControl/TrackItem.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace SimControl
|
||||||
|
{
|
||||||
|
|
||||||
|
TrackItem::TrackItem(SimCore::SimTrack track)
|
||||||
|
:SimCore::SimTrack(track), markedAsDeleted(false),lastReceiveTimestamp_(time(0))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void TrackItem::markAsDelete()
|
||||||
|
{
|
||||||
|
markedAsDeleted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TrackItem::isMarkedAsDelete()
|
||||||
|
{
|
||||||
|
return markedAsDeleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::time_t TrackItem::getLastUpdateTimestamp()
|
||||||
|
{
|
||||||
|
return lastReceiveTimestamp_;
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json TrackItem::toJSON()
|
||||||
|
{
|
||||||
|
|
||||||
|
nlohmann::json j;
|
||||||
|
j["id"] = this->getIdentifier().getUUID();
|
||||||
|
j["Name"] = this->Name.getValue();
|
||||||
|
j["Course"] = this->Course.getValue();
|
||||||
|
j["Speed"] = this->Speed.getValue();
|
||||||
|
j["External"] = this->getIdentifier().isExternal();
|
||||||
|
j["Position"] = {this->getPosition().getGeodesicPos()[SimCore::LATITUDE], this->getPosition().getGeodesicPos()[SimCore::LONGITUDE]};
|
||||||
|
j["Height"] = this->getPosition().getGeodesicPos()[SimCore::HEIGHT];
|
||||||
|
j["Type"] = SimCore::Kind::EntityKindMap[this->EntityKind.getValue()];
|
||||||
|
j["Side"] = SimCore::Side::EntitySideMap[this->EntitySide.getValue()];
|
||||||
|
return j;
|
||||||
|
}
|
||||||
|
std::string TrackItem::toString()
|
||||||
|
{
|
||||||
|
return toJSON().dump();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include "SimControl/TrackItem.hpp"
|
||||||
#include "SimCore/SimCore.hpp"
|
#include "SimCore/SimCore.hpp"
|
||||||
#include "nlohmann/json_fwd.hpp"
|
#include "nlohmann/json_fwd.hpp"
|
||||||
#include <SimControl/Tracklist.hpp>
|
#include <SimControl/Tracklist.hpp>
|
||||||
@@ -14,51 +15,61 @@ namespace SimControl
|
|||||||
TrackList::TrackList()
|
TrackList::TrackList()
|
||||||
{
|
{
|
||||||
|
|
||||||
TrackStore_ = std::map<std::string, std::shared_ptr<SimCore::SimTrack>>();
|
TrackStore_ = std::map<std::string, std::shared_ptr<SimControl::TrackItem>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackList::addTrack(std::shared_ptr<SimCore::SimTrack> Track)
|
void TrackList::addTrack(std::shared_ptr<SimControl::TrackItem> Track)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mx_);
|
std::lock_guard<std::mutex> lock(mx_);
|
||||||
|
// LOG_S(INFO)<<markedAsDeletedTracks_.size();
|
||||||
checkTracksTimeout();
|
checkTracksTimeout();
|
||||||
|
|
||||||
|
|
||||||
auto it = markedAsDeletedTracks_.find(Track->getIdentifier().getUUID());
|
// auto it = markedAsDeletedTracks_.find(Track->getIdentifier().getUUID());
|
||||||
if (it == markedAsDeletedTracks_.end() )
|
// 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)
|
||||||
{
|
{
|
||||||
auto [iterator, inserted] = TrackStore_.try_emplace(Track->getIdentifier().getUUID(),Track);
|
if (iterator->second->isMarkedAsDelete() == false)
|
||||||
if (!inserted) { iterator->second = Track; }
|
{
|
||||||
|
iterator->second = Track;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void TrackList::checkTracksTimeout()
|
void TrackList::checkTracksTimeout()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (markedAsDeletedTracks_.size() == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( std::map<std::string,std::time_t>::iterator it=markedAsDeletedTracks_.begin(); it != markedAsDeletedTracks_.end();)
|
for (std::map<std::string, std::shared_ptr<SimControl::TrackItem>>::iterator it=TrackStore_.begin(); it != TrackStore_.end();)
|
||||||
|
{
|
||||||
|
|
||||||
|
if ((time(0) - it->second->getLastUpdateTimestamp())>= 6 )
|
||||||
{
|
{
|
||||||
if (it->second + TrackTimeoutTime < time(0))
|
it = TrackStore_.erase(it);
|
||||||
{
|
}else {
|
||||||
it = markedAsDeletedTracks_.erase(it);
|
it++;
|
||||||
}else {
|
|
||||||
it++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<SimCore::SimTrack> TrackList::getTrack(const SimCore::Identifier ID)
|
std::shared_ptr<SimControl::TrackItem> TrackList::getTrack(const SimCore::Identifier ID)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mx_);
|
std::lock_guard<std::mutex> lock(mx_);
|
||||||
|
|
||||||
@@ -77,38 +88,49 @@ namespace SimControl
|
|||||||
void TrackList::deleteTrack(std::string ID)
|
void TrackList::deleteTrack(std::string ID)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mx_);
|
std::lock_guard<std::mutex> lock(mx_);
|
||||||
markedAsDeletedTracks_.emplace(std::make_pair(ID, std::time(0)));
|
|
||||||
auto it = TrackStore_.find(ID);
|
auto it = TrackStore_.find(ID);
|
||||||
TrackStore_.erase(it);
|
if(it != TrackStore_.end())
|
||||||
|
{
|
||||||
|
it->second->markAsDelete();
|
||||||
|
// markedAsDeletedTracks_.emplace(std::make_pair(ID, std::time(0)));
|
||||||
|
// TrackStore_.erase(it);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackList::deleteTrack(SimCore::Identifier ID)
|
void TrackList::deleteTrack(SimCore::Identifier ID)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mx_);
|
std::lock_guard<std::mutex> lock(mx_);
|
||||||
markedAsDeletedTracks_.emplace(std::make_pair(ID.getUUID(), std::time(0)));
|
// markedAsDeletedTracks_.emplace(std::make_pair(ID.getUUID(), std::time(0)));
|
||||||
auto it = TrackStore_.find(ID.getUUID());
|
auto it = TrackStore_.find(ID.getUUID());
|
||||||
TrackStore_.erase(it);
|
it->second->markAsDelete();
|
||||||
|
// TrackStore_.erase(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TrackList::getJsonTRackList(nlohmann::json &message)
|
void TrackList::getJsonTRackList(nlohmann::json &message)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mx_);
|
|
||||||
try {
|
|
||||||
for (std::map<std::string, std::shared_ptr<SimCore::SimTrack>>::iterator it=TrackStore_.begin(); it!=TrackStore_.end(); ++it)
|
|
||||||
{
|
|
||||||
nlohmann::json j;
|
|
||||||
j["id"] = it->first;
|
|
||||||
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()];
|
|
||||||
|
|
||||||
message["Entities"].push_back(j);
|
std::lock_guard<std::mutex> lock(mx_);
|
||||||
|
checkTracksTimeout();
|
||||||
|
try {
|
||||||
|
for (std::map<std::string, std::shared_ptr<SimControl::TrackItem>>::iterator it=TrackStore_.begin(); it!=TrackStore_.end(); ++it)
|
||||||
|
{
|
||||||
|
if(!it->second->isMarkedAsDelete())
|
||||||
|
{
|
||||||
|
message["Entities"].push_back(it->second->toJSON());
|
||||||
|
}
|
||||||
|
// nlohmann::json j;
|
||||||
|
// j["id"] = it->first;
|
||||||
|
// 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()];
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}catch (const std::exception e) {
|
}catch (const std::exception e) {
|
||||||
LOG_S(ERROR)<< e.what();
|
LOG_S(ERROR)<< e.what();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include "SimControl/TrackItem.hpp"
|
||||||
#include "SimControl/Tracklist.hpp"
|
#include "SimControl/Tracklist.hpp"
|
||||||
#include "SimCore/Identifier.hpp"
|
#include "SimCore/Identifier.hpp"
|
||||||
#include "SimCore/Messages/SimTrack.hpp"
|
#include "SimCore/Messages/SimTrack.hpp"
|
||||||
@@ -46,7 +47,7 @@ void createScenario(SimControl::TrackList *list,std::vector<std::string> *ids)
|
|||||||
pos.setGeodesicPos(lat2, lon2, 0);
|
pos.setGeodesicPos(lat2, lon2, 0);
|
||||||
auto track = std::make_shared<SimCore::SimTrack>(id,name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL);
|
auto track = std::make_shared<SimCore::SimTrack>(id,name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL);
|
||||||
track->setPosition(pos);
|
track->setPosition(pos);
|
||||||
list->addTrack(track);
|
list->addTrack(std::make_shared<SimControl::TrackItem>(*track));
|
||||||
// SimControl::startNewShip(name, std::to_string(lat2), std::to_string(lon2), "0", "0", "0");
|
// SimControl::startNewShip(name, std::to_string(lat2), std::to_string(lon2), "0", "0", "0");
|
||||||
lonTmp = lon2;
|
lonTmp = lon2;
|
||||||
counter ++;
|
counter ++;
|
||||||
@@ -93,14 +94,14 @@ auto track = list.getTrackBySringID(ids[3]);
|
|||||||
|
|
||||||
list.deleteTrack(track->getIdentifier());
|
list.deleteTrack(track->getIdentifier());
|
||||||
|
|
||||||
list.addTrack(track);
|
list.addTrack(std::make_shared<SimControl::TrackItem>(*track));
|
||||||
REQUIRE(list.getTracklistSize() == 24);
|
// REQUIRE(list.getTracklistSize() == 24);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(7500));
|
std::this_thread::sleep_for(std::chrono::milliseconds(7500));
|
||||||
LOG_S(INFO)<<"add saved track";
|
LOG_S(INFO)<<"add saved track";
|
||||||
list.addTrack(track);
|
list.addTrack(std::make_shared<SimControl::TrackItem>(*track));
|
||||||
LOG_S(INFO)<<"added saved track";
|
LOG_S(INFO)<<"added saved track";
|
||||||
|
|
||||||
REQUIRE(list.getTracklistSize() == 25);
|
REQUIRE(list.getTracklistSize() == 1);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user