203 lines
7.8 KiB
C++
Executable File
203 lines
7.8 KiB
C++
Executable File
/**
|
|
* Handler for all oc situation data at the server per client
|
|
* $Id: handler_oc_situation_data.h 57655 2022-07-20 11:38:28Z karwat $
|
|
* $HeadURL: svn://192.168.133.21/TDS/branches/product/features/3dws_devel/Lts/Services/OcSituationServer/handler_oc_situation_data.h $
|
|
* $Author: karwat $
|
|
* Created by Philipp Dassow, NLST, 27-02-2018
|
|
*/
|
|
#pragma once
|
|
|
|
#include <QMutex>
|
|
#include <QObject>
|
|
#include <QTimer>
|
|
#include <QThread>
|
|
#include <QVector>
|
|
#include <QPolygonF>
|
|
#include <QSet>
|
|
|
|
#include <AreaEffectSimulation/aes_dtc.h>
|
|
#include <ParticipantManagement/ppm_dtc.h>
|
|
|
|
#include "main_handler.h"
|
|
#include "position_converter.h"
|
|
#include "oc_situation.h"
|
|
#include "logger.h"
|
|
|
|
namespace OcSituationServer
|
|
{
|
|
|
|
class HandlerOcCentralAesData;
|
|
class CentralAesDataQueue;
|
|
|
|
class ThreadOcCentralAesData : public QThread
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit ThreadOcCentralAesData(MainHandler *mainHandler,
|
|
int equipmentId,
|
|
int centerEquipmentId,
|
|
int radius);
|
|
|
|
public slots:
|
|
void requestOcCentralAesData(OcSituation::SituationCenterType centerType,
|
|
int centerEquipmentId,
|
|
const Core::GeoPosition2D &position,
|
|
int radius,
|
|
bool initial);
|
|
|
|
signals:
|
|
void sendOcData(const TrainingAreaBase::SendOcDataRequest &);
|
|
|
|
protected:
|
|
virtual void run();
|
|
|
|
private:
|
|
OcSituation::SituationCenterType m_centerType = OcSituation::SituationCenterType::Equipment; // which kind of center is used for the situation
|
|
Core::GeoPosition2D m_position; // center position a situation can be requested around
|
|
LtsCoordTrans::UtmCoordinate m_baseCoordinate;
|
|
|
|
int m_equipmentId{0}; // id from requesting OC-laptop
|
|
int m_centerEquipmentId{0}; // equipment in the center of situation
|
|
int m_radius{0}; // observer radius in meter
|
|
|
|
MainHandler *m_mainHandler{nullptr}; // provides TAB FTC and PPM DTC
|
|
HandlerOcCentralAesData *m_handler{nullptr}; // OC-Thread-Object
|
|
QMutex m_accessMutex; // Mutex-Object
|
|
|
|
LOGGER_T &m_logger; // Logger-Object
|
|
};
|
|
|
|
|
|
class HandlerOcCentralAesData : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit HandlerOcCentralAesData(const std::shared_ptr<DdsHandler> &dds,
|
|
const LtsCoordTrans::UtmCoordinate &baseCoordinate,
|
|
int equipmentId);
|
|
|
|
bool withCompression() const { return m_bWithCompression; }
|
|
void setWithCompression(bool bOn) { m_bWithCompression = bOn; }
|
|
bool withVBGTime() const { return m_bWithVBGTime; }
|
|
void setWithVBGTime(bool bOn) { m_bWithVBGTime = bOn; }
|
|
|
|
private:
|
|
void fetchAesItemsInRange();
|
|
|
|
template <typename T>
|
|
qint32 fetchAesItemsInCircle(const QHash<qint32, T> &aesItems);
|
|
|
|
QPolygonF polygonFromForm(const std::vector<Core::GeoPosition> &form) const;
|
|
QList<qint32> allInternalAesItemIds() const;
|
|
|
|
template <typename T>
|
|
void onAesItemChanged(QHash<qint32, T> &container, const T &data, DataModification modType);
|
|
|
|
template <typename T>
|
|
void addAesItemsToBuilder(const QHash<qint32, T> &aesItems, const QSet<qint32> &validIds);
|
|
|
|
void removeKickedOutAesItems(const QSet<qint32> &aesItemsSentBefore);
|
|
void buildSituationCircle();
|
|
qreal calculateDistanceToCircleCenter(qint32 aesItemId) const;
|
|
|
|
public slots:
|
|
void setRequestCentralAesData(OcSituation::SituationCenterType centerType,
|
|
int centerEquipmentId,
|
|
const Core::GeoPosition2D ¢erPosition,
|
|
int radius,
|
|
bool initial);
|
|
|
|
private slots:
|
|
void onParticipantPositionChanged(const ParticipantManagement::ParticipantPosition &data, DataModification modType);
|
|
void onPartitionTimeChanged(qint64 partitionTime) { m_partitionTime = partitionTime; }
|
|
|
|
void onEffectClusterChanged(const AreaEffectSimulation::EffectCluster &data, DataModification modType);
|
|
void onNContaminationChanged(const AreaEffectSimulation::NContamination &data, DataModification modType);
|
|
void onBCContaminationChanged(const AreaEffectSimulation::BCContamination &data, DataModification modType);
|
|
void onExplosionAreaChanged(const AreaEffectSimulation::ExplosionArea &data, DataModification modType);
|
|
void onExplosionSingleChanged(const AreaEffectSimulation::ExplosionSingle &data, DataModification modType);
|
|
void onMineAreaChanged(const AreaEffectSimulation::MineArea &data, DataModification modType);
|
|
void onFunctionalAreaChanged(const AreaEffectSimulation::FunctionalArea &data, DataModification modType);
|
|
void onBoobyTrapChanged(const AreaEffectSimulation::BoobyTrap &data, DataModification modType);
|
|
void onOffRouteMineChanged(const AreaEffectSimulation::OffRouteMine &data, DataModification modType);
|
|
void onExplosionClusterChanged(const AreaEffectSimulation::ExplosionCluster &data, DataModification modType);
|
|
|
|
void onAesItemViewChanged(const AreaEffectSimulation::AesItemView &data, DataModification modType);
|
|
|
|
void handleSituation();
|
|
void resetAliveTimer();
|
|
void aliveTimeout();
|
|
void onResetInternalData();
|
|
|
|
signals:
|
|
void sendOcData(const TrainingAreaBase::SendOcDataRequest &);
|
|
void resetInternalData();
|
|
|
|
private:
|
|
//helper struct
|
|
struct AesItemInfo
|
|
{
|
|
int32_t id;
|
|
AreaEffectSimulation::AesType type;
|
|
|
|
AesItemInfo()
|
|
: id(-1)
|
|
, type(AreaEffectSimulation::AesType::inner_enum::AtUnknown)
|
|
{}
|
|
|
|
AesItemInfo(int32_t id, AreaEffectSimulation::AesType type)
|
|
: id(id)
|
|
, type(type)
|
|
{}
|
|
};
|
|
|
|
LtsCoordTrans::UtmCoordinate m_baseCoordinate;
|
|
QPolygonF m_situationCircle;
|
|
|
|
std::shared_ptr<AreaEffectSimulation::Interface::Dtc> m_aesDtc;
|
|
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
|
|
|
|
// request data
|
|
OcSituation::SituationCenterType m_centerType{OcSituation::SituationCenterType::Equipment}; // which kind of center is used for the situation
|
|
Core::GeoPosition2D m_centerPosition; // center position a situation can be requested around
|
|
int m_equipmentId{0}; // id from requesting OC-laptop
|
|
int m_centerEquipmentId{0}; // equipment in the center of situation
|
|
int m_centerParticipantId{0};
|
|
int m_radius{0}; // observer radius in meter
|
|
int m_retryCount{0};
|
|
bool m_participantOverloaded{false};
|
|
|
|
// internal aes data
|
|
QHash<qint32, AreaEffectSimulation::EffectCluster> m_allCentralEffectClusters;
|
|
QHash<qint32, AreaEffectSimulation::NContamination> m_allCentralNContaminations;
|
|
QHash<qint32, AreaEffectSimulation::BCContamination> m_allCentralBCContaminations;
|
|
QHash<qint32, AreaEffectSimulation::ExplosionArea> m_allCentralExplosionsArea;
|
|
QHash<qint32, AreaEffectSimulation::ExplosionSingle> m_allCentralExplosionsSingle;
|
|
QHash<qint32, AreaEffectSimulation::MineArea> m_allCentralMineAreas;
|
|
QHash<qint32, AreaEffectSimulation::FunctionalArea> m_allCentralFunctionalAreas;
|
|
QHash<qint32, AreaEffectSimulation::BoobyTrap> m_allCentralBoobyTraps;
|
|
QHash<qint32, AreaEffectSimulation::OffRouteMine> m_allCentralOffRouteMines;
|
|
QHash<qint32, AreaEffectSimulation::ExplosionCluster> m_allCentralExplosionClusters;
|
|
QHash<qint32, AreaEffectSimulation::AesItemView> m_allCentralAesItemViews; // <aesItemId, AesItemView>
|
|
|
|
QSet<qint32> m_aesItemsInRange;
|
|
|
|
// options, must be in sync with osc
|
|
bool m_bWithCompression{true};
|
|
bool m_bWithVBGTime{true};
|
|
bool m_bInitialDataTransfer{true};
|
|
|
|
qint64 m_partitionTime;
|
|
|
|
// thread management
|
|
QMutex m_accessMutex; // Mutex-Object
|
|
QTimer *m_aliveTimer{nullptr}; // alive timer
|
|
QTimer *m_txTimer{nullptr}; // tx cycle timer
|
|
|
|
CentralAesDataQueue *m_dataQueue;
|
|
LOGGER_T &m_logger;
|
|
};
|
|
|
|
} // namespace OcSituationServer
|