ADD: SensorManager with Trackfusion Trackstore and Sensor List wich contains every contact a sensor has

This commit is contained in:
Henry Winkel
2024-02-14 14:11:42 +01:00
parent cfe2aff5ce
commit 2a279f59ec
17 changed files with 678 additions and 425 deletions

View File

@@ -43,20 +43,20 @@ add_library(EntityLibrary STATIC
include/Entities/Movement.hpp
src/Entities/Movement.cpp
include/Entities/SensorControl.hpp
src/Entities/SensorControl.cpp
include/Entities/SensorManager.hpp
src/Entities/SensorManager.cpp
include/Entities/Tracklist/Trackfusion.hpp
src/Entities/Tracklist/Trackfusion.cpp
include/Entities/Tracklist/Tracklist.hpp
src/Entities/Tracklist/Tracklist.cpp
include/Entities/Tracklist/TracklistItem.hpp
src/Entities/Tracklist/TrackListItem.cpp
include/Entities/SensorManager.hpp
src/Entities/SensorManager.cpp
include/Entities/SensorControl.hpp
src/Entities/SensorControl.cpp
)
@@ -76,7 +76,9 @@ target_include_directories(EntityLibrary PUBLIC
src)
add_custom_command(TARGET EntityLibrary POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_SOURCE_DIR}/libs/KubeControl/docs $<TARGET_FILE_DIR:${PROJECT_NAME}>/docs)
#
# Everything TEST related
@@ -100,13 +102,13 @@ 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)
catch_discover_tests(test_MovementClass)
add_executable(test_SensorManager tests/test_SensorManager.cpp)
target_link_libraries(test_SensorManager Catch2::Catch2 EntityLibrary loguru)
catch_discover_tests(test_SensorManager)
ENDIF()

View File

