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

@@ -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);
};
}