ADD: updated Tracklist and TracklistItem with tests
This commit is contained in:
@@ -91,6 +91,10 @@ IF (${TEST_ENTITIY_LIBRARY})
|
||||
target_link_libraries(test_Tracklist Catch2::Catch2 EntityLibrary loguru)
|
||||
catch_discover_tests(test_Tracklist)
|
||||
|
||||
add_executable(test_TracklistItem tests/test_TracklistItem.cpp)
|
||||
target_link_libraries(test_TracklistItem Catch2::Catch2 EntityLibrary loguru)
|
||||
catch_discover_tests(test_TracklistItem)
|
||||
|
||||
|
||||
add_executable(test_MovementClass tests/test_MovementClass.cpp)
|
||||
target_link_libraries(test_MovementClass Catch2::Catch2 EntityLibrary loguru)
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <SimCore/Position.hpp>
|
||||
#include <SimCore/SafeMap.hpp>
|
||||
#include <Entities/Tracklist/TracklistItem.hpp>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <loguru.hpp>
|
||||
|
||||
@@ -26,7 +27,7 @@ namespace TrackList
|
||||
|
||||
void stopSanitizer();
|
||||
|
||||
SimCore::Identifier getTrackID(SimCore::ObjectSource source);
|
||||
// SimCore::Identifier getTrackID(SimCore::ObjectSource source);
|
||||
|
||||
void addTrack(std::shared_ptr<SimCore::SimTrack> track);
|
||||
|
||||
@@ -38,6 +39,9 @@ namespace TrackList
|
||||
|
||||
size_t size();
|
||||
|
||||
void setTrackTimeout(int millseconds);
|
||||
int getTrackTimeoutValue();
|
||||
|
||||
private:
|
||||
|
||||
const SimCore::Identifier OwnID_;
|
||||
@@ -56,6 +60,7 @@ namespace TrackList
|
||||
std::thread sanitizerThread_;
|
||||
std::atomic_bool sanitizerIsRunning_;
|
||||
std::atomic_bool stopSanitizer_;
|
||||
int TrackTimeout_ = 1000;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "SimCore/SimCore.hpp"
|
||||
#include <SimCore/Position.hpp>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
@@ -28,30 +29,12 @@ namespace TrackList {
|
||||
|
||||
|
||||
|
||||
class TracklistItem
|
||||
class TracklistItem: public SimCore::SimTrack
|
||||
{
|
||||
public:
|
||||
TracklistItem(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData);
|
||||
TracklistItem(std::shared_ptr<SimCore::SimTrack> track);
|
||||
|
||||
SimCore::Identifier getID();
|
||||
|
||||
void setPosition(SimCore::Position position);
|
||||
SimCore::Position getPosition();
|
||||
|
||||
void setSpeed(double speed);
|
||||
double getSpeed();
|
||||
|
||||
void setCourse(double course);
|
||||
double getCourse();
|
||||
|
||||
void setPitch(double pitch);
|
||||
double getpitch();
|
||||
|
||||
double getBearing();
|
||||
double getRange();
|
||||
|
||||
SimCore::ObjectSource getObjectSource();
|
||||
|
||||
std::chrono::time_point<std::chrono::steady_clock> getLastUpdateTimestamp();
|
||||
|
||||
@@ -65,30 +48,14 @@ namespace TrackList {
|
||||
|
||||
void addSensorDataToSensorList(SensorData sensorData);
|
||||
|
||||
size_t getSensorCount();
|
||||
|
||||
|
||||
private:
|
||||
const SimCore::Identifier trackID_;
|
||||
|
||||
/// position of the track
|
||||
SimCore::Position position_;
|
||||
/// speed the track
|
||||
double speed_ = 0;
|
||||
/// course of the track
|
||||
double course_ = 0;
|
||||
|
||||
double pitch_ = 0;
|
||||
|
||||
/// bearing
|
||||
double bearing_;
|
||||
///range in meters
|
||||
double range_;
|
||||
//environment (AIR,SURFACE,SUBSURFACE,SPACE)
|
||||
SimCore::Kind::EntityKind kind_;
|
||||
|
||||
|
||||
std::chrono::time_point<std::chrono::steady_clock> lastUpdateTimestamp_;
|
||||
|
||||
SimCore::ObjectSource ObjectSource_;
|
||||
|
||||
std::vector<SensorData> SensorList;
|
||||
|
||||
|
||||
|
||||
Submodule libs/OrderLibrary updated: 836cee9d6c...f4f98191bf
Submodule libs/json updated: 6eab7a2b18...5d2754306d
Submodule libs/nlohmannJSON updated: 6eab7a2b18...5d2754306d
@@ -3,85 +3,32 @@
|
||||
#include <Entities/Tracklist/TracklistItem.hpp>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <chrono>
|
||||
#include <tuple>
|
||||
|
||||
namespace TrackList {
|
||||
|
||||
TracklistItem::TracklistItem(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData):trackID_(track->getIdentifier())
|
||||
TracklistItem::TracklistItem(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData):
|
||||
SimCore::SimTrack(*track.get())
|
||||
{
|
||||
|
||||
updateTrack(track,sensorData);
|
||||
addSensorDataToSensorList(sensorData);
|
||||
|
||||
addSensorDataToSensorList(sensorData);
|
||||
lastUpdateTimestamp_ = std::chrono::steady_clock::now();
|
||||
|
||||
}
|
||||
|
||||
TracklistItem::TracklistItem(std::shared_ptr<SimCore::SimTrack> track):trackID_(track->getIdentifier())
|
||||
TracklistItem::TracklistItem(std::shared_ptr<SimCore::SimTrack> track):
|
||||
SimCore::SimTrack(*track.get())
|
||||
{
|
||||
updateTrack(track);
|
||||
lastUpdateTimestamp_ = std::chrono::steady_clock::now();
|
||||
|
||||
updateTrack(track);
|
||||
|
||||
}
|
||||
|
||||
SimCore::Identifier TracklistItem::getID()
|
||||
{
|
||||
return trackID_;
|
||||
}
|
||||
|
||||
|
||||
void TracklistItem::setPosition(SimCore::Position position)
|
||||
{
|
||||
position_ = position;
|
||||
}
|
||||
|
||||
SimCore::Position TracklistItem::getPosition()
|
||||
{
|
||||
return position_;
|
||||
}
|
||||
|
||||
void TracklistItem::setSpeed(double speed)
|
||||
{
|
||||
speed_ = speed;
|
||||
}
|
||||
|
||||
double TracklistItem::getSpeed()
|
||||
{
|
||||
return speed_;
|
||||
}
|
||||
|
||||
void TracklistItem::setCourse(double course)
|
||||
{
|
||||
course_ = course;
|
||||
}
|
||||
|
||||
double TracklistItem::getCourse()
|
||||
{
|
||||
return course_;;
|
||||
}
|
||||
|
||||
void TracklistItem::setPitch(double pitch)
|
||||
{
|
||||
pitch_ = pitch;
|
||||
}
|
||||
|
||||
double TracklistItem::getpitch()
|
||||
{
|
||||
return pitch_;
|
||||
}
|
||||
|
||||
double TracklistItem::getBearing()
|
||||
{
|
||||
return bearing_;
|
||||
}
|
||||
double TracklistItem::getRange()
|
||||
{
|
||||
return range_;
|
||||
}
|
||||
|
||||
SimCore::ObjectSource TracklistItem::getObjectSource()
|
||||
{
|
||||
return ObjectSource_;
|
||||
}
|
||||
|
||||
|
||||
std::chrono::time_point<std::chrono::steady_clock> TracklistItem::getLastUpdateTimestamp()
|
||||
{
|
||||
@@ -91,33 +38,41 @@ namespace TrackList {
|
||||
|
||||
void TracklistItem::updateTrack(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData)
|
||||
{
|
||||
|
||||
|
||||
position_ = track->getPosition();
|
||||
course_ = track->Course.getValue();
|
||||
speed_ = track->Speed.getValue();
|
||||
lastUpdateTimestamp_ = std::chrono::steady_clock::now();
|
||||
if(this->getIdentifier() == track->getIdentifier())
|
||||
{
|
||||
|
||||
this->setPosition(track->getPosition());
|
||||
this->Speed.setValue(track->Speed.getValue());
|
||||
this->Course.setValue(track->Course.getValue());
|
||||
|
||||
|
||||
|
||||
|
||||
if (isSensorinSensorlist(sensorData) != true) {
|
||||
addSensorDataToSensorList(sensorData);
|
||||
}
|
||||
|
||||
if (!isSensorinSensorlist(sensorData))
|
||||
{
|
||||
SensorList.push_back(sensorData);
|
||||
}
|
||||
lastUpdateTimestamp_ = std::chrono::steady_clock::now();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void TracklistItem::updateTrack(std::shared_ptr<SimCore::SimTrack> track )
|
||||
{
|
||||
|
||||
position_ = track->getPosition();
|
||||
course_ = track->Course.getValue();
|
||||
speed_ = track->Speed.getValue();
|
||||
lastUpdateTimestamp_ = std::chrono::steady_clock::now();
|
||||
|
||||
|
||||
|
||||
if(this->getIdentifier() == track->getIdentifier())
|
||||
{
|
||||
this->setPosition(track->getPosition());
|
||||
this->Speed.setValue(track->Speed.getValue());
|
||||
this->Course.setValue(track->Course.getValue());
|
||||
|
||||
}
|
||||
lastUpdateTimestamp_ = std::chrono::steady_clock::now();
|
||||
|
||||
}
|
||||
|
||||
size_t TracklistItem::getSensorCount()
|
||||
{
|
||||
return SensorList.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#include "SimCore/Identifier.hpp"
|
||||
#include "SimCore/Messages/SimTrack.hpp"
|
||||
#include <Entities/Tracklist/Tracklist.hpp>
|
||||
#include <ranges>
|
||||
#include <utility>
|
||||
|
||||
|
||||
|
||||
#define TRACK_TIMEOUT 5 * 60 *1000
|
||||
|
||||
namespace TrackList
|
||||
{
|
||||
|
||||
TrackList::TrackList(SimCore::Identifier OwnID):OwnID_(OwnID)
|
||||
TrackList::TrackList(SimCore::Identifier OwnID):OwnID_(OwnID),TrackTimeout_(5 * 60 *1000)
|
||||
{
|
||||
stopSanitizer_ = false;
|
||||
sanitizerThread_ = std::thread(&TrackList::tracklistSanitizer,this);
|
||||
@@ -31,90 +32,40 @@ namespace TrackList
|
||||
|
||||
|
||||
|
||||
SimCore::Identifier TrackList::getTrackID(SimCore::ObjectSource source)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
return *IDMaker.getNewIdentifier(source).get();
|
||||
}
|
||||
|
||||
|
||||
void TrackList::addTrack(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData)
|
||||
{
|
||||
|
||||
auto AllIDs = getAllIDs();
|
||||
// std::unique_lock<std::mutex> lock(mutex_);
|
||||
// lock.unlock();
|
||||
|
||||
if (AllIDs.size() == 0) {
|
||||
addNewTrack( track, sensorData);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto ID:AllIDs) {
|
||||
// std::lock_guard<std::mutex> lock(mutex_);
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
|
||||
auto TracklistItem = TrackList_.find(ID.serialize());
|
||||
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);
|
||||
|
||||
if (TracklistItem->second->isSensorIDKnown(sensorData.sensorID) == true) {
|
||||
|
||||
TracklistItem->second->updateTrack(track, sensorData);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// lock.unlock();
|
||||
|
||||
addNewTrack( track, sensorData);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}else {
|
||||
iterator->second->updateTrack(track,sensorData);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief
|
||||
/// @param track
|
||||
void TrackList::addTrack(std::shared_ptr<SimCore::SimTrack> track)
|
||||
|
||||
|
||||
void TrackList::addTrack(std::shared_ptr<SimCore::SimTrack> track)
|
||||
{
|
||||
|
||||
auto AllIDs = getAllIDs();
|
||||
// std::unique_lock<std::mutex> lock(mutex_);
|
||||
// lock.unlock();
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
|
||||
if (AllIDs.size() == 0) {
|
||||
addNewTrack( track);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto ID:AllIDs) {
|
||||
// std::lock_guard<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);
|
||||
|
||||
auto TracklistItem = TrackList_.find(ID.serialize());
|
||||
|
||||
if (TracklistItem != TrackList_.end()) {
|
||||
|
||||
TracklistItem->second->updateTrack(track);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// lock.unlock();
|
||||
|
||||
addNewTrack( track);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}else {
|
||||
iterator->second->updateTrack(track);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// lock.unlock();
|
||||
|
||||
}
|
||||
|
||||
void TrackList::addNewTrack(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData)
|
||||
@@ -123,8 +74,9 @@ namespace TrackList
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
auto item = std::make_shared<TracklistItem>( track, sensorData);
|
||||
std::string id = track->getIdentifier().serialize();
|
||||
TrackList_.emplace(id,item);
|
||||
|
||||
TrackList_.emplace(std::make_pair(track->getIdentifier().getUUID(),item));
|
||||
|
||||
}
|
||||
|
||||
void TrackList::addNewTrack(std::shared_ptr<SimCore::SimTrack> track)
|
||||
@@ -132,8 +84,7 @@ namespace TrackList
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
auto item = std::make_shared<TracklistItem>( track);
|
||||
std::string id = track->getIdentifier().serialize();
|
||||
TrackList_.emplace(id,item);
|
||||
TrackList_.emplace(track->getIdentifier().getUUID(),item);
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +93,7 @@ namespace TrackList
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
|
||||
std::shared_ptr<TracklistItem> result = nullptr;
|
||||
result = TrackList_.at(TrackID.serialize());
|
||||
result = TrackList_.at(TrackID.getUUID());
|
||||
if (result == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -155,7 +106,7 @@ namespace TrackList
|
||||
|
||||
std::vector<SimCore::Identifier> list;
|
||||
for (const auto& [key,value] : TrackList_) {
|
||||
list.emplace_back(SimCore::Identifier(key));
|
||||
list.emplace_back(key);
|
||||
}
|
||||
|
||||
return list;
|
||||
@@ -168,6 +119,15 @@ namespace TrackList
|
||||
|
||||
}
|
||||
|
||||
void TrackList::setTrackTimeout(int millseconds)
|
||||
{
|
||||
this->TrackTimeout_ = millseconds;
|
||||
}
|
||||
|
||||
int TrackList::getTrackTimeoutValue()
|
||||
{
|
||||
return TrackTimeout_;
|
||||
}
|
||||
|
||||
|
||||
void TrackList::tracklistSanitizer()
|
||||
@@ -182,9 +142,11 @@ namespace TrackList
|
||||
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 >= TRACK_TIMEOUT) {
|
||||
if (duration >= TrackTimeout_) {
|
||||
|
||||
it = TrackList_.erase(it);
|
||||
LOG_S(INFO)<<"Erased Track";
|
||||
|
||||
|
||||
}else
|
||||
{
|
||||
@@ -194,9 +156,10 @@ namespace TrackList
|
||||
lock.unlock() ;
|
||||
lock.lock();
|
||||
}
|
||||
// LOG_S(INFO)<<"running";
|
||||
|
||||
lock.unlock();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
lock.release();
|
||||
|
||||
}
|
||||
|
||||
@@ -22,20 +22,57 @@ SCENARIO("Testing the SimCore Sensor")
|
||||
{
|
||||
GIVEN("different Attributes for a Track in different forms")
|
||||
{
|
||||
|
||||
SimCore::Identifier OwnID;
|
||||
TrackList::TrackList List(OwnID);
|
||||
List.setTrackTimeout(5000);
|
||||
|
||||
double speed = 10;
|
||||
double course = 90;
|
||||
SimCore::Identifier id;
|
||||
auto track = std::make_shared<SimCore::SimTrack>(id,"Hamburg", SimCore::Kind::EntityKind::SURFACE,SimCore::Side::FRIEND);
|
||||
SimCore::Position pos;
|
||||
pos.setGeodesicPos(55, 8, 0);
|
||||
track->setPosition(pos);
|
||||
track->Speed.setValue(speed);
|
||||
track->Course.setValue(course);
|
||||
|
||||
|
||||
TrackList::SensorData Sensor1 =
|
||||
{
|
||||
.sensorID = SimCore::Identifier(),
|
||||
.Sensorname = "ARPA"
|
||||
};
|
||||
|
||||
TrackList::SensorData Sensor2 =
|
||||
{
|
||||
.sensorID = SimCore::Identifier(),
|
||||
.Sensorname = "SMART-L"
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
WHEN("constructing Track Object with data")
|
||||
{
|
||||
|
||||
List.addTrack(track,Sensor1);
|
||||
THEN("check if Track attributes are correct")
|
||||
{
|
||||
|
||||
// REQUIRE(InternalTracklist.size() == 1);
|
||||
|
||||
REQUIRE(List.size() == 1);
|
||||
REQUIRE(List.getTrack(id)->getPosition().getGeocentricPos() == pos.getGeocentricPos());
|
||||
REQUIRE(List.getTrack(id)->Speed.getValue() == speed);
|
||||
REQUIRE(List.getTrack(id)->Course.getValue() == course);
|
||||
REQUIRE(List.getTrack(id)->getSensorCount() == 1);
|
||||
track->Course.setValue(270);
|
||||
List.addTrack(track,Sensor2);
|
||||
// REQUIRE(List.getTrack(id)->Course.getValue() == 270);
|
||||
REQUIRE(List.getTrack(id)->getSensorCount() == 2);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5500));
|
||||
REQUIRE(List.size() == 0);
|
||||
|
||||
List.stopSanitizer();
|
||||
|
||||
|
||||
|
||||
} //THEN
|
||||
} // WHEN
|
||||
|
||||
79
tests/test_TracklistItem.cpp
Normal file
79
tests/test_TracklistItem.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
#include "Entities/Tracklist/Tracklist.hpp"
|
||||
#include "Entities/Tracklist/TracklistItem.hpp"
|
||||
#include "SimCore/IdentifierMaker.hpp"
|
||||
#include "SimCore/Messages/SimTrack.hpp"
|
||||
#include "SimCore/Position.hpp"
|
||||
#include "WHISPER/Messages/Message.hpp"
|
||||
#include <SimCore/Identifier.hpp>
|
||||
#include <SimCore/SimCore.hpp>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch2/catch.hpp>
|
||||
#include <loguru.hpp>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SCENARIO("Testing the SimCore Sensor")
|
||||
{
|
||||
GIVEN("different Attributes for a Track in different forms")
|
||||
{
|
||||
double speed = 10;
|
||||
double course = 90;
|
||||
SimCore::Identifier id;
|
||||
auto track = std::make_shared<SimCore::SimTrack>(id,"Hamburg", SimCore::Kind::EntityKind::SURFACE,SimCore::Side::FRIEND);
|
||||
SimCore::Position pos;
|
||||
pos.setGeodesicPos(55, 8, 0);
|
||||
track->setPosition(pos);
|
||||
track->Speed.setValue(speed);
|
||||
track->Course.setValue(course);
|
||||
|
||||
TrackList::TracklistItem item(track);
|
||||
|
||||
TrackList::SensorData Sensor1 =
|
||||
{
|
||||
.sensorID = SimCore::Identifier(),
|
||||
.Sensorname = "ARPA"
|
||||
};
|
||||
|
||||
TrackList::SensorData Sensor2 =
|
||||
{
|
||||
.sensorID = SimCore::Identifier(),
|
||||
.Sensorname = "SMART-L"
|
||||
};
|
||||
|
||||
item.addSensorDataToSensorList(Sensor1);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
WHEN("constructing Track Object with data")
|
||||
{
|
||||
track->Course.setValue(270);
|
||||
|
||||
item.updateTrack(track,Sensor2);
|
||||
|
||||
THEN("check if Track attributes are correct")
|
||||
{
|
||||
|
||||
REQUIRE(item.getPosition().getGeocentricPos() == pos.getGeocentricPos());
|
||||
REQUIRE(item.Speed.getValue() == speed);
|
||||
REQUIRE(item.Course.getValue() != course);
|
||||
REQUIRE(item.isSensorIDKnown(Sensor1.sensorID) == true);
|
||||
|
||||
REQUIRE(item.getSensorCount() == 2);
|
||||
REQUIRE(item.getLastUpdateTimestamp() < std::chrono::steady_clock::now());
|
||||
|
||||
|
||||
|
||||
} //THEN
|
||||
} // WHEN
|
||||
} // GIVEN
|
||||
} //SCENARIO
|
||||
Reference in New Issue
Block a user