@@ -31,13 +31,13 @@
namespace Entities {
struct SensorClientData
{
std::string SensorName;
bool isActive;
SimCore::Identifier SensorID;
// std::shared_ptr<WHISPER::InternalUDPSender> SensorSender;
};
// struct SensorClientData
// {
// std::string SensorName;
// bool isActive;
// SimCore::Identifier SensorID;
// // std::shared_ptr<WHISPER::InternalUDPSender> SensorSender;
// };
struct EffectorClientData
{
@@ -131,11 +131,11 @@ namespace Entities {
void startSensor();
std::shared_ptr<std::list<Entities::SensorClientData>> SensorStore_;
// std::shared_ptr<std::list<Entities::SensorClientData>> SensorStore_;
std::shared_ptr<SimCore::SafeMap<SimCore::Identifier, std::shared_ptr< SimCore::SimTrack>>> Trackstore_;
// std::shared_ptr<SimCore::SafeMap<SimCore::Identifier, std::shared_ptr< SimCore::SimTrack>>> Trackstore_;
};

View File

@@ -1,69 +1,34 @@
#pragma once
#include "SimCore/Identifier.hpp"
#include "SimCore/SimCore.hpp"
#include <SimCore/Messages/SimTrack.hpp>
#include <kubecontrol/KubePod.hpp>
#include <Entities/Tracklist/Tracklist.hpp>
#include <SimCore/Messages/SensorData.hpp>
#include <loguru.hpp>
#include <memory>
#include <string>
#include <vector>
namespace Entities
namespace Sensor
{
class SensorControl
class SensorControl : public SimCore::SensorData
{
public:
SensorControl(std::string ID, std::string Name, std::string IP, SimCore::SensorKinds sensorKind);
SensorControl(SimCore::Identifier ID, std::string Name, std::string IP, SimCore::SensorKinds sensorKind);
/**
* @brief Get the Name of the Sensor
*
* @return std::string
*/
std::string getName();
/**
* @brief Get the UUID of the Sensor
*
* @return std::string
*/
std::string getID();
/**
* @brief Get the Sensor Kind
*
* @return SimCore::SensorKinds
*/
SimCore::SensorKinds getSensorKind();
/**
* @brief Get the Sensor Status
*
* @return SimCore::Status
*/
SimCore::Status getSensorStatus();
/**
* @brief updates the sensor status
*
* @param SimCore::Status
*/
void updateStatus(SimCore::Status status);
std::unique_ptr<TrackList::TrackList> TrackStore;
TrackList::TrackList TrackStore;
private:
const std::string ID_;
std::string Name_;
std::string IP_;
SimCore::SensorKinds SensorKind_;
SimCore::Status SensorSatus_;

View File

@@ -2,10 +2,13 @@
#include "DirectCommunicationServer.hpp"
#include "Entities/SensorControl.hpp"
#include "Entities/Tracklist/Trackfusion.hpp"
#include "SimCore/Identifier.hpp"
#include "SimCore/Messages/SimTrack.hpp"
#include "SimCore/Messages/TracklistUpdate.hpp"
#include "SimCore/SimCore.hpp"
#include "kubecontrol/PodController.hpp"
#include <cstddef>
#include <loguru.hpp>
#include <map>
@@ -36,12 +39,34 @@ namespace Entities
*/
void stopSenser(std::string uuid);
/**
* @brief stopps all sensors
*
*/
void stopAllSensors();
/**
*@brief deletes a sensor pod based on the uuid
*@param string uuid sensor
*/
void deleteSensor(std::string uuid);
/**
* @brief deletes all sensors
*
*/
void deleteAllSensor();
/**
* @brief Get the Sensor By UUID
*
* @param uuid
* @return std::shared_ptr<Sensor::SensorControl>
*/
std::shared_ptr<Sensor::SensorControl> getSensorByUUID(std::string uuid);
/**
*@brief get the Tracklist as JSON formatted string where you can see the tracks every sensor detects
*@return string - JSON formatted string
@@ -62,15 +87,49 @@ namespace Entities
*/
void updateTracklistForSensor(std::string uuidSensor, std::shared_ptr<SimCore::SimTrack> track);
/**
* @brief sends a message to a specific sensor if uuid is passed else it sends to everyone
*
* @param message - string of the message
* @param uuid - uuid as string
*/
void sendMessageToSensor(std::string message, std::string uuid = "");
/**
* @brief adds a Sensorcontroll unique pointer to sensor store without starting a pod. it is just local
* @param sensor
*
*/
void addSensorLocal(std::unique_ptr<Sensor::SensorControl> sensor);
/**
* @brief Get the number of sensors
*
* @return size_t
*/
size_t getSensorCount();
/**
* @brief Get the Track List Update object
*
* @return std::unique_ptr<SimCore::TracklistUpdate>
*/
std::unique_ptr<SimCore::TracklistUpdate> getTrackListUpdate();
private:
const SimCore::Identifier OwnId_;
ushort SensorPort_ = 5557;
std::map<std::string, std::unique_ptr<Entities::SensorControl>> SensorStore;
std::map<std::string, std::shared_ptr<Sensor::SensorControl>> SensorStore;
std::shared_ptr<kubecontrol::PodController> PodController_;
TrackList::Trackfusion Trackfusion_;
std::shared_ptr<DirectCommunication::DirectCommunicationServer> SensorServer_ = nullptr;
void handlSensorMessages(std::string Message);

View File

@@ -0,0 +1,84 @@
#pragma once
#include <SimCore/Messages/TracklistItem.hpp>
#include "SimCore/Identifier.hpp"
#include "SimCore/Messages/SimTrack.hpp"
#include <SimCore/Messages/TracklistUpdate.hpp>
#include <map>
#include <memory>
#include <mutex>
#include <string>
namespace TrackList
{
class Trackfusion
{
public:
/**
* @brief adds or updates track
*
* @param track shared pointer of a simtrack
* @param sensorData
*/
void addOrUpdateTrack(std::shared_ptr<SimCore::SimTrack> track,std::shared_ptr<SimCore::SensorData> sensorData);
/**
* @brief deltets a track based on a SimCore::Identifier
*
*/
void deleteTrack(SimCore::Identifier id);
/**
* @brief deletes a track based on a string uuid
*
* @param UUID
*/
void deleteTrack(std::string UUID);
/**
* @brief Get the Tracklist As String
*
* @return std::string
*/
std::string getTracklistAsString();
/**
* @brief retruns a shared pointer of a track
*
* @param id
* @return std::shared_ptr<TracklistItem>
*/
std::shared_ptr<SimCore::TracklistItem> findTrack(SimCore::Identifier id);
/**
* @brief returns a shared pointer of a track
*
* @param UUID
* @return std::shared_ptr<TracklistItem>
*/
std::shared_ptr<SimCore::TracklistItem> findTrack(std::string UUID);
/**
* @brief Get the Track List Update object
*
* @return std::unique_ptr<SimCore::TracklistUpdate>
*/
std::unique_ptr<SimCore::TracklistUpdate> getTrackListUpdate(SimCore::Identifier ID);
private:
mutable std::mutex mx_;
std::unordered_map<SimCore::Identifier, std::shared_ptr<SimCore::TracklistItem>> TrackStore_;
};
}

View File

@@ -12,7 +12,7 @@
#include <SimCore/Position.hpp>
#include <SimCore/SafeMap.hpp>
#include <Entities/Tracklist/TracklistItem.hpp>
// #include <Entities/Tracklist/TracklistItem.hpp>
#include <string>
#include <thread>
#include <loguru.hpp>

View File

@@ -1,70 +0,0 @@
#pragma once
#include "SimCore/Identifier.hpp"
#include "SimCore/Messages/SimTrack.hpp"
#include "SimCore/SimCore.hpp"
#include <SimCore/Position.hpp>
#include <chrono>
#include <cstddef>
#include <list>
#include <memory>
#include <vector>
namespace TrackList {
struct SensorData {
SimCore::Identifier sensorID;
// SimCore::Identifier SensorTrackID;
std::string Sensorname;
};
inline bool operator==(const SensorData& lhs, const SensorData& rhs)
{
return lhs.sensorID == rhs.sensorID;
}
class TracklistItem: public SimCore::SimTrack
{
public:
TracklistItem(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData);
TracklistItem(std::shared_ptr<SimCore::SimTrack> track);
std::chrono::time_point<std::chrono::steady_clock> getLastUpdateTimestamp();
void updateTrack(std::shared_ptr<SimCore::SimTrack> track,SensorData sensorData);
void updateTrack(std::shared_ptr<SimCore::SimTrack> track);
bool checkIfSensorIDIsIn(SimCore::Identifier SensorTrackID);
bool isSensorIDKnown(SimCore::Identifier);
void addSensorDataToSensorList(SensorData sensorData);
size_t getSensorCount();
private:
std::chrono::time_point<std::chrono::steady_clock> lastUpdateTimestamp_;
std::vector<SensorData> SensorList;
bool isSensorinSensorlist(SensorData sensorData);
};
}

View File

@@ -3,6 +3,7 @@
#include "Entities/SensorManager.hpp"
#include "Orders/MoveOrder.hpp"
#include "Orders/Order.hpp"
#include "Orders/TracklistRequest.hpp"
#include "SimCore/Messages/Control.hpp"
#include "SimCore/Messages/SimTrack.hpp"
#include "SimCore/UtilFunctions.hpp"
@@ -68,10 +69,9 @@ namespace Entities
MovemtServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(__MOVEMENT_SERVER_PORT__,OwnID.getUUID());
CommandCommsServer_ = std::make_shared<DirectCommunication::DirectCommunicationServer>(CommandPort,OwnID.getUUID());
CommandCommsServer_->registerMessageCallback(std::bind(&Entity::handleExternalComms,this,std::placeholders::_1));
BroadcastServer_ = std::make_shared<WHISPER::InternalUDPSender>(GroundTruthAddr, GroundTruthPort);
BroadcastServer_ = std::make_shared<WHISPER::InternalUDPSender>(OwnID.getUUID(),GroundTruthAddr, GroundTruthPort);
@@ -98,7 +98,7 @@ namespace Entities
moveorder.setPosition(pos);
if(MovementWorkerStarted == true)
{
MovemtServer_->sendMessage(moveorder.buildMessage().serialize());
MovemtServer_->sendMessage(moveorder.buildMessage());
LOG_S(INFO)<<"Move Order send";
}
}
@@ -109,7 +109,7 @@ namespace Entities
moveorder.Speed.setValue(val);
if(MovementWorkerStarted == true)
{
MovemtServer_->sendMessage(moveorder.buildMessage().serialize());
MovemtServer_->sendMessage(moveorder.buildMessage());
LOG_S(INFO)<<"Move Order send with Speed";
}
}
@@ -120,7 +120,7 @@ namespace Entities
moveorder.Course.setValue(val);
if(MovementWorkerStarted == true)
{
MovemtServer_->sendMessage(moveorder.buildMessage().serialize());
MovemtServer_->sendMessage(moveorder.buildMessage());
LOG_S(INFO)<<"Move Order send with Course";
}
}
@@ -202,7 +202,7 @@ namespace Entities
LOG_S(INFO)<< "POS: LAT: "<< OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LATITUDE) << " LON: " << OwnShipTrack->getPosition().getGeodesicPos()(SimCore::LONGITUDE);
MovementWorkerStarted = true;
MovemtServer_->sendMessage(OwnShipTrack->buildMessage().serialize());
MovemtServer_->sendMessage(OwnShipTrack->buildMessage());
LOG_S(INFO)<< "Initial Message send to MovementWorker";
}
@@ -292,8 +292,17 @@ namespace Entities
break;
}
case Orders::TRACKLIST_REQUEST:
{
{
auto TrackListRequest = Orders::TracklistRequest::unpack(whisperMsg);
if (TrackListRequest == nullptr)
{
break;
}
if (TrackListRequest->EntityID == OwnShipTrack->getIdentifier())
{
std::string senderUUID = whisperMsg.senderUUID_;
CommandCommsServer_->sendMessage(SensorManager_->getTrackListUpdate()->buildMessage().serialize(OwnShipTrack->getIdentifier().getUUID()),senderUUID);
}
break;
}
break;

View File

@@ -197,7 +197,7 @@ void Sensor::updateOwnShipFunction()
if (track != nullptr)
{
LOG_S(INFO)<<"updated Tracklist";
client_->sendMessage(track->buildMessage().serialize());
client_->sendMessage(track->buildMessage());
}
}

