323 lines
9.1 KiB
C++
Executable File
323 lines
9.1 KiB
C++
Executable File
/**
|
|
* IsmHandler for WirelessLocationSystem
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Christian Ehrlicher, SLSE, 2016-04-14
|
|
*/
|
|
|
|
#include "ppm_handler.h"
|
|
|
|
#include <QJsonDocument>
|
|
|
|
|
|
namespace ApHlaJson
|
|
{
|
|
|
|
/*!
|
|
\brief
|
|
\author Niklas Schmidt
|
|
\details Recognize changes from PPM and creates new Telegram for these changes, than send to Hla
|
|
Excon -> HLA
|
|
\param parent
|
|
*/
|
|
PpmHandler::PpmHandler(QObject *parent)
|
|
: QObject(parent)
|
|
, m_logger(getLogger("PpmHandler"))
|
|
{}
|
|
|
|
bool PpmHandler::init(MainDispatcher* mainDispatcher)
|
|
{
|
|
if (m_dtcPpm)
|
|
return true;
|
|
|
|
m_dtcPpm = ParticipantManagement::Interface::Dtc::create(mainDispatcher->ddsHandler()->ddsConnector());
|
|
|
|
if (!m_dtcPpm->enableParticipant() || !m_dtcPpm->enableDynamicParticipantData() || !m_dtcPpm->enableParticipantPosition())
|
|
{
|
|
ERROR_LOG(m_logger) << "Can not read data from Ppm";
|
|
return false;
|
|
}
|
|
|
|
m_dtcPpm->waitForHistoricalDataParticipant(1000);
|
|
m_dtcPpm->waitForHistoricalDataDynamicParticipantData(1000);
|
|
m_dtcPpm->waitForHistoricalDataParticipantPosition(1000);
|
|
|
|
connect(m_dtcPpm.get(), &ParticipantManagement::Interface::Dtc::participantChanged,
|
|
this, &PpmHandler::onParticipantChanged);
|
|
|
|
connect(m_dtcPpm.get(), &ParticipantManagement::Interface::Dtc::participantPositionChanged,
|
|
this, &PpmHandler::onParticipantPositionChanged);
|
|
|
|
connect(m_dtcPpm.get(), &ParticipantManagement::Interface::Dtc::dynamicParticipantDataChanged,
|
|
this, &PpmHandler::onDynamicParticipantDataChanged);
|
|
|
|
return true;
|
|
}
|
|
|
|
QString PpmHandler::fromDisInt(qint64 value)
|
|
{
|
|
QString s;
|
|
|
|
s.prepend(QString::number(value % 1000));
|
|
s.prepend(QLatin1Literal("."));
|
|
value /= 1000;
|
|
s.prepend(QString::number(value % 1000));
|
|
s.prepend(QLatin1Literal("."));
|
|
value /= 1000;
|
|
s.prepend(QString::number(value % 1000));
|
|
s.prepend(QLatin1Literal("."));
|
|
value /= 1000;
|
|
s.prepend(QString::number(value % 1000));
|
|
s.prepend(QLatin1Literal("."));
|
|
value /= 1000;
|
|
s.prepend(QString::number(value % 1000));
|
|
s.prepend(QLatin1Literal("."));
|
|
value /= 1000;
|
|
s.prepend(QString::number(value % 1000));
|
|
s.prepend(QLatin1Literal("."));
|
|
value /= 1000;
|
|
s.prepend(QString::number(value % 1000));
|
|
return s;
|
|
}
|
|
|
|
void PpmHandler::getParticipants()
|
|
{
|
|
|
|
if(!m_dtcPpm)
|
|
return;
|
|
|
|
for (const auto participant : m_dtcPpm->participants())
|
|
{
|
|
onParticipantChanged(participant, DataModification::eAdded);
|
|
}
|
|
}
|
|
|
|
bool PpmHandler::isEqNumberInExercise(int equipmentNumber) const
|
|
{
|
|
bool result = m_dtcPpm->participantIdByEquipmentNumber(equipmentNumber) > 0;
|
|
|
|
return result;
|
|
//return m_participantIdsByEqNo.contains(equipmentNumber);
|
|
}
|
|
|
|
/**
|
|
* @brief AddParticipant Telegram
|
|
*
|
|
*
|
|
* @details Example Telegram:
|
|
* {
|
|
* typeId:8000,
|
|
* type: ApacheHlaAddParticipant,
|
|
* data:
|
|
* {
|
|
* header: {
|
|
* equipmentNumber: 42,
|
|
* timeStamp: MsecsSinceEpoch
|
|
* },
|
|
* status: 11,
|
|
* forceIdentifier: 42,
|
|
* ets: "2.0.0.0.0.0.1",
|
|
* GeoPosition: {
|
|
* lon: 15.145274,
|
|
* lat: 24.5554556,
|
|
* z: 55.000124
|
|
* }
|
|
* }
|
|
* }
|
|
*/
|
|
|
|
|
|
/**
|
|
* @brief RemoveParticipant Telegram
|
|
*
|
|
*
|
|
* @details Example Telegram:
|
|
* {
|
|
* typeId:8001,
|
|
* type: ApacheHlaRemoveParticipant,
|
|
* data:
|
|
* {
|
|
* header: {
|
|
* equipmentNumber: 42,
|
|
* timeStamp: MsecsSinceEpoch
|
|
* }
|
|
* }
|
|
* }
|
|
*/
|
|
|
|
void PpmHandler::onParticipantChanged(const ParticipantManagement::Participant &participant, DataModification modType)
|
|
{
|
|
|
|
//NOTE:Hier kommt er hin!
|
|
|
|
if(!participant.equipmentNumber().is_set())
|
|
{
|
|
for(auto it = m_participantIdsByEqNo.begin(); it != m_participantIdsByEqNo.end(); ++it)
|
|
if (it.value() == participant.id())
|
|
{
|
|
m_participantIdsByEqNo.remove(it.key());
|
|
break;
|
|
}
|
|
return;
|
|
}
|
|
if (participant.externalId() > 0)
|
|
return;
|
|
|
|
QJsonObject headerJson;
|
|
headerJson[QStringLiteral("equipmentNumber")] = participant.equipmentNumber().get();
|
|
headerJson[QStringLiteral("timeStamp")] = QDateTime::currentMSecsSinceEpoch();
|
|
|
|
if (modType == DataModification::eRemoved)
|
|
{
|
|
m_participantIdsByEqNo.remove(participant.equipmentNumber().get());
|
|
QJsonObject telegram;
|
|
QJsonObject data;
|
|
data[QStringLiteral("header")] = headerJson;
|
|
|
|
telegram[QStringLiteral("data")] = data;
|
|
telegram[QStringLiteral("type")] = QStringLiteral("ApacheHlaRemoveParticipant");
|
|
telegram[QStringLiteral("typeId")] = 8001;
|
|
emit participantChanged(telegram);
|
|
|
|
return;
|
|
}
|
|
if (m_participantIdsByEqNo.contains(participant.equipmentNumber().get()))
|
|
{
|
|
if (m_participantIdsByEqNo[participant.equipmentNumber().get()] != participant.id())
|
|
{
|
|
for(auto it = m_participantIdsByEqNo.begin(); it != m_participantIdsByEqNo.end(); ++it)
|
|
if (it.value() == participant.id())
|
|
{
|
|
m_participantIdsByEqNo.remove(it.key());
|
|
break;
|
|
}
|
|
m_participantIdsByEqNo[participant.equipmentNumber().get()] = participant.id();
|
|
}
|
|
}
|
|
else
|
|
m_participantIdsByEqNo[participant.equipmentNumber().get()] = participant.id();
|
|
|
|
|
|
ParticipantManagement::DynamicParticipantData dynamicData = m_dtcPpm->dynamicParticipantData(participant.id());
|
|
ParticipantManagement::Party party = m_dtcPpm->party(participant.partyId());
|
|
ParticipantManagement::Type type = m_dtcPpm->type(participant.typeId());
|
|
ParticipantManagement::ParticipantPosition partPos = m_dtcPpm->participantPosition(participant.id());
|
|
|
|
QJsonObject telegram;
|
|
|
|
QJsonObject geoPositionObj;
|
|
geoPositionObj[QStringLiteral("lon")] = partPos.pos().lon();
|
|
geoPositionObj[QStringLiteral("lat")] = partPos.pos().lat();
|
|
geoPositionObj[QStringLiteral("z")] = partPos.pos().z();
|
|
|
|
QJsonObject data;
|
|
data[QStringLiteral("header")] = headerJson;
|
|
|
|
data[QStringLiteral("status")] = static_cast<int>(m_dtcPpm->youngestStateInformation(dynamicData.stateHistory()).vulnerabilityState().underlying());
|
|
data[QStringLiteral("forceIdentifier")] = static_cast<int>(party.hlaForceIdentifier().underlying());
|
|
|
|
data[QStringLiteral("ets")] = type.disEntities().empty() ? QStringLiteral("2.0.0.0.0.0.1") : fromDisInt(type.disEntities().front());
|
|
data[QStringLiteral("geoPosition")] = geoPositionObj;
|
|
telegram[QStringLiteral("data")] = data;
|
|
telegram[QStringLiteral("type")] = QStringLiteral("ApacheHlaAddParticipant");
|
|
telegram[QStringLiteral("typeId")] = 8000;
|
|
emit participantChanged(telegram);
|
|
}
|
|
|
|
/**
|
|
* @brief Change Position Telegram
|
|
*
|
|
*
|
|
* @details Example Telegram:
|
|
* {
|
|
* typeId:8002,
|
|
* type: ApacheHlaPositionChanged,
|
|
* data:
|
|
* {
|
|
* header: {
|
|
* equipmentNumber: 42,
|
|
* timeStamp: MsecsSinceEpoch
|
|
* },
|
|
* lon: 15.275884,
|
|
* lat: 37.854856,
|
|
* z: 42.255278
|
|
* }
|
|
* }
|
|
*/
|
|
void PpmHandler::onParticipantPositionChanged(const ParticipantManagement::ParticipantPosition &position, DataModification modType)
|
|
{
|
|
if (modType == DataModification::eRemoved)
|
|
return;
|
|
|
|
ParticipantManagement::Participant part = m_dtcPpm->participant(position.participantId());
|
|
|
|
if (part.externalId() > 0 || !part.equipmentNumber().is_set())
|
|
return;
|
|
|
|
QJsonObject telegram;
|
|
telegram[QStringLiteral("typeId")] = 8002;
|
|
telegram[QStringLiteral("type")] = QStringLiteral("ApacheHlaPositionChanged");
|
|
|
|
QJsonObject headerJson;
|
|
headerJson[QStringLiteral("equipmentNumber")] = part.equipmentNumber().get();
|
|
headerJson[QStringLiteral("timeStamp")] = QDateTime::currentMSecsSinceEpoch();
|
|
|
|
QJsonObject data;
|
|
data[QStringLiteral("header")] = headerJson;
|
|
data[QStringLiteral("lon")] = position.pos().lon();
|
|
data[QStringLiteral("lat")] = position.pos().lat();
|
|
data[QStringLiteral("z")] = position.pos().z();
|
|
|
|
telegram[QStringLiteral("data")] = data;
|
|
emit participantChanged(telegram);
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief Change VulnerabilityState Telegram
|
|
*
|
|
*
|
|
* @details Example Telegram:
|
|
* {
|
|
* typeId:8003,
|
|
* type: ApacheHlaVulnerabilityStateChanged,
|
|
* data:
|
|
* {
|
|
* header: {
|
|
* equipmentNumber: 42,
|
|
* timeStamp: MsecsSinceEpoch
|
|
* },
|
|
* status: 11
|
|
* }
|
|
* }
|
|
*/
|
|
void PpmHandler::onDynamicParticipantDataChanged(const ParticipantManagement::DynamicParticipantData &dynPartData, DataModification modType)
|
|
{
|
|
if (modType == DataModification::eRemoved)
|
|
return;
|
|
|
|
ParticipantManagement::Participant part = m_dtcPpm->participant(dynPartData.participantId());
|
|
|
|
if (part.externalId() > 0 || !part.equipmentNumber().is_set())
|
|
return;
|
|
|
|
QJsonObject telegram;
|
|
telegram[QStringLiteral("typeId")] = 8003;
|
|
telegram[QStringLiteral("type")] = QStringLiteral("ApacheHlaVulnerabilityStateChanged");
|
|
|
|
QJsonObject headerJson;
|
|
headerJson[QStringLiteral("equipmentNumber")] = part.equipmentNumber().get();
|
|
headerJson[QStringLiteral("timeStamp")] = QDateTime::currentMSecsSinceEpoch();
|
|
|
|
QJsonObject data;
|
|
data[QStringLiteral("header")] = headerJson;
|
|
|
|
data[QStringLiteral("status")] = static_cast<int>(m_dtcPpm->youngestStateInformation(dynPartData.stateHistory()).vulnerabilityState().underlying());
|
|
telegram[QStringLiteral("data")] = data;
|
|
|
|
emit participantChanged(telegram);
|
|
}
|
|
|
|
} // namespace ApHlaJson
|