From f53fa3e32de60cf0c6a1a1e9e294e843bbf6054a Mon Sep 17 00:00:00 2001 From: Henry Winkel Date: Thu, 30 Mar 2023 10:24:29 +0200 Subject: [PATCH] ADD: added source to track --- include/SimCore/Messages/Track.hpp | 12 ++++++---- include/SimCore/Position.hpp | 9 +++++++- include/SimCore/SafeMap.hpp | 36 +++++++++++++++++++++--------- src/SimCore/Messages/Track.cpp | 9 +++++++- src/SimCore/Position.cpp | 10 ++++----- 5 files changed, 54 insertions(+), 22 deletions(-) diff --git a/include/SimCore/Messages/Track.hpp b/include/SimCore/Messages/Track.hpp index 6c36d03..baecab3 100644 --- a/include/SimCore/Messages/Track.hpp +++ b/include/SimCore/Messages/Track.hpp @@ -29,9 +29,10 @@ namespace SimCore { const SimCore::Identifier ID_; const SimCore::TrackKind TrackKind_ = UNKNOWN_TRACK; - - - const WHISPER::SourceType SourceType_; + + const WHISPER::SourceType SourceType_; + + const SimCore::ObjectSource ObjectSource_; @@ -44,7 +45,7 @@ namespace SimCore { * * @return */ - Track( WHISPER::SourceType src,SimCore::Identifier id, SimCore::TrackKind trackkind); + Track( WHISPER::SourceType src,SimCore::Identifier id, SimCore::TrackKind trackkind,SimCore::ObjectSource ObjectSource = EXTERNAL); @@ -54,6 +55,9 @@ namespace SimCore { const WHISPER::SourceType getSourceType(); + const SimCore::ObjectSource getObjectSource(); + + protected: diff --git a/include/SimCore/Position.hpp b/include/SimCore/Position.hpp index f30d935..b87fc0a 100644 --- a/include/SimCore/Position.hpp +++ b/include/SimCore/Position.hpp @@ -37,7 +37,14 @@ namespace SimCore { bool isValid(); - double distanceToPosition(Position &p2); + /** + * @brief calculates the disatance and the bearing from this->position to the other position + * + * @param Position + * + * @return std::tuple + */ + std::tuple distanceBearingToPosition(Position &p2); bool operator== ( Position &lhs); diff --git a/include/SimCore/SafeMap.hpp b/include/SimCore/SafeMap.hpp index fb71d56..3c7cddf 100644 --- a/include/SimCore/SafeMap.hpp +++ b/include/SimCore/SafeMap.hpp @@ -12,8 +12,8 @@ namespace SimCore { private: std::map store; - mutable std::mutex mx; - std::condition_variable c; + mutable std::mutex mx_; + std::condition_variable c_; protected: @@ -26,31 +26,31 @@ namespace SimCore { void addValue(K key, V value ) { - std::lock_guard lock(mx); + std::lock_guard lock(mx_); store.emplace(key,value); - c.notify_one(); + c_.notify_one(); } void removePair(K key) { - std::lock_guard lock(mx); + std::lock_guard lock(mx_); auto search = store.find(key); if (search != store.end()) { search = store.erase(search); } - c.notify_one(); + c_.notify_one(); } void overRideValue(K key, V newValue) { - std::lock_guard lock(mx); + std::lock_guard lock(mx_); auto search = store.find(key); if (search != store.end()) { store[key] = newValue; } - c.notify_one(); + c_.notify_one(); } @@ -58,7 +58,7 @@ namespace SimCore { V getValue(K key) { - std::lock_guard lock(mx); + std::lock_guard lock(mx_); V value; auto search = store.find(key); if (search != store.end()) { @@ -70,7 +70,7 @@ namespace SimCore { bool hasKey(K key) { - std::lock_guard lock(mx); + std::lock_guard lock(mx_); auto search = store.find(key); if (search != store.end()) { return true; @@ -84,10 +84,24 @@ namespace SimCore { long size() { - std::lock_guard lock(std::mutex); + std::lock_guard lock(mx_); return store.size(); } + + + const V& operator[](const K& key) const + { + std::lock_guard lock(mx_); + return store.at(key); + } + + V& operator[](const K& key) + { + std::lock_guard lock(mx_); + return store[key]; + } + diff --git a/src/SimCore/Messages/Track.cpp b/src/SimCore/Messages/Track.cpp index 238f45e..cd1d927 100644 --- a/src/SimCore/Messages/Track.cpp +++ b/src/SimCore/Messages/Track.cpp @@ -17,7 +17,8 @@ namespace SimCore { - Track::Track( WHISPER::SourceType src,SimCore::Identifier id, SimCore::TrackKind trackkind):ID_(id),TrackKind_(trackkind),SourceType_(src) + Track::Track( WHISPER::SourceType src,SimCore::Identifier id, SimCore::TrackKind trackkind,SimCore::ObjectSource ObjectSource ) + :ID_(id),TrackKind_(trackkind),SourceType_(src),ObjectSource_(ObjectSource) { } @@ -35,6 +36,12 @@ namespace SimCore { { return SourceType_; } + + const SimCore::ObjectSource Track::getObjectSource() + { + return ObjectSource_; + } + diff --git a/src/SimCore/Position.cpp b/src/SimCore/Position.cpp index fac49f3..c6889bd 100644 --- a/src/SimCore/Position.cpp +++ b/src/SimCore/Position.cpp @@ -83,8 +83,8 @@ namespace SimCore { valid_ = true; } - - double Position::distanceToPosition(Position &p2) + + std::tuple Position::distanceBearingToPosition(Position &p2) { if (valid_) { std::lock_guard lock(mx); @@ -93,12 +93,12 @@ namespace SimCore { this->GeodesicPos_[LONGITUDE], p2.GeodesicPos_[LATITUDE], p2.GeodesicPos_[LONGITUDE], - s12); + s12,azi1,azi2); - return s12; + return {s12,azi1}; }else { - return 0; + return {0,0}; } }