/** * @RDE_HEADER@ * The ProxyEmulator class emulates FTs of the TetraRadio Proxy to send position data * $Id$ * $HeadURL$ * $Author$ * Created by Hannes Baeuerle, SLSE, 2016-08-09 */ #include "proxy_emulator.h" #include #include #include #include #include #include VulnerabilityStateGenerator::ProxyEmulator::ProxyEmulator(const std::shared_ptr &ddsConnector, QObject *parent) : QObject(parent) , m_ddsConnector(ddsConnector) , m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger(metaObject()->className())) {} bool VulnerabilityStateGenerator::ProxyEmulator::init() { m_tabDts = (TrainingAreaBase::Interface::Dts::create(m_ddsConnector)); DEBUG_LOG(m_logger) << "Initializing TAB DTS ..."; if (!m_tabDts->enableAll()) { ERROR_LOG(m_logger) << "Could not init TAB DTS"; return false; } DEBUG_LOG(m_logger) << "... done"; return true; } void VulnerabilityStateGenerator::ProxyEmulator::giveInitState(const QMap &participants) { DEBUG_LOG(m_logger) << participants.size() << " participants found. Trying to give them init states." ; int participantsWithEquipmentNumber = 0; for (auto it = participants.begin(); it != participants.end(); ++it) { const ParticipantManagement::Participant ¤tParticipant = it.value(); if (currentParticipant.equipmentNumber().is_set()) { ++participantsWithEquipmentNumber; TrainingAreaBase::EquipmentState state; state.equipmentNumber(currentParticipant.equipmentNumber().get()); state.sampleTime(QDateTime::currentMSecsSinceEpoch()); state.vulnerabilityState(ProjectDataManagement::VulnerabilityState_def::CombatReady); m_tabDts->publish(state); } } if (participants.size() != participantsWithEquipmentNumber) { DEBUG_LOG(m_logger) << "Actually gave " << participantsWithEquipmentNumber << " participants an init position, because the rest does not have an equipment number" ; } else { DEBUG_LOG(m_logger) << "... done"; } } void VulnerabilityStateGenerator::ProxyEmulator::publishNewState(ProjectDataManagement::VulnerabilityState newState, ParticipantManagement::Participant participant) { TrainingAreaBase::EquipmentState state; state.equipmentNumber(participant.equipmentNumber().get()); state.sampleTime(QDateTime::currentMSecsSinceEpoch()); state.vulnerabilityState(newState); DEBUG_LOG(m_logger) << "participantId: " << participant.id() << ", state: " << newState << ", equipNo: " << participant.equipmentNumber().get(); m_tabDts->publish(state); }