Adds initial intermediate qt6 porting state
This commit is contained in:
11247 files changed
+1891537
No files matched your search
+147
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The FiringUnitValidator regulates the rules for firing units
|
||||
* $Id: participant_dis_helper.h 37747 2017-12-08 08:07:01Z ehrlicher $
|
||||
* $HeadURL: svn://10.196.0.54/TDS/branches/product/features/24_vulcano/Lts/Plugins/ParticipantManagement/Gui/Common/participant_dis_helper.h $
|
||||
* $Author: ehrlicher $
|
||||
* Created by Hannes Fritsche, ESZS, 2024-03-07
|
||||
*/
|
||||
|
||||
#include "firing_unit_validator.h"
|
||||
|
||||
#include <LtsUtilsSettings/settings.h>
|
||||
#include <ParticipantManagement/ppm.hpp>
|
||||
#include "ParticipantManagement/settings.h"
|
||||
#include "TypeHandling/type_handler.h"
|
||||
#include "participant_handler.h"
|
||||
#include "participant.h"
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
namespace ParticipantHandling
|
||||
{
|
||||
|
||||
FiringUnitValidator::FiringUnitValidator(const std::shared_ptr<ParticipantHandler> &participantHandler,
|
||||
const std::shared_ptr<TypeHandling::TypeHandler> &typeHandler,
|
||||
QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_participantHandler(participantHandler)
|
||||
, m_typeHandler(typeHandler)
|
||||
{
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject FiringUnitValidator::firingUnitError(const QHash<int, int> &modIdToParticipantId, const QVector<ParticipantData> &participantData)
|
||||
{
|
||||
QString error;
|
||||
|
||||
for (const ParticipantData ¤tData : participantData)
|
||||
{
|
||||
if (!m_typeHandler->isFiringUnitType(currentData.typeId()))
|
||||
continue;
|
||||
|
||||
int unitModId = currentData.modId();
|
||||
|
||||
error = getError(modIdToParticipantId, participantData, unitModId);
|
||||
|
||||
if (!error.isEmpty())
|
||||
break;
|
||||
}
|
||||
|
||||
return Core::FunctionReplyObject(error.toStdString().c_str());
|
||||
}
|
||||
|
||||
QString FiringUnitValidator::getError(const QHash<int, int> &modIdToParticipantId, const QVector<ParticipantData> &participantData, int unitModId) const
|
||||
{
|
||||
bool hasCapacityError = false;
|
||||
bool hasFalseTypeError = false;
|
||||
bool hasMixedTypeError = false;
|
||||
uint maxParticipantsPerFiringUnit = Settings::maxParticipantsPerFiringUnit();
|
||||
uint participantsInFiringUnit = nonModdedInferiorsCount(unitModId, modIdToParticipantId);
|
||||
int typeId = participantTypeInFiringUnit(unitModId, modIdToParticipantId);
|
||||
|
||||
for (const ParticipantData ¤tData : participantData)
|
||||
{
|
||||
if (currentData.superiorModId() != unitModId)
|
||||
continue;
|
||||
|
||||
// capacity error
|
||||
hasCapacityError = ++participantsInFiringUnit > maxParticipantsPerFiringUnit;
|
||||
|
||||
if (hasCapacityError)
|
||||
return tr("There are only %1 participants allowed per firing unit.").arg(maxParticipantsPerFiringUnit);
|
||||
|
||||
// false type error
|
||||
hasFalseTypeError = !m_typeHandler->isArtilleryParticipantType(currentData.typeId());
|
||||
|
||||
if (hasFalseTypeError)
|
||||
return tr("There are only artillery participants allowed in firing units.");
|
||||
|
||||
// mixed type error
|
||||
if (typeId == -1)
|
||||
typeId = currentData.typeId();
|
||||
|
||||
hasMixedTypeError = currentData.typeId() != typeId;
|
||||
|
||||
if (hasMixedTypeError)
|
||||
return tr("There are no mixed types allowed in firing units.");
|
||||
}
|
||||
|
||||
return QString();
|
||||
}
|
||||
|
||||
int FiringUnitValidator::nonModdedInferiorsCount(int unitModId, const QHash<int, int> &modIdToParticipantId) const
|
||||
{
|
||||
if (!modIdToParticipantId.contains(unitModId))
|
||||
return 0;
|
||||
|
||||
const int unitParticipantId = modIdToParticipantId.value(unitModId);
|
||||
const Participant *unitParticipant = m_participantHandler->participantById(unitParticipantId);
|
||||
|
||||
if (!unitParticipant)
|
||||
return 0;
|
||||
|
||||
const QList<int> moddedParticipantIds = modIdToParticipantId.keys();
|
||||
int nonModdedInferiorsCountRet = 0;
|
||||
|
||||
for (int inferiorId : unitParticipant->inferiors())
|
||||
{
|
||||
if (moddedParticipantIds.contains(inferiorId)) // only non modded participants
|
||||
continue;
|
||||
|
||||
++nonModdedInferiorsCountRet;
|
||||
}
|
||||
|
||||
return nonModdedInferiorsCountRet;
|
||||
}
|
||||
|
||||
int FiringUnitValidator::participantTypeInFiringUnit(int unitModId, const QHash<int, int> &modIdToParticipantId) const
|
||||
{
|
||||
if (!modIdToParticipantId.contains(unitModId))
|
||||
return -1;
|
||||
|
||||
const int unitParticipantId = modIdToParticipantId.value(unitModId);
|
||||
const Participant *unitParticipant = m_participantHandler->participantById(unitParticipantId);
|
||||
|
||||
if (!unitParticipant)
|
||||
return -1;
|
||||
|
||||
const QList<int> moddedParticipantIds = modIdToParticipantId.keys();
|
||||
|
||||
for (int inferiorId : unitParticipant->inferiors())
|
||||
{
|
||||
if (moddedParticipantIds.contains(inferiorId)) // only non modded participants
|
||||
continue;
|
||||
|
||||
const Participant *inferior = m_participantHandler->participantById(inferiorId);
|
||||
|
||||
if (!inferior)
|
||||
continue;
|
||||
|
||||
return inferior->typeId();
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
} // namespace ParticipantHandling
|
||||
} // namespace ParticipantManagement
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* The FiringUnitValidator regulates the rules for firing units serverside
|
||||
* $Id: participant_dis_helper.h 37747 2017-12-08 08:07:01Z ehrlicher $
|
||||
* $HeadURL: svn://10.196.0.54/TDS/branches/product/features/24_vulcano/Lts/Plugins/ParticipantManagement/Gui/Common/participant_dis_helper.h $
|
||||
* $Author: ehrlicher $
|
||||
* Created by Hannes Fritsche, ESZS, 2024-03-07
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <memory>
|
||||
#include <DDS/Core/function_reply_object.h>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
|
||||
class ParticipantData;
|
||||
|
||||
namespace TypeHandling
|
||||
{
|
||||
class TypeHandler;
|
||||
} //namespace TypeHandling
|
||||
|
||||
namespace ParticipantHandling
|
||||
{
|
||||
class ParticipantHandler;
|
||||
|
||||
class FiringUnitValidator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FiringUnitValidator(const std::shared_ptr<ParticipantHandler> &participantHandler,
|
||||
const std::shared_ptr<TypeHandling::TypeHandler> &typeHandler,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
Core::FunctionReplyObject firingUnitError(const QHash<int, int> &modIdToParticipantId, const QVector<ParticipantData> &participantData);
|
||||
|
||||
private:
|
||||
QString getError(const QHash<int, int> &modIdToParticipantId, const QVector<ParticipantData> &participantData, int unitModId) const;
|
||||
|
||||
int nonModdedInferiorsCount(int unitModId, const QHash<int, int> &modIdToParticipantId) const;
|
||||
int participantTypeInFiringUnit(int unitModId, const QHash<int, int> &modIdToParticipantId) const;
|
||||
|
||||
std::shared_ptr<ParticipantHandler> m_participantHandler;
|
||||
std::shared_ptr<TypeHandling::TypeHandler> m_typeHandler;
|
||||
}; // namespace FiringUnitValidator
|
||||
} //namespace ParticipantHandling
|
||||
} // namespace ParticipantManagement
|
||||
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Handler for all request journal objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2015-01-13
|
||||
*/
|
||||
|
||||
#include "get_participants.h"
|
||||
#include "main_handler.h"
|
||||
|
||||
#include <ParticipantManagement/ppm_record_replay_plugin.h>
|
||||
#include <ngldb/nsqlquery.h>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
|
||||
GetParticipants::GetParticipants(MainHandler *mainHandler)
|
||||
: Interface::Fts::GetParticipantsRequestHandler(mainHandler->fts())
|
||||
, m_mainHandler(mainHandler)
|
||||
, m_logger(getLogger("GetParticipants"))
|
||||
{}
|
||||
|
||||
GetParticipants::~GetParticipants()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void GetParticipants::onGetParticipantsRequest(const rti::core::SampleIdentity &cookie,
|
||||
const GetParticipantsRequest &request)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onGetParticipantsRequest" << request;
|
||||
|
||||
|
||||
// Initialize RecordReplay to get initial participants
|
||||
RecordReplayPlugin recordReplay;
|
||||
// no ddsconnector - we don't want to publish data here
|
||||
recordReplay.initDtc(nullptr, m_mainHandler->exerciseId());
|
||||
|
||||
NSqlQuery q(m_mainHandler->db()->database());
|
||||
recordReplay.readParticipantAt(q, request.timeStamp());
|
||||
|
||||
// key is sampleTime -> multiMap
|
||||
auto participantsMmap = recordReplay.getParticipantMap();
|
||||
QMap<int, Participant> participants;
|
||||
|
||||
// only take the newest entries (participantsMmap may contain more than one entry per participantId
|
||||
for (auto it = participantsMmap.begin(); it != participantsMmap.end(); ++it)
|
||||
{
|
||||
Participant &p = it.value();
|
||||
if (p.isDeleted())
|
||||
participants.remove(p.id());
|
||||
else
|
||||
participants[p.id()] = std::move(p);
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "Starting to read participant from record replay. Size: "
|
||||
<< participants.size();
|
||||
|
||||
GetParticipantsReply reply;
|
||||
reply.requestId(request.requestId());
|
||||
|
||||
auto &vecPart = reply.participants();
|
||||
vecPart.reserve(participants.size());
|
||||
for (auto it = participants.begin(); it != participants.end(); ++it)
|
||||
{
|
||||
if (request.partyId() >= 0 && it.value().partyId() != request.partyId())
|
||||
continue;
|
||||
vecPart.push_back(it.value());
|
||||
}
|
||||
|
||||
m_mainHandler->fts()->getParticipantsReply(cookie, reply);
|
||||
}
|
||||
|
||||
} // Namespace ParticipantManagement
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Handler for all situation replay objects
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hanna E. Rathje, SLSE, 2016-01-13
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "logger.h"
|
||||
#include <ParticipantManagement/ppm_fts.h>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
class MainHandler;
|
||||
class GetParticipants final : protected Interface::Fts::GetParticipantsRequestHandler
|
||||
{
|
||||
public:
|
||||
explicit GetParticipants(MainHandler *mainHandler);
|
||||
~GetParticipants();
|
||||
|
||||
private:
|
||||
void onGetParticipantsRequest(const rti::core::SampleIdentity &cookie,
|
||||
const GetParticipantsRequest &request) override;
|
||||
|
||||
private:
|
||||
MainHandler *m_mainHandler;
|
||||
NGL::INGLLogger &m_logger;
|
||||
|
||||
};
|
||||
}
|
||||
+1141
File diff suppressed because it is too large.
Load diff
Executable
+147
@@ -0,0 +1,147 @@
|
||||
/**
|
||||
* The Participant class is the base class for either Buildings or ExerciseParticipants.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Baeuerle, SLSE, 2016-05-23
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "logger.h"
|
||||
#include <ParticipantManagement/ppm_db_structs.h>
|
||||
#include <ParticipantManagement/ppm.hpp>
|
||||
#include <TrainingAreaBase/tab.hpp>
|
||||
|
||||
#include <QMutex>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
class MainHandler;
|
||||
namespace Interface
|
||||
{
|
||||
class Dts;
|
||||
}
|
||||
namespace ParticipantHandling
|
||||
{
|
||||
class ParticipantHandler;
|
||||
class UnitPositionCalculator;
|
||||
class Participant
|
||||
{
|
||||
public:
|
||||
Participant(ParticipantHandler *participantHandler,
|
||||
UnitPositionCalculator *unitPosCalculator,
|
||||
const Database::PpmParticipant &data,
|
||||
const char *loggerName);
|
||||
|
||||
virtual ~Participant();
|
||||
|
||||
int32_t id() const { return m_participantData.id(); }
|
||||
int32_t typeId() const { return m_participantData.typeId(); }
|
||||
int32_t superiorId() const { return m_participantData.superiorId(); }
|
||||
// return optional?
|
||||
int32_t equipmentNumber() const { return m_participantData.equipmentNumber().is_set() ? m_participantData.equipmentNumber().get() : 0; }
|
||||
int32_t partyId() const { return m_participantData.partyId(); }
|
||||
bool isDeleted() const { return m_participantData.isDeleted(); }
|
||||
ParticipantAssignState assignState() const { return m_participantData.assignState(); }
|
||||
const std::vector<int32_t> &inferiors() const { return m_participantData.inferiorIds(); }
|
||||
ParticipantPosition position() const { return m_positionPublished; }
|
||||
const DynamicParticipantData &dynamicParticipantData() const { return m_dynamicData; }
|
||||
const ParticipantManagement::Participant &participantData() const { return m_participantData; }
|
||||
|
||||
void markAsDeleted();
|
||||
|
||||
bool isValidPosition(qint64 sampleTime, const Core::GeoPosition &pos, Core::PositionReportingSource repSource) const;
|
||||
bool setPosition(const TrainingAreaBase::EquipmentPosition &newPosition);
|
||||
bool setPosition(const ParticipantManagement::ParticipantPosition &newPosition, bool bForce = false);
|
||||
// returns true when the positionTime is newer than the old positionTime
|
||||
bool setCalculatedPosition(const Core::GeoPosition &pos, int64_t positionTime);
|
||||
bool setState(const TrainingAreaBase::EquipmentState &newState, int originatorId);
|
||||
bool setSpecialSensorData(const TrainingAreaBase::SpecialSensorData &data);
|
||||
bool setGear(const TrainingAreaBase::EquipmentGearAssignment &gearAssignment);
|
||||
bool setSanitationMaterial(int materialCount,
|
||||
const std::vector<int> &materialStock,
|
||||
int abgSn,
|
||||
qint64 sampleTime,
|
||||
Qualification qualif,
|
||||
qint64 eqNo);
|
||||
bool setSanitation(qint64 sanitationProceduresTaken,
|
||||
TrainingAreaBase::SanitationResult sanitationResult,
|
||||
TrainingAreaBase::SanitationEvaluation sanitationEvaluation,
|
||||
int originatorId,
|
||||
TrainingAreaBase::Qualification qualification,
|
||||
qint64 sampleTime);
|
||||
bool setOperatorAction(int action, int originatorId, qint64 sampleTime);
|
||||
bool setEquipmentEvent(int event, qint64 sampleTime);
|
||||
|
||||
bool setGearCharge(const TrainingAreaBase::GearCharge &charge, qint64 sampleTime);
|
||||
bool setGearCharge(const GearInformation &gearInfo);
|
||||
void setDynamicData(const DynamicParticipantData &data);
|
||||
void setMode(const ParticipantMode &data);
|
||||
|
||||
bool isNewAssignStateValid(const ParticipantManagement::ParticipantAssignState &newAssignState, int32_t equipmentNumber) const;
|
||||
|
||||
/**
|
||||
* @brief Method to set this participants data by a modify request and to
|
||||
* detect if the request really changes the data
|
||||
* @param data - participant data from a modify request
|
||||
* @return true if data differs from this participants data, otherwise false
|
||||
*/
|
||||
bool hasToBeChanged(const ParticipantManagement::Participant &data);
|
||||
bool hasToBeChanged(const ParticipantManagement::ParticipantBase &data);
|
||||
bool hasNewSuperiorId(int32_t superiorId);
|
||||
bool hasNewInferiorStructure(std::vector<int32_t> inferiorIds);
|
||||
bool setOperationalState(const TrainingAreaBase::EquipmentOperationalState &operationalState);
|
||||
|
||||
RegisterParticipantRequest toRegisterParticipantRequest() const;
|
||||
|
||||
|
||||
virtual void removeFromDds();
|
||||
virtual bool publishPosition();
|
||||
virtual bool publishDynamicData();
|
||||
virtual bool publishMode();
|
||||
virtual bool publishParticipant();
|
||||
|
||||
Database::PpmParticipant toDbParticipant() const;
|
||||
static ParticipantManagement::Participant toDdsParticipant(const Database::PpmParticipant &data);
|
||||
|
||||
protected:
|
||||
virtual bool updateEquipmentExerciseMapping(int oldEqId, int newEqId) = 0;
|
||||
bool setPosition(const TrainingAreaBase::EquipmentPosition &newPosition, int mountedToId);
|
||||
void unmountParticipantById(const TrainingAreaBase::EquipmentPosition &newPosition, int32_t id);
|
||||
|
||||
void removeManipulation(int32_t equipmentFunctionId);
|
||||
void cleanManipulations();
|
||||
|
||||
bool gearHasCharge(int32_t gearId) const;
|
||||
int32_t indexByGearAndChargeId(int32_t gearId, int32_t chargeTypeId = -1) const;
|
||||
|
||||
ParticipantHandler *particpantHandler() { return m_participantHandler; }
|
||||
const ParticipantHandler *particpantHandler() const { return m_participantHandler; }
|
||||
qint64 currentTimeMSec() const;
|
||||
std::shared_ptr<Interface::Dts> dts() const;
|
||||
|
||||
protected: // attributes
|
||||
ParticipantHandler *m_participantHandler;
|
||||
UnitPositionCalculator *m_unitPosCalculator;
|
||||
qint64 m_lastGearUsage;
|
||||
qint64 m_lastSanMatUsage{0};
|
||||
qint64 m_lastManipulationReset;
|
||||
qint64 m_lastNbcState;
|
||||
qint64 m_lastSpecialSensorData;
|
||||
|
||||
ParticipantPosition m_positionPublished;
|
||||
ParticipantPosition m_positionToPublish;
|
||||
DynamicParticipantData m_dynamicData;
|
||||
DynamicParticipantData m_dynamicDataPublished;
|
||||
ParticipantManagement::Participant m_participantData;
|
||||
ParticipantManagement::Participant m_participantPublished;
|
||||
ParticipantManagement::ParticipantMode m_participantMode;
|
||||
ParticipantManagement::ParticipantMode m_participantModePublished;
|
||||
|
||||
bool m_bPublishPosition; // false for units
|
||||
QMutex m_mutex;
|
||||
LOGGER_T m_logger;
|
||||
}; // class ParticipantBase
|
||||
|
||||
} // namespace ParticipantManagement
|
||||
} // namespace ParticipantHandling
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* The ParticipantDonator class is an interface for returning a Participant to a given id.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Baeuerle, SLSE, 2016-06-06
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
namespace ParticipantHandling
|
||||
{
|
||||
class Participant;
|
||||
class ParticipantDonator
|
||||
{
|
||||
public:
|
||||
virtual Participant *participantById(int participantId) const = 0;
|
||||
virtual bool isUnitType(int typeId) const = 0;
|
||||
}; // class ParticipantDonator
|
||||
} // namespace ParticipantHandling
|
||||
} // namespace ParticipantManagement
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* The Participant class is the base class for either Buildings or ExerciseParticipants.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Baeuerle, SLSE, 2016-05-23
|
||||
*/
|
||||
|
||||
#include "participant_for_exercise.h"
|
||||
#include "main_handler.h"
|
||||
#include "convert_db_to_dds.h"
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
namespace ParticipantHandling
|
||||
{
|
||||
|
||||
//
|
||||
// ParticipantForExercise
|
||||
//
|
||||
ParticipantForExercise::ParticipantForExercise(MainHandler *mainHandler,
|
||||
ParticipantHandler *particpantHandler,
|
||||
UnitPositionCalculator *unitPosCalculator,
|
||||
const Database::PpmParticipant &data)
|
||||
: Participant(particpantHandler, unitPosCalculator, data, "Participant")
|
||||
, m_mainHandler(mainHandler)
|
||||
{}
|
||||
|
||||
ParticipantForExercise::~ParticipantForExercise()
|
||||
{
|
||||
removeFromDds();
|
||||
}
|
||||
|
||||
bool ParticipantForExercise::applyEquipmentExerciseMapping(int newEqId)
|
||||
{
|
||||
if (!newEqId)
|
||||
return true;
|
||||
|
||||
if (m_equipmentExerciseMappingPublished.equipmentNumber == newEqId &&
|
||||
m_equipmentExerciseMappingPublished.participantId == id() &&
|
||||
m_equipmentExerciseMappingPublished.exerciseId == m_mainHandler->exerciseId())
|
||||
return true;
|
||||
|
||||
|
||||
Database::EquipmentExerciseMapping dbEem;
|
||||
dbEem.equipmentNumber = newEqId;
|
||||
dbEem.participantId = id();
|
||||
dbEem.exerciseId = m_mainHandler->exerciseId();
|
||||
|
||||
DEBUG_LOG(m_logger) << "Inserting EquipmentExerciseMapping into db: " << dbEem.equipmentNumber
|
||||
<< ", " << dbEem.participantId
|
||||
<< ", " << dbEem.exerciseId;
|
||||
if (!m_mainHandler->dbEx0()->insert(dbEem))
|
||||
{
|
||||
m_participantData.equipmentNumber().reset();
|
||||
m_participantData.assignState(ParticipantAssignState::NotAssigned);
|
||||
publishParticipant();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_participantHandler->setEquipmentNumberForParticipant(m_equipmentExerciseMappingPublished.equipmentNumber,
|
||||
dbEem.equipmentNumber,
|
||||
id());
|
||||
m_equipmentExerciseMappingPublished = dbEem;
|
||||
return true;
|
||||
}
|
||||
|
||||
void ParticipantForExercise::removeEquipmentExerciseMapping(int oldEqId, bool bIsShutdown)
|
||||
{
|
||||
if (!oldEqId)
|
||||
return;
|
||||
m_equipmentExerciseMappingPublished = Database::EquipmentExerciseMapping();
|
||||
|
||||
if (!bIsShutdown)
|
||||
{
|
||||
Database::EquipmentExerciseMapping dbEem;
|
||||
dbEem.equipmentNumber = oldEqId;
|
||||
dbEem.participantId = id();
|
||||
dbEem.exerciseId = m_mainHandler->exerciseId();
|
||||
m_mainHandler->dbEx0()->removeEquipmentExerciseMapping(dbEem);
|
||||
m_participantHandler->setEquipmentNumberForParticipant(oldEqId, 0, id());
|
||||
}
|
||||
}
|
||||
|
||||
bool ParticipantForExercise::updateEquipmentExerciseMapping(int oldEqId, int newEqId)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "updateEquipmentExerciseMapping from " << oldEqId << " to " << newEqId;
|
||||
if (oldEqId == newEqId)
|
||||
return true;
|
||||
removeEquipmentExerciseMapping(oldEqId, false);
|
||||
return applyEquipmentExerciseMapping(newEqId);
|
||||
}
|
||||
|
||||
bool ParticipantForExercise::publishParticipant()
|
||||
{
|
||||
return Participant::publishParticipant();
|
||||
}
|
||||
|
||||
void ParticipantForExercise::removeFromDds() // only called on shutdown
|
||||
{
|
||||
removeEquipmentExerciseMapping(equipmentNumber(), true);
|
||||
Participant::removeFromDds();
|
||||
}
|
||||
|
||||
void ParticipantForExercise::registerInfoFromFt(const RegisterParticipantRequest &request)
|
||||
{
|
||||
m_participantData.info(request.info());
|
||||
m_participantData.identification(request.identification());
|
||||
}
|
||||
|
||||
bool ParticipantForExercise::registerFromFt(const RegisterParticipantRequest &request)
|
||||
{
|
||||
int newEquipmentNumber = request.equipmentNumber();
|
||||
// just to be sure ...
|
||||
if (request.assignState() == ParticipantAssignState::NotAssigned)
|
||||
newEquipmentNumber = 0;
|
||||
|
||||
if (!updateEquipmentExerciseMapping(equipmentNumber(), newEquipmentNumber))
|
||||
return false;
|
||||
particpantHandler()->setEquipmentNumberForParticipant(equipmentNumber(),
|
||||
newEquipmentNumber,
|
||||
id());
|
||||
|
||||
INFO_LOG(m_logger) << "Set assign state for participant " << id() << " from "
|
||||
<< assignState() << " to " << request.assignState()
|
||||
<< ", old eqid: " << equipmentNumber() << ", new eqid: "
|
||||
<< newEquipmentNumber;
|
||||
|
||||
if (newEquipmentNumber)
|
||||
m_participantData.equipmentNumber(newEquipmentNumber);
|
||||
else
|
||||
m_participantData.equipmentNumber().reset();
|
||||
m_participantData.assignState(request.assignState());
|
||||
m_participantData.info(request.info());
|
||||
m_participantData.identification(request.identification());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace ParticipantHandling
|
||||
} // namespace ParticipantManagement
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* The Participant class is the base class for either Buildings or ExerciseParticipants.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Baeuerle, SLSE, 2016-05-23
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "participant.h"
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
class MainHandler;
|
||||
|
||||
namespace ParticipantHandling
|
||||
{
|
||||
class ParticipantHandler;
|
||||
class UnitPositionCalculator;
|
||||
|
||||
class ParticipantForExercise final : public Participant
|
||||
{
|
||||
public:
|
||||
ParticipantForExercise(MainHandler *mainHandler,
|
||||
ParticipantHandler *particpantHandler,
|
||||
UnitPositionCalculator *unitPosCalculator,
|
||||
const Database::PpmParticipant &data);
|
||||
~ParticipantForExercise();
|
||||
|
||||
bool publishParticipant() override;
|
||||
void removeFromDds() override;
|
||||
|
||||
bool registerFromFt(const RegisterParticipantRequest &request);
|
||||
void registerInfoFromFt(const RegisterParticipantRequest &request);
|
||||
private:
|
||||
bool applyEquipmentExerciseMapping(int newEqId);
|
||||
void removeEquipmentExerciseMapping(int oldEqId, bool bIsShutdown);
|
||||
bool updateEquipmentExerciseMapping(int oldEqId, int newEqId) override;
|
||||
private:
|
||||
Database::EquipmentExerciseMapping m_equipmentExerciseMappingPublished;
|
||||
ParticipantManagement::MainHandler *m_mainHandler;
|
||||
|
||||
}; // class Participant
|
||||
} // namespace ParticipantManagement
|
||||
} // namespace ParticipantHandling
|
||||
+778
@@ -0,0 +1,778 @@
|
||||
/**
|
||||
* The ParticipantHandler class manages all participant related function topics and holds classes for
|
||||
* further participant data.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Baeuerle, SLSE, 2016-05-12
|
||||
*/
|
||||
#include "participant_handler.h"
|
||||
|
||||
#include "participant.h"
|
||||
#include "ppm_common.h"
|
||||
#include "settings.h"
|
||||
#include "unit_position_calculator.h"
|
||||
|
||||
#include <Buildings/bld.hpp>
|
||||
#include <ProjectDataManagement/pdm_dtc.h>
|
||||
|
||||
#include <LtsUtilsCore/outdated_position.h>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
namespace ParticipantHandling
|
||||
{
|
||||
|
||||
//
|
||||
// ParticipantHandler
|
||||
//
|
||||
ParticipantHandler::ParticipantHandler(BaseDataProvider *bdp, const char *loggerName) : QObject(), m_hitLineId(0), m_bdp(bdp), m_logger(getLogger(loggerName)) {}
|
||||
|
||||
ParticipantHandler::~ParticipantHandler()
|
||||
{
|
||||
if (m_unitPositionCalculator)
|
||||
m_unitPositionCalculator->stopCalculation();
|
||||
|
||||
clearParticipants();
|
||||
}
|
||||
|
||||
void ParticipantHandler::clearParticipants()
|
||||
{
|
||||
// clear maps
|
||||
for (auto it = m_hitLineInfoMap.cbegin(); it != m_hitLineInfoMap.cend(); ++it)
|
||||
dts()->removeHitLineInfoByKey(it.value().id());
|
||||
m_hitLineInfoMap.clear();
|
||||
|
||||
for (auto p : qAsConst(m_participants))
|
||||
{
|
||||
p->removeFromDds();
|
||||
delete p;
|
||||
}
|
||||
m_participants.clear();
|
||||
}
|
||||
|
||||
bool ParticipantHandler::init()
|
||||
{
|
||||
clearParticipants();
|
||||
|
||||
m_unitPositionCalculator.reset(new UnitPositionCalculator(this));
|
||||
|
||||
m_webSocketHandler = std::make_shared<WebSocketHandler>(this);
|
||||
|
||||
if (!m_webSocketHandler->init(Settings::getWebSocketServerPortRange(2)))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "could not init websockethandler";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ParticipantHandler::setEquipmentNumberForParticipant(int oldEqNo, int newEqNo, int participantId)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "setEquipmentNumberForParticipant, old: " << oldEqNo << ", new: " << newEqNo << ", participant: " << participantId;
|
||||
if (oldEqNo > 0)
|
||||
m_equipNumber2ParticipantId.remove(oldEqNo);
|
||||
if (newEqNo > 0)
|
||||
{
|
||||
int &val = m_equipNumber2ParticipantId[newEqNo];
|
||||
if (val != 0 && val != participantId)
|
||||
WARNING_LOG(m_logger) << "Another participant (" << val << ") already has the equipment number " << newEqNo << " - overriding it with participant "
|
||||
<< participantId;
|
||||
val = participantId;
|
||||
}
|
||||
}
|
||||
|
||||
Participant *ParticipantHandler::participantById(int32_t participantId) const { return m_participants.value(participantId); }
|
||||
|
||||
Participant *ParticipantHandler::participantByEquipmentNumber(int32_t equipmentNumber)
|
||||
{
|
||||
const int participantId = m_equipNumber2ParticipantId.value(equipmentNumber);
|
||||
DEBUG_LOG(m_logger) << " >>>>>> [ParticipantHandler] participantByEquipmentNumber participantId: " << participantId << " | equipNumb: " << equipmentNumber;
|
||||
return participantById(participantId);
|
||||
}
|
||||
|
||||
void ParticipantHandler::onNewGearEvent(const TrainingAreaBase::EquipmentGearEvent &gearEvent)
|
||||
{
|
||||
if (isTelegramInFuture(gearEvent))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got an EquipmentGearEvent which has a timestamp in the future: " << gearEvent.sampleTime();
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: gearEvent.chargeAmount() is not used because there is no usecase for this value ... atm
|
||||
|
||||
Participant *participantToBeChanged = participantByEquipmentNumber(gearEvent.equipmentNumber());
|
||||
if (!participantToBeChanged)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got gear charge state for unknown equipment number " << gearEvent.equipmentNumber();
|
||||
return;
|
||||
}
|
||||
|
||||
participantToBeChanged->setGearCharge(gearEvent.charge(), gearEvent.sampleTime());
|
||||
participantToBeChanged->publishDynamicData();
|
||||
|
||||
// publish gear event
|
||||
dts()->publish(
|
||||
ParticipantGearEvent(participantToBeChanged->id(),
|
||||
gearEvent.sampleTime(),
|
||||
gearEvent.chargeAmount(),
|
||||
GearCharge(gearEvent.charge().gearId(), gearEvent.charge().gearTypeId(), gearEvent.charge().chargeTypeId(), gearEvent.charge().remain())));
|
||||
}
|
||||
|
||||
void ParticipantHandler::onNewGearChargeStateFromProxy(const TrainingAreaBase::EquipmentGearChargeState &chargeState)
|
||||
{
|
||||
if (isTelegramInFuture(chargeState))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got an EquipmentGearChargeState which has a timestamp in the future: " << chargeState.sampleTime();
|
||||
return;
|
||||
}
|
||||
|
||||
const int equipNo = chargeState.equipmentNumber();
|
||||
Participant *participantToBeChanged = equipNo < 0 ? participantById(-equipNo) : participantByEquipmentNumber(equipNo);
|
||||
|
||||
if (!participantToBeChanged)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got gear charge state for unknown equipment number " << chargeState.equipmentNumber();
|
||||
return;
|
||||
}
|
||||
|
||||
for (const TrainingAreaBase::GearCharge &charge : chargeState.charge())
|
||||
participantToBeChanged->setGearCharge(charge, chargeState.sampleTime());
|
||||
participantToBeChanged->publishDynamicData();
|
||||
|
||||
emit gearChargeChanged(participantToBeChanged->id(), participantToBeChanged->partyId());
|
||||
}
|
||||
|
||||
void ParticipantHandler::onNewGearAssignmentFromProxy(const TrainingAreaBase::EquipmentGearAssignment &gearAssignment)
|
||||
{
|
||||
if (isTelegramInFuture(gearAssignment))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got an EquipmentGearAssignment which has a timestamp in the future: " << gearAssignment.sampleTime();
|
||||
return;
|
||||
}
|
||||
Participant *participantToBeChanged = participantByEquipmentNumber(gearAssignment.equipmentNumber());
|
||||
if (!participantToBeChanged)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got gear assignment for unknown equipment number " << gearAssignment.equipmentNumber();
|
||||
return;
|
||||
}
|
||||
|
||||
participantToBeChanged->setGear(gearAssignment);
|
||||
participantToBeChanged->publishDynamicData();
|
||||
}
|
||||
|
||||
void ParticipantHandler::onNewStateFromProxy(const TrainingAreaBase::EquipmentState &data)
|
||||
{
|
||||
if (isTelegramInFuture(data))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got an EquipmentState which has a timestamp in the future: " << data.sampleTime();
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. handle included EquipmentPosition:
|
||||
TrainingAreaBase::EquipmentPosition pos;
|
||||
pos.equipmentNumber(data.equipmentNumber());
|
||||
pos.sampleTime(data.sampleTime());
|
||||
if (data.position().is_set())
|
||||
{
|
||||
pos.position(data.position().get());
|
||||
onNewPositionFromProxy(pos);
|
||||
}
|
||||
|
||||
// 2. handle EquipmentState
|
||||
Participant *participantToBeChanged = participantByEquipmentNumber(data.equipmentNumber());
|
||||
if (!participantToBeChanged)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got equipment state for unknown equipment number " << data.equipmentNumber();
|
||||
return;
|
||||
}
|
||||
|
||||
// convert eqNo to participantId if originator was a participant and data.originatorId() is an equipment number
|
||||
int originatorId = data.originatorId();
|
||||
Participant *originParticipant = nullptr;
|
||||
if (data.originatorType() == ProjectDataManagement::StateChangeOriginator::Participant)
|
||||
{
|
||||
originParticipant = participantByEquipmentNumber(data.originatorId());
|
||||
if (originParticipant)
|
||||
originatorId = originParticipant->id();
|
||||
else
|
||||
originatorId = -originatorId;
|
||||
}
|
||||
|
||||
// Make Laser Designations to Laser Designations
|
||||
auto dtcPdm = m_bdp->pdmDtc();
|
||||
if (dtcPdm && dtcPdm->getChargeTypeSpecialProperty(data.originatorChargeTypeId(), 0, 0) == ProjectDataManagement::ChargeTypeProperty_def::LTD && originParticipant)
|
||||
{
|
||||
QSet<int> ldGearTypes{1043}; // Need Property for LTD...
|
||||
DynamicParticipantData dpd = originParticipant->dynamicParticipantData();
|
||||
auto it = std::find_if(dpd.gear().cbegin(), dpd.gear().cend(), [ldGearTypes](const GearInformation &gi) { return ldGearTypes.contains(gi.gearTypeId()); });
|
||||
if (it != dpd.gear().cend())
|
||||
{
|
||||
for (auto &ld : dpd.designations())
|
||||
{
|
||||
if (ld.gearId() != it->gearId())
|
||||
continue;
|
||||
|
||||
ld.spotLocation() = pos.position().position();
|
||||
ld.outputPower() = 1.0;
|
||||
originParticipant->setDynamicData(dpd);
|
||||
originParticipant->publishDynamicData();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!participantToBeChanged->setState(data, originatorId))
|
||||
return; // outdated - ignore
|
||||
|
||||
participantToBeChanged->publishDynamicData();
|
||||
|
||||
createHitlineInfo(originatorId, originParticipant, participantToBeChanged, pos, data.originatorChargeTypeId(), data.sampleTime());
|
||||
}
|
||||
|
||||
void ParticipantHandler::createHitlineInfo(int, Participant *, Participant *, const TrainingAreaBase::EquipmentPosition &, int, qint64)
|
||||
{
|
||||
// replay participant is filled with setHitlineInfoFromReplay
|
||||
return;
|
||||
}
|
||||
|
||||
void ParticipantHandler::onNewPositionFromProxy(const TrainingAreaBase::EquipmentPosition &position)
|
||||
{
|
||||
if (isTelegramInFuture(position))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got an EquipmentPosition which has a timestamp in the future: " << position.sampleTime();
|
||||
return;
|
||||
}
|
||||
if (isTelegramOutdated(position) && position.position().reportingSource() != Core::PositionReportingSource::SetByOperator)
|
||||
{
|
||||
INFO_LOG(m_logger) << "position is outdated: " << position;
|
||||
return;
|
||||
}
|
||||
DEBUG_LOG(m_logger) << "Got new position from proxy: " << position;
|
||||
|
||||
const int equipNo = position.equipmentNumber();
|
||||
// negative - treat as participantId
|
||||
Participant *participantWithNewPosition = equipNo < 0 ? participantById(-equipNo) : participantByEquipmentNumber(equipNo);
|
||||
|
||||
if (!participantWithNewPosition)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got EquipmentPosition " << position << " for unknown equipment number: " << equipNo;
|
||||
return;
|
||||
}
|
||||
|
||||
if (participantWithNewPosition->setPosition(position))
|
||||
participantWithNewPosition->publishPosition();
|
||||
}
|
||||
|
||||
void ParticipantHandler::onNewEquipmentOperationalStateFromProxy(const TrainingAreaBase::EquipmentOperationalState &operationalState)
|
||||
{
|
||||
if (isTelegramInFuture(operationalState))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got an EquipmentOperationalState which has a timestamp in the future: " << operationalState.sampleTime();
|
||||
return;
|
||||
}
|
||||
|
||||
Participant *participantToUpdate = participantByEquipmentNumber(operationalState.equipmentNumber());
|
||||
if (!participantToUpdate)
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got EquipmentOperationalState for unknown equipment number: " << operationalState;
|
||||
return;
|
||||
}
|
||||
|
||||
participantToUpdate->setOperationalState(operationalState);
|
||||
participantToUpdate->publishDynamicData();
|
||||
}
|
||||
|
||||
void ParticipantHandler::onNewBiteFromProxy(const TrainingAreaBase::EquipmentBite &bite)
|
||||
{
|
||||
if (isTelegramInFuture(bite))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got an EquipmentBite which has a timestamp in the future: " << bite.sampleTime();
|
||||
return;
|
||||
}
|
||||
if (isTelegramOutdated(bite))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got an EquipmentBite which has a timestamp in the past: " << bite.sampleTime();
|
||||
return;
|
||||
}
|
||||
|
||||
Bite biteData;
|
||||
|
||||
Participant *p = participantByEquipmentNumber(bite.equipmentNumber());
|
||||
biteData.participantId(p ? p->id() : -1);
|
||||
biteData.equipmentNumber(bite.equipmentNumber());
|
||||
biteData.sampleTime(bite.sampleTime());
|
||||
biteData.registerType(bite.registerType());
|
||||
biteData.biteState(bite.biteState());
|
||||
biteData.configState(bite.configState());
|
||||
biteData.batteryState(bite.batteryState());
|
||||
biteData.configError(bite.configError());
|
||||
|
||||
biteData.biteErrors().reserve(bite.biteErrors().size());
|
||||
for (const TrainingAreaBase::EquipmentBiteError &error : bite.biteErrors())
|
||||
biteData.biteErrors().emplace_back(error.errorNumber(), error.canDeviceNumber(), error.subdeviceNumber(), error.uniqueId());
|
||||
|
||||
dts()->publish(biteData);
|
||||
}
|
||||
|
||||
void ParticipantHandler::onNewCtaDataErrorFromProxy(const TrainingAreaBase::CtaDataError &error)
|
||||
{
|
||||
CtaError ctasErrorData;
|
||||
|
||||
ctasErrorData.equipmentNumber(error.equipmentNumber());
|
||||
ctasErrorData.timeReceipt(currentTimeMSec());
|
||||
ctasErrorData.timePlayerUnit(error.sampleTime());
|
||||
ctasErrorData.errorReason(error.reason());
|
||||
ctasErrorData.telegramId(error.originTelegramId());
|
||||
|
||||
dts()->publish(ctasErrorData);
|
||||
}
|
||||
|
||||
void ParticipantHandler::onNewParticipantModeReport(const TrainingAreaBase::ParticipantModeReport &report)
|
||||
{
|
||||
if (isTelegramInFuture(report))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got a ParticipantModeReport which has a timestamp in the future: " << report.sampleTime();
|
||||
return;
|
||||
}
|
||||
if (isTelegramOutdated(report))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got a ParticipantModeReport which has a timestamp in the past: " << report.sampleTime();
|
||||
return;
|
||||
}
|
||||
|
||||
Participant *participant = participantByEquipmentNumber(report.equipmentNumber());
|
||||
if (!participant)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << "Could not find participant with equipment number " << report.equipmentNumber();
|
||||
return;
|
||||
}
|
||||
|
||||
ParticipantMode ddsData;
|
||||
|
||||
ddsData.participantId(participant->id());
|
||||
ddsData.language(report.language());
|
||||
ddsData.opMode(report.operationMode());
|
||||
ddsData.reactivationDecontamination(report.reactivationDetoxication());
|
||||
ddsData.reactivationMaintenance(report.reactivationMaintenance());
|
||||
ddsData.reactivationMedic(report.reactivationMedic());
|
||||
ddsData.modeVest(report.protectionModeVest());
|
||||
ddsData.modeHelmet(report.protectionModeHelmet());
|
||||
ddsData.modePersonalProtection(report.personellProtectionMode());
|
||||
ddsData.protectionLevel(report.protectionLevel());
|
||||
ddsData.handgrenadeSearchMode(report.handgrenadeSearchMode());
|
||||
ddsData.internationalMode(report.internationalMode());
|
||||
ddsData.abcProtectionMode(report.abcProtectionMode());
|
||||
|
||||
ddsData.sampleTime(report.sampleTime());
|
||||
participant->setMode(ddsData);
|
||||
participant->publishMode();
|
||||
}
|
||||
|
||||
void ParticipantHandler::onNewSpecialSensorData(const TrainingAreaBase::SpecialSensorData &data)
|
||||
{
|
||||
if (isTelegramInFuture(data))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got a SpecialSensorData which has a timestamp in the future: " << data.sampleTime();
|
||||
return;
|
||||
}
|
||||
if (isTelegramOutdated(data))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Got a SpecialSensorData which has a timestamp in the past: " << data.sampleTime();
|
||||
return;
|
||||
}
|
||||
|
||||
Participant *participant = data.equipmentNumber() < 0 ? participantById(-data.equipmentNumber()) : participantByEquipmentNumber(data.equipmentNumber());
|
||||
|
||||
if (!participant)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << "Could not find participant with equipment number " << data.equipmentNumber();
|
||||
return;
|
||||
}
|
||||
|
||||
TrainingAreaBase::EquipmentPosition pos;
|
||||
pos.equipmentNumber(data.equipmentNumber());
|
||||
pos.sampleTime(data.sampleTime());
|
||||
if (data.position().is_set())
|
||||
{
|
||||
Core::GeoPosition geoPos(data.position().get().lon(), data.position().get().lat(), 0);
|
||||
pos.position().position(geoPos);
|
||||
if (participant->setPosition(pos))
|
||||
participant->publishPosition();
|
||||
}
|
||||
|
||||
participant->setSpecialSensorData(data);
|
||||
participant->publishDynamicData();
|
||||
}
|
||||
|
||||
void ParticipantHandler::onNewLaserDesignation(const TrainingAreaBase::LaserDesignation &data)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "New Laser Designation: "
|
||||
<< "Code: " << data.code() << ", GearID: " << data.gearId() << ", EqNo: " << data.equipmentNumber() << ", Lon: " << data.spotLocation().lon()
|
||||
<< ", Lat: " << data.spotLocation().lat() << ", Power: " << data.outputPower();
|
||||
Participant *participant = participantByEquipmentNumber(data.equipmentNumber());
|
||||
|
||||
if (!participant)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << "Could not find participant with equipment number " << data.equipmentNumber();
|
||||
return;
|
||||
}
|
||||
|
||||
DynamicParticipantData dpd = participant->dynamicParticipantData();
|
||||
|
||||
DEBUG_LOG(m_logger) << "Begin Update Laser Designation: ";
|
||||
updateLaserDesignation(dpd, data);
|
||||
|
||||
DEBUG_LOG(m_logger) << "End Update Laser Designation: ";
|
||||
|
||||
DEBUG_LOG(m_logger) << "Set DPD and publish ";
|
||||
participant->setDynamicData(dpd);
|
||||
participant->publishDynamicData();
|
||||
}
|
||||
|
||||
void ParticipantHandler::onLaserDesignationRemoved(int equipmentNumber, int gearId)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "On Remove Laser Designation: ";
|
||||
|
||||
Participant *participant = participantByEquipmentNumber(equipmentNumber);
|
||||
|
||||
if (!participant)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << "Could not find participant with equipment number " << equipmentNumber;
|
||||
return;
|
||||
}
|
||||
DynamicParticipantData dpd = participant->dynamicParticipantData();
|
||||
|
||||
DEBUG_LOG(m_logger) << "Begin Remove Laser Designation: ";
|
||||
removeLaserDesignation(dpd, gearId);
|
||||
DEBUG_LOG(m_logger) << "End Remove Laser Designation: ";
|
||||
|
||||
DEBUG_LOG(m_logger) << "Set DPD and publish ";
|
||||
participant->setDynamicData(dpd);
|
||||
participant->publishDynamicData();
|
||||
}
|
||||
|
||||
void ParticipantHandler::onBuildingHitLineInfo(const Buildings::BuildingHitLineInfo &data)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onBuildingHitLineInfo "
|
||||
<< "BuildingId=" << data.buildingId() << " originatorParticipantId=" << data.originatorParticipantId();
|
||||
auto dtcPdm = m_bdp->pdmDtc();
|
||||
// NOTE: igniterTypeId/IgniterFunction = 0 as long as BuildingHitLineInfo does not contain values
|
||||
if (dtcPdm->getChargeTypeSpecialProperty(data.chargeTypeId(), 0, 0) != ProjectDataManagement::ChargeTypeProperty_def::LTD)
|
||||
return;
|
||||
|
||||
Participant *participant = participantById(data.originatorParticipantId());
|
||||
|
||||
if (!participant)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << "Could not find participant with participantId: " << data.originatorParticipantId();
|
||||
return;
|
||||
}
|
||||
|
||||
DynamicParticipantData dpd = participant->dynamicParticipantData();
|
||||
|
||||
DEBUG_LOG(m_logger) << "Begin Update Laser Designation: ";
|
||||
updateLaserDesignation(dpd, data);
|
||||
DEBUG_LOG(m_logger) << "End Update Laser Designation: ";
|
||||
|
||||
DEBUG_LOG(m_logger) << "setDynamicData";
|
||||
participant->setDynamicData(dpd);
|
||||
DEBUG_LOG(m_logger) << "publishDynamicData"
|
||||
<< " dpd.designations().size()=" << dpd.designations().size();
|
||||
participant->publishDynamicData();
|
||||
}
|
||||
|
||||
void ParticipantHandler::onSanitaryMaterialStockReport(const TrainingAreaBase::ParticipantSanitaryMaterialStockReport &data)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onSanitaryMaterialStockReport";
|
||||
Participant *participant = participantByEquipmentNumber(data.equipmentNumber());
|
||||
if (!participant)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << "Could not find participant with equipment number " << data.equipmentNumber();
|
||||
return;
|
||||
}
|
||||
if (data.qualification() == TrainingAreaBase::Qualification::NotDefined)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "!!! Clear Materials : equipment number " << data.equipmentNumber();
|
||||
DEBUG_LOG(m_logger) << "!!! Clear Materials : sample time " << data.sampleTime();
|
||||
participant->setSanitationMaterial(0,
|
||||
std::vector<int>(),
|
||||
data.uniqueId(),
|
||||
data.sampleTime(),
|
||||
Qualification::NotAssigned,
|
||||
data.originatorEquipmentNumber()); // this is a deassociation so clear material
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "!!! Set Materials : equipment number " << data.equipmentNumber();
|
||||
DEBUG_LOG(m_logger) << "!!! Set Materials : sample time " << data.sampleTime();
|
||||
participant->setSanitationMaterial(data.sanitaryMaterialCount(),
|
||||
data.sanitaryMaterialStock(),
|
||||
data.uniqueId(),
|
||||
data.sampleTime(),
|
||||
static_cast<ParticipantManagement::Qualification_def::type>(data.qualification().underlying()),
|
||||
data.originatorEquipmentNumber());
|
||||
}
|
||||
participant->publishDynamicData();
|
||||
}
|
||||
|
||||
void ParticipantHandler::onParticipantSanitation(const TrainingAreaBase::ParticipantSanitation &data)
|
||||
{
|
||||
Participant *participant = participantByEquipmentNumber(data.equipmentNumber());
|
||||
Participant *participantOrig = participantByEquipmentNumber(data.originatorEquipmentNumber());
|
||||
if (!participant)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << "Could not find participant with equipment number " << data.equipmentNumber();
|
||||
return;
|
||||
}
|
||||
int participantOrigId = data.originatorEquipmentNumber();
|
||||
if (participantOrig)
|
||||
participantOrigId = participantOrig->id();
|
||||
|
||||
if (data.qualification() == TrainingAreaBase::Qualification::NotDefined && data.proceduresTaken() == 0)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "!!! Clear Sanitation = " << data.sampleTime();
|
||||
DEBUG_LOG(m_logger) << "!!! Clear Sanitation: equipNo = " << data.equipmentNumber();
|
||||
participant->setSanitationMaterial(0, std::vector<int>(), 0, data.sampleTime(), Qualification::NotAssigned, 0); // this is a deassociation so clear material
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "!!! SetSanitation: sample time = " << data.sampleTime();
|
||||
DEBUG_LOG(m_logger) << "!!! SetSanitation: equipNo = " << data.equipmentNumber();
|
||||
participant->setSanitation(data.proceduresTaken(), data.sanitationResult(), data.sanitationEvaluation(), participantOrigId, data.qualification(), data.sampleTime());
|
||||
}
|
||||
participant->publishDynamicData();
|
||||
}
|
||||
|
||||
void ParticipantHandler::onOperatorAction(const TrainingAreaBase::OperatorAction &data)
|
||||
{
|
||||
// maybe use other commands later?!
|
||||
if (data.action() != 8 && data.action() != 35)
|
||||
return;
|
||||
|
||||
Participant *participant = participantByEquipmentNumber(data.equipmentNumber());
|
||||
if (!participant)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << "Could not find participant with equipment number " << data.equipmentNumber();
|
||||
return;
|
||||
}
|
||||
|
||||
if (participant->setOperatorAction(data.action(), data.operatorId(), data.sampleTime()))
|
||||
participant->publishDynamicData();
|
||||
}
|
||||
|
||||
void ParticipantHandler::onEquipmentEvent(const TrainingAreaBase::EquipmentEvent &data)
|
||||
{
|
||||
// maybe use other commands later?!
|
||||
if (data.source().subDeviceId() != 14 || data.source().equipmentFunctionId() != 5)
|
||||
return;
|
||||
|
||||
if (data.code() == 1 || data.code() == 2) // 1: 9Liner 2: Transport
|
||||
{
|
||||
Participant *participant = participantByEquipmentNumber(data.equipmentNumber());
|
||||
if (!participant)
|
||||
return;
|
||||
|
||||
if (participant->setEquipmentEvent(data.code(), data.sampleTime()))
|
||||
participant->publishDynamicData();
|
||||
}
|
||||
}
|
||||
|
||||
void ParticipantHandler::onNewFunctionalAreaEntryChanged(const TrainingAreaBase::FunctionalAreaEntry &data)
|
||||
{
|
||||
Participant *participant = participantByEquipmentNumber(data.equipmentNumber());
|
||||
|
||||
if (!participant)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << "Could not find participant with equipment number " << data.equipmentNumber();
|
||||
return;
|
||||
}
|
||||
|
||||
TrainingAreaBase::EquipmentPosition pos;
|
||||
pos.equipmentNumber(data.equipmentNumber());
|
||||
pos.sampleTime(data.sampleTime());
|
||||
Core::GeoPosition geoPos(data.position().lon(), data.position().lat(), 0);
|
||||
pos.position().position(geoPos);
|
||||
if (participant->setPosition(pos))
|
||||
participant->publishPosition();
|
||||
|
||||
StateInformation oldState = youngestStateInformation(participant->dynamicParticipantData().stateHistory(), false);
|
||||
TrainingAreaBase::EquipmentState state;
|
||||
state.equipmentNumber(data.equipmentNumber());
|
||||
state.originatorId(data.aesItemId());
|
||||
state.originatorType(ProjectDataManagement::StateChangeOriginator::FunctionalArea);
|
||||
state.sampleTime(data.sampleTime());
|
||||
state.vulnerabilityState(ProjectDataManagement::VulnerabilityState::HitWithNoEffect); // no effect - it's an entry into a functional area
|
||||
state.vulnerabilityBits(oldState.vulnerabilityBits());
|
||||
state.vulnerabilityKindId(oldState.vulnerabilityKindId());
|
||||
state.vitality(oldState.vitality());
|
||||
|
||||
participant->setState(state, data.aesItemId());
|
||||
participant->publishDynamicData();
|
||||
}
|
||||
|
||||
inline bool isOutdated(qint64 curTime, qint64 posTime)
|
||||
{
|
||||
// maxDisplayDuration = 2min -> use 3min
|
||||
return curTime > (posTime + 3 * 60 * 1000);
|
||||
}
|
||||
|
||||
void ParticipantHandler::onHitLineInfoTimeout()
|
||||
{
|
||||
const qint64 tNow = currentTimeMSec();
|
||||
|
||||
auto it = m_hitLineInfoMap.begin();
|
||||
while (it != m_hitLineInfoMap.end())
|
||||
{
|
||||
if (!isOutdated(tNow, it.value().sampleTime()))
|
||||
break;
|
||||
dts()->removeHitLineInfoByKey(it.value().id());
|
||||
|
||||
it = m_hitLineInfoMap.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void ParticipantHandler::setPosition(const ParticipantManagement::ParticipantPosition &data)
|
||||
{
|
||||
Participant *participant = participantById(data.participantId());
|
||||
|
||||
if (!participant)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << "Could not find participant with id " << data.participantId();
|
||||
return;
|
||||
}
|
||||
|
||||
participant->setPosition(data, true);
|
||||
}
|
||||
|
||||
void ParticipantHandler::setHitlineInfoFromReplay(const HitLineInfo &data)
|
||||
{
|
||||
if (!dts()->publish(data))
|
||||
return;
|
||||
m_hitLineInfoMap.insert(data.id(), data);
|
||||
}
|
||||
|
||||
void ParticipantHandler::setUASFromReplay(const UAS &data)
|
||||
{
|
||||
dts()->publish(data);
|
||||
}
|
||||
|
||||
bool ParticipantHandler::isSupportTypeClass(const ParticipantManagement::TypeClass &typeClass)
|
||||
{
|
||||
return (typeClass == TypeClass::SupportUnit || typeClass == TypeClass::SupportEntity);
|
||||
}
|
||||
|
||||
bool ParticipantHandler::isSampleTimeOutdated(qint64 sampleTime) const
|
||||
{
|
||||
const qint64 curTime = currentTimeMSec();
|
||||
return sampleTime < curTime - 11 * 60 * 1000;
|
||||
}
|
||||
|
||||
bool ParticipantHandler::isSampleTimeInFuture(qint64 sampleTime) const
|
||||
{
|
||||
const qint64 curTime = currentTimeMSec();
|
||||
return sampleTime > curTime + 1 * 60 * 1000;
|
||||
}
|
||||
|
||||
std::shared_ptr<Interface::Dts> ParticipantHandler::dts() const { return m_bdp->dts(); }
|
||||
|
||||
qint64 ParticipantHandler::currentTimeMSec() const { return m_bdp->currentTimeMSec(); }
|
||||
|
||||
quint16 ParticipantHandler::getWebSocketPort() const { return m_webSocketHandler->listenPort(); }
|
||||
|
||||
void ParticipantHandler::updateLaserDesignation(DynamicParticipantData &data, const TrainingAreaBase::LaserDesignation &newLaserDesignation)
|
||||
{
|
||||
LOGGER_T m_logger = getLogger("ParticipantHandler.Laser");
|
||||
DEBUG_LOG(m_logger) << "-Update Laser Designation - Start ";
|
||||
|
||||
for (LaserDesignation &laserDesignation : data.designations())
|
||||
{
|
||||
if (laserDesignation.gearId() != newLaserDesignation.gearId())
|
||||
continue;
|
||||
|
||||
DEBUG_LOG(m_logger) << "-Update Laser Designation - Gear with id " << laserDesignation.gearId() << " found in designations";
|
||||
laserDesignation.code(newLaserDesignation.code());
|
||||
|
||||
if (!qFuzzyIsNull(laserDesignation.outputPower()) && !qFuzzyIsNull(newLaserDesignation.spotLocation().lat())
|
||||
&& !qFuzzyIsNull(newLaserDesignation.spotLocation().lon()))
|
||||
laserDesignation.spotLocation(Core::GeoPosition(newLaserDesignation.spotLocation().lon(), newLaserDesignation.spotLocation().lat(), 0.0));
|
||||
|
||||
// If Laser was on before and now is turned off, we have to reset spot Location
|
||||
if (!qFuzzyIsNull(laserDesignation.outputPower()) && qFuzzyIsNull(newLaserDesignation.outputPower()))
|
||||
laserDesignation.spotLocation(Core::GeoPosition(0.0, 0.0, 0.0));
|
||||
|
||||
laserDesignation.outputPower(newLaserDesignation.outputPower());
|
||||
DEBUG_LOG(m_logger) << "-Update Laser Designation - Data updated, returning";
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "-Update Laser Designation - Gear with id " << newLaserDesignation.gearId() << " NOT found in designations";
|
||||
|
||||
int gearId = newLaserDesignation.gearId();
|
||||
auto it = std::find_if(data.gear().cbegin(), data.gear().cend(), [gearId](const GearInformation &gi) { return gearId == gi.gearId(); });
|
||||
if (it == data.gear().cend()) // No gear, no designation...
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "-Update Laser Designation - Gear with id " << newLaserDesignation.gearId() << " NOT found in Gears";
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "-Update Laser Designation - Gear with id " << newLaserDesignation.gearId() << " found in Gears";
|
||||
DEBUG_LOG(m_logger) << "-Update Laser Designation - Adding new designation";
|
||||
data.designations().emplace_back(newLaserDesignation.gearId(),
|
||||
Core::GeoPosition(newLaserDesignation.spotLocation().lon(), newLaserDesignation.spotLocation().lat(), 0.0),
|
||||
newLaserDesignation.code(),
|
||||
newLaserDesignation.outputPower());
|
||||
}
|
||||
|
||||
void ParticipantHandler::updateLaserDesignation(DynamicParticipantData &dataInOut, const Buildings::BuildingHitLineInfo &newLaserDesignation)
|
||||
{
|
||||
LOGGER_T m_logger = getLogger("ParticipantHandler.Laser");
|
||||
// Todo: Die erste vorhandene LaserDesignation wird angepasst. Ein Laser On muss vorher gekommen sein, damit das Element da ist.
|
||||
// Mehrere Designatoren pro Teilnehmer werden nicht unterstützt.
|
||||
DEBUG_LOG(m_logger) << "-Update Laser Designation by Building Hitline Info";
|
||||
|
||||
for (LaserDesignation &laserDesignation : dataInOut.designations())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "-Update Laser Designation by Building Hitline Info - Updating (first) Designation with GearId " << laserDesignation.gearId();
|
||||
laserDesignation.outputPower(1.0);
|
||||
laserDesignation.spotLocation(newLaserDesignation.buildingPos());
|
||||
return;
|
||||
}
|
||||
|
||||
QSet<int> ldGearTypes{1043}; // Need Property for LTD...
|
||||
auto it = std::find_if(dataInOut.gear().cbegin(), dataInOut.gear().cend(), [ldGearTypes](const GearInformation &gi) { return ldGearTypes.contains(gi.gearTypeId()); });
|
||||
if (it != dataInOut.gear().cend())
|
||||
{
|
||||
LaserDesignation ld;
|
||||
ld.gearId() = it->gearId();
|
||||
ld.code() = 0;
|
||||
ld.spotLocation() = newLaserDesignation.buildingPos();
|
||||
ld.outputPower(1.0);
|
||||
dataInOut.designations().emplace_back(ld);
|
||||
ERROR_LOG(m_logger) << "-Update Laser Designation by Building Hitline Info - Added Designation";
|
||||
}
|
||||
ERROR_LOG(m_logger) << "-Update Laser Designation by Building Hitline Info - No laserDesignation available participantId="
|
||||
<< newLaserDesignation.originatorParticipantId();
|
||||
}
|
||||
|
||||
void ParticipantHandler::removeLaserDesignation(DynamicParticipantData &data, qint32 gearId)
|
||||
{
|
||||
LOGGER_T m_logger = getLogger("ParticipantHandler.Laser");
|
||||
|
||||
DEBUG_LOG(m_logger) << "-Remove Laser Designation: Start";
|
||||
auto validationFunction = [gearId](ParticipantManagement::LaserDesignation laserDesignation) { return laserDesignation.gearId() == gearId; };
|
||||
auto eraseIterator = std::find_if(data.designations().begin(), data.designations().end(), validationFunction);
|
||||
|
||||
if (eraseIterator == data.designations().end())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "-Remove Laser Designation: GearId NOT found";
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "-Remove Laser Designation: Removing Designation";
|
||||
data.designations().erase(eraseIterator);
|
||||
}
|
||||
|
||||
} // namespace ParticipantHandling
|
||||
} // namespace ParticipantManagement
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
* The ParticipantHandler class manages all participant related function topics and holds classes for
|
||||
* further participant data.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Baeuerle, SLSE, 2016-05-12
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QString>
|
||||
|
||||
#include <Proxies/TrainingAreaBase/tab_dtc.h>
|
||||
|
||||
#include <ParticipantManagement/ppm_db_structs.h>
|
||||
#include <ParticipantManagement/ppm_dts.h>
|
||||
#include <ParticipantManagement/web_socket_handler.h>
|
||||
|
||||
#include "logger.h"
|
||||
#include "participant_donator.h"
|
||||
|
||||
namespace Buildings
|
||||
{
|
||||
class BuildingHitLineInfo;
|
||||
}
|
||||
|
||||
namespace ProjectDataManagement
|
||||
{
|
||||
namespace Interface
|
||||
{
|
||||
class Dtc;
|
||||
}
|
||||
} // namespace ProjectDataManagement
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
class MainHandler;
|
||||
namespace ParticipantHandling
|
||||
{
|
||||
class Participant;
|
||||
class ExerciseParticipant;
|
||||
class SupportParticipant;
|
||||
class UnitPositionCalculator;
|
||||
|
||||
class BaseDataProvider
|
||||
{
|
||||
public:
|
||||
BaseDataProvider() = default;
|
||||
virtual ~BaseDataProvider() = default;
|
||||
virtual std::shared_ptr<Interface::Dts> dts() const = 0;
|
||||
virtual std::shared_ptr<ProjectDataManagement::Interface::Dtc> pdmDtc() const = 0;
|
||||
virtual qint64 currentTimeMSec() const = 0;
|
||||
};
|
||||
|
||||
struct ParticipantOrganisationEx : public ParticipantOrganisation
|
||||
{
|
||||
int dbId = 0;
|
||||
void copy(const ParticipantOrganisation &o)
|
||||
{
|
||||
ParticipantOrganisation *that = this;
|
||||
*that = o;
|
||||
}
|
||||
};
|
||||
|
||||
class ParticipantHandler
|
||||
: public QObject
|
||||
, public ParticipantDonator
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ParticipantHandler(BaseDataProvider *bdp, const char *loggerName);
|
||||
~ParticipantHandler();
|
||||
|
||||
void clearParticipants();
|
||||
virtual bool init();
|
||||
|
||||
virtual void setEquipmentNumberForParticipant(int oldEqNo, int newEqNo, int participantId);
|
||||
|
||||
Participant *participantById(int32_t participantId) const override;
|
||||
Participant *participantByEquipmentNumber(int32_t equipmentNumber);
|
||||
// only needed in Exercise, correctly reimplemented in ParticipantHandlerForExercise
|
||||
bool isUnitType(int typeId) const override
|
||||
{
|
||||
Q_UNUSED(typeId);
|
||||
return false;
|
||||
}
|
||||
|
||||
Q_SIGNALS:
|
||||
void gearChargeChanged(int participantId, int partyId);
|
||||
|
||||
public Q_SLOTS:
|
||||
void onNewGearEvent(const TrainingAreaBase::EquipmentGearEvent &gearEvent);
|
||||
void onNewGearChargeStateFromProxy(const TrainingAreaBase::EquipmentGearChargeState &chargeState);
|
||||
void onNewGearAssignmentFromProxy(const TrainingAreaBase::EquipmentGearAssignment &gearAssignment);
|
||||
void onNewStateFromProxy(const TrainingAreaBase::EquipmentState &data);
|
||||
void onNewPositionFromProxy(const TrainingAreaBase::EquipmentPosition &position);
|
||||
void onNewEquipmentOperationalStateFromProxy(const TrainingAreaBase::EquipmentOperationalState &operationalState);
|
||||
void onNewBiteFromProxy(const TrainingAreaBase::EquipmentBite &bite);
|
||||
void onNewCtaDataErrorFromProxy(const TrainingAreaBase::CtaDataError &error);
|
||||
void onNewParticipantModeReport(const TrainingAreaBase::ParticipantModeReport &report);
|
||||
void onNewSpecialSensorData(const TrainingAreaBase::SpecialSensorData &data);
|
||||
void onNewFunctionalAreaEntryChanged(const TrainingAreaBase::FunctionalAreaEntry &data);
|
||||
void onNewLaserDesignation(const TrainingAreaBase::LaserDesignation &data);
|
||||
void onLaserDesignationRemoved(int equipmentNumber, int gearId);
|
||||
void onSanitaryMaterialStockReport(const TrainingAreaBase::ParticipantSanitaryMaterialStockReport &data);
|
||||
void onParticipantSanitation(const TrainingAreaBase::ParticipantSanitation &data);
|
||||
void onOperatorAction(const TrainingAreaBase::OperatorAction &data);
|
||||
void onEquipmentEvent(const TrainingAreaBase::EquipmentEvent &data);
|
||||
void onBuildingHitLineInfo(const Buildings::BuildingHitLineInfo &data);
|
||||
void onHitLineInfoTimeout();
|
||||
|
||||
public:
|
||||
void newData(const TrainingAreaBase::EquipmentGearEvent &data) { onNewGearEvent(data); }
|
||||
void newData(const TrainingAreaBase::EquipmentGearChargeState &data) { onNewGearChargeStateFromProxy(data); }
|
||||
void newData(const TrainingAreaBase::EquipmentGearAssignment &data) { onNewGearAssignmentFromProxy(data); }
|
||||
void newData(const TrainingAreaBase::EquipmentState &data) { onNewStateFromProxy(data); }
|
||||
void newData(const TrainingAreaBase::EquipmentPosition &data) { onNewPositionFromProxy(data); }
|
||||
void newData(const TrainingAreaBase::EquipmentOperationalState &data) { onNewEquipmentOperationalStateFromProxy(data); }
|
||||
void newData(const TrainingAreaBase::EquipmentBite &data) { onNewBiteFromProxy(data); }
|
||||
void newData(const TrainingAreaBase::CtaDataError &data) { onNewCtaDataErrorFromProxy(data); }
|
||||
void newData(const TrainingAreaBase::ParticipantModeReport &data) { onNewParticipantModeReport(data); }
|
||||
void newData(const TrainingAreaBase::SpecialSensorData &data) { onNewSpecialSensorData(data); }
|
||||
void newData(const TrainingAreaBase::ParticipantSanitation &data) { onParticipantSanitation(data); }
|
||||
void newData(const TrainingAreaBase::ParticipantSanitaryMaterialStockReport &data) { onSanitaryMaterialStockReport(data); }
|
||||
void newData(const TrainingAreaBase::EquipmentEvent &data) { onEquipmentEvent(data); }
|
||||
void newData(const ParticipantPosition &data) { setPosition(data); }
|
||||
void newData(const HitLineInfo &data) { setHitlineInfoFromReplay(data); }
|
||||
void newData(const UAS &data) { setUASFromReplay(data); }
|
||||
|
||||
std::shared_ptr<Interface::Dts> dts() const;
|
||||
qint64 currentTimeMSec() const;
|
||||
|
||||
quint16 getWebSocketPort() const;
|
||||
|
||||
protected:
|
||||
static void updateLaserDesignation(DynamicParticipantData &data, const TrainingAreaBase::LaserDesignation &newLaserDesignation);
|
||||
void updateLaserDesignation(DynamicParticipantData &dataInOut, const Buildings::BuildingHitLineInfo &newLaserDesignation);
|
||||
static void removeLaserDesignation(DynamicParticipantData &data, qint32 gearId);
|
||||
void setPosition(const ParticipantPosition &data);
|
||||
void setHitlineInfoFromReplay(const HitLineInfo &data);
|
||||
void setUASFromReplay(const UAS &data);
|
||||
|
||||
virtual void createHitlineInfo(int originatorId,
|
||||
Participant *originParticipant,
|
||||
Participant *participantToBeChanged,
|
||||
const TrainingAreaBase::EquipmentPosition &pos,
|
||||
int originatorChargeTypeId,
|
||||
qint64 sampleTime);
|
||||
|
||||
static bool isSupportTypeClass(const TypeClass &typeClass);
|
||||
// t - 11min <= sampleTime
|
||||
template <typename T> inline bool isTelegramOutdated(const T &tele) const { return isSampleTimeOutdated(tele.sampleTime()); }
|
||||
virtual bool isSampleTimeOutdated(qint64 sampleTime) const;
|
||||
// sampleTime > t + 1min
|
||||
template <typename T> inline bool isTelegramInFuture(const T &tele) const { return isSampleTimeInFuture(tele.sampleTime()); }
|
||||
virtual bool isSampleTimeInFuture(qint64 sampleTime) const;
|
||||
|
||||
protected:
|
||||
std::unique_ptr<UnitPositionCalculator> m_unitPositionCalculator;
|
||||
QHash<int, int> m_equipNumber2ParticipantId;
|
||||
QHash<int, Participant *> m_participants;
|
||||
QHash<int, ParticipantOrganisationEx> m_participantOrganisations;
|
||||
int m_hitLineId;
|
||||
QMap<int, HitLineInfo> m_hitLineInfoMap;
|
||||
|
||||
BaseDataProvider *m_bdp;
|
||||
LOGGER_T m_logger;
|
||||
|
||||
std::shared_ptr<WebSocketHandler> m_webSocketHandler;
|
||||
|
||||
friend class Participant;
|
||||
};
|
||||
} // namespace ParticipantHandling
|
||||
} // namespace ParticipantManagement
|
||||
+2026
File diff suppressed because it is too large.
Load diff
+199
@@ -0,0 +1,199 @@
|
||||
/**
|
||||
* The ParticipantHandler class manages all participant related function topics and holds classes for
|
||||
* further participant data.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Baeuerle, SLSE, 2016-05-12
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "participant_handler.h"
|
||||
|
||||
#include <QtCore/QElapsedTimer>
|
||||
#include <QtCore/QHash>
|
||||
#include <QtCore/QMutex>
|
||||
#include <QtCore/QString>
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <ExerciseManagement/exm_dtc.h>
|
||||
#include <ParticipantManagement/ppm_dtc.h>
|
||||
#include <ParticipantManagement/ppm_fts.h>
|
||||
#include <ProjectDataManagement/pdm_dtc.h>
|
||||
#include <TrainingAreaBase/tab_dts.h>
|
||||
|
||||
class QTimer;
|
||||
class QTransform;
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
class MainHandler;
|
||||
|
||||
namespace ParticipantHandling
|
||||
{
|
||||
class FiringUnitValidator;
|
||||
class ProxyListener;
|
||||
|
||||
class ParticipantHandlerForExercise final
|
||||
: public ParticipantHandler
|
||||
, protected Interface::Fts::ModifyStateRequestHandler
|
||||
, protected Interface::Fts::ModifyParticipantDataRequestHandler
|
||||
, protected Interface::Fts::InitParticipantRequestHandler
|
||||
, protected Interface::Fts::SetParticipantModeRequestHandler
|
||||
, protected Interface::Fts::SendMessageRequestHandler
|
||||
, protected Interface::Fts::RegisterParticipantRequestHandler
|
||||
, protected Interface::Fts::SetSimulatedPositionRequestHandler
|
||||
, protected Interface::Fts::SetSimulatedPositionRelativeRequestHandler
|
||||
, protected Interface::Fts::SetSimulatedParticipantFormationRequestHandler
|
||||
, protected Interface::Fts::SetSanitationRequestHandler
|
||||
, protected Interface::Fts::SelectiveReammunitionRequestHandler
|
||||
, protected Interface::Fts::SetAsSimulatedRequestHandler
|
||||
, protected Interface::Fts::OcCommandRequestHandler
|
||||
, protected Interface::Fts::ModifyUasStateRequestHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ParticipantHandlerForExercise(MainHandler *mainHandler);
|
||||
~ParticipantHandlerForExercise();
|
||||
bool init() override;
|
||||
|
||||
void setEquipmentNumberForParticipant(int oldEqNo, int newEqNo, int participantId) override;
|
||||
bool isUnitType(int typeId) const override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void onGearChargeChanged(int participantId, int partyId);
|
||||
|
||||
protected:
|
||||
struct ParticipantFormationStruct
|
||||
{
|
||||
QString geometry = QStringLiteral("line");
|
||||
double distance = -1;
|
||||
double angle = -1;
|
||||
QString jsonData;
|
||||
QJsonObject distanceSetsObj;
|
||||
QVariantMap distanceSets;
|
||||
ParticipantFormationStruct() {}
|
||||
explicit ParticipantFormationStruct(const QString &formationProperty) : jsonData(formationProperty)
|
||||
{
|
||||
const QJsonObject formationObj = QJsonDocument::fromJson(QByteArray::fromStdString(jsonData.toStdString())).object();
|
||||
if (formationObj.isEmpty())
|
||||
return;
|
||||
geometry = formationObj[QStringLiteral("geometry")].toString(QStringLiteral("line"));
|
||||
angle = formationObj[QStringLiteral("angle")].toDouble(-1);
|
||||
distance = formationObj[QStringLiteral("distance")].toDouble(-1);
|
||||
distanceSetsObj = formationObj[QStringLiteral("distanceSets")].toObject();
|
||||
distanceSets = distanceSetsObj.toVariantMap();
|
||||
}
|
||||
|
||||
public:
|
||||
bool hasFormationData() const { return ((angle != -1) && (distance != -1)); }
|
||||
};
|
||||
|
||||
void getFormationParameters(const QString &jsdata, QString &geometry, double &distance, double &angle);
|
||||
void setFormationAsLine(Participant *participant, const SetSimulatedParticipantFormation &request, const double distance, const double angleDeg);
|
||||
|
||||
void createHitlineInfo(int originatorId,
|
||||
Participant *originParticipant,
|
||||
Participant *participantToBeChanged,
|
||||
const TrainingAreaBase::EquipmentPosition &pos,
|
||||
int originatorChargeTypeId,
|
||||
qint64 sampleTime) override;
|
||||
void onModifyParticipantDataRequest(const rti::core::SampleIdentity &cookie, const ModifyParticipantDataRequest &request) override;
|
||||
Core::FunctionReplyObject modifyParticipantDataRequest(const ModifyParticipantDataRequest &request);
|
||||
// ModifyState
|
||||
void onModifyStateRequest(const rti::core::SampleIdentity &cookie, const ModifyStateRequest &request) override;
|
||||
Core::FunctionReplyObject modifyStateRequest(const rti::core::SampleIdentity &cookie, const ModifyStateRequest &request);
|
||||
// Init
|
||||
void onInitParticipantRequest(const rti::core::SampleIdentity &cookie, const InitParticipantRequest &request) override;
|
||||
Core::FunctionReplyObject initParticipantRequest(const rti::core::SampleIdentity &cookie, const InitParticipantRequest &request);
|
||||
// Mode
|
||||
void onSetParticipantModeRequest(const rti::core::SampleIdentity &cookie, const SetParticipantModeRequest &request) override;
|
||||
Core::FunctionReplyObject setParticipantModeRequest(const rti::core::SampleIdentity &cookie, const SetParticipantModeRequest &request);
|
||||
|
||||
void onSendMessageRequest(const rti::core::SampleIdentity &cookie, const SendMessageRequest &request) override;
|
||||
Core::FunctionReplyObject sendMessageRequest(const rti::core::SampleIdentity &cookie, const SendMessageRequest &request);
|
||||
void onRegisterParticipantRequest(const rti::core::SampleIdentity &cookie, const RegisterParticipantRequest &request) override;
|
||||
Core::FunctionReplyObject registerParticipantRequest(const RegisterParticipantRequest &request_, RegisterReturnValue &retVal);
|
||||
|
||||
void onSetSimulatedPositionRequest(const rti::core::SampleIdentity &cookie, const SetSimulatedPosition &request) override;
|
||||
Core::FunctionReplyObject setSimulatedPositionRequest(const SetSimulatedPosition &request);
|
||||
void setSimulatedPosition(Participant *participant, const SetSimulatedPosition &request);
|
||||
|
||||
void onSetSimulatedPositionRelativeRequest(const rti::core::SampleIdentity &cookie, const SetSimulatedPositionRelative &request) override;
|
||||
Core::FunctionReplyObject setSimulatedPositionRelativeRequest(const SetSimulatedPositionRelative &request);
|
||||
void setSimulatedPositionRelative(Participant *participant, const SetSimulatedPositionRelative &request);
|
||||
|
||||
void onSetSimulatedParticipantFormationRequest(const rti::core::SampleIdentity &cookie, const SetSimulatedParticipantFormation &request) override;
|
||||
Core::FunctionReplyObject setSimulatedParticipantFormationRequest(const SetSimulatedParticipantFormation &request);
|
||||
|
||||
void onSetSanitationRequest(const rti::core::SampleIdentity &cookie, const SetSanitationRequest &request) override;
|
||||
Core::FunctionReplyObject setSanitationRequest(const rti::core::SampleIdentity &cookie, const SetSanitationRequest &request);
|
||||
|
||||
void onSelectiveReammunitionRequest(const rti::core::SampleIdentity &cookie, const SelectiveReammunitionRequest &request) override;
|
||||
Core::FunctionReplyObject selectiveReammunitionRequest(const rti::core::SampleIdentity &cookie, const SelectiveReammunitionRequest &request);
|
||||
|
||||
void onSetAsSimulatedRequest(const rti::core::SampleIdentity &cookie, const SetAsSimulated &request) override;
|
||||
Core::FunctionReplyObject setAsSimulatedRequest(const SetAsSimulated &request);
|
||||
|
||||
// OcCommand
|
||||
void onOcCommandRequest(const rti::core::SampleIdentity &cookie, const OcCommandRequest &request) override;
|
||||
Core::FunctionReplyObject ocCommandRequest(const rti::core::SampleIdentity &cookie, const OcCommandRequest &request);
|
||||
|
||||
void updateParticipantFormation(Participant *participant, const Core::GeoPosition &position, const QPointF &offset);
|
||||
void setAsSimulated(const SetAsSimulated &request);
|
||||
void onModifyUasStateRequest(const rti::core::SampleIdentity &cookie, const ModifyUasStateRequest &request) override final;
|
||||
|
||||
private: // methods
|
||||
struct ValidateParticipantData // is needed as QtConcurrent can only handle functions with up to 5 parameter ...
|
||||
{
|
||||
QVector<ParticipantData> participantsToBeCreatedOrModified;
|
||||
QHash<int, int> modIdToParticipantId; // <modId, participantId>
|
||||
QVector<int> participantsToResetEquipmentNumber; // when move from template to pool, we have to reset the equipment number if it already exists
|
||||
bool forceAddWithId;
|
||||
};
|
||||
|
||||
Core::FunctionReplyObject createNewParticipants(std::vector<Database::PpmParticipant> &dbParticipantsToBeCreated,
|
||||
const std::vector<int> &dbParticipantsToBeCreatedIndexes,
|
||||
const QVector<ParticipantData> &participantsToBeCreatedOrModified,
|
||||
QHash<int, int> &modIdToParticipantId,
|
||||
QSet<Participant *> &participantsWithChanges);
|
||||
Core::FunctionReplyObject validateParticipantData(ValidateParticipantData &data, const ParticipantManagement::ParticipantData &participantToValidate);
|
||||
|
||||
std::vector<int32_t> inferiorIdsForParticipant(int32_t superiorParticipantId) const;
|
||||
Core::FunctionReplyObject checkDeleteParticipant(int id);
|
||||
Core::FunctionReplyObject deleteParticipant(int32_t id, bool permanentRemove, bool isTriggeredFromFtRequest = false);
|
||||
|
||||
const Type *typeById(int typeId) const;
|
||||
bool isSupportType(int typeId) const;
|
||||
bool isParticipantType(int typeId) const;
|
||||
|
||||
void startLongAction();
|
||||
void checkLongActionBreak();
|
||||
|
||||
bool participantIds2EquipmentNumbers(const std::vector<int32_t> &participantIds, std::vector<int32_t> &equipmentNumbers, int *failedParticipantId) const;
|
||||
void onEquipmentExerciseMappingChanged(const EquipmentExerciseMapping &data, DataModification mod);
|
||||
void onExerciseChanged(const ExerciseManagement::Exercise &data, DataModification mod);
|
||||
void publishEquipmentExerciseMapping();
|
||||
bool isCurrentExerciseActive() const;
|
||||
|
||||
QString lookUpHierachy(int participantId) const;
|
||||
QString participantInfosFromId(int participantId) const;
|
||||
void customedSetGearCharges(Participant *participant);
|
||||
Core::FunctionReplyObject modifyUasStateRequest(const rti::core::SampleIdentity &cookie, const ParticipantManagement::ModifyUasStateRequest &request);
|
||||
|
||||
private: // attributes
|
||||
MainHandler *m_mainHandler;
|
||||
FiringUnitValidator *m_firingUnitValidator{nullptr};
|
||||
std::shared_ptr<ExerciseManagement::Interface::Dtc> m_exmDtc;
|
||||
std::shared_ptr<TrainingAreaBase::Interface::Dts> m_dtsTab;
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
|
||||
std::shared_ptr<ProjectDataManagement::Interface::Dtc> m_pdmDtc;
|
||||
std::unique_ptr<ProxyListener> m_proxyListener;
|
||||
QElapsedTimer m_longActionTimer;
|
||||
QTimer *m_hitLineInfoTimer;
|
||||
QTimer *m_publishEquipmentExerciseMappingsTimer;
|
||||
QHash<int, Database::EquipmentExerciseMapping> m_equipmentExerciseMappings; // QHash<eqId, Database::EquipmentExerciseMapping>
|
||||
bool m_publishEquipmentExerciseMappings;
|
||||
}; // class ParticipantHandler
|
||||
} // namespace ParticipantHandling
|
||||
} // namespace ParticipantManagement
|
||||
+589
@@ -0,0 +1,589 @@
|
||||
/**
|
||||
* The ProxyListener class subscribes to participant related proxy data topics and distributes
|
||||
* the collected data via Q_SIGNALS.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Baeuerle, SLSE, 2016-05-13
|
||||
*/
|
||||
#include "proxy_listener.h"
|
||||
#include "main_handler.h"
|
||||
#include <UasHandling/mission_plan_handler.h>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
namespace ParticipantHandling
|
||||
{
|
||||
|
||||
ProxyListener::ProxyListener(MainHandler *mainHandler)
|
||||
: QObject()
|
||||
, m_mainHandler(mainHandler)
|
||||
, m_logger(getLogger("ProxyListener"))
|
||||
{}
|
||||
|
||||
bool ProxyListener::init()
|
||||
{
|
||||
m_tabDtc = TrainingAreaBase::Interface::Dtc::create(m_mainHandler->dds());
|
||||
m_bldDtc = Buildings::Interface::Dtc::create(m_mainHandler->dds());
|
||||
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::equipmentBiteChanged,
|
||||
this, &ProxyListener::onProxyEquipmentBiteChanged);
|
||||
if (!m_tabDtc->enableEquipmentBite())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not initialize TraininAreaBase data topic client";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m_mainHandler->exerciseId() > 0)
|
||||
{
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::equipmentPositionChanged,
|
||||
this, &ProxyListener::onProxyEquipmentPositionChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::equipmentGearAssignmentChanged,
|
||||
this, &ProxyListener::onProxyEquipmentGearAssignmentChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::equipmentGearEventChanged,
|
||||
this, &ProxyListener::onProxyEquipmentGearEventChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::participantSanitaryMaterialStockReportChanged,
|
||||
this, &ProxyListener::onProxyParticipantSanitaryMaterialStockReportChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::equipmentGearChargeStateChanged,
|
||||
this, &ProxyListener::onProxyEquipmentGearChargeStateChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::equipmentStateChanged,
|
||||
this, &ProxyListener::onProxyEquipmentStateChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::equipmentOperationalStateChanged,
|
||||
this, &ProxyListener::onProxyEquipmentOperationalStateChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::ctaDataErrorChanged,
|
||||
this, &ProxyListener::onProxyCtaDataErrorChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::participantModeReportChanged,
|
||||
this, &ProxyListener::onProxyParticipantModeReportChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::specialSensorDataChanged,
|
||||
this, &ProxyListener::onSpecialSensorDataChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::functionalAreaEntryChanged,
|
||||
this, &ProxyListener::onFunctionalAreaEntryChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::laserDesignationChanged,
|
||||
this, &ProxyListener::onLaserDesignationChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::participantSanitationChanged,
|
||||
this, &ProxyListener::onProxyParticipantSanitationChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::operatorActionChanged,
|
||||
this, &ProxyListener::onOperatorActionChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::equipmentEventChanged,
|
||||
this, &ProxyListener::onEquipmentEventChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::uASStatusChanged,
|
||||
this, &ProxyListener::onUASStatusChanged);
|
||||
connect(m_tabDtc.get(), &TrainingAreaBase::Interface::Dtc::uASMissionStatusChanged,
|
||||
this, &ProxyListener::onUASMissionStatusChanged);
|
||||
connect(m_bldDtc.get(), &Buildings::Interface::Dtc::buildingHitLineInfoChanged,
|
||||
this, &ProxyListener::onBuildingHitLineInfoChanged);
|
||||
|
||||
if (!m_tabDtc->enableEquipmentPosition() ||
|
||||
!m_tabDtc->enableEquipmentGearAssignment() ||
|
||||
!m_tabDtc->enableEquipmentEvent() ||
|
||||
!m_tabDtc->enableEquipmentGearEvent() ||
|
||||
!m_tabDtc->enableEquipmentGearChargeState() ||
|
||||
!m_tabDtc->enableEquipmentState() ||
|
||||
!m_tabDtc->enableEquipmentOperationalState() ||
|
||||
!m_tabDtc->enableCtaDataError() ||
|
||||
!m_tabDtc->enableParticipantModeReport() ||
|
||||
!m_tabDtc->enableFunctionalAreaEntry() ||
|
||||
!m_tabDtc->enableLaserDesignation() ||
|
||||
!m_tabDtc->enableSpecialSensorData() ||
|
||||
!m_tabDtc->enableParticipantSanitaryMaterialStockReport() ||
|
||||
!m_tabDtc->enableOperatorAction() ||
|
||||
!m_tabDtc->enableParticipantSanitation() ||
|
||||
!m_tabDtc->enableUASStatus() ||
|
||||
!m_tabDtc->enableUASMissionStatus() ||
|
||||
!m_bldDtc->enableBuildingHitLineInfo())
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not initialize TraininAreaBase data topic client";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProxyListener::onProxyEquipmentPositionChanged(const TrainingAreaBase::EquipmentPosition &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got new position data from proxy " << data;
|
||||
|
||||
emit newPosition(data);
|
||||
}
|
||||
|
||||
void ProxyListener::onProxyEquipmentGearAssignmentChanged(const TrainingAreaBase::EquipmentGearAssignment &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got new gear assignment from proxy " << data;
|
||||
|
||||
emit newGearAssignment(data);
|
||||
}
|
||||
|
||||
void ProxyListener::onProxyEquipmentGearEventChanged(const TrainingAreaBase::EquipmentGearEvent &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got new gear event " << data;
|
||||
|
||||
emit newGearEvent(data);
|
||||
}
|
||||
|
||||
void ProxyListener::onProxyEquipmentGearChargeStateChanged(const TrainingAreaBase::EquipmentGearChargeState &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got new gear charge state " << data;
|
||||
|
||||
emit newGearChargeState(data);
|
||||
}
|
||||
|
||||
void ProxyListener::onProxyParticipantSanitaryMaterialStockReportChanged(const TrainingAreaBase::ParticipantSanitaryMaterialStockReport &data, DataModification modType)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "FUCKING FUCK FUCK" << data;
|
||||
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got new material stock report" << data;
|
||||
|
||||
emit newSanitaryMaterialStockReport(data);
|
||||
}
|
||||
|
||||
void ProxyListener::onProxyEquipmentStateChanged(const TrainingAreaBase::EquipmentState &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got new equipment state " << data;
|
||||
|
||||
emit newState(data);
|
||||
}
|
||||
|
||||
void ProxyListener::onProxyEquipmentOperationalStateChanged(const TrainingAreaBase::EquipmentOperationalState &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got new equipment operational state " << data;
|
||||
|
||||
emit newEquipmentOperationalState(data);
|
||||
}
|
||||
|
||||
void ProxyListener::onProxyEquipmentBiteChanged(const TrainingAreaBase::EquipmentBite &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got new equipment bite " << data;
|
||||
|
||||
emit newEquipmentBite(data);
|
||||
}
|
||||
|
||||
void ProxyListener::onProxyCtaDataErrorChanged(const TrainingAreaBase::CtaDataError &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got new Combat Training Area Data error: " << data;
|
||||
|
||||
emit newCtaDataError(data);
|
||||
}
|
||||
|
||||
void ProxyListener::onSpecialSensorDataChanged(const TrainingAreaBase::SpecialSensorData &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got new Special Sensor data: " << data;
|
||||
|
||||
emit newSpecialSensorData(data);
|
||||
}
|
||||
|
||||
void ProxyListener::onFunctionalAreaEntryChanged(const TrainingAreaBase::FunctionalAreaEntry &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got functional area entry: " << data;
|
||||
|
||||
emit newFunctionalAreaEntryChanged(data);
|
||||
}
|
||||
|
||||
void ProxyListener::onLaserDesignationChanged(const TrainingAreaBase::LaserDesignation &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Got no laser designation data: " << data;
|
||||
emit laserDesignationRemoved(data.equipmentNumber(), data.gearId());
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got laser designation data: " << data;
|
||||
|
||||
emit newLaserDesignationData(data);
|
||||
}
|
||||
|
||||
void ProxyListener::onProxyParticipantSanitationChanged(const TrainingAreaBase::ParticipantSanitation &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got new Participant Sanitation" << data;
|
||||
|
||||
emit newParticipantSanitation(data);
|
||||
}
|
||||
|
||||
void ProxyListener::onOperatorActionChanged(const TrainingAreaBase::OperatorAction &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got new Operator Action" << data;
|
||||
|
||||
emit newOperatorAction(data);
|
||||
}
|
||||
|
||||
void ProxyListener::onEquipmentEventChanged(const TrainingAreaBase::EquipmentEvent &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got new Operator Action" << data;
|
||||
|
||||
emit newEquipmentEvent(data);
|
||||
|
||||
}
|
||||
|
||||
void ProxyListener::onUASStatusChanged(const TrainingAreaBase::UASStatus &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
|
||||
m_mainHandler->ddsHandler()->dtc()->waitForHistoricalDataParticipant(3000);
|
||||
int participantId = m_mainHandler->ddsHandler()->dtc()->participantIdByEquipmentNumber(data.equipmentNumber());
|
||||
|
||||
if (participantId <= 0)
|
||||
return;
|
||||
const auto uas = m_mainHandler->ddsHandler()->dtc()->getUasByParticipantId(participantId, m_mainHandler->exerciseId());
|
||||
|
||||
if (uas.id() <= 0)
|
||||
return;
|
||||
//new PPM Telegram
|
||||
UASRadioLinkConnectionStatus newState;
|
||||
newState.id(uas.id());
|
||||
newState.uasState(data.uasState());
|
||||
DEBUG_LOG(m_logger) << "Publish new UAS State " << newState;
|
||||
m_mainHandler->ddsHandler()->exAnyDts()->publish(newState);
|
||||
}
|
||||
|
||||
void ProxyListener::onUASMissionStatusChanged(const TrainingAreaBase::UASMissionStatus &data, DataModification modType)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "currentTask = " << (int)data.currentTask().underlying() << ", currentMissionName = " << data.currentMissionName() << ", name of ended mission: " << data.missionEnded();
|
||||
/*
|
||||
was wenn random mehrfach hintereinander loiter gesendet wird??
|
||||
dann überspringt er eine action! der tab darf also nur senden wenn wirklich ein state change kam
|
||||
- aber wie stellt man dann sicher dass der handler den letzen state kennt?
|
||||
z.B. würde ein IA restart ein neues loiter senden und somit würde eine action übersprungen werden
|
||||
*/
|
||||
if (modType == DataModification::eRemoved)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "removed - stop";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!data.currentMissionName().empty() || data.currentTask().underlying() != ProjectDataManagement::UasActionTask::Loiter || data.missionEnded().empty())
|
||||
{
|
||||
//DEBUG As this will happen a lot
|
||||
DEBUG_LOG(m_logger) << "not fulfilling current mission ("<<data.currentMissionName()<<") action because either a mission is still active or current task ("<<(int)data.currentTask().underlying()<<") is not Loiter or mission not ended ("<< data.missionEnded() << (data.missionEnded().empty() ? " [NOT ENDED]" : " [ ENDED ]")<<")";
|
||||
return;
|
||||
}
|
||||
|
||||
m_mainHandler->ddsHandler()->dtc()->waitForHistoricalDataParticipant(3000);
|
||||
const int participantId = m_mainHandler->ddsHandler()->dtc()->participantIdByEquipmentNumber(data.equipmentNumber());
|
||||
if (participantId <= 0)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "participant for eqid " << data.equipmentNumber() << " not found - unable to fulfill current mission action";
|
||||
return;
|
||||
}
|
||||
|
||||
QTimer::singleShot(1000, [this, participantId, data]() // give tab plugin time to clean stuff up before sending new missions (by marking an action as fulfilled)
|
||||
{
|
||||
// mission empty & task = loiter? mission done, run next mission (by setting current mission's current action as fulfilled, which will trigger the next action automatically (see ces))
|
||||
if (!m_mainHandler->missionPlanHandler()->setCurrentMissionActionFulfilled(participantId, QString::fromStdString(data.missionEnded())))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "setCurrentMissionActionFulfilled didn't work out";
|
||||
return;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "setCurrentMissionActionFulfilled done !";
|
||||
});
|
||||
}
|
||||
|
||||
void ProxyListener::onBuildingHitLineInfoChanged(const Buildings::BuildingHitLineInfo &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got new Building Hitline Info" << data;
|
||||
|
||||
emit newBuildingHitLineInfo(data);
|
||||
|
||||
}
|
||||
|
||||
void ProxyListener::onProxyParticipantModeReportChanged(const TrainingAreaBase::ParticipantModeReport &data, DataModification modType)
|
||||
{
|
||||
if (modType == DataModification::eRemoved)
|
||||
return;
|
||||
|
||||
DEBUG_LOG(m_logger) << "Got new Participant Mode Report Training Area Data error " << data;
|
||||
|
||||
emit newParticipantModeReport(data);
|
||||
}
|
||||
|
||||
// VulnerabilityStateChange
|
||||
Core::FunctionReplyObject ProxyListener::demandVulnerabilityStateChange(const rti::core::SampleIdentity &cookie,
|
||||
const TrainingAreaBase::DemandVulnerabilityStateChangeRequest &req)
|
||||
{
|
||||
if (!m_mainHandler->tabFtc()->demandVulnerabilityStateChangeRequest(req, this))
|
||||
return Core::FunctionReplyObject(tr_lts("dds", "Error passing the Vulnerability state change request to the proxy"));
|
||||
|
||||
const int requestId = req.requestId();
|
||||
auto cb = [this, requestId]()
|
||||
{
|
||||
INFO_LOG(m_logger) << "VulnerabilityStateChange timeout for " << requestId;
|
||||
onDemandVulnerabilityStateChangeReply(Core::FunctionReplyObject(requestId, tr_lts("dds", "Timeout while waiting for the proxy")));
|
||||
};
|
||||
addToTrainingAreaRequests(cb, req.requestId(), cookie);
|
||||
|
||||
return Core::FunctionReplyObject();
|
||||
}
|
||||
|
||||
void ProxyListener::onDemandVulnerabilityStateChangeReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
auto cb = [this](const rti::core::SampleIdentity & cookie, const Core::FunctionReplyObject & replyObject)
|
||||
{
|
||||
m_mainHandler->fts()->modifyStateReply(cookie, replyObject);
|
||||
};
|
||||
handleReply(cb, replyObject, "VulnerabilityStateChange");
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject ProxyListener::sendModifyUasStateRequest(const rti::core::SampleIdentity &cookie,
|
||||
const TrainingAreaBase::SendModifyUasStateRequest &req)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << " -- [ProxyListener] sendModifyUasStateRequest uasId: " << req.uasId();
|
||||
if (!m_mainHandler->tabFtc()->sendModifyUasStateRequest(req, this))
|
||||
return Core::FunctionReplyObject(tr_lts("dds", "Error passing the UAS state change request to the proxy"));
|
||||
|
||||
const int requestId = req.requestId();
|
||||
auto cb = [this, requestId]()
|
||||
{
|
||||
INFO_LOG(m_logger) << "ModifyUasState timeout for " << requestId;
|
||||
onSendModifyUasStateReply(Core::FunctionReplyObject(requestId, tr_lts("dds", "Timeout while waiting for the proxy")));
|
||||
};
|
||||
addToTrainingAreaRequests(cb, req.requestId(), cookie);
|
||||
|
||||
return Core::FunctionReplyObject();
|
||||
}
|
||||
|
||||
void ProxyListener::onSendModifyUasStateReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
auto cb = [this](const rti::core::SampleIdentity & cookie, const Core::FunctionReplyObject & replyObject)
|
||||
{
|
||||
m_mainHandler->fts()->modifyUasStateReply(cookie, replyObject);
|
||||
};
|
||||
handleReply(cb, replyObject, "ModifyUasState");
|
||||
}
|
||||
// Init
|
||||
Core::FunctionReplyObject ProxyListener::demandInitRequest(const rti::core::SampleIdentity &cookie,
|
||||
const TrainingAreaBase::DemandInitRequest &req)
|
||||
{
|
||||
if (!m_mainHandler->tabFtc()->demandInitRequest(req, this))
|
||||
return Core::FunctionReplyObject(tr_lts("dds", "Error passing the INIT request to the proxy"));
|
||||
|
||||
const int requestId = req.requestId();
|
||||
auto cb = [this, requestId]()
|
||||
{
|
||||
INFO_LOG(m_logger) << "DemandInit timeout for " << requestId;
|
||||
onDemandInitReply(Core::FunctionReplyObject(requestId, tr_lts("dds", "Timeout while waiting for the proxy")));
|
||||
};
|
||||
addToTrainingAreaRequests(cb, req.requestId(), cookie);
|
||||
|
||||
return Core::FunctionReplyObject();
|
||||
}
|
||||
|
||||
void ProxyListener::onDemandInitReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
auto cb = [this](const rti::core::SampleIdentity & cookie, const Core::FunctionReplyObject & replyObject)
|
||||
{
|
||||
m_mainHandler->fts()->initParticipantReply(cookie, replyObject);
|
||||
};
|
||||
handleReply(cb, replyObject, "DemandInit");
|
||||
}
|
||||
|
||||
// SendEquipmentMessage
|
||||
Core::FunctionReplyObject ProxyListener::sendEquipmentMessage(const rti::core::SampleIdentity &cookie,
|
||||
const TrainingAreaBase::SendEquipmentMessageRequest &req)
|
||||
{
|
||||
if (!m_mainHandler->tabFtc()->sendEquipmentMessageRequest(req, this))
|
||||
return Core::FunctionReplyObject(tr_lts("dds", "Error passing SendMessage request to the proxy"));
|
||||
|
||||
const int requestId = req.requestId();
|
||||
auto cb = [this, requestId]()
|
||||
{
|
||||
INFO_LOG(m_logger) << "SendMessage timeout for " << requestId;
|
||||
onSendEquipmentMessageReply(Core::FunctionReplyObject(requestId, tr_lts("dds", "Timeout while waiting for the proxy")));
|
||||
};
|
||||
addToTrainingAreaRequests(cb, req.requestId(), cookie);
|
||||
|
||||
return Core::FunctionReplyObject();
|
||||
}
|
||||
|
||||
void ProxyListener::onSendEquipmentMessageReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
auto cb = [this](const rti::core::SampleIdentity & cookie, const Core::FunctionReplyObject & replyObject)
|
||||
{
|
||||
m_mainHandler->fts()->sendMessageReply(cookie, replyObject);
|
||||
};
|
||||
handleReply(cb, replyObject, "SendParticipantMessage");
|
||||
}
|
||||
|
||||
// SendParticipantMode
|
||||
Core::FunctionReplyObject ProxyListener::sendParticipantModeRequest(const rti::core::SampleIdentity &cookie,
|
||||
const TrainingAreaBase::SendParticipantModeRequest &req)
|
||||
{
|
||||
if (!m_mainHandler->tabFtc()->sendParticipantModeRequest(req, this))
|
||||
return Core::FunctionReplyObject(req.participantId(), tr_lts("dds", "Error passing the INIT request to the proxy"));
|
||||
|
||||
const int requestId = req.requestId();
|
||||
auto cb = [this, requestId]()
|
||||
{
|
||||
INFO_LOG(m_logger) << "SendParticipantMode timeout for " << requestId;
|
||||
onSendParticipantModeReply(Core::FunctionReplyObject(requestId, tr_lts("dds", "Timeout while waiting for the proxy")));
|
||||
};
|
||||
addToTrainingAreaRequests(cb, req.requestId(), cookie);
|
||||
|
||||
return Core::FunctionReplyObject(req.participantId());
|
||||
}
|
||||
|
||||
void ProxyListener::onSendParticipantModeReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
auto cb = [this](const rti::core::SampleIdentity & cookie, const Core::FunctionReplyObject & replyObject)
|
||||
{
|
||||
m_mainHandler->fts()->setParticipantModeReply(cookie, replyObject);
|
||||
};
|
||||
handleReply(cb, replyObject, "SendParticipantMode");
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject ProxyListener::sendSetSanitationRequest(const rti::core::SampleIdentity &cookie, const TrainingAreaBase::SendSetSanitationRequest &req)
|
||||
{
|
||||
if (!m_mainHandler->tabFtc()->sendSetSanitationRequest(req, this))
|
||||
return Core::FunctionReplyObject(req.participantId(), tr_lts("dds", "Error passing the SetSanitation request to the proxy"));
|
||||
const int requestId = req.requestId();
|
||||
auto cb = [this, requestId]()
|
||||
{
|
||||
INFO_LOG(m_logger) << "sendSetSanitationRequest timeout for " << requestId;
|
||||
onSendSetSanitationReply(Core::FunctionReplyObject(requestId, tr_lts("dds", "Timeout while waiting for the proxy")));
|
||||
};
|
||||
addToTrainingAreaRequests(cb, req.requestId(), cookie);
|
||||
return Core::FunctionReplyObject(req.participantId());
|
||||
}
|
||||
|
||||
void ProxyListener::onSendSetSanitationReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
auto cb = [this](const rti::core::SampleIdentity & cookie, const Core::FunctionReplyObject & replyObject)
|
||||
{
|
||||
m_mainHandler->fts()->setSanitationReply(cookie, replyObject);
|
||||
};
|
||||
handleReply(cb, replyObject, "SetSanitationReply");
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject ProxyListener::selectiveReammunitionRequest(const rti::core::SampleIdentity &cookie, const TrainingAreaBase::SendSelectiveReammunitionRequest &req)
|
||||
{
|
||||
if (!m_mainHandler->tabFtc()->sendSelectiveReammunitionRequest(req, this))
|
||||
return Core::FunctionReplyObject(req.participantId(), tr_lts("dds", "Error passing the SendSelectiveReammunition request to the proxy"));
|
||||
const int requestId = req.requestId();
|
||||
auto cb = [this, requestId]()
|
||||
{
|
||||
INFO_LOG(m_logger) << "selectiveReammunitionRequest timeout for " << requestId;
|
||||
onSendSelectiveReammunitionReply(Core::FunctionReplyObject(requestId, tr_lts("dds", "Timeout while waiting for the proxy")));
|
||||
};
|
||||
addToTrainingAreaRequests(cb, req.requestId(), cookie);
|
||||
return Core::FunctionReplyObject(req.participantId());
|
||||
}
|
||||
|
||||
void ProxyListener::onSendSelectiveReammunitionReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
auto cb = [this](const rti::core::SampleIdentity & cookie, const Core::FunctionReplyObject & replyObject)
|
||||
{
|
||||
m_mainHandler->fts()->selectiveReammunitionReply(cookie, replyObject);
|
||||
};
|
||||
handleReply(cb, replyObject, "SelectiveReammunitionReply");
|
||||
}
|
||||
|
||||
// OcCommand
|
||||
Core::FunctionReplyObject ProxyListener::sendOcCommandRequest(const rti::core::SampleIdentity &cookie,
|
||||
const TrainingAreaBase::SendOcCommandRequest &req)
|
||||
{
|
||||
if (!m_mainHandler->tabFtc()->sendOcCommandRequest(req, this))
|
||||
return Core::FunctionReplyObject(tr_lts("dds", "Error passing the OcCommand request to the proxy"));
|
||||
|
||||
const int requestId = req.requestId();
|
||||
auto cb = [this, requestId]()
|
||||
{
|
||||
INFO_LOG(m_logger) << "SendOcCommand timeout for " << requestId;
|
||||
onSendOcCommandReply(Core::FunctionReplyObject(requestId, tr_lts("dds", "Timeout while waiting for the proxy")));
|
||||
};
|
||||
addToTrainingAreaRequests(cb, req.requestId(), cookie);
|
||||
|
||||
return Core::FunctionReplyObject();
|
||||
}
|
||||
|
||||
void ProxyListener::onSendOcCommandReply(const Core::FunctionReplyObject &replyObject)
|
||||
{
|
||||
auto cb = [this](const rti::core::SampleIdentity & cookie, const Core::FunctionReplyObject & replyObject)
|
||||
{
|
||||
m_mainHandler->fts()->ocCommandReply(cookie, replyObject);
|
||||
};
|
||||
handleReply(cb, replyObject, "SendOcCommand");
|
||||
}
|
||||
|
||||
// Helper
|
||||
void ProxyListener::addToTrainingAreaRequests(const std::function<void()> &cb,
|
||||
int requestId,
|
||||
const rti::core::SampleIdentity &cookie)
|
||||
{
|
||||
QTimer *timeoutTimer = new QTimer(this);
|
||||
timeoutTimer->setSingleShot(true);
|
||||
timeoutTimer->setInterval(5000);
|
||||
m_trainingAreaRequests.insert(requestId, {cookie, timeoutTimer});
|
||||
connect(timeoutTimer, &QTimer::timeout, this, cb);
|
||||
}
|
||||
|
||||
void ProxyListener::handleReply(const std::function<void(const rti::core::SampleIdentity &, const Core::FunctionReplyObject &)> &cb,
|
||||
const Core::FunctionReplyObject &replyObject,
|
||||
const char *requestType)
|
||||
{
|
||||
if (replyObject.error())
|
||||
WARNING_LOG(m_logger) << requestType << ": " << replyObject();
|
||||
|
||||
auto it = m_trainingAreaRequests.find(replyObject.id());
|
||||
if (it != m_trainingAreaRequests.end())
|
||||
{
|
||||
const auto &dp = it.value();
|
||||
if (dp.timer)
|
||||
dp.timer->deleteLater();
|
||||
cb(dp.cookie, replyObject);
|
||||
|
||||
m_trainingAreaRequests.erase(it);
|
||||
}
|
||||
else
|
||||
WARNING_LOG(m_logger) << requestType << " with request id " << replyObject.id() << " was not replied to by the proxy";
|
||||
}
|
||||
|
||||
|
||||
} // namespace ParticipantHandling
|
||||
} // namespace ParticipantManagement
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
/**
|
||||
* The ProxyListener class subscribes to participant related proxy data topics and distributes
|
||||
* the collected data via Q_SIGNALS.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Hannes Baeuerle, SLSE, 2016-05-13
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QPointer>
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "logger.h"
|
||||
#include <TrainingAreaBase/tab_dtc.h>
|
||||
#include <TrainingAreaBase/tab_ftc.h>
|
||||
|
||||
#include <Buildings/bld_dtc.h>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
class MainHandler;
|
||||
|
||||
namespace ParticipantHandling
|
||||
{
|
||||
class ProxyListener final
|
||||
: public QObject
|
||||
, public TrainingAreaBase::Interface::Ftc::DemandVulnerabilityStateChangeReplyHandler
|
||||
, public TrainingAreaBase::Interface::Ftc::DemandInitReplyHandler
|
||||
, public TrainingAreaBase::Interface::Ftc::SendEquipmentMessageReplyHandler
|
||||
, public TrainingAreaBase::Interface::Ftc::SendParticipantModeReplyHandler
|
||||
, public TrainingAreaBase::Interface::Ftc::SendSetSanitationReplyHandler
|
||||
, public TrainingAreaBase::Interface::Ftc::SendSelectiveReammunitionReplyHandler
|
||||
, public TrainingAreaBase::Interface::Ftc::SendOcCommandReplyHandler
|
||||
, public TrainingAreaBase::Interface::Ftc::SendModifyUasStateReplyHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ProxyListener(MainHandler *mainHandler);
|
||||
|
||||
bool init();
|
||||
|
||||
Core::FunctionReplyObject demandVulnerabilityStateChange(const rti::core::SampleIdentity &cookie,
|
||||
const TrainingAreaBase::DemandVulnerabilityStateChangeRequest &req);
|
||||
Core::FunctionReplyObject demandInitRequest(const rti::core::SampleIdentity &cookie,
|
||||
const TrainingAreaBase::DemandInitRequest &req);
|
||||
Core::FunctionReplyObject sendEquipmentMessage(const rti::core::SampleIdentity &cookie,
|
||||
const TrainingAreaBase::SendEquipmentMessageRequest &req);
|
||||
Core::FunctionReplyObject sendParticipantModeRequest(const rti::core::SampleIdentity &cookie,
|
||||
const TrainingAreaBase::SendParticipantModeRequest &req);
|
||||
Core::FunctionReplyObject sendSetSanitationRequest(const rti::core::SampleIdentity &cookie,
|
||||
const TrainingAreaBase::SendSetSanitationRequest &req);
|
||||
Core::FunctionReplyObject selectiveReammunitionRequest(const rti::core::SampleIdentity &cookie,
|
||||
const TrainingAreaBase::SendSelectiveReammunitionRequest &req);
|
||||
Core::FunctionReplyObject sendOcCommandRequest(const rti::core::SampleIdentity &cookie,
|
||||
const TrainingAreaBase::SendOcCommandRequest &req);
|
||||
Core::FunctionReplyObject sendModifyUasStateRequest(const rti::core::SampleIdentity &cookie,
|
||||
const TrainingAreaBase::SendModifyUasStateRequest &req);
|
||||
private:
|
||||
void onDemandVulnerabilityStateChangeReply(const Core::FunctionReplyObject &replyObject) override;
|
||||
void onDemandInitReply(const Core::FunctionReplyObject &replyObject) override;
|
||||
void onSendEquipmentMessageReply(const Core::FunctionReplyObject &replyObject) override;
|
||||
void onSendParticipantModeReply(const Core::FunctionReplyObject &replyObject) override;
|
||||
void onSendSetSanitationReply(const Core::FunctionReplyObject &replyObject) override;
|
||||
void onSendSelectiveReammunitionReply(const Core::FunctionReplyObject &replyObject) override;
|
||||
void onSendOcCommandReply(const Core::FunctionReplyObject &replyObject) override;
|
||||
void onSendModifyUasStateReply(const Core::FunctionReplyObject &replyObject) override;
|
||||
|
||||
// Helper
|
||||
void addToTrainingAreaRequests(const std::function<void()> &cb,
|
||||
int requestId,
|
||||
const rti::core::SampleIdentity &cookie);
|
||||
void handleReply(const std::function<void(const rti::core::SampleIdentity &, const Core::FunctionReplyObject &)> &cb,
|
||||
const Core::FunctionReplyObject &replyObject,
|
||||
const char *requestType);
|
||||
|
||||
Q_SIGNALS:
|
||||
void newPosition(const TrainingAreaBase::EquipmentPosition &position);
|
||||
void newState(const TrainingAreaBase::EquipmentState &state);
|
||||
void newGearAssignment(const TrainingAreaBase::EquipmentGearAssignment &gearAssignment);
|
||||
void newGearChargeState(const TrainingAreaBase::EquipmentGearChargeState &chargeState);
|
||||
void newGearEvent(const TrainingAreaBase::EquipmentGearEvent &gearEvent);
|
||||
void newEquipmentOperationalState(const TrainingAreaBase::EquipmentOperationalState &operationalState);
|
||||
void newEquipmentBite(const TrainingAreaBase::EquipmentBite &bite);
|
||||
void newCtaDataError(const TrainingAreaBase::CtaDataError &error);
|
||||
void newParticipantModeReport(const TrainingAreaBase::ParticipantModeReport &modeReport);
|
||||
void newSpecialSensorData(const TrainingAreaBase::SpecialSensorData &data);
|
||||
void newFunctionalAreaEntryChanged(const TrainingAreaBase::FunctionalAreaEntry &data);
|
||||
void newLaserDesignationData(const TrainingAreaBase::LaserDesignation &data);
|
||||
void newSanitaryMaterialStockReport(const TrainingAreaBase::ParticipantSanitaryMaterialStockReport &data);
|
||||
void laserDesignationRemoved(int equipmentNumber, int gearId);
|
||||
void newParticipantSanitation(const TrainingAreaBase::ParticipantSanitation &data);
|
||||
void newOperatorAction(const TrainingAreaBase::OperatorAction &data);
|
||||
void newEquipmentEvent(const TrainingAreaBase::EquipmentEvent &data);
|
||||
void newBuildingHitLineInfo(const Buildings::BuildingHitLineInfo &data);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onProxyEquipmentPositionChanged(const TrainingAreaBase::EquipmentPosition &data, DataModification modType);
|
||||
void onProxyEquipmentGearAssignmentChanged(const TrainingAreaBase::EquipmentGearAssignment &data, DataModification modType);
|
||||
void onProxyEquipmentGearEventChanged(const TrainingAreaBase::EquipmentGearEvent &data, DataModification modType);
|
||||
void onProxyEquipmentGearChargeStateChanged(const TrainingAreaBase::EquipmentGearChargeState &data, DataModification modType);
|
||||
void onProxyParticipantSanitaryMaterialStockReportChanged(const TrainingAreaBase::ParticipantSanitaryMaterialStockReport &data, DataModification modType);
|
||||
void onProxyEquipmentStateChanged(const TrainingAreaBase::EquipmentState &data, DataModification modType);
|
||||
void onProxyEquipmentOperationalStateChanged(const TrainingAreaBase::EquipmentOperationalState &data, DataModification modType);
|
||||
void onProxyEquipmentBiteChanged(const TrainingAreaBase::EquipmentBite &data, DataModification modType);
|
||||
void onProxyCtaDataErrorChanged(const TrainingAreaBase::CtaDataError &data, DataModification modType);
|
||||
void onProxyParticipantModeReportChanged(const TrainingAreaBase::ParticipantModeReport &data, DataModification modType);
|
||||
void onSpecialSensorDataChanged(const TrainingAreaBase::SpecialSensorData &data, DataModification modType);
|
||||
void onFunctionalAreaEntryChanged(const TrainingAreaBase::FunctionalAreaEntry &data, DataModification modType);
|
||||
void onLaserDesignationChanged(const TrainingAreaBase::LaserDesignation &data, DataModification modType);
|
||||
void onProxyParticipantSanitationChanged(const TrainingAreaBase::ParticipantSanitation &data, DataModification modType);
|
||||
void onOperatorActionChanged(const TrainingAreaBase::OperatorAction &data, DataModification modType);
|
||||
void onEquipmentEventChanged(const TrainingAreaBase::EquipmentEvent &data, DataModification modType);
|
||||
void onUASStatusChanged(const TrainingAreaBase::UASStatus &data, DataModification modType);
|
||||
void onUASMissionStatusChanged(const TrainingAreaBase::UASMissionStatus &data, DataModification modType);
|
||||
void onBuildingHitLineInfoChanged(const Buildings::BuildingHitLineInfo &data, DataModification modType);
|
||||
|
||||
private: // attributes
|
||||
struct TrainingAreaRequests
|
||||
{
|
||||
rti::core::SampleIdentity cookie;
|
||||
QPointer<QTimer> timer;
|
||||
};
|
||||
QMap<int, TrainingAreaRequests> m_trainingAreaRequests;
|
||||
|
||||
std::shared_ptr<TrainingAreaBase::Interface::Dtc> m_tabDtc;
|
||||
std::shared_ptr<Buildings::Interface::Dtc> m_bldDtc;
|
||||
MainHandler *m_mainHandler;
|
||||
LOGGER_T m_logger;
|
||||
|
||||
}; // class ProxyListener
|
||||
} // namespace ParticipantHandling
|
||||
} // namespace ParticipantManagement
|
||||
+334
@@ -0,0 +1,334 @@
|
||||
/**
|
||||
* Calculate the focal point for units based on it's superiors
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2017-09-05
|
||||
*/
|
||||
|
||||
|
||||
#include "unit_position_calculator.h"
|
||||
#include "participant_handler.h"
|
||||
#include <QTimer>
|
||||
#include <LtsCoordTrans/lts_coord_trans.h>
|
||||
#include <LtsUtilsCore/qpoint3d.h>
|
||||
#include <LtsUtilsCore/outdated_position.h>
|
||||
#include <QPointF>
|
||||
#include <QDateTime>
|
||||
#include <QtConcurrent>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
namespace ParticipantHandling
|
||||
{
|
||||
UnitPositionCalculator::UnitPositionCalculator(ParticipantHandler *participantHandler, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_participantHandler(participantHandler)
|
||||
, m_bSomethingChangedSinceLastCalculation(false)
|
||||
, m_timer(new QTimer(this))
|
||||
, m_bRunning(true)
|
||||
, m_logger(getLogger("UnitPositionCalculator"))
|
||||
{
|
||||
connect(m_timer, &QTimer::timeout, this, &UnitPositionCalculator::calculate);
|
||||
m_timer->setSingleShot(true);
|
||||
|
||||
connect(&m_calculationWatcher, &QFutureWatcher<Result>::finished,
|
||||
this, &UnitPositionCalculator::onCalculationDone);
|
||||
}
|
||||
|
||||
UnitPositionCalculator::~UnitPositionCalculator()
|
||||
{
|
||||
stopCalculation();
|
||||
m_calculationWatcher.disconnect(this);
|
||||
m_calculationWatcher.cancel();
|
||||
m_calculationWatcher.waitForFinished();
|
||||
}
|
||||
|
||||
void UnitPositionCalculator::startCalculation()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Starting calculation timer";
|
||||
m_timer->start();
|
||||
m_bRunning = true;
|
||||
}
|
||||
|
||||
void UnitPositionCalculator::stopCalculation()
|
||||
{
|
||||
m_timer->stop();
|
||||
m_participantData.clear();
|
||||
m_publishedPositionData.clear();
|
||||
m_bRunning = false;
|
||||
}
|
||||
|
||||
void UnitPositionCalculator::waitForCalculationFinished()
|
||||
{
|
||||
if (m_calculationWatcher.isRunning())
|
||||
m_calculationWatcher.waitForFinished();
|
||||
}
|
||||
|
||||
|
||||
void UnitPositionCalculator::onParticipantDeleted(int participantId)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Participant " << participantId << " deleted";
|
||||
auto it = m_participantData.find(participantId);
|
||||
if (it == m_participantData.end())
|
||||
return;
|
||||
m_participantData.erase(it);
|
||||
}
|
||||
|
||||
void UnitPositionCalculator::onPositionChanged(int participantId, int64_t positionTime, const Core::GeoPosition &pos)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Position for participant " << participantId << " changed to "
|
||||
<< pos << " (" << positionTime / 1000 << "s)";
|
||||
CalculatedUnitPosition &data = getParticipant(participantId);
|
||||
if (data.sampleTimeLeader() >= positionTime)
|
||||
return;
|
||||
|
||||
data.sampleTimeCenter(positionTime);
|
||||
data.sampleTimeLeader(positionTime);
|
||||
data.positionCenter(pos);
|
||||
data.positionLeader(pos);
|
||||
m_bSomethingChangedSinceLastCalculation = true;
|
||||
}
|
||||
|
||||
void UnitPositionCalculator::onSuperiorChanged(int participantId, int superiorId)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Superior for participant " << participantId << " changed to " << superiorId;
|
||||
CalculatedUnitPosition &data = getParticipant(participantId);
|
||||
data.superiorId = superiorId;
|
||||
m_bSomethingChangedSinceLastCalculation = true;
|
||||
}
|
||||
|
||||
void UnitPositionCalculator::onInferiorChanged(int participantId, const std::vector<int> &inferiorIds)
|
||||
{
|
||||
if (m_logger.isDebugEnabled())
|
||||
{
|
||||
QStringList slIds;
|
||||
slIds.reserve(inferiorIds.size());
|
||||
for (int id : inferiorIds)
|
||||
slIds += QString::number(id);
|
||||
DEBUG_LOG(m_logger) << "Inferior for participant " << participantId << " changed, size: " << slIds.join(QLatin1Char(' '));
|
||||
}
|
||||
|
||||
CalculatedUnitPosition &data = getParticipant(participantId);
|
||||
data.inferiorIds = inferiorIds;
|
||||
m_bSomethingChangedSinceLastCalculation = true;
|
||||
}
|
||||
|
||||
UnitPositionCalculator::CalculatedUnitPosition &UnitPositionCalculator::getParticipant(int participantId)
|
||||
{
|
||||
auto it = m_participantData.find(participantId);
|
||||
if (it == m_participantData.end())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "No information for participant " << participantId << " - creating dummy data";
|
||||
|
||||
CalculatedUnitPosition data;
|
||||
data.participantId(participantId);
|
||||
static const Core::GeoPosition s_invalidPos(std::nan(""), std::nan(""), std::nan(""));
|
||||
data.positionCenter(s_invalidPos);
|
||||
data.positionLeader(s_invalidPos);
|
||||
it = m_participantData.insert({participantId, std::move(data)}).first;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
void UnitPositionCalculator::calculate()
|
||||
{
|
||||
static bool s_bDebugOnce = false;
|
||||
// theoretisches Problem: wenn sich keiner bewegt werden die Unit-Symbole nicht aktualisiert wenn
|
||||
// dann Teilnehmer out-of-date gehen
|
||||
if (!m_bSomethingChangedSinceLastCalculation)
|
||||
{
|
||||
if (!s_bDebugOnce)
|
||||
DEBUG_LOG(m_logger) << "Nothing changed - no calculation needed -> waiting for new data";
|
||||
s_bDebugOnce = true;
|
||||
m_timer->start(1000);
|
||||
return;
|
||||
}
|
||||
|
||||
s_bDebugOnce = false;
|
||||
m_bSomethingChangedSinceLastCalculation = false;
|
||||
// copy data (before thread starts), can be done better with c++14 (lambda captures)
|
||||
std::unordered_map<int, CalculatedUnitPosition> *participantData(new std::unordered_map<int, CalculatedUnitPosition>(m_participantData));
|
||||
const qint64 currentTime = m_participantHandler->currentTimeMSec();
|
||||
auto cb = [this, participantData, currentTime]() -> Result
|
||||
{
|
||||
const auto ret = doCalculation(*participantData, currentTime, m_logger);
|
||||
delete participantData;
|
||||
return ret;
|
||||
};
|
||||
m_calculationWatcher.setFuture(QtConcurrent::run(cb));
|
||||
}
|
||||
|
||||
UnitPositionCalculator::Result UnitPositionCalculator::doCalculation(std::unordered_map<int, CalculatedUnitPosition> &participantData,
|
||||
qint64 currentTime,
|
||||
NGL::INGLLogger &logger)
|
||||
{
|
||||
DEBUG_LOG(logger) << "Starting calculation loop";
|
||||
|
||||
Result result;
|
||||
result.reserve(participantData.size());
|
||||
|
||||
// search all top-level units
|
||||
std::vector<int> topLevelIds;
|
||||
topLevelIds.reserve(10);
|
||||
for (const auto &data : participantData)
|
||||
{
|
||||
const int superiorId = data.second.superiorId;
|
||||
const int participantId = data.second.participantId();
|
||||
DEBUG_LOG(logger) << "Participant " << participantId << " has superior " << superiorId;
|
||||
if (superiorId == 0 || participantData.find(superiorId) == participantData.end())
|
||||
{
|
||||
DEBUG_LOG(logger) << "Participant " << participantId << " is a toplevel participant";
|
||||
topLevelIds.push_back(data.second.participantId());
|
||||
}
|
||||
}
|
||||
// TODO: check for correct (non-cyclic) hierarchy?
|
||||
|
||||
for (const int topLevelId : topLevelIds)
|
||||
{
|
||||
DEBUG_LOG(logger) << "Calculating positions for toplevel participant " << topLevelId;
|
||||
calculatePosition(topLevelId, participantData, currentTime, 1, logger, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void UnitPositionCalculator::calculatePosition(int participantId,
|
||||
std::unordered_map<int, CalculatedUnitPosition> &participantData,
|
||||
qint64 currentTime,
|
||||
int level,
|
||||
NGL::INGLLogger &logger,
|
||||
Result &result)
|
||||
{
|
||||
static const Core::GeoPosition s_invalidPos(std::nan(""), std::nan(""), std::nan(""));
|
||||
|
||||
const QByteArray dbgLvlSpaces(level, ' ');
|
||||
auto it = participantData.find(participantId);
|
||||
if (it == participantData.end())
|
||||
{
|
||||
WARNING_LOG(logger) << "Participant " << participantId << " not found for unit position calculation!";
|
||||
return;
|
||||
}
|
||||
CalculatedUnitPosition &data = it->second;
|
||||
// found leaf -> return
|
||||
if (data.inferiorIds.size() == 0)
|
||||
{
|
||||
DEBUG_LOG(logger) << dbgLvlSpaces << "Participant " << participantId
|
||||
<< " is a leaf: " << data.positionCenter()
|
||||
<< " (" << data.sampleTimeCenter() / 1000 << "s)";
|
||||
return;
|
||||
}
|
||||
|
||||
data.positionCenter(s_invalidPos);
|
||||
data.positionLeader(s_invalidPos);
|
||||
|
||||
// calculate position for inferiors
|
||||
DEBUG_LOG(logger) << dbgLvlSpaces << "Participant " << participantId << ": Start calculating child positions";
|
||||
for (const int inferiorId : data.inferiorIds)
|
||||
{
|
||||
DEBUG_LOG(logger) << dbgLvlSpaces << "Participant " << participantId << ": calculating child position for " << inferiorId;
|
||||
calculatePosition(inferiorId, participantData, currentTime, level + 1, logger, result);
|
||||
}
|
||||
DEBUG_LOG(logger) << dbgLvlSpaces << "Participant " << participantId << ": Finished calculating child positions";
|
||||
|
||||
// now calc own position
|
||||
int utmZone = -1;
|
||||
int childCount = 0;
|
||||
LtsUtils::QPoint3D pos;
|
||||
qint64 childPositionTime = 0;
|
||||
bool bFirst = true;
|
||||
for (const int inferiorId : data.inferiorIds)
|
||||
{
|
||||
auto itChild = participantData.find(inferiorId);
|
||||
// Warning was already given in loop before
|
||||
if (itChild == participantData.end())
|
||||
{
|
||||
WARNING_LOG(logger) << dbgLvlSpaces << "Child " << inferiorId << ": could not find data";
|
||||
continue;
|
||||
}
|
||||
|
||||
const CalculatedUnitPosition &child = itChild->second;
|
||||
// older than 10 minutes -> ignore
|
||||
if (LtsUtils::isPositionTimeOutdated(currentTime, child.sampleTimeCenter()))
|
||||
{
|
||||
DEBUG_LOG(logger) << dbgLvlSpaces << "Child " << inferiorId << ": position out-of-date - ignoring";
|
||||
continue;
|
||||
}
|
||||
|
||||
// invalid position -> ignore
|
||||
if (std::isnan(child.positionCenter().lon()) ||
|
||||
std::isnan(child.positionCenter().lat()))
|
||||
{
|
||||
DEBUG_LOG(logger) << dbgLvlSpaces << "Child " << inferiorId << ": has invalid position - ignoring";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (bFirst)
|
||||
{
|
||||
bFirst = false;
|
||||
data.positionLeader(child.positionLeader());
|
||||
data.sampleTimeLeader(child.sampleTimeLeader());
|
||||
}
|
||||
|
||||
const auto utm = LtsCoordTrans::UtmCoordinate::fromGeographic(child.positionCenter().lon(),
|
||||
child.positionCenter().lat(),
|
||||
utmZone);
|
||||
if (utmZone == -1)
|
||||
utmZone = utm.zone;
|
||||
|
||||
pos += LtsUtils::QPoint3D(utm.x, utm.y, child.positionCenter().z());
|
||||
if (child.sampleTimeCenter() > childPositionTime)
|
||||
childPositionTime = child.sampleTimeCenter();
|
||||
|
||||
++childCount;
|
||||
}
|
||||
|
||||
data.sampleTimeCenter(childPositionTime);
|
||||
if (childCount > 0)
|
||||
{
|
||||
pos /= childCount;
|
||||
const LtsCoordTrans::UtmCoordinate utm(utmZone, pos.x(), pos.y(),true);
|
||||
const QPointF lonLat = utm.geographic();
|
||||
data.positionCenter(Core::GeoPosition(lonLat.x(), lonLat.y(), pos.z()));
|
||||
}
|
||||
DEBUG_LOG(logger) << dbgLvlSpaces
|
||||
<< "Participant " << participantId
|
||||
<< ": Mean position: " << data.positionCenter()
|
||||
<< " #relavant children: " << childCount
|
||||
<< " (" << data.sampleTimeCenter() / 1000 << "s)";
|
||||
|
||||
result.push_back(std::move(data));
|
||||
}
|
||||
|
||||
void UnitPositionCalculator::onCalculationDone()
|
||||
{
|
||||
const Result &calculatedPositions = m_calculationWatcher.future().result();
|
||||
|
||||
auto dts = m_participantHandler->dts();
|
||||
for (const auto &pos : calculatedPositions)
|
||||
{
|
||||
auto it = m_publishedPositionData.find(pos.participantId());
|
||||
if (it != m_publishedPositionData.end())
|
||||
{
|
||||
ParticipantManagement::UnitPosition &up = it->second;
|
||||
DEBUG_LOG(m_logger) << "old: " << up << ", new: " << pos << ", equal: " << (up == pos);
|
||||
if (up == pos)
|
||||
continue;
|
||||
// nan == nan is always false, have to check it on our own
|
||||
if (std::isnan(up.positionCenter().lat()) && std::isnan(pos.positionCenter().lat()))
|
||||
continue;
|
||||
up = pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_publishedPositionData.insert(std::make_pair(pos.participantId(), pos));
|
||||
}
|
||||
dts->publish(pos);
|
||||
}
|
||||
|
||||
m_timer->start(1000);
|
||||
}
|
||||
|
||||
|
||||
} // namespace ParticipantHandling
|
||||
} // namespace ParticipantManagement
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Calculate the focal point for units based on it's superiors
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Christian Ehrlicher, SLSE, 2017-09-05
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QFutureWatcher>
|
||||
#include <Core/core.hpp>
|
||||
#include <unordered_map>
|
||||
#include "participant_handler.h"
|
||||
|
||||
class QTimer;
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
|
||||
namespace ParticipantHandling
|
||||
{
|
||||
class UnitPositionCalculator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UnitPositionCalculator(ParticipantHandler *participantHandler, QObject *parent = nullptr);
|
||||
~UnitPositionCalculator();
|
||||
|
||||
void startCalculation();
|
||||
void stopCalculation(); // also clear all participants
|
||||
void waitForCalculationFinished();
|
||||
|
||||
void onParticipantDeleted(int participantId);
|
||||
void onPositionChanged(int participantId, int64_t positionTime, const Core::GeoPosition &pos);
|
||||
void onSuperiorChanged(int participantId, int superiorId);
|
||||
void onInferiorChanged(int participantId, const std::vector<int> &inferiorIds);
|
||||
|
||||
private:
|
||||
struct CalculatedUnitPosition : public ParticipantManagement::UnitPosition
|
||||
{
|
||||
int superiorId = 0;
|
||||
std::vector<int> inferiorIds;
|
||||
};
|
||||
|
||||
private:
|
||||
CalculatedUnitPosition &getParticipant(int participantId);
|
||||
void calculate();
|
||||
// no const ref - must be a copy since this is running in a different thread
|
||||
using Result = std::vector<CalculatedUnitPosition>;
|
||||
static Result doCalculation(std::unordered_map<int, CalculatedUnitPosition> &participantData,
|
||||
qint64 currentTime,
|
||||
NGL::INGLLogger &logger);
|
||||
static void calculatePosition(int participantId,
|
||||
std::unordered_map<int, CalculatedUnitPosition> &participantData,
|
||||
qint64 currentTime,
|
||||
int level,
|
||||
NGL::INGLLogger &logger,
|
||||
Result &result);
|
||||
|
||||
private Q_SLOTS:
|
||||
void onCalculationDone();
|
||||
|
||||
private:
|
||||
std::unordered_map<int, CalculatedUnitPosition> m_participantData;
|
||||
std::unordered_map<int, CalculatedUnitPosition> m_publishedPositionData;
|
||||
|
||||
QFutureWatcher<Result> m_calculationWatcher;
|
||||
|
||||
ParticipantHandler *m_participantHandler;
|
||||
bool m_bSomethingChangedSinceLastCalculation;
|
||||
QTimer *m_timer;
|
||||
bool m_bRunning;
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
|
||||
} // namespace ParticipantHandling
|
||||
} // namespace ParticipantManagement
|
||||
Reference in new issue
Block a user