- NGL_ADD_LIBRARY2: 87 CMakeLists.txt konvertiert für Export-Header Generierung - 44 Export-Header Include-Pfade korrigiert (_export.h) - 81 DDS-Stub-Header generiert (*_dtc.h, *_fts.h, *_dts.h, *_ftc.h) - INGLLogger: Duplikat gelöscht, m_logger Member entfernt, variadische Makros - Q_FUNC_INFO Redefinition behoben (Qt6 definiert bereits) - FATAL_LOG Makro hinzugefügt - InfrastructureManagement DDS-Stubs (ism.hpp, ism_enums.hpp, ism_ftc.h) - FilterManagement DDS-Stubs (flt_ftc.h, flt_dts.h) - AreaEffectSimulation DDS-Stubs (aes.hpp, aes_enums.hpp) - SymbolAppearance Klasse vollständig definiert mit content() Methode - BuildingComponentFilter Klasse definiert mit Copy-Konstruktor - Ftc Factory: nullptr Return (abstract class) - AesFilter Klasse in aes.hpp hinzugefügt - Dtc Klasse in ppm.hpp mit participantChanged Signal - AesType Enum: alle 15 At* Werte definiert - AesEffectState_def: EsReceived hinzugefügt - DataModification Enum: eAdded/eModified/eRemoved - function_reply_object.h → core_types.h Include-Pfad (72 Dateien) - Enum-Class-Streaming Template-Operator in INGLLogger.h - ism_mounting_point.h: QImage → QtGui/QImage, QGuiApplication/QScreen - ism_data_plugin_interface.h: QSet Include, Include-Reihenfolge - QRegExp → QRegularExpression in tpm_js_parser.cpp - .underlying() Aufrufe zu direktem Enum-Vergleich korrigiert - Include-Pfade: aes.hpp in symbol_appearance_settings_impl.h und aes_display_filter_impl.h Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
280 lines
9.7 KiB
C++
Executable File
280 lines
9.7 KiB
C++
Executable File
|
|
|
|
|
|
#include "json_api.h"
|
|
#include <utility>
|
|
#include "web_socket_handler.h"
|
|
#include "web_socket_telegrams.h"
|
|
#include <QWebSocket>
|
|
#include <QtGlobal>
|
|
|
|
namespace BuildingControlUnit
|
|
{
|
|
namespace Json
|
|
{
|
|
Api::Api(QObject *parent)
|
|
: QObject(parent)
|
|
, m_webSocketHandler(new WebSocketHandler(this))
|
|
{
|
|
connect(m_webSocketHandler, &WebSocketHandler::telegramReceived,
|
|
this, &Api::onTelegramReceived);
|
|
connect(m_webSocketHandler, &WebSocketHandler::webSocketConnected,
|
|
this, &Api::webSocketConnected);
|
|
}
|
|
|
|
bool Api::init(quint16 listenPort)
|
|
{
|
|
return m_webSocketHandler->init(listenPort);
|
|
}
|
|
|
|
void Api::onHitResult(const HitResult &hitResult, const QMap<int, ContaminationState> &contaminationStates, bool playSound)
|
|
{
|
|
Q_UNUSED(playSound);
|
|
sendHitResult(hitResult, contaminationStates, nullptr);
|
|
}
|
|
|
|
void Api::sendHitResult(const HitResult &hitResult, const QMap <int, ContaminationState> &contaminationStates, QWebSocket *ws)
|
|
{
|
|
Telegrams::HitResult tele;
|
|
tele.timestamp = hitResult.effectTimeMSec;
|
|
tele.hitResult.sensorId = hitResult.sensorId;
|
|
tele.hitResult.originatorId = hitResult.originatorId;
|
|
tele.hitResult.originatorType = hitResult.originatorType;
|
|
tele.hitResult.chargeTypeId = hitResult.chargeTypeId;
|
|
tele.hitResult.damagePercentOld = hitResult.damagePercentOld;
|
|
tele.hitResult.damagePercentNew = hitResult.damagePercentNew;
|
|
tele.hitResult.effectSoundId = hitResult.effectSoundId;
|
|
tele.hitResult.damageState = hitResult.damageState;
|
|
tele.hitResult.rooms.reserve(hitResult.rooms.size());
|
|
for (const HitRoom &hr : hitResult.rooms)
|
|
{
|
|
Telegrams::HitResult::HitRoomInfo hri;
|
|
hri.roomId = hr.roomId;
|
|
hri.damagePercent = hr.damagePercent;
|
|
hri.remainingEffectPercent = hr.remainingEffectPercent;
|
|
hri.fortifyFactor = hr.fortifyFactor;
|
|
if (hr.directHit)
|
|
tele.hitResult.hitOnRoomId = hr.roomId;
|
|
tele.hitResult.rooms += hri;
|
|
}
|
|
for (const auto &cs : contaminationStates)
|
|
{
|
|
Telegrams::HitResult::ContaminationStateInfo csi;
|
|
csi.aesId = cs.aesId;
|
|
csi.rooms = cs.rooms;
|
|
tele.hitResult.contaminations += csi;
|
|
}
|
|
|
|
DEBUG_LOG() << Q_FUNC_INFO << ", tele = " << tele.toJson();
|
|
|
|
m_webSocketHandler->sendTelegram(&tele, ws);
|
|
}
|
|
|
|
void Api::onBsmState(const QVector<BSM::BsmState> &bsmStates)
|
|
{
|
|
sendBsmState(bsmStates, nullptr);
|
|
}
|
|
|
|
void Api::onRelayState(const RelayState &relayState)
|
|
{
|
|
sendRelayState(relayState.hostname, relayState.stateTime, relayState.offlineTime, relayState.relayStates, nullptr);
|
|
}
|
|
|
|
void Api::sendBsmState(const QVector<BSM::BsmState> &bsmStates, QWebSocket *ws)
|
|
{
|
|
Telegrams::BsmState tele;
|
|
tele.timestamp = QDateTime::currentMSecsSinceEpoch();
|
|
tele.bsmStates.reserve(bsmStates.size());
|
|
Telegrams::BsmState::BsmStateInfo bsi;
|
|
for (const BSM::BsmState &state : bsmStates)
|
|
{
|
|
bsi.connected = state.bConnected;
|
|
bsi.hostname = state.hostname;
|
|
bsi.id = state.id;
|
|
bsi.port = state.port;
|
|
bsi.versionInfo = state.versionInfo;
|
|
tele.bsmStates += bsi;
|
|
}
|
|
m_webSocketHandler->sendTelegram(&tele, ws);
|
|
}
|
|
|
|
void Api::sendRelayState(const QString &segment,
|
|
const qint64 stateTime,
|
|
const qint64 offlineTime,
|
|
const QVector<RelayStateInfo> &relayStates,
|
|
QWebSocket *ws)
|
|
{
|
|
Telegrams::RelayState tele;
|
|
tele.segment = segment;
|
|
tele.stateTime = stateTime;
|
|
tele.offlineTime = offlineTime;
|
|
Telegrams::RelayState::RelayStateInfo rsi;
|
|
for (const RelayStateInfo &state : relayStates)
|
|
{
|
|
rsi.id = state.id;
|
|
rsi.state = state.state;
|
|
tele.relayStates += rsi;
|
|
}
|
|
m_webSocketHandler->sendTelegram(&tele, ws);
|
|
}
|
|
|
|
void Api::sendEffectOverrides(const QString &segment,
|
|
const qint64 stateTime,
|
|
const qint64 offlineTime,
|
|
const QVector<BcuEffectState> &effectOverrides,
|
|
QWebSocket *ws)
|
|
{
|
|
Telegrams::EffectOverride tele;
|
|
tele.segment = segment;
|
|
tele.stateTime = stateTime;
|
|
tele.offlineTime = offlineTime;
|
|
Telegrams::EffectOverride::OverrideInfo rsi;
|
|
for (const BcuEffectState &state : effectOverrides)
|
|
{
|
|
rsi.id = state.id;
|
|
rsi.effectOverride = state.effectOverride;
|
|
tele.overrides += rsi;
|
|
}
|
|
m_webSocketHandler->sendTelegram(&tele, ws);
|
|
}
|
|
|
|
|
|
void Api::onTelegramReceived(const std::shared_ptr<Telegrams::BaseTelegram> &tele)
|
|
{
|
|
DEBUG_LOG() << "tele->telegramId(): " << tele->telegramId();
|
|
|
|
if (tele->telegramId() == Telegrams::SetDamageState::telegramId())
|
|
{
|
|
Telegrams::SetDamageState *sds = static_cast<Telegrams::SetDamageState *>(tele.get());
|
|
emit damageStateRequest(sds->originatorId, sds->damageState, sds->roomIds);
|
|
return;
|
|
}
|
|
|
|
if (tele->telegramId() == Telegrams::ResetContaminationState::telegramId())
|
|
{
|
|
emit resetContaminationRequest();
|
|
return;
|
|
}
|
|
|
|
if (tele->telegramId() == Telegrams::SetContaminationState::telegramId())
|
|
{
|
|
Telegrams::SetContaminationState *scs = static_cast<Telegrams::SetContaminationState *> (tele.get());
|
|
emit setContaminationStateRequest(scs->contaminationStates);
|
|
return;
|
|
}
|
|
|
|
if (tele->telegramId() == Telegrams::SetEffectStates::telegramId())
|
|
{
|
|
Telegrams::SetEffectStates *sff = static_cast<Telegrams::SetEffectStates *>(tele.get());
|
|
QVector<BcuEffectState> val;
|
|
val.reserve(sff->effectStates.size());
|
|
for(const auto &fi : std::as_const(sff->effectStates))
|
|
{
|
|
BcuEffectState ff;
|
|
ff.id = fi.id;
|
|
ff.type = fi.type;
|
|
ff.effectOverride = fi.effectOverride;
|
|
val += ff;
|
|
}
|
|
emit setEffectStatesRequest(sff->segment, val);
|
|
return;
|
|
}
|
|
if (tele->telegramId() == Telegrams::SwitchRelay::telegramId())
|
|
{
|
|
Telegrams::SwitchRelay *sff = static_cast<Telegrams::SwitchRelay *>(tele.get());
|
|
|
|
emit switchRelayRequest(sff->segment, sff->switchRelayValues);
|
|
return;
|
|
}
|
|
|
|
if (tele->telegramId() == Telegrams::SetFortifyFactor::telegramId())
|
|
{
|
|
Telegrams::SetFortifyFactor *sff = static_cast<Telegrams::SetFortifyFactor *>(tele.get());
|
|
QVector<FortifyInfo> val;
|
|
val.reserve(sff->fortifyFactors.size());
|
|
for(const auto &fi : std::as_const(sff->fortifyFactors))
|
|
{
|
|
FortifyInfo ff;
|
|
ff.roomId = fi.roomId;
|
|
ff.fortifyFactor = fi.fortifyFactor;
|
|
val += ff;
|
|
}
|
|
emit setFortifyFactorRequest(sff->originatorId, val);
|
|
return;
|
|
}
|
|
if (tele->telegramId() == Telegrams::RelayState::telegramId())
|
|
{
|
|
Telegrams::RelayState *sff = static_cast<Telegrams::RelayState *>(tele.get());
|
|
QVector<RelayStateInfo> val;
|
|
val.reserve(sff->relayStates.size());
|
|
for(const auto &fi : std::as_const(sff->relayStates))
|
|
{
|
|
RelayStateInfo ff;
|
|
ff.id = fi.id;
|
|
ff.state = fi.state;
|
|
val += ff;
|
|
}
|
|
emit relayStatesRequest(sff->segment, val);
|
|
return;
|
|
}
|
|
|
|
if (tele->telegramId() == Telegrams::BsmTriggerFlashlight::telegramId())
|
|
{
|
|
Telegrams::BsmTriggerFlashlight *btf = static_cast<Telegrams::BsmTriggerFlashlight *>(tele.get());
|
|
emit bsmTriggerFlashlightRequest(btf->sensorId, btf->hostname, btf->numberOfFlashes, btf->pauseBetweenFlashesSec);
|
|
return;
|
|
}
|
|
if (tele->telegramId() == Telegrams::CentralEffectSimulationHit::telegramId())
|
|
{
|
|
Telegrams::CentralEffectSimulationHit *cesHit = static_cast<Telegrams::CentralEffectSimulationHit*>(tele.get());
|
|
emit centralEffectSimulationHit(cesHit->effectTimeMSec, cesHit->chargeTypeId,
|
|
cesHit->destructiveFactor, cesHit->penetrationFactor,
|
|
cesHit->aesId,
|
|
LtsUtils::QPoint3D(cesHit->relPosition.x, cesHit->relPosition.y, cesHit->relPosition.z),
|
|
cesHit->properties);
|
|
return;
|
|
}
|
|
if (tele->telegramId() == Telegrams::CentralEffectSimulationHit3D::telegramId())
|
|
{
|
|
Telegrams::CentralEffectSimulationHit3D *cesHit = static_cast<Telegrams::CentralEffectSimulationHit3D*>(tele.get());
|
|
emit centralEffectSimulationHit3D(cesHit->effectTimeMSec, cesHit->chargeTypeId,
|
|
cesHit->destructiveFactor, cesHit->penetrationFactor,
|
|
cesHit->aesId,
|
|
LtsUtils::QPoint3D(cesHit->impactPosition.x, cesHit->impactPosition.y, cesHit->impactPosition.z),
|
|
LtsUtils::QPoint3D(cesHit->detonationLocation.x, cesHit->detonationLocation.y, cesHit->detonationLocation.z),
|
|
cesHit->detonationDistance,
|
|
cesHit->properties);
|
|
return;
|
|
}
|
|
if (tele->telegramId() == Telegrams::DebugSimulateBSMHit::telegramId())
|
|
{
|
|
Telegrams::DebugSimulateBSMHit *bsmHit = static_cast<Telegrams::DebugSimulateBSMHit*>(tele.get());
|
|
qint64 effectTimeMSec = bsmHit->effectTimeMSec ? bsmHit->effectTimeMSec : QDateTime::currentMSecsSinceEpoch();
|
|
emit simulateBSMHit(effectTimeMSec, bsmHit->sensorId, bsmHit->originatorId, bsmHit->chargeTypeId, bsmHit->deposition1, bsmHit->deposition2);
|
|
return;
|
|
}
|
|
if (tele->telegramId() == Telegrams::GetBsmConfiguration::telegramId())
|
|
{
|
|
Telegrams::GetBsmConfiguration *tel = static_cast<Telegrams::GetBsmConfiguration*>(tele.get());
|
|
emit getBsmConfiguration(tel->sensorId);
|
|
return;
|
|
}
|
|
if (tele->telegramId() == Telegrams::GetBsmBitTimeout::telegramId())
|
|
{
|
|
Telegrams::GetBsmBitTimeout *tel = static_cast<Telegrams::GetBsmBitTimeout*>(tele.get());
|
|
emit getBsmBitTimeout(tel->sensorId);
|
|
return;
|
|
}
|
|
if (tele->telegramId() == Telegrams::GetBsmTechnicalStatus::telegramId())
|
|
{
|
|
Telegrams::GetBsmTechnicalStatus *tel = static_cast<Telegrams::GetBsmTechnicalStatus*>(tele.get());
|
|
emit getBsmTechnicalStatus(tel->sensorId);
|
|
return;
|
|
}
|
|
WARNING_LOG() << "Received unhandled telegram " << tele->telegramId();
|
|
}
|
|
|
|
|
|
}
|
|
}
|