Compare commits

..

10 Commits

Author SHA1 Message Date
hwinkel
b5eb76771d ADD: added comments to entity library and changed drone.yml and removed some specific ide files 2024-03-15 12:46:03 +01:00
hwinkel
0ec7bb4c66 FIX: fixed protobuf path 2024-03-15 11:46:59 +01:00
Henry Winkel
b2da644fa2 ADD: added drone.yml and codecheck.skip 2024-03-14 18:24:42 +01:00
Henry Winkel
e039b36ed5 FIX: fixed automated deletion of tracks after time 2024-03-14 18:23:21 +01:00
Henry Winkel
671f763f45 ADD: added function to get all sensors as vector and map 2024-03-14 18:23:00 +01:00
Henry Winkel
87368640e2 ADD: added automatic delete of lost tracks 2024-03-14 17:48:54 +01:00
Henry Winkel
d56df03ed4 ADD: changed way how sensors are recognised 2024-03-14 17:48:18 +01:00
Henry Winkel
56577388e8 ADD: added Command Port to protected variables 2024-03-14 17:46:01 +01:00
Henry Winkel
453d3c27c4 ADD: added tests 2024-03-11 13:12:56 +01:00
Henry Winkel
ae7a65dff9 ADD: added use of raw tracklist update 2024-03-11 12:58:45 +01:00
17 changed files with 397 additions and 173 deletions

52
.drone.yml Normal file
View File

@@ -0,0 +1,52 @@
kind: pipeline
type: kubernetes
name: default-build
steps:
- name: submodules
image: alpine/git
commands:
- sed -i 's/ssh\\:..git@/https\\:\\/\\//' .gitmodules
- sed -i 's/\:12000//' .gitmodules
- git submodule update --init --recursive --jobs=4
- name: build
image: kmaster.ti.unibw-hamburg.de:30808/debianbullseye
commands:
- sed -i 's/ssh\\:..git@/https\\:\\/\\//' .gitmodules
- sed -i 's/\:12000//' .gitmodules
- git submodule update --init --recursive --jobs=4
- mkdir -p build && cd build
- CC=clang-11 CXX=clang++-11 cmake -DCMAKE_BUILD_TYPE=DEBUG ..
- make -j
- make test
# - name: EntiyLibrary
# image: kmaster.ti.unibw-hamburg.de:30808/drone-ftewa-codechecker
# pull: always
# settings:
# CODECHECKER_URL: "http://codechecker:8001"
# CODECHECKER_PRODUCT: "EntiyLibrary"
# CODECHECKER_USER:
# from_secret: CODECHECKER_USER_SECRET
# CODECHECKER_PASS:
# from_secret: CODECHECKER_PASS_SECRET
# when:
# event:
# include:
# - push
# - pull_request
---
kind: secret
name: CODECHECKER_USER_SECRET
get:
path: codechecker-client
name: username
---
kind: secret
name: CODECHECKER_PASS_SECRET
get:
path: codechecker-client
name: password

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
build/
.cache
.vscode

16
.vscode/launch.json vendored
View File

@@ -1,16 +0,0 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug-SensorManager",
"type": "gdb",
"request": "launch",
"target": "./test_SensorManager",
"cwd": "${workspaceRoot}/build",
"valuesFormatting": "parseText"
}
]
}

View File

@@ -16,7 +16,7 @@ function(protobuf_generate_cpp)
${ARGN})
FILE(GLOB PROTO_FILES ${protobuf_PROTO_PATH}/*.proto)
set(PROTOC ${CMAKE_BINARY_DIR}/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/protoc)
set(PROTOC ${CMAKE_BINARY_DIR}/libs/OrderLibrary/libs/SimCore/libs/SimCom/libs/protobuf/protoc)
message(STATUS "protoc path: " ${PROTOC})
FOREACH(proto ${PROTO_FILES})
@@ -29,7 +29,7 @@ function(protobuf_generate_cpp)
add_custom_command(
OUTPUT "${protoDIR}/${protoFILENAME}.pb.cc"
DEPENDS "${protoDIR}/${protoFILENAME}.proto"
COMMAND ${PROTOC} --cpp_out=${protoDIR} --proto_path=${protoDIR} --proto_path="${CMAKE_SOURCE_DIR}/libs/OrderLibrary/libs/SimCore/include/SimCore/Messages/Protos" --proto_path="${CMAKE_SOURCE_DIR}/libs/OrderLibrary/libs/SimCore/libs/whisper-com/libs/protobuf/src" "${protoDIR}/${protoFILENAME}.proto"
COMMAND ${PROTOC} --cpp_out=${protoDIR} --proto_path=${protoDIR} --proto_path="${CMAKE_SOURCE_DIR}/libs/OrderLibrary/libs/SimCore/include/SimCore/Messages/Protos" --proto_path="${CMAKE_SOURCE_DIR}/libs/OrderLibrary/libs/SimCore/libs/SimCom/libs/protobuf/src" "${protoDIR}/${protoFILENAME}.proto"
)

4
codecheck.skip Normal file
View File

@@ -0,0 +1,4 @@
-/usr/*
-*/tests/test_*
-*/libs/*

View File

@@ -1,5 +1,7 @@
#pragma once
#define LOGURU_WITH_STREAMS 1
#include <loguru.hpp>
#include <Entities/Tracklist/Tracklist.hpp>
#include "DirectCommunicationServer.hpp"
@@ -31,24 +33,6 @@
namespace Entities {
// struct SensorClientData
// {
// std::string SensorName;
// bool isActive;
// SimCore::Identifier SensorID;
// // std::shared_ptr<WHISPER::InternalUDPSender> SensorSender;
// };
struct EffectorClientData
{
std::string EffectorName;
bool isActive;
SimCore::Identifier EffectorID;
std::shared_ptr<WHISPER::InternalUDPSender> EffectorSender;
};
class Entity {
public:
Entity(const SimCore::Identifier OwnID,
@@ -64,59 +48,95 @@ namespace Entities {
bool online);
~Entity();
/**
* @brief starts the Entity APP
*/
void start();
/**
* @brief stops the Entity
*/
void stop();
void setPosition(SimCore::Position);
/**
* @brief sets the current entity position
*/
void setPosition(SimCore::Position pos);
/**
* @brief sets the speed of the Entity
* @param speed - double
*/
void setSpeed(double speed);
/**
* @brief set the course of the entity (heading, course over ground) in degree
* @param course - double
*/
void setCourse(double course);
/**
* @brief sets the pitch (climb angle) in degree
* @param pitch - double
*/
void setPitch( double pitch);
protected:
/**
* @brief is the child worker function which is called on every circle
*/
virtual void childWorker() = 0;
/**
* @brief is function whick is called to stop the specific child class
*/
virtual void stopChild() = 0;
protected:
/// @brief shared_ptr of the own track
std::shared_ptr<SimCore::SimTrack> OwnShipTrack = nullptr;
std::unique_ptr<TrackList::TrackList> TrackList_ = nullptr;
/// @brief name of the entity (marking)
std::string EntityName_;
/// @brief Entity Kind var (is enum)
SimCore::Kind::EntityKind EntityKind_;
/// @brief Entity Side (is enum)
SimCore::Side::EntitySide EntitySide_;
/// @brief Radar cross section
double RCS_;
/// @brief port of the movement worker
ushort MovemntWorkerPort_;
/// @brief port which the sensor are connecting to
ushort SensorPort_;
/// @brief shared ptr of the Podcontroller
std::shared_ptr<kubecontrol::PodController> PodController_;
/// @brief unique ptr of the sensor manager
std::unique_ptr<SensorManager> SensorManager_;
/// @brief broadcast server the own ship message is use to send
std::shared_ptr<WHISPER::InternalUDPSender> BroadcastServer_;
/// @brief address of the ground thruth (default = 239.0.0.1)
std::string GroundTruthAddr_;
/// @brief port of the ground thruth
std::uint32_t GroundTruthPort_;
/// @brief port on which commands are received
ushort CommandPort_;
private:
/// @brief indicates if entity is startet in a kubernetes cluster
bool online_;
std::vector<std::thread> threads;
std::atomic<bool> stopMainLoop = false;
/// @brief vector of all startet threads
std::vector<std::thread> threads_;
///
std::atomic_bool stopMainLoop_ = false;
void MainLoop();
void startMovementWorker();
std::atomic<bool> MovementWorkerStarted = false;
std::atomic_bool MovementWorkerStarted_ = false;
std::shared_ptr<DirectCommunication::DirectCommunicationServer> MovemtServer_ = nullptr;
void handleMovement();
std::string MovementPodUUID_;
@@ -124,7 +144,7 @@ namespace Entities {
std::shared_ptr<DirectCommunication::DirectCommunicationServer> CommandCommsServer_ = nullptr;
void handleExternalComms(std::string msg);
void handleExternalComms(const std::string &msg);

View File

@@ -1,5 +1,6 @@
#pragma once
#include "SimCore/Identifier.hpp"
#include "SimCore/Messages/SensorTracklistItem.hpp"
#include "SimCore/SimCore.hpp"
#include <SimCore/Messages/SimTrack.hpp>
#include <kubecontrol/KubePod.hpp>
@@ -20,6 +21,7 @@ namespace Sensor
SensorControl(SimCore::Identifier ID, std::string Name, std::string IP, SimCore::SensorKinds sensorKind);
SimCore::SensorTracklistItem getSensorTracklistItem();

View File

@@ -4,6 +4,7 @@
#include "Entities/SensorControl.hpp"
#include "Entities/Tracklist/Trackfusion.hpp"
#include "SimCore/Identifier.hpp"
#include "SimCore/Messages/SensorTracklistUpdate.hpp"
#include "SimCore/Messages/SimTrack.hpp"
#include "SimCore/Messages/TracklistUpdate.hpp"
#include "SimCore/SimCore.hpp"
@@ -15,6 +16,7 @@
#include <memory>
#include <string>
#include <sys/types.h>
#include <vector>
namespace Entities
{
@@ -68,6 +70,20 @@ namespace Entities
*/
std::shared_ptr<Sensor::SensorControl> getSensorByUUID(std::string uuid);
/**
* @brief Get the Sensor List As Vector of shared pointer of sensorcontrols
*
* @return std::vector<std::shared_ptr<Sensor::SensorControl>>
*/
std::vector<std::shared_ptr<Sensor::SensorControl>> getSensorListAsVector();
/**
* @brief Get the Sensor List As Map of shared pointer of sensorcontrols
*
* @return std::map<std::string, std::shared_ptr<Sensor::SensorControl>>
*/
std::map<std::string, std::shared_ptr<Sensor::SensorControl>> getSensorListAsMap();
/**
@@ -117,7 +133,17 @@ namespace Entities
*
* @return std::unique_ptr<SimCore::TracklistUpdate>
*/
std::unique_ptr<SimCore::TracklistUpdate> getTrackListUpdate();
std::unique_ptr<SimCore::TracklistUpdate> getTrackListUpdateFusioned();
/**
* @brief Get the Track List Update Raw
*
* in this list every sensor has its own tracks without a sensorfusion over all sensors
*
* @return std::unique_ptr<SimCore::SensorTracklistUpdate>
*/
std::unique_ptr<SimCore::SensorTracklistUpdate> getTrackListUpdateRaw();
/**
* @brief send the ownShipTrack to all connected Sensors

View File

@@ -3,6 +3,7 @@
#include "SimCore/Identifier.hpp"
#include "SimCore/IdentifierMaker.hpp"
#include "SimCore/Messages/SensorTrack.hpp"
#include "SimCore/Messages/SimTrack.hpp"
#include "nlohmann/json.hpp"
#include <atomic>
@@ -16,6 +17,7 @@
#include <string>
#include <thread>
#include <loguru.hpp>
#include <SimCore/CallBackTimer.hpp>
namespace TrackList
{
@@ -24,21 +26,36 @@ namespace TrackList
{
public:
TrackList();
void addTrack(std::shared_ptr<SimCore::SimTrack> Track);
std::shared_ptr<SimCore::SimTrack> getTrack(SimCore::Identifier);
~TrackList();
TrackList(const TrackList &other);
TrackList& operator=(const TrackList & oter);
void addTrack(std::shared_ptr<SimCore::SensorTrack> Track);
std::shared_ptr<SimCore::SensorTrack> getTrack(SimCore::Identifier);
void deleteTrack(std::string ID);
void deleteTrack(SimCore::Identifier);
std::shared_ptr<SimCore::SimTrack> getTrackBySringID(std::string ID);
std::shared_ptr<SimCore::SensorTrack> getTrackBySringID(std::string ID);
size_t getSize();
void getJsonTRackList(nlohmann::json &message);
std::map<std::string, std::shared_ptr<SimCore::SensorTrack>> getTrackStore();
/**
* @brief cheks the trackstore for old tracks to delete
*
*/
void checkTrackStore();
private:
mutable std::mutex mx_;
std::map<std::string, std::shared_ptr<SimCore::SimTrack>> TrackStore_;
std::map<std::string, std::shared_ptr<SimCore::SensorTrack>> TrackStore_;
/// seconds after the last updated a track gets deleted
const int trackNoUpdateTime = 10;
CallBackTimer timer_;
};

View File

@@ -1,4 +1,4 @@
#include "DirectCommunicationServer.hpp"
#include <DirectCommunicationServer.hpp>
#include "Entities/Movement.hpp"
#include "Entities/SensorManager.hpp"
#include "Orders/MoveOrder.hpp"
@@ -56,6 +56,7 @@ namespace Entities
EntitySide_(EntitySide),
GroundTruthPort_(GroundTruthPort),
GroundTruthAddr_(GroundTruthAddr),
CommandPort_(CommandPort),
SensorPort_(SensorPort),
online_(online)
@@ -79,7 +80,6 @@ namespace Entities
// BroadcastServer_ = std::make_shared<WHISPER::InternalUDPSender>("239.0.0.1", 10000);
// TrackList_ = std::make_unique<TrackList::TrackList>();
}
@@ -98,7 +98,7 @@ namespace Entities
Orders::MoveOrder moveorder(OwnShipTrack->getIdentifier());
moveorder.setPosition(pos);
if(MovementWorkerStarted == true)
if(MovementWorkerStarted_ == true)
{
MovemtServer_->sendMessage(moveorder.buildMessage());
LOG_S(INFO)<<"Move Order send";
@@ -109,7 +109,7 @@ namespace Entities
OwnShipTrack->Speed.setValue(val);
Orders::MoveOrder moveorder(OwnShipTrack->getIdentifier());
moveorder.Speed.setValue(val);
if(MovementWorkerStarted == true)
if(MovementWorkerStarted_ == true)
{
MovemtServer_->sendMessage(moveorder.buildMessage());
LOG_S(INFO)<<"Move Order send with Speed";
@@ -120,7 +120,7 @@ namespace Entities
OwnShipTrack->Course.setValue(val);
Orders::MoveOrder moveorder(OwnShipTrack->getIdentifier());
moveorder.Course.setValue(val);
if(MovementWorkerStarted == true)
if(MovementWorkerStarted_ == true)
{
MovemtServer_->sendMessage(moveorder.buildMessage());
LOG_S(INFO)<<"Move Order send with Course";
@@ -135,13 +135,9 @@ namespace Entities
void Entity::start()
{
stopMainLoop_ = false;
stopMainLoop = false;
threads.emplace_back(std::thread(&Entity::MainLoop,this));
threads_.emplace_back(std::thread(&Entity::MainLoop,this));
}
@@ -160,18 +156,18 @@ namespace Entities
SensorManager_->stop();
for (std::vector<std::thread>::iterator it = threads.begin(); it != threads.end();)
for (std::vector<std::thread>::iterator it = threads_.begin(); it != threads_.end();)
{
if (it->joinable())
{
it->join();
it = threads.erase(it);
it = threads_.erase(it);
}
}
LOG_S(ERROR)<< "Remaining Threads: " << threads.size();
LOG_S(ERROR)<< "Remaining Threads: " << threads_.size();
// std::this_thread::sleep_for(std::chrono::milliseconds(30000));
// exit(0);
@@ -184,10 +180,13 @@ namespace Entities
LOG_S(INFO)<<"__ONLINE__";
MovementPodUUID_ = xg::newGuid().str();
LOG_S(INFO)<<this->OwnShipTrack->getIdentifier().getUUID();
kubecontrol::KubePod MovementPod(this->OwnShipTrack->getIdentifier().getUUID(),MovementPodUUID_,"movementimage:latest");
std::string MovementImage = "movementimage:latest";
std::string component = "MovementCalculation";
std::string uuid = this->OwnShipTrack->getIdentifier().getUUID();
kubecontrol::KubePod MovementPod(uuid,MovementPodUUID_,MovementImage);
MovementPod.setEnvironmentVar("SERVER_IP", SimCore::UtilFunctions::getOwnIP());
MovementPod.setComponent("MovementCalculation");
MovementPod.setComponent(component);
PodController_->startPod(MovementPod);
LOG_S(INFO)<<PodController_->getServerAddress();
@@ -204,7 +203,7 @@ namespace Entities
{
LOG_S(INFO)<< "POS: LAT: "<< OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LATITUDE) << " LON: " << OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LONGITUDE);
MovementWorkerStarted = true;
MovementWorkerStarted_ = true;
MovemtServer_->sendMessage(OwnShipTrack->buildMessage());
LOG_S(INFO)<< "Initial Message send to MovementWorker";
}
@@ -214,7 +213,7 @@ namespace Entities
void Entity::handleMovement()
{
if (!MovementWorkerStarted)
if (!MovementWorkerStarted_)
{
startMovementWorker();
}else
@@ -229,20 +228,20 @@ namespace Entities
if (MovemtServer_->countClients() == 0)
{
MovementWorkerStarted = false;
MovementWorkerStarted_ = false;
LOG_S(WARNING)<<"Movementclient lost";
}
// std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
void Entity::handleExternalComms(std::string msg)
void Entity::handleExternalComms(const std::string &msg)
{
try {
WHISPER::Message whisperMsg(msg);
LOG_S(INFO)<<"New Message from TCP Client";
LOG_S(INFO)<<"Message Type is: " << whisperMsg.msgType_;
// LOG_S(INFO)<<"New Message from TCP Client";
// LOG_S(INFO)<<"Message Type is: " << whisperMsg.msgType_;
switch (whisperMsg.msgType_)
{
@@ -302,9 +301,16 @@ namespace Entities
break;
}
if (TrackListRequest->EntityID == OwnShipTrack->getIdentifier())
{
if (TrackListRequest->requestedFusioned() == true)
{
std::string senderUUID = whisperMsg.senderUUID_;
CommandCommsServer_->sendMessage(SensorManager_->getTrackListUpdate()->buildMessage(),senderUUID);
CommandCommsServer_->sendMessage(SensorManager_->getTrackListUpdateFusioned()->buildMessage(),senderUUID);
}else {
std::string senderUUID = whisperMsg.senderUUID_;
CommandCommsServer_->sendMessage(SensorManager_->getTrackListUpdateRaw()->buildMessage(),senderUUID);
}
}
break;
}
@@ -355,6 +361,7 @@ namespace Entities
default:
{
DLOG_S(INFO)<<"Message Type is: " << whisperMsg.msgType_;
}
@@ -372,7 +379,7 @@ namespace Entities
void Entity::MainLoop()
{
LOG_S(INFO)<< "main loop started";
while (!stopMainLoop)
while (!stopMainLoop_)
{
handleMovement();
childWorker();

View File

@@ -1,6 +1,7 @@
#include <SimCore/Messages/SensorData.hpp>
#include "Entities/Tracklist/Tracklist.hpp"
#include "SimCore/Identifier.hpp"
#include "SimCore/Messages/SensorTracklistItem.hpp"
#include "nlohmann/json_fwd.hpp"
#include <Entities/SensorControl.hpp>
#include <memory>
@@ -19,6 +20,22 @@ namespace Sensor
SimCore::SensorTracklistItem SensorControl::getSensorTracklistItem()
{
auto data = std::make_shared<SimCore::SensorData>(this->getID(),this->getName(),this->getIP(),this->getSensorKind());
SimCore::SensorTracklistItem item(data);
for(auto [key, track]: TrackStore.getTrackStore())
{
item.updateTrack(track);
}
return item;
}
}

View File

@@ -37,7 +37,7 @@ namespace Entities
void SensorManager::startSensor(std::shared_ptr<kubecontrol::KubePod> pod,SimCore::SensorKinds SensorKind)
{
PodController_->startPod(pod);
SensorStore[pod->getUUID()] = std::make_unique<Sensor::SensorControl>(SimCore::Identifier(pod->getUUID()),pod->getName(),pod->getIp(),SensorKind);
// SensorStore[pod->getUUID()] = std::make_unique<Sensor::SensorControl>(SimCore::Identifier(pod->getUUID()),pod->getName(),pod->getIp(),SensorKind);
}
@@ -87,6 +87,26 @@ namespace Entities
}
std::vector<std::shared_ptr<Sensor::SensorControl>> SensorManager::getSensorListAsVector()
{
std::vector<std::shared_ptr<Sensor::SensorControl>> SensorVector;
for (auto [key, value] : SensorStore)
{
SensorVector.push_back(value);
}
return SensorVector;
}
std::map<std::string, std::shared_ptr<Sensor::SensorControl>> SensorManager::getSensorListAsMap()
{
return SensorStore;
}
size_t SensorManager::getSensorCount()
{
return SensorStore.size();
@@ -96,6 +116,7 @@ namespace Entities
void SensorManager::handlSensorMessages(std::string Message)
{
WHISPER::Message msg(Message);
@@ -129,19 +150,16 @@ namespace Entities
void SensorManager::updateTracklistForSensor(std::string uuidSensor, std::shared_ptr<SimCore::SensorTrack> track)
{
auto sensor= getSensorByUUID(uuidSensor);
auto sensor = getSensorByUUID(uuidSensor);
if(sensor == nullptr)
{
return;
SensorStore[track->getSensorData()->getID().getUUID()] = std::make_unique<Sensor::SensorControl>(track->getSensorData()->getID(),track->getSensorData()->getName(),track->getSensorData()->getIP(),track->getSensorData()->getSensorKind());
sensor = getSensorByUUID(uuidSensor);
}
sensor->TrackStore.addTrack(track);
// auto it = SensorStore.find(uuidSensor);
// if( it != SensorStore.end())
// {
// it->second->TrackStore.addTrack(std::move(track));
// }
}
@@ -169,29 +187,29 @@ namespace Entities
nlohmann::json sonar;
nlohmann::json visual;
for(const auto& [key, value] : SensorStore )
for(const auto& [key, sensorItem] : SensorStore )
{
nlohmann::json sensor;
sensor["SensorName"] = value->getName();
sensor["SensorID"] = value->getID().getUUID();
sensor["SensorStatus"] = SimCore::toString(value->getSensorStatus());
sensor["SensorName"] = sensorItem->getName();
sensor["SensorID"] = sensorItem->getID().getUUID();
sensor["SensorStatus"] = SimCore::toString(sensorItem->getSensorStatus());
sensor["SensorEnabled"] = "false";
if (value->getSensorStatus() == SimCore::Status::ACTIVE)
if (sensorItem->getSensorStatus() == SimCore::Status::ACTIVE)
{
sensor["SensorEnabled"] = "true";
}
sensor["SensorDamaged"] = "false";
if (value->getSensorStatus() == SimCore::Status::DEFEKT || value->getSensorStatus() == SimCore::Status::DEGRADED)
if (sensorItem->getSensorStatus() == SimCore::Status::DEFEKT || sensorItem->getSensorStatus() == SimCore::Status::DEGRADED)
{
sensor["SensorDamaged"] = "true";
}
nlohmann::json contacts;
value->TrackStore.getJsonTRackList(contacts);
sensorItem->TrackStore.getJsonTRackList(contacts);
sensor["SensorContacts"] = contacts["Entities"];
switch (value->getSensorKind()) {
switch (sensorItem->getSensorKind()) {
case SimCore::SensorKinds::RADAR:
{
@@ -246,12 +264,32 @@ namespace Entities
}
std::unique_ptr<SimCore::TracklistUpdate> SensorManager::getTrackListUpdate()
std::unique_ptr<SimCore::TracklistUpdate> SensorManager::getTrackListUpdateFusioned()
{
return std::move(Trackfusion_.getTrackListUpdate(OwnId_));
}
std::unique_ptr<SimCore::SensorTracklistUpdate> SensorManager::getTrackListUpdateRaw()
{
auto Update = std::make_unique<SimCore::SensorTracklistUpdate>(OwnId_);
for(auto [key,item]: SensorStore)
{
Update->addTrack(item->getSensorTracklistItem());
}
return Update;
}
void SensorManager::sendOwnShipTrackToSensors()
{

View File

@@ -1,4 +1,6 @@
#include <Entities/Tracklist/Tracklist.hpp>
#include <chrono>
#include "SimCore/Messages/SensorTrack.hpp"
#include "SimCore/Messages/SimTrack.hpp"
@@ -6,13 +8,31 @@
namespace TrackList
{
TrackList::TrackList()
TrackList::TrackList():mx_()
{
TrackStore_ = std::map<std::string, std::shared_ptr<SimCore::SimTrack>>();
TrackStore_ = std::map<std::string, std::shared_ptr<SimCore::SensorTrack>>();
timer_.start(1000, std::bind(&TrackList::checkTrackStore,this));
}
void TrackList::addTrack(std::shared_ptr<SimCore::SimTrack> Track)
TrackList::~TrackList()
{
if (timer_.is_running()) {
timer_.stop();
}
}
TrackList::TrackList(const TrackList &other):mx_()
{
this->TrackStore_ = other.TrackStore_;
}
TrackList& TrackList::operator=(const TrackList & other)
{
this->TrackStore_ = other.TrackStore_;
return *this;
}
void TrackList::addTrack(std::shared_ptr<SimCore::SensorTrack> Track)
{
std::lock_guard<std::mutex> lock(mx_);
@@ -22,7 +42,7 @@ namespace TrackList
}
std::shared_ptr<SimCore::SimTrack> TrackList::getTrack(const SimCore::Identifier ID)
std::shared_ptr<SimCore::SensorTrack> TrackList::getTrack(const SimCore::Identifier ID)
{
std::lock_guard<std::mutex> lock(mx_);
@@ -30,7 +50,7 @@ namespace TrackList
return it->second;
}
std::shared_ptr<SimCore::SimTrack> TrackList::getTrackBySringID(std::string ID)
std::shared_ptr<SimCore::SensorTrack> TrackList::getTrackBySringID(std::string ID)
{
std::lock_guard<std::mutex> lock(mx_);
@@ -52,12 +72,17 @@ namespace TrackList
TrackStore_.erase(it);
}
std::map<std::string, std::shared_ptr<SimCore::SensorTrack>> TrackList::getTrackStore()
{
return TrackStore_;
}
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)
for (std::map<std::string, std::shared_ptr<SimCore::SensorTrack>>::iterator it=TrackStore_.begin(); it!=TrackStore_.end(); ++it)
{
nlohmann::json j;
j["id"] = it->first;
@@ -85,6 +110,26 @@ namespace TrackList
}
void TrackList::checkTrackStore()
{
std::lock_guard<std::mutex> lock(mx_);
for (auto iter = TrackStore_.begin(); iter != TrackStore_.end();)
{
if(duration_cast<std::chrono::seconds>(std::chrono::system_clock::now() - iter->second->getLastUpdateTime()).count() >= trackNoUpdateTime)
{
iter = TrackStore_.erase(iter);
}else {
iter++;
}
}
}

View File

@@ -215,7 +215,10 @@ SCENARIO("Testing the SimCore SensorManager with local sensors")
std::string tracklist1 = SensorManager_->getTracklistStringBySensor();
std::string tracklist2 = SensorManager_->getTracklistStringFusioned();
LOG_S(INFO)<<tracklist2;
LOG_S(INFO)<<tracklist1;
THEN("check if Track attributes are correct")
{
@@ -234,7 +237,14 @@ SCENARIO("Testing the SimCore SensorManager with local sensors")
REQUIRE( j2.size() == 8);
REQUIRE(SensorManager_->getSensorCount() == 4);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
REQUIRE(SensorManager_->getTrackListUpdateRaw()->getSensors().size() == 4);
REQUIRE(SensorManager_->getTrackListUpdateRaw()->getSensors().at(0).getTracksCount() == 3);
std::this_thread::sleep_for(std::chrono::milliseconds(10000));
REQUIRE(SensorManager_->getSensorListAsVector().at(0)->TrackStore.getSize() == 0);
SensorManager_->stop();

View File

@@ -34,6 +34,7 @@ SCENARIO("Testing the SimCore Sensor")
track->setPosition(pos);
track->Speed.setValue(speed);
track->Course.setValue(course);
auto SensorTrack = std::make_shared<SimCore::SensorTrack>(track);
SimCore::SensorData Sensor1(SimCore::Identifier(),"ARPA","127.0.0.1", SimCore::SensorKinds::RADAR);
@@ -45,7 +46,7 @@ SCENARIO("Testing the SimCore Sensor")
WHEN("constructing Track Object with data")
{
List.addTrack(track);
List.addTrack(SensorTrack);
THEN("check if Track attributes are correct")
{
@@ -55,7 +56,7 @@ SCENARIO("Testing the SimCore Sensor")
REQUIRE(List.getTrack(id)->Course.getValue() == course);
// REQUIRE(List.getTrack(id)->getSensorCount() == 1);
track->Course.setValue(270);
List.addTrack(track);
List.addTrack(SensorTrack);
// REQUIRE(List.getTrack(id)->Course.getValue() == 270);
// REQUIRE(List.getTrack(id)->getSensorCount() == 2);
std::this_thread::sleep_for(std::chrono::milliseconds(3000));