Files
EntityLibrary/include/Entities/Entity.hpp

162 lines
5.0 KiB
C++

#pragma once
#define LOGURU_WITH_STREAMS 1
#include <loguru.hpp>
#include <Entities/Tracklist/Tracklist.hpp>
#include "DirectCommunicationServer.hpp"
#include "Entities/Movement.hpp"
#include "Entities/SensorManager.hpp"
#include "SimCore/Messages/SimTrack.hpp"
#include "SimCore/Orientation.hpp"
#include "SimCore/SafeMap.hpp"
#include "SimCore/SimCore.hpp"
#include "kubecontrol/PodController.hpp"
#include <WHISPER/InternalUDPService.hpp>
#include <WHISPER/InternalUDPSender.hpp>
#include <WHISPER/InternalUDPListener.hpp>
#include <WHISPER/Messages/Message.hpp>
#include <WHISPER/threadSafeQueue.hpp>
#include <SimCore/Identifier.hpp>
#include <SimCore/Position.hpp>
#include <nlohmann/json.hpp>
#include <atomic>
#include <chrono>
#include <memory>
#include <string>
#include <thread>
#include <utility>
namespace Entities {
class Entity {
public:
Entity(const SimCore::Identifier OwnID,
std::string EnttityName,
WHISPER::SourceType OwnType,
double RadarCrossSection,
SimCore::Kind::EntityKind EntityKind,
SimCore::Side::EntitySide EntitySide,
std::string GroundTruthAddr,
std::uint32_t GroundTruthPort,
ushort CommandPort,
ushort SensorPort,
bool online);
~Entity();
/**
* @brief starts the Entity APP
*/
void start();
/**
* @brief stops the Entity
*/
void stop();
/**
* @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;
/// @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_;
/// @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::shared_ptr<DirectCommunication::DirectCommunicationServer> MovemtServer_ = nullptr;
void handleMovement();
std::string MovementPodUUID_;
std::shared_ptr<DirectCommunication::DirectCommunicationServer> CommandCommsServer_ = nullptr;
void handleExternalComms(const std::string &msg);
void startSensor();
// std::shared_ptr<std::list<Entities::SensorClientData>> SensorStore_;
// std::shared_ptr<SimCore::SafeMap<SimCore::Identifier, std::shared_ptr< SimCore::SimTrack>>> Trackstore_;
};
}