409 lines
11 KiB
C++
Executable File
409 lines
11 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* JsonHandlerTx for AdlerJson Plugin
|
|
* $Id: hla_handler_tx.cpp 62899 2024-05-29 11:08:50Z ewert_j $
|
|
* $HeadURL: svn://slssvn/TDS/branches/product/features/ufom/Lts/Proxies/TrainingAreaBase/Plugins/AdlerJson/hla_handler_tx.cpp $
|
|
* $Author: ewert_j $
|
|
* Created by Julius Ewert, ESIM, 2024-03-20
|
|
*/
|
|
|
|
#include "json_handler_tx.h"
|
|
#include "json_dispatcher.h"
|
|
#include "ppm_handler.h"
|
|
#include "pdm_handler.h"
|
|
#include "aes_handler.h"
|
|
#include <ProjectDataManagement/pdm_enums.hpp>
|
|
#include <QJsonDocument>
|
|
#include <QWebSocket>
|
|
namespace AdlerJson
|
|
{
|
|
class PpmHandler;
|
|
JsonHandlerTx::JsonHandlerTx(TrainingAreaBase::Plugin::DataProvider *pdp, MainDispatcher *mainDispatcher)
|
|
: m_pdp(pdp)
|
|
, m_mainDispatcher(mainDispatcher)
|
|
, m_webSocket(nullptr)
|
|
, m_bWebsocketConnectedToExternalSystem(false)
|
|
, m_logger(getLogger("JsonHandlerTx"))
|
|
{}
|
|
|
|
void JsonHandlerTx::onWebSocketConnected(QWebSocket *webSocket)
|
|
{
|
|
m_webSocket = webSocket;
|
|
if (!m_webSocket)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
void JsonHandlerTx::onWebSocketDisconnected()
|
|
{
|
|
m_mainDispatcher->ppmHandler()->disconnect(this);
|
|
m_mainDispatcher->pdmHandler()->disconnect(this);
|
|
m_webSocket = nullptr;
|
|
}
|
|
|
|
void JsonHandlerTx::onWebsocketConnectedToExternalSystem(bool bConnected)
|
|
{
|
|
m_bWebsocketConnectedToExternalSystem = bConnected;
|
|
|
|
INFO_LOG(m_logger) << "Connected to SAA";
|
|
const auto tele2 = m_pdp->exerciseEnvironmentData();
|
|
sendToTx(&tele2, true);
|
|
connect(m_mainDispatcher->aesHandler().get(), &AesHandler::explosionSingleChanged, this, &JsonHandlerTx::onGenericTelegram, Qt::UniqueConnection);
|
|
connect(m_mainDispatcher->ppmHandler().get(), &PpmHandler::participantUnmount, this, &JsonHandlerTx::onGenericTelegram, Qt::UniqueConnection);
|
|
connect(m_mainDispatcher->ppmHandler().get(), &PpmHandler::participantMount, this, &JsonHandlerTx::onGenericTelegram, Qt::UniqueConnection);
|
|
connect(m_mainDispatcher->ppmHandler().get(), &PpmHandler::participantChanged, this, &JsonHandlerTx::onGenericTelegram, Qt::UniqueConnection);
|
|
connect(m_mainDispatcher->pdmHandler().get(), &PdmHandler::sendChargeTypes, this, &JsonHandlerTx::onGenericTelegram, Qt::UniqueConnection);
|
|
m_mainDispatcher->pdmHandler()->getChargeTypes();
|
|
m_mainDispatcher->ppmHandler()->getParticipants();
|
|
}
|
|
|
|
TrainingAreaBase::SendToTab::HandleState JsonHandlerTx::canHandleTelegram(int equipmentNumber, int telegramId) const
|
|
{
|
|
Q_UNUSED(equipmentNumber);
|
|
using namespace TrainingAreaBase::TetraIcd;
|
|
// This will sy NO when there is no websocket connection
|
|
//XKCD
|
|
/*
|
|
if (!m_webSocket || !m_bWebsocketConnectedToExternalSystem)
|
|
return HandleState::No;
|
|
*/
|
|
if (telegramId == Constraints<CreateSingleExplosion>::id())
|
|
return HandleState::YesShare;
|
|
|
|
//XKCD fill m_dataCommunicationPossible
|
|
//if (equipmentNumber <= 0 || !m_dataCommunicationPossible.value(equipmentNumber, false))
|
|
// return HandleState::No;
|
|
|
|
if (telegramId == Constraints<ExConfirmationReport>::id() ||
|
|
telegramId == Constraints<ExFireReadiness>::id() ||
|
|
telegramId == Constraints<ExFiredReport>::id())
|
|
return HandleState::YesConsume;
|
|
return HandleState::No;
|
|
}
|
|
|
|
void JsonHandlerTx::resetSendCounter()
|
|
{
|
|
// nothing to do
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::Init &data)
|
|
{
|
|
return sendToTx(&data);
|
|
}
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::DemandVulnerabilityStateChange &data)
|
|
{
|
|
return sendToTx(&data);
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::CesHitInformation &data)
|
|
{
|
|
return sendToTx(&data);
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::ExerciseEnvironmentData &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::Acknowledge &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::DemandBite &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::SetVulnerabilityModel &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::DemandEquipmentConfigurationReport &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::LanguageSelection &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::EquipmentMessage &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::EquipmentMessageOC &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::CreateSingleExplosion &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
//m_mainDispatcher->aesHandler()->handleCreateSingleExplosion(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::CreateAreaExplosion &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::CreateMineArea &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::MineAreaSingleMineState &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::CreateNContamination &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::CreateCContamination &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::DeactivateEffectSimulation &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::ModifyAreaEffectSimulationName &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::PauseEffectSimulation &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::ResumeEffectSimulation &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::MineTriggered &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::DusMineReactivation &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::CreateFunctionalArea &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::CreateDusSingleMine &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::ExerciseStateData &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::OpaquePayloadDataOut &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::ParticipantSwVersionsRequest &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::TechnicalArea &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false; // only for Tetra - really?
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::CesHitRequest &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::ParticipantMode &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::DemandParticipantMode &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::ParticipantConfiguration &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::DemandParticipantConfiguration &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::ExerciseEquipmentAssignmentComplete &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::Sanitation &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::SelectiveReammunition &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::SetDevicePowerRequest &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::OcCommand &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::UAVPerformMission &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::UAVChangeState &data)
|
|
{
|
|
Q_UNUSED(data);
|
|
return false;
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::ExFireReadiness &data)
|
|
{
|
|
FATAL_LOG(m_logger) << "!!!!!!!!!!!!!!!!!!!!!!!!!!!! Received ExFireReadiness for " << data.partyId << " ref: " << data.reference;
|
|
ExFeuerbereit ex;
|
|
ex.feuerkampfdaten.feuerkampfReferenz = data.reference;
|
|
return m_mainDispatcher->jsonDispatcher()->sendExFeuerbereit(ex, data.partyId);
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::ExFiredReport &data)
|
|
{
|
|
FATAL_LOG(m_logger) << "!!!!!!!!!!!!!!!!!!!!!!!!!!!! Received ExFiredReport for " << data.partyId << " ref: " << data.reference << " unit/identifier "<< data.unitIdentifier << "/" << data.identifier;
|
|
ExAbgefeuert exa;
|
|
exa.feuerkampfdaten.feuerkampfReferenz = data.reference;
|
|
exa.feuerkampfdaten.kenner = waffensystemkennerMap.value(data.identifier); //data.identifier // new ENUM!;
|
|
exa.feuerkampfdaten.verein = data.unitIdentifier;
|
|
return m_mainDispatcher->jsonDispatcher()->sendExAbgefeuert(exa, data.partyId);
|
|
}
|
|
|
|
bool JsonHandlerTx::txData(const TrainingAreaBase::TetraIcd::ExConfirmationReport &data)
|
|
{
|
|
FATAL_LOG(m_logger) << "!!!!!!!!!!!!!!!!!!!!!!!!!!!! Received ExConfirmationReport for " << data.partyId << " ref: " << data.reference << " unit/identifier "<< data.unitIdentifier << "/" << data.identifier;
|
|
ExVollzugsmeldung exv;
|
|
exv.feuerkampfdaten.feuerkampfReferenz = data.reference;
|
|
exv.feuerkampfdaten.kenner = waffensystemkennerMap.value(data.identifier);
|
|
exv.feuerkampfdaten.verein = data.unitIdentifier;
|
|
return m_mainDispatcher->jsonDispatcher()->sendExVollzugsmeldung(exv, data.partyId);
|
|
}
|
|
|
|
void JsonHandlerTx::onParticipantConnectionState(const int equipmentNumber, const bool dataCommunicationPossible)
|
|
{
|
|
INFO_LOG(m_logger) << "onParticipantConnectionState - " << equipmentNumber
|
|
<< ", communication possible: " << dataCommunicationPossible;
|
|
if (equipmentNumber == -1)
|
|
m_dataCommunicationPossible.clear();
|
|
m_dataCommunicationPossible[equipmentNumber] = dataCommunicationPossible;
|
|
}
|
|
|
|
void JsonHandlerTx::onGenericTelegram(const QJsonObject &telegram)
|
|
{
|
|
if (!m_webSocket || !m_bWebsocketConnectedToExternalSystem)
|
|
return;
|
|
const QByteArray ba = QJsonDocument(telegram).toJson(QJsonDocument::Compact);
|
|
DEBUG_LOG(m_logger) << "Sending tele: " << ba;
|
|
m_webSocket->sendTextMessage(QString::fromUtf8(ba));
|
|
}
|
|
|
|
void JsonHandlerTx::onGenericTelegram1(const int wsId, const QJsonObject &telegram)
|
|
{
|
|
m_wsInterface->sendTelegram(wsId,&telegram);
|
|
}
|
|
|
|
bool JsonHandlerTx::sendToTx(const TrainingAreaBase::TetraIcd::TrainingAreaTelegram *data, const bool bForce)
|
|
{
|
|
Q_UNUSED(bForce);
|
|
QJsonObject telegram;
|
|
telegram[QStringLiteral("data")] = data->toJson();
|
|
telegram[QStringLiteral("type")] = data->type();
|
|
telegram[QStringLiteral("typeId")] = data->id();
|
|
ERROR_LOG(m_logger) << QJsonDocument(telegram).toJson(QJsonDocument::Compact).toStdString();
|
|
onGenericTelegram(telegram);
|
|
return true;
|
|
}
|
|
|
|
QHash<int, bool> JsonHandlerTx::dataCommunicationPossible() const
|
|
{
|
|
return m_dataCommunicationPossible;
|
|
}
|
|
|
|
|
|
} // namespace AdlerJson
|
|
|
|
|
|
|
|
|