View File

@@ -1,4 +1,6 @@
#include <SimCore/Messages/SensorData.hpp>
#include "Entities/Tracklist/Tracklist.hpp"
#include "SimCore/Identifier.hpp"
#include "nlohmann/json_fwd.hpp"
#include <Entities/SensorControl.hpp>
#include <memory>
@@ -8,41 +10,14 @@
namespace Entities
namespace Sensor
{
SensorControl::SensorControl(std::string ID, std::string Name, std::string IP, SimCore::SensorKinds sensorKind):
ID_(ID),IP_(IP),Name_(Name),SensorKind_(sensorKind)
SensorControl::SensorControl(SimCore::Identifier ID, std::string Name, std::string IP, SimCore::SensorKinds sensorKind)
:SimCore::SensorData(ID,Name,IP,sensorKind)
{
TrackStore = std::make_unique<TrackList::TrackList>();
}
std::string SensorControl::getName()
{
return Name_;
}
std::string SensorControl::getID()
{
return ID_;
}
SimCore::SensorKinds SensorControl::getSensorKind()
{
return SensorKind_;
}
void SensorControl::updateStatus(SimCore::Status status)
{
SensorSatus_ = status;
}
SimCore::Status SensorControl::getSensorStatus()
{
return SensorSatus_;
}

View File

@@ -1,4 +1,5 @@
#include "Entities/SensorControl.hpp"
#include "SimCore/Identifier.hpp"
#include "SimCore/Messages/SimTrack.hpp"
#include "SimCore/SimCore.hpp"
#include "WHISPER/Messages/Message.hpp"
@@ -21,7 +22,7 @@ namespace Entities
void SensorManager::startSensor(std::shared_ptr<kubecontrol::KubePod> pod,SimCore::SensorKinds SensorKind)
{
PodController_->startPod(pod);
SensorStore[pod->getUUID()] = std::make_unique<Entities::SensorControl>(pod->getUUID(),pod->getName(),pod->getIp(),SensorKind);
SensorStore[pod->getUUID()] = std::make_unique<Sensor::SensorControl>(SimCore::Identifier(pod->getUUID()),pod->getName(),pod->getIp(),SensorKind);
}
@@ -30,6 +31,14 @@ namespace Entities
//TODO send stop message to sensor
}
void SensorManager::stopAllSensors()
{
//TODO send stop message to sensor
}
void SensorManager::deleteSensor(std::string uuid)
{
@@ -38,18 +47,55 @@ namespace Entities
}
void SensorManager::deleteAllSensor()
{
PodController_->stopAllPods();
SensorStore.clear();
}
std::shared_ptr<Sensor::SensorControl> SensorManager::getSensorByUUID(std::string uuid)
{
auto it = SensorStore.find(uuid);
if( it != SensorStore.end())
{
return it->second;
}
return nullptr;
}
void SensorManager::addSensorLocal(std::unique_ptr<Sensor::SensorControl> sensor)
{
SensorStore[sensor->getID().getUUID()] = std::move(sensor);
}
size_t SensorManager::getSensorCount()
{
return SensorStore.size();
}
void SensorManager::handlSensorMessages(std::string Message)
{
WHISPER::Message msg(Message);
WHISPER::Message msg(Message);
switch (msg.msgType_)
{
case WHISPER::MsgType::SIM_TRACK:
{
{
auto track = std::make_shared<SimCore::SimTrack>(SimCore::SimTrack::unpack(msg));
updateTracklistForSensor(msg.senderUUID_, track);
if(track != nullptr)
{
updateTracklistForSensor(msg.senderUUID_, track);
auto sensor = getSensorByUUID(msg.senderUUID_);
Trackfusion_.addOrUpdateTrack(track, sensor);
}
break;
}
case WHISPER::MsgType::SYSTEMSTATE_UPDATE:
@@ -66,30 +112,53 @@ namespace Entities
void SensorManager::updateTracklistForSensor(std::string uuidSensor, std::shared_ptr<SimCore::SimTrack> track)
{
auto it = SensorStore.find(uuidSensor);
it->second->TrackStore->addTrack(track);
auto sensor= getSensorByUUID(uuidSensor);
if(sensor == nullptr)
{
return;
}
sensor->TrackStore.addTrack(std::move(track));
// auto it = SensorStore.find(uuidSensor);
// if( it != SensorStore.end())
// {
// it->second->TrackStore.addTrack(std::move(track));
// }
}
void SensorManager::sendMessageToSensor(std::string message, std::string uuid )
{
if (uuid.empty())
{
SensorServer_->sendMessage(message);
}else {
SensorServer_->sendMessage(message,uuid);
}
}
std::string SensorManager::getTracklistStringBySensor()
{
nlohmann::json result;
nlohmann::json radar;
radar["SensorType"] = SimCore::toString(SimCore::SensorKinds::RADAR);
nlohmann::json esm;
esm["SensorType"] = SimCore::toString(SimCore::SensorKinds::ESM);
nlohmann::json sonar;
sonar["SensorType"] = SimCore::toString(SimCore::SensorKinds::SONAR);
nlohmann::json visual;
visual["SensorType"] = SimCore::toString(SimCore::SensorKinds::VISUAL);
for(const auto& [key, value] : SensorStore )
{
nlohmann::json sensor;
sensor["SensorName"] = value->getName();
sensor["SensorID"] = value->getID();
sensor["SensorID"] = value->getID().getUUID();
sensor["SensorStatus"] = SimCore::toString(value->getSensorStatus());
sensor["SensorEnabled"] = "false";
if (value->getSensorStatus() == SimCore::Status::ACTIVE)
@@ -102,57 +171,73 @@ namespace Entities
sensor["SensorDamaged"] = "true";
}
nlohmann::json contacts;
value->TrackStore->getJsonTRackList(contacts);
sensor["SensorContacts"].push_back(contacts);
value->TrackStore.getJsonTRackList(contacts);
sensor["SensorContacts"] = contacts["Entities"];
switch (value->getSensorKind()) {
case SimCore::SensorKinds::RADAR:
{
radar["Sensors"].push_back(sensor);
radar.push_back(sensor);
break;
}
case SimCore::SensorKinds::ESM :
{
esm["Sensors"].push_back(sensor);
esm.push_back(sensor);
break;
}
case SimCore::SensorKinds::SONAR :
{
sonar["Sensors"].push_back(sensor);
sonar.push_back(sensor);
break;
}
case SimCore::SensorKinds::VISUAL :
{
visual["Sensors"].push_back(sensor);
visual.push_back(sensor);
break;
}
}
result.push_back(radar);
result.push_back(esm);
result.push_back(sonar);
result.push_back(visual);
// result.push_back(esm);
// result.push_back(sonar);
// result.push_back(visual);
}
result[(int)SimCore::SensorKinds::RADAR]["SensorType"] = "Radar";
result[(int)SimCore::SensorKinds::RADAR]["Sensors"]= radar;
result[(int)SimCore::SensorKinds::ESM]["SensorType"] = SimCore::toString(SimCore::SensorKinds::ESM);
result[(int)SimCore::SensorKinds::ESM]["Sensors"] = esm;
result[(int)SimCore::SensorKinds::SONAR]["SensorType"] = SimCore::toString(SimCore::SensorKinds::SONAR);
result[(int)SimCore::SensorKinds::SONAR]["Sensors"] = sonar;
result[(int)SimCore::SensorKinds::VISUAL]["SensorType"] = SimCore::toString(SimCore::SensorKinds::VISUAL);
result[(int)SimCore::SensorKinds::VISUAL]["Sensors"] = visual;
return result.dump();
}
std::string SensorManager::getTracklistStringFusioned()
{
std::string result = Trackfusion_.getTracklistAsString();
return result;
}
std::unique_ptr<SimCore::TracklistUpdate> SensorManager::getTrackListUpdate()
{
return std::move(Trackfusion_.getTrackListUpdate(OwnId_));
}
}

View File

@@ -1,129 +0,0 @@
#include "SimCore/Messages/SimTrack.hpp"
#include <SimCore/SimCore.hpp>
#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):
SimCore::SimTrack(*track.get())
{
addSensorDataToSensorList(sensorData);
lastUpdateTimestamp_ = std::chrono::steady_clock::now();
}
TracklistItem::TracklistItem(std::shared_ptr<SimCore::SimTrack> track):
SimCore::SimTrack(*track.get())
{
updateTrack(track);
lastUpdateTimestamp_ = std::chrono::steady_clock::now();
}
std::chrono::time_point<std::chrono::steady_clock> TracklistItem::getLastUpdateTimestamp()
{
return lastUpdateTimestamp_;
}
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());
}
if (!isSensorinSensorlist(sensorData))
{
SensorList.push_back(sensorData);
}
lastUpdateTimestamp_ = std::chrono::steady_clock::now();
}
void TracklistItem::updateTrack(std::shared_ptr<SimCore::SimTrack> track )
{
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();
}
bool TracklistItem::isSensorinSensorlist(SensorData sensorData)
{
auto it = std::find(SensorList.begin(),SensorList.end(), sensorData);
if (it != SensorList.end()) {
return true;
} else {
return false;
}
}
bool TracklistItem::isSensorIDKnown(SimCore::Identifier SensorID)
{
for (auto i: SensorList) {
if (i.sensorID == SensorID)
{
return true;
}
}
return false;
}
void TracklistItem::addSensorDataToSensorList(SensorData sensorData)
{
if (isSensorinSensorlist(sensorData) == false) {
SensorList.emplace_back(sensorData);
}
}
bool TracklistItem::checkIfSensorIDIsIn(SimCore::Identifier SensorID)
{
for (auto i:SensorList) {
if (i.sensorID == SensorID) {
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,131 @@
#include <SimCore/Messages/TracklistItem.hpp>
#include "SimCore/Messages/SimTrack.hpp"
#include "SimCore/Messages/TracklistUpdate.hpp"
#include "nlohmann/json_fwd.hpp"
#include <Entities/Tracklist/Trackfusion.hpp>
#include <memory>
#include <mutex>
namespace TrackList
{
void Trackfusion::addOrUpdateTrack(std::shared_ptr<SimCore::SimTrack> track, std::shared_ptr<SimCore::SensorData> sensorData)
{
std::lock_guard<std::mutex> lock(mx_);
auto iterator = TrackStore_.find(track->getIdentifier());
if (iterator == TrackStore_.end())
{
auto Item = std::make_shared<SimCore::TracklistItem>(track,*sensorData);
TrackStore_[Item->getIdentifier()] = Item;
}else {
iterator->second->updateTrack(track);
iterator->second->addSensorDataToSensorList(*sensorData);
}
}
void Trackfusion::deleteTrack(SimCore::Identifier id)
{
std::lock_guard<std::mutex> lock(mx_);
auto it = TrackStore_.find(id);
if (it != TrackStore_.end())
{
it = TrackStore_.erase(it);
}
}
void Trackfusion::deleteTrack(std::string uuid)
{
std::lock_guard<std::mutex> lock(mx_);
for (auto it = TrackStore_.begin(); it != TrackStore_.end();)
{
if (it->first.getUUID() == uuid)
{
it = TrackStore_.erase(it);
}
else{
++it;
}
}
}
std::shared_ptr<SimCore::TracklistItem> Trackfusion::findTrack(SimCore::Identifier id)
{
std::lock_guard<std::mutex> lock(mx_);
auto it = TrackStore_.find(id);
if (it != TrackStore_.end())
{
return it->second;
}
return nullptr;
}
std::shared_ptr<SimCore::TracklistItem> Trackfusion::findTrack(std::string uuid)
{
std::lock_guard<std::mutex> lock(mx_);
for (auto it = TrackStore_.begin(); it != TrackStore_.end();)
{
if (it->first.getUUID() == uuid)
{
return it->second;
}
}
return nullptr;
}
std::string Trackfusion::getTracklistAsString()
{
std::lock_guard<std::mutex> lock(mx_);
nlohmann::json j;
LOG_S(INFO)<<" Trackstore size: " <<TrackStore_.size();
for (auto it :TrackStore_)
{
j.push_back(it.second->getsTrackListItemAsJSON());
}
return j.dump();
}
std::unique_ptr<SimCore::TracklistUpdate> Trackfusion::getTrackListUpdate(SimCore::Identifier ID)
{
auto update = std::make_unique<SimCore::TracklistUpdate>(ID);
for (auto it :TrackStore_)
{
// update->addTrack(*it.second);
}
return std::move(update);
}
}

View File

@@ -0,0 +1,229 @@
#include "DirectCommunicationClient.hpp"
#include "Entities/SensorControl.hpp"
#include "Entities/SensorManager.hpp"
#include "SimCore/Messages/SimTrack.hpp"
#include "SimCore/Position.hpp"
#include "nlohmann/json_fwd.hpp"
#include <kubecontrol/PodController.hpp>
#include <SimCore/Identifier.hpp>
#include <SimCore/SimCore.hpp>
#include <memory>
#include <string>
#include <thread>
#include <utility>
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include <Entities/Sensor.hpp>
// SimCore::Identifier OwnID, SimCore::Identifier ParentID, SimCore::SensorKinds SensorKind,std::uint32_t GroundTruthPort, std::uint32_t ParentPort,std::string ParentIPAddress
double fRand(double fMin, double fMax)
{
double f = (double)rand() / RAND_MAX;
return fMin + f * (fMax - fMin);
}
void sendRandomTrack(std::shared_ptr<DirectCommunication::DirectCommunicationClient> client, int number)
{
for (int i = 0; i < number; i++) {
std::string name = "test1-" + std::to_string(i);
SimCore::SimTrack track(name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL);
SimCore::Position pos;
double lat = fRand(-90, 90);
double lon = fRand(-180, 180);
pos.setGeodesicPos( lat, lon, 0);
track.setPosition(pos);
client->sendMessage(track.buildMessage());
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
void sendRandomTracktoManager(std::shared_ptr<Entities::SensorManager> SensorManager_)
{
for (int i = 0; i < 5; i++) {
std::string name = "test1-" + std::to_string(i);
SimCore::SimTrack track(name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL);
SimCore::Position pos;
double lat = fRand(-90, 90);
double lon = fRand(-180, 180);
pos.setGeodesicPos( lat, lon, 0);
track.setPosition(pos);
}
auto id0 = SimCore::Identifier();
LOG_S(INFO)<<id0.getUUID();
auto control = std::make_unique<Sensor::SensorControl>(id0.getUUID(),"Sensor", "127.0.0.1", SimCore::SensorKinds::RADAR);
auto client = std::make_shared<DirectCommunication::DirectCommunicationClient>(5557,"127.0.0.1",id0.getUUID());
SensorManager_->addSensorLocal(std::move(control));
// sendRandomTrack(client,5);
auto id1 = SimCore::Identifier();
auto control1 = std::make_unique<Sensor::SensorControl>(id1.getUUID(),"Sensor1", "127.0.0.1", SimCore::SensorKinds::RADAR);
auto client1 = std::make_shared<DirectCommunication::DirectCommunicationClient>(5557,"127.0.0.1",id1.getUUID());
SensorManager_->addSensorLocal(std::move(control1));
// sendRandomTrack(client1,5);
auto id2 = SimCore::Identifier();
auto control2 = std::make_unique<Sensor::SensorControl>(id2.getUUID(),"Sensor2", "127.0.0.1", SimCore::SensorKinds::VISUAL);
auto client2 = std::make_shared<DirectCommunication::DirectCommunicationClient>(5557,"127.0.0.1",id2.getUUID());
SensorManager_->addSensorLocal(std::move(control2));
// sendRandomTrack(client2,5);
auto id3 = SimCore::Identifier();
auto control3 = std::make_unique<Sensor::SensorControl>(id3.getUUID(),"Sensor3", "127.0.0.1", SimCore::SensorKinds::ESM);
auto client3 = std::make_shared<DirectCommunication::DirectCommunicationClient>(5557,"127.0.0.1",id3.getUUID());
SensorManager_->addSensorLocal(std::move(control3));
sendRandomTrack(client2,5);
for (int i = 0; i < 3; i++) {
std::string name = "identical-" + std::to_string(i);
SimCore::SimTrack track(name,SimCore::Kind::EntityKind::SURFACE,SimCore::Side::NEUTRAL);
SimCore::Position pos;
double lat = fRand(-90, 90);
double lon = fRand(-180, 180);
pos.setGeodesicPos( lat, lon, 0);
track.setPosition(pos);
client->sendMessage(track.buildMessage());
std::this_thread::sleep_for(std::chrono::milliseconds(100));
client1->sendMessage(track.buildMessage());
std::this_thread::sleep_for(std::chrono::milliseconds(100));
client2->sendMessage(track.buildMessage());
std::this_thread::sleep_for(std::chrono::milliseconds(100));
client3->sendMessage(track.buildMessage());
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
void startSensors(SimCore::Identifier ownid, std::string GroundTruthAddr_,ushort GroundTruthPort_, ushort SensorPort_ , auto SensorManager_)
{
LOG_S(INFO)<<"__ONLINE__";
std::string SensorUUID_ = xg::newGuid().str();
LOG_S(INFO)<<ownid.getUUID();
auto RadarPod = std::make_shared<kubecontrol::KubePod>(ownid.getUUID(),SensorUUID_,"radar:latest");
RadarPod->setEnvironmentVar("SERVER_IP", SimCore::UtilFunctions::getOwnIP());
nlohmann::json vars;
vars["OWN_SHIP_ID"] = ownid.getUUID();
vars["SENSOR_ID"] = SensorUUID_;
vars["SENSOR_NAME"] = "APAR";
vars["GROUNDTRUTH_PORT"] = std::to_string(GroundTruthPort_);
vars["GROUNDTRUTH_ADDR"] = GroundTruthAddr_;
vars["TRANSMIT_POWER"] = "66";
vars["GAIN_TRANSMIT"] = "40";
vars["GAIN_RECEIVE"] = "40";
vars["TRANSMIT_FREQUENCY"] = "2657";
vars["INSTRUMENTED_RANGE"] = "150000";
vars["MOUNTED_HEIGHT"] = "23";
vars["OWN_SHIP_IP"] = SimCore::UtilFunctions::getOwnIP();
vars["OWN_SHIP_PORT"] = std::to_string(SensorPort_);
RadarPod->setEnvironmentVar("CONFIG", vars.dump());
RadarPod->setComponent("Radar");
SensorManager_->startSensor(RadarPod, SimCore::SensorKinds::RADAR);
}
SCENARIO("Testing the SimCore SensorManager")
{
GIVEN("different Attributes for a Track in different forms")
{
SimCore::Identifier id;
auto PodController_ = std::make_shared<kubecontrol::PodController>("docs/config");
auto SensorManager_ = std::make_shared<Entities::SensorManager>(id, PodController_,5557);
startSensors(id, "239.0.0.1", 7000, 5557, SensorManager_);
WHEN("constructing Track Object with data")
{
THEN("check if Track attributes are correct")
{
REQUIRE(PodController_->getInfoForAllPods().size() == 1);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
SensorManager_->deleteAllSensor();
REQUIRE(PodController_->getInfoForAllPods().size() == 0);
} //THEN
} // WHEN
} // GIVEN
} //SCENARIO
SCENARIO("Testing the SimCore SensorManager with local sensors")
{
GIVEN("different Attributes for a Track in different forms")
{
SimCore::Identifier id;
auto PodController_ = std::make_shared<kubecontrol::PodController>("docs/config");
auto SensorManager_ = std::make_shared<Entities::SensorManager>(id, PodController_,5557);
sendRandomTracktoManager(SensorManager_);
// std::this_thread::sleep_for(std::chrono::milliseconds(1000));
WHEN("constructing Track Object with data")
{
std::string tracklist1 = SensorManager_->getTracklistStringBySensor();
std::string tracklist2 = SensorManager_->getTracklistStringFusioned();
LOG_S(INFO)<<tracklist2;
THEN("check if Track attributes are correct")
{
nlohmann::json j = nlohmann::json::parse(tracklist1);
nlohmann::json j2 = nlohmann::json::parse(tracklist2);
REQUIRE( j[0]["Sensors"].size() == 2);
REQUIRE( j[0]["Sensors"][0]["SensorContacts"].size() == 3);
REQUIRE( j[0]["Sensors"][0]["SensorContacts"].size() == j[0]["Sensors"][1]["SensorContacts"].size());
REQUIRE( j[0]["Sensors"][0]["SensorContacts"][0]["id"] == j[0]["Sensors"][1]["SensorContacts"][0]["id"]);
REQUIRE( j[0]["Sensors"][0]["SensorContacts"][0]["id"] == j[1]["Sensors"][0]["SensorContacts"][0]["id"]);
REQUIRE( j2.size() == 8);
REQUIRE(SensorManager_->getSensorCount() == 4);
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
} //THEN
} // WHEN
} // GIVEN
} //SCENARIO

View File

@@ -1,6 +1,6 @@
#include "Entities/Tracklist/Tracklist.hpp"
#include "Entities/Tracklist/TracklistItem.hpp"
#include <SimCore/Messages/TracklistItem.hpp>
#include "SimCore/IdentifierMaker.hpp"
#include "SimCore/Messages/SimTrack.hpp"
#include "SimCore/Position.hpp"
@@ -36,17 +36,9 @@ SCENARIO("Testing the SimCore Sensor")
track->Course.setValue(course);
TrackList::SensorData Sensor1 =
{
.sensorID = SimCore::Identifier(),
.Sensorname = "ARPA"
};
SimCore::SensorData Sensor1(SimCore::Identifier(),"ARPA","127.0.0.1", SimCore::SensorKinds::RADAR);
TrackList::SensorData Sensor2 =
{
.sensorID = SimCore::Identifier(),
.Sensorname = "SMART-L"
};
SimCore::SensorData Sensor2(SimCore::Identifier(),"SMART","127.0.0.1", SimCore::SensorKinds::RADAR);
@@ -66,8 +58,8 @@ SCENARIO("Testing the SimCore Sensor")
List.addTrack(track);
// REQUIRE(List.getTrack(id)->Course.getValue() == 270);
// REQUIRE(List.getTrack(id)->getSensorCount() == 2);
std::this_thread::sleep_for(std::chrono::milliseconds(5500));
REQUIRE(List.getSize() == 0);
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
REQUIRE(List.getSize() == 1);
// List.stopSanitizer();

View File

@@ -1,79 +0,0 @@
#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