ADD: added new Tracklist and some changes to Entity class
This commit is contained in:
@@ -53,12 +53,13 @@ namespace Entities {
|
||||
Entity(const SimCore::Identifier OwnID,
|
||||
std::string EnttityName,
|
||||
WHISPER::SourceType OwnType,
|
||||
double RadarCrossSection,
|
||||
SimCore::Kind::EntityKind EntityKind,
|
||||
SimCore::Side::EntitySide EntitySide,
|
||||
std::string GroundTruthAddr,
|
||||
std::uint32_t GroundTruthPort,
|
||||
ushort CommandPort,
|
||||
bool online);
|
||||
bool online);
|
||||
~Entity();
|
||||
|
||||
void start();
|
||||
@@ -73,6 +74,7 @@ namespace Entities {
|
||||
|
||||
|
||||
virtual void childWorker() = 0;
|
||||
virtual void stopChild() = 0;
|
||||
|
||||
|
||||
protected:
|
||||
@@ -82,6 +84,7 @@ namespace Entities {
|
||||
std::string EntityName_;
|
||||
SimCore::Kind::EntityKind EntityKind_;
|
||||
SimCore::Side::EntitySide EntitySide_;
|
||||
double RCS_;
|
||||
|
||||
|
||||
ushort MovemntWorkerPort_;
|
||||
@@ -91,6 +94,9 @@ namespace Entities {
|
||||
std::shared_ptr<WHISPER::InternalUDPSender> BroadcastServer_;
|
||||
|
||||
|
||||
std::string GroundTruthAddr_;
|
||||
std::uint32_t GroundTruthPort_;
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "SimCore/Identifier.hpp"
|
||||
#include "SimCore/IdentifierMaker.hpp"
|
||||
#include "SimCore/Messages/SimTrack.hpp"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <list>
|
||||
@@ -19,49 +20,25 @@
|
||||
namespace TrackList
|
||||
{
|
||||
|
||||
class TrackList
|
||||
class TrackList
|
||||
{
|
||||
public:
|
||||
TrackList(SimCore::Identifier OwnID);
|
||||
~TrackList();
|
||||
public:
|
||||
TrackList();
|
||||
void addTrack(std::shared_ptr<SimCore::SimTrack> Track);
|
||||
std::shared_ptr<SimCore::SimTrack> getTrack(SimCore::Identifier);
|
||||
|
||||
void deleteTrack(std::string ID);
|
||||
void deleteTrack(SimCore::Identifier);
|
||||
std::shared_ptr<SimCore::SimTrack> getTrackBySringID(std::string ID);
|
||||
|
||||
void stopSanitizer();
|
||||
size_t getSize();
|
||||
|
||||
// SimCore::Identifier getTrackID(SimCore::ObjectSource source);
|
||||
|
||||
void addTrack(std::shared_ptr<SimCore::SimTrack> track);
|
||||
|
||||
void addTrack(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData);
|
||||
|
||||
std::shared_ptr<TracklistItem> getTrack(SimCore::Identifier TrackID);
|
||||
|
||||
std::vector<SimCore::Identifier> getAllIDs();
|
||||
|
||||
size_t size();
|
||||
|
||||
void setTrackTimeout(int millseconds);
|
||||
int getTrackTimeoutValue();
|
||||
|
||||
private:
|
||||
|
||||
const SimCore::Identifier OwnID_;
|
||||
|
||||
SimCore::IdentifierMaker IDMaker;
|
||||
|
||||
void tracklistSanitizer();
|
||||
|
||||
void addNewTrack(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData);
|
||||
void addNewTrack(std::shared_ptr<SimCore::SimTrack> track);
|
||||
|
||||
std::map<std::string, std::shared_ptr<TracklistItem>> TrackList_;
|
||||
|
||||
mutable std::mutex mutex_;
|
||||
|
||||
std::thread sanitizerThread_;
|
||||
std::atomic_bool sanitizerIsRunning_;
|
||||
std::atomic_bool stopSanitizer_;
|
||||
int TrackTimeout_ = 1000;
|
||||
void getJsonTRackList(nlohmann::json &message);
|
||||
|
||||
|
||||
private:
|
||||
mutable std::mutex mx_;
|
||||
std::map<std::string, std::shared_ptr<SimCore::SimTrack>> TrackStore_;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace Entities
|
||||
Entity::Entity(const SimCore::Identifier OwnID,
|
||||
std::string EnttityName,
|
||||
WHISPER::SourceType OwnType,
|
||||
double RadarCrossSection,
|
||||
SimCore::Kind::EntityKind EntityKind,
|
||||
SimCore::Side::EntitySide EntitySide,
|
||||
std::string GroundTruthAddr,
|
||||
@@ -46,13 +47,17 @@ namespace Entities
|
||||
bool online):
|
||||
EntityName_(EnttityName),
|
||||
EntityKind_(EntityKind),
|
||||
RCS_(RadarCrossSection),
|
||||
EntitySide_(EntitySide),
|
||||
GroundTruthPort_(GroundTruthPort),
|
||||
GroundTruthAddr_(GroundTruthAddr),
|
||||
online_(online)
|
||||
|
||||
{
|
||||
PodController_ = std::make_unique<kubecontrol::PodController>("docs/config");
|
||||
OwnShipTrack = std::make_shared<SimCore::SimTrack>(OwnID, EnttityName, EntityKind,EntitySide);
|
||||
OwnShipTrack->setPosition(SimCore::Position());
|
||||
OwnShipTrack->RCS.setValue(RCS_);
|
||||
|
||||
MovemtServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(__MOVEMENT_SERVER_PORT__);
|
||||
|
||||
@@ -131,7 +136,7 @@ namespace Entities
|
||||
|
||||
void Entity::stop()
|
||||
{
|
||||
|
||||
stopChild();
|
||||
|
||||
PodController_->stopAllPods();
|
||||
|
||||
@@ -205,7 +210,7 @@ namespace Entities
|
||||
if (newTrack != nullptr)
|
||||
{
|
||||
OwnShipTrack->setPosition(newTrack->getPosition());
|
||||
LOG_S(INFO)<< "new POS: LAT: "<< OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LATITUDE) << " LON: " << OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LONGITUDE);
|
||||
// LOG_S(INFO)<< "new POS: LAT: "<< OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LATITUDE) << " LON: " << OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LONGITUDE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,171 +1,88 @@
|
||||
#include "SimCore/Identifier.hpp"
|
||||
#include "SimCore/Messages/SimTrack.hpp"
|
||||
#include <Entities/Tracklist/Tracklist.hpp>
|
||||
#include <ranges>
|
||||
#include <utility>
|
||||
#include "SimCore/Messages/SimTrack.hpp"
|
||||
|
||||
|
||||
|
||||
namespace TrackList
|
||||
{
|
||||
|
||||
TrackList::TrackList(SimCore::Identifier OwnID):OwnID_(OwnID),TrackTimeout_(5 * 60 *1000)
|
||||
{
|
||||
stopSanitizer_ = false;
|
||||
sanitizerThread_ = std::thread(&TrackList::tracklistSanitizer,this);
|
||||
}
|
||||
TrackList::TrackList()
|
||||
{
|
||||
|
||||
TrackList::~TrackList()
|
||||
{
|
||||
if (sanitizerIsRunning_ == true) {
|
||||
stopSanitizer();
|
||||
}
|
||||
}
|
||||
TrackStore_ = std::map<std::string, std::shared_ptr<SimCore::SimTrack>>();
|
||||
}
|
||||
|
||||
void TrackList::addTrack(std::shared_ptr<SimCore::SimTrack> Track)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mx_);
|
||||
|
||||
auto [iterator, inserted] = TrackStore_.try_emplace(Track->getIdentifier().getUUID(),Track);
|
||||
// LOG_S(INFO)<< Track->Name.getValue()<<" was: " << (inserted ? "inserted: " : "ignored: ");
|
||||
if (!inserted) { TrackStore_[Track->getIdentifier().getUUID()] = Track; }
|
||||
|
||||
|
||||
void TrackList::stopSanitizer()
|
||||
{
|
||||
stopSanitizer_ = true;
|
||||
sanitizerThread_.join();
|
||||
}
|
||||
std::shared_ptr<SimCore::SimTrack> TrackList::getTrack(const SimCore::Identifier ID)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mx_);
|
||||
|
||||
}
|
||||
auto it = TrackStore_.find(ID.getUUID());
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::shared_ptr<SimCore::SimTrack> TrackList::getTrackBySringID(std::string ID)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mx_);
|
||||
|
||||
auto it = TrackStore_.find(ID);
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void TrackList::deleteTrack(std::string ID)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mx_);
|
||||
auto it = TrackStore_.find(ID);
|
||||
TrackStore_.erase(it);
|
||||
}
|
||||
|
||||
void TrackList::deleteTrack(SimCore::Identifier ID)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mx_);
|
||||
auto it = TrackStore_.find(ID.getUUID());
|
||||
TrackStore_.erase(it);
|
||||
}
|
||||
|
||||
|
||||
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()];
|
||||
|
||||
void TrackList::addTrack(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData)
|
||||
{
|
||||
message["Entities"].push_back(j);
|
||||
}
|
||||
}catch (const std::exception e) {
|
||||
LOG_S(ERROR)<< e.what();
|
||||
}
|
||||
}
|
||||
|
||||
size_t TrackList::getSize()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mx_);
|
||||
return TrackStore_.size();
|
||||
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
|
||||
auto iterator = TrackList_.find(track->getIdentifier().getUUID());
|
||||
if (iterator == TrackList_.end()) {
|
||||
auto item = std::make_shared<TracklistItem>( track,sensorData);
|
||||
TrackList_.emplace(track->getIdentifier().getUUID(),item);
|
||||
|
||||
}else {
|
||||
iterator->second->updateTrack(track,sensorData);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void TrackList::addTrack(std::shared_ptr<SimCore::SimTrack> track)
|
||||
{
|
||||
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
|
||||
auto iterator = TrackList_.find(track->getIdentifier().getUUID());
|
||||
if (iterator == TrackList_.end()) {
|
||||
auto item = std::make_shared<TracklistItem>( track);
|
||||
TrackList_.emplace(track->getIdentifier().getUUID(),item);
|
||||
|
||||
}else {
|
||||
iterator->second->updateTrack(track);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TrackList::addNewTrack(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData)
|
||||
{
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
auto item = std::make_shared<TracklistItem>( track, sensorData);
|
||||
|
||||
TrackList_.emplace(std::make_pair(track->getIdentifier().getUUID(),item));
|
||||
|
||||
}
|
||||
|
||||
void TrackList::addNewTrack(std::shared_ptr<SimCore::SimTrack> track)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
auto item = std::make_shared<TracklistItem>( track);
|
||||
TrackList_.emplace(track->getIdentifier().getUUID(),item);
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<TracklistItem> TrackList::getTrack(SimCore::Identifier TrackID)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
std::shared_ptr<TracklistItem> result = nullptr;
|
||||
result = TrackList_.at(TrackID.getUUID());
|
||||
if (result == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<SimCore::Identifier> TrackList::getAllIDs()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
std::vector<SimCore::Identifier> list;
|
||||
for (const auto& [key,value] : TrackList_) {
|
||||
list.emplace_back(key);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
size_t TrackList::size()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return TrackList_.size();
|
||||
|
||||
}
|
||||
|
||||
void TrackList::setTrackTimeout(int millseconds)
|
||||
{
|
||||
this->TrackTimeout_ = millseconds;
|
||||
}
|
||||
|
||||
int TrackList::getTrackTimeoutValue()
|
||||
{
|
||||
return TrackTimeout_;
|
||||
}
|
||||
|
||||
|
||||
void TrackList::tracklistSanitizer()
|
||||
{
|
||||
sanitizerIsRunning_ = true;
|
||||
|
||||
while(stopSanitizer_ == false)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
for ( auto it = TrackList_.begin(); it != TrackList_.end();) {
|
||||
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
std::chrono::milliseconds::rep duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - it->second->getLastUpdateTimestamp() ).count();
|
||||
|
||||
if (duration >= TrackTimeout_) {
|
||||
|
||||
it = TrackList_.erase(it);
|
||||
LOG_S(INFO)<<"Erased Track";
|
||||
|
||||
|
||||
}else
|
||||
{
|
||||
it++;
|
||||
}
|
||||
|
||||
lock.unlock() ;
|
||||
lock.lock();
|
||||
}
|
||||
// LOG_S(INFO)<<"running";
|
||||
|
||||
lock.unlock();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
lock.release();
|
||||
|
||||
}
|
||||
sanitizerIsRunning_ = false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user