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)
|
target_link_libraries(test_Tracklist Catch2::Catch2 EntityLibrary loguru)
|
||||||
catch_discover_tests(test_Tracklist)
|
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)
|
add_executable(test_MovementClass tests/test_MovementClass.cpp)
|
||||||
target_link_libraries(test_MovementClass Catch2::Catch2 EntityLibrary loguru)
|
target_link_libraries(test_MovementClass Catch2::Catch2 EntityLibrary loguru)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <SimCore/Position.hpp>
|
#include <SimCore/Position.hpp>
|
||||||
#include <SimCore/SafeMap.hpp>
|
#include <SimCore/SafeMap.hpp>
|
||||||
#include <Entities/Tracklist/TracklistItem.hpp>
|
#include <Entities/Tracklist/TracklistItem.hpp>
|
||||||
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
|
|
||||||
@@ -26,7 +27,7 @@ namespace TrackList
|
|||||||
|
|
||||||
void stopSanitizer();
|
void stopSanitizer();
|
||||||
|
|
||||||
SimCore::Identifier getTrackID(SimCore::ObjectSource source);
|
// SimCore::Identifier getTrackID(SimCore::ObjectSource source);
|
||||||
|
|
||||||
void addTrack(std::shared_ptr<SimCore::SimTrack> track);
|
void addTrack(std::shared_ptr<SimCore::SimTrack> track);
|
||||||
|
|
||||||
@@ -38,6 +39,9 @@ namespace TrackList
|
|||||||
|
|
||||||
size_t size();
|
size_t size();
|
||||||
|
|
||||||
|
void setTrackTimeout(int millseconds);
|
||||||
|
int getTrackTimeoutValue();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
const SimCore::Identifier OwnID_;
|
const SimCore::Identifier OwnID_;
|
||||||
@@ -56,6 +60,7 @@ namespace TrackList
|
|||||||
std::thread sanitizerThread_;
|
std::thread sanitizerThread_;
|
||||||
std::atomic_bool sanitizerIsRunning_;
|
std::atomic_bool sanitizerIsRunning_;
|
||||||
std::atomic_bool stopSanitizer_;
|
std::atomic_bool stopSanitizer_;
|
||||||
|
int TrackTimeout_ = 1000;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "SimCore/SimCore.hpp"
|
#include "SimCore/SimCore.hpp"
|
||||||
#include <SimCore/Position.hpp>
|
#include <SimCore/Position.hpp>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <cstddef>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -28,30 +29,12 @@ namespace TrackList {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TracklistItem
|
class TracklistItem: public SimCore::SimTrack
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
TracklistItem(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData);
|
TracklistItem(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData);
|
||||||
TracklistItem(std::shared_ptr<SimCore::SimTrack> track);
|
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();
|
std::chrono::time_point<std::chrono::steady_clock> getLastUpdateTimestamp();
|
||||||
|
|
||||||
@@ -65,30 +48,14 @@ namespace TrackList {
|
|||||||
|
|
||||||
void addSensorDataToSensorList(SensorData sensorData);
|
void addSensorDataToSensorList(SensorData sensorData);
|
||||||
|
|
||||||
|
size_t getSensorCount();
|
||||||
|
|
||||||
|
|
||||||
private:
|
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_;
|
std::chrono::time_point<std::chrono::steady_clock> lastUpdateTimestamp_;
|
||||||
|
|
||||||
SimCore::ObjectSource ObjectSource_;
|
|
||||||
|
|
||||||
std::vector<SensorData> SensorList;
|
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 <Entities/Tracklist/TracklistItem.hpp>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cstddef>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
namespace TrackList {
|
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);
|
updateTrack(track);
|
||||||
|
lastUpdateTimestamp_ = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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()
|
std::chrono::time_point<std::chrono::steady_clock> TracklistItem::getLastUpdateTimestamp()
|
||||||
{
|
{
|
||||||
@@ -90,34 +37,42 @@ namespace TrackList {
|
|||||||
|
|
||||||
|
|
||||||
void TracklistItem::updateTrack(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData)
|
void TracklistItem::updateTrack(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData)
|
||||||
|
{
|
||||||
|
if(this->getIdentifier() == track->getIdentifier())
|
||||||
{
|
{
|
||||||
|
|
||||||
|
this->setPosition(track->getPosition());
|
||||||
|
this->Speed.setValue(track->Speed.getValue());
|
||||||
|
this->Course.setValue(track->Course.getValue());
|
||||||
|
|
||||||
position_ = track->getPosition();
|
}
|
||||||
course_ = track->Course.getValue();
|
|
||||||
speed_ = track->Speed.getValue();
|
if (!isSensorinSensorlist(sensorData))
|
||||||
|
{
|
||||||
|
SensorList.push_back(sensorData);
|
||||||
|
}
|
||||||
lastUpdateTimestamp_ = std::chrono::steady_clock::now();
|
lastUpdateTimestamp_ = std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (isSensorinSensorlist(sensorData) != true) {
|
|
||||||
addSensorDataToSensorList(sensorData);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TracklistItem::updateTrack(std::shared_ptr<SimCore::SimTrack> track )
|
void TracklistItem::updateTrack(std::shared_ptr<SimCore::SimTrack> track )
|
||||||
{
|
{
|
||||||
|
|
||||||
position_ = track->getPosition();
|
if(this->getIdentifier() == track->getIdentifier())
|
||||||
course_ = track->Course.getValue();
|
{
|
||||||
speed_ = track->Speed.getValue();
|
this->setPosition(track->getPosition());
|
||||||
|
this->Speed.setValue(track->Speed.getValue());
|
||||||
|
this->Course.setValue(track->Course.getValue());
|
||||||
|
|
||||||
|
}
|
||||||
lastUpdateTimestamp_ = std::chrono::steady_clock::now();
|
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 "SimCore/Messages/SimTrack.hpp"
|
||||||
#include <Entities/Tracklist/Tracklist.hpp>
|
#include <Entities/Tracklist/Tracklist.hpp>
|
||||||
|
#include <ranges>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define TRACK_TIMEOUT 5 * 60 *1000
|
|
||||||
|
|
||||||
namespace TrackList
|
namespace TrackList
|
||||||
{
|
{
|
||||||
|
|
||||||
TrackList::TrackList(SimCore::Identifier OwnID):OwnID_(OwnID)
|
TrackList::TrackList(SimCore::Identifier OwnID):OwnID_(OwnID),TrackTimeout_(5 * 60 *1000)
|
||||||
{
|
{
|
||||||
stopSanitizer_ = false;
|
stopSanitizer_ = false;
|
||||||
sanitizerThread_ = std::thread(&TrackList::tracklistSanitizer,this);
|
sanitizerThread_ = std::thread(&TrackList::tracklistSanitizer,this);
|
||||||
@@ -31,100 +32,51 @@ 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)
|
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) {
|
std::unique_lock<std::mutex> lock(mutex_);
|
||||||
addNewTrack( track, sensorData);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (auto ID:AllIDs) {
|
|
||||||
// std::lock_guard<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) {
|
}else {
|
||||||
|
iterator->second->updateTrack(track,sensorData);
|
||||||
TracklistItem->second->updateTrack(track, sensorData);
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// lock.unlock();
|
|
||||||
|
|
||||||
addNewTrack( 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_);
|
||||||
// std::unique_lock<std::mutex> lock(mutex_);
|
|
||||||
// lock.unlock();
|
|
||||||
|
|
||||||
if (AllIDs.size() == 0) {
|
auto iterator = TrackList_.find(track->getIdentifier().getUUID());
|
||||||
addNewTrack( track);
|
if (iterator == TrackList_.end()) {
|
||||||
}
|
auto item = std::make_shared<TracklistItem>( track);
|
||||||
else
|
TrackList_.emplace(track->getIdentifier().getUUID(),item);
|
||||||
{
|
|
||||||
for (auto ID:AllIDs) {
|
|
||||||
// std::lock_guard<std::mutex> lock(mutex_);
|
|
||||||
|
|
||||||
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)
|
void TrackList::addNewTrack(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData)
|
||||||
{
|
{
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
|
||||||
auto item = std::make_shared<TracklistItem>( track, sensorData);
|
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)
|
void TrackList::addNewTrack(std::shared_ptr<SimCore::SimTrack> track)
|
||||||
@@ -132,8 +84,7 @@ namespace TrackList
|
|||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
|
||||||
auto item = std::make_shared<TracklistItem>( track);
|
auto item = std::make_shared<TracklistItem>( track);
|
||||||
std::string id = track->getIdentifier().serialize();
|
TrackList_.emplace(track->getIdentifier().getUUID(),item);
|
||||||
TrackList_.emplace(id,item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -142,7 +93,7 @@ namespace TrackList
|
|||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
|
||||||
std::shared_ptr<TracklistItem> result = nullptr;
|
std::shared_ptr<TracklistItem> result = nullptr;
|
||||||
result = TrackList_.at(TrackID.serialize());
|
result = TrackList_.at(TrackID.getUUID());
|
||||||
if (result == nullptr) {
|
if (result == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@@ -155,7 +106,7 @@ namespace TrackList
|
|||||||
|
|
||||||
std::vector<SimCore::Identifier> list;
|
std::vector<SimCore::Identifier> list;
|
||||||
for (const auto& [key,value] : TrackList_) {
|
for (const auto& [key,value] : TrackList_) {
|
||||||
list.emplace_back(SimCore::Identifier(key));
|
list.emplace_back(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
@@ -168,6 +119,15 @@ namespace TrackList
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrackList::setTrackTimeout(int millseconds)
|
||||||
|
{
|
||||||
|
this->TrackTimeout_ = millseconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
int TrackList::getTrackTimeoutValue()
|
||||||
|
{
|
||||||
|
return TrackTimeout_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void TrackList::tracklistSanitizer()
|
void TrackList::tracklistSanitizer()
|
||||||
@@ -182,9 +142,11 @@ namespace TrackList
|
|||||||
auto end = std::chrono::steady_clock::now();
|
auto end = std::chrono::steady_clock::now();
|
||||||
std::chrono::milliseconds::rep duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - it->second->getLastUpdateTimestamp() ).count();
|
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);
|
it = TrackList_.erase(it);
|
||||||
|
LOG_S(INFO)<<"Erased Track";
|
||||||
|
|
||||||
|
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
@@ -194,9 +156,10 @@ namespace TrackList
|
|||||||
lock.unlock() ;
|
lock.unlock() ;
|
||||||
lock.lock();
|
lock.lock();
|
||||||
}
|
}
|
||||||
|
// LOG_S(INFO)<<"running";
|
||||||
|
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||||
lock.release();
|
lock.release();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,19 +22,56 @@ SCENARIO("Testing the SimCore Sensor")
|
|||||||
{
|
{
|
||||||
GIVEN("different Attributes for a Track in different forms")
|
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")
|
WHEN("constructing Track Object with data")
|
||||||
{
|
{
|
||||||
|
List.addTrack(track,Sensor1);
|
||||||
THEN("check if Track attributes are correct")
|
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
|
} //THEN
|
||||||
|
|||||||
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