Files
EntityLibrary/include/Entities/SensorManager.hpp
2024-03-11 12:58:45 +01:00

161 lines
5.0 KiB
C++

#pragma once
#include "DirectCommunicationServer.hpp"
#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"
#include "kubecontrol/PodController.hpp"
#include <cstddef>
#include <loguru.hpp>
#include <map>
#include <memory>
#include <string>
#include <sys/types.h>
namespace Entities
{
class SensorManager
{
public:
SensorManager(std::shared_ptr<SimCore::SimTrack> OwnShipTrack,std::shared_ptr<kubecontrol::PodController> PodController, ushort sensorPort = 5557);
/**
* @brief stops the sensor manager
*/
void stop();
/**
*@brief starts a Sensor based on a KubePod Object
*@param KubePod - a KubePod Item ready to start
*@param SensorKind - numeric value of the SensorKind from SimCore
*/
void startSensor(std::shared_ptr<kubecontrol::KubePod> pod, SimCore::SensorKinds SensorKind);
/**
*@brief stops a Sensor based on a uuid ( the sensors just stops to operate)
*@param string uuid sensor
*/
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
*/
std::string getTracklistStringBySensor();
/**
*@brief get the Tracklist as JSON formatted string where the tracks are fusiond with a list for each track which sensor has detected that track
*@return string - JSON formatted string
*/
std::string getTracklistStringFusioned();
/**
*@brief Updates the Tracklist for the Specific Sensor
*@param string uuid for the Sensor
*@param SimTrack updated Track
*/
void updateTracklistForSensor(std::string uuidSensor, std::shared_ptr<SimCore::SensorTrack> 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::shared_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> 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
*/
void sendOwnShipTrackToSensors();
private:
const SimCore::Identifier OwnId_;
std::shared_ptr<SimCore::SimTrack> OwnShiptrack_;
ushort SensorPort_ = 5557;
std::map<std::string, std::shared_ptr<Sensor::SensorControl>> SensorStore;
std::shared_ptr<kubecontrol::PodController> PodController_;
TrackList::Trackfusion Trackfusion_;
std::thread sensorUpdater_;
std::atomic_bool stopUpdater_;
std::shared_ptr<DirectCommunication::DirectCommunicationServer> SensorServer_ = nullptr;
void handlSensorMessages(std::string Message);
};
}