/** * Msg Function Topic Module Test * $Id$ * $HeadURL$ * $Author$ */ #include "ces_tests_gas_pipe.h" #include "CentralEffectSimulation/ces_dtc.h" #include "CentralEffectSimulation/ces_ftc.h" #include #include #include #include #include #include /* ---------------------------------------------------------------------------------- * HOW TO RUN THE TESTS (example) * ---------------------------------------------------------------------------------- * 0. Preconditions: * make test-db * Start services: (SV) * ./svcCentralEffectSimulation -e 42 & * ./cesTestsGasPipe -t 1 -e 42 // Gas Pipe explosion */ namespace CentralEffectSimulation { CesTestsGasPipe::CesTestsGasPipe(QObject *parent) : QObject(parent) , m_bTestsSuccessful(true) , m_refPos(LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32UMD8000090000"))) , m_logger(getLogger("CesTestGasPipe")) , m_testId(0) , m_participantIndex(0) , m_id(20) , m_equipmentNumber(60) , m_DynamicParticipantIndex(0) , m_aesItemId(5) , m_chargeTypeId(374) // SMART , m_countEventGasPipe(0) {} CesTestsGasPipe::~CesTestsGasPipe() {} bool CesTestsGasPipe::init(int domainId, int exerciseId, int testId) { bool bRet = true; int equipmentTypeIdVehicle = 35; int equipmentTypeIdSoldier = 30; // dds-Topic Participant-Management::Type INFO_LOG(m_logger) << "init begin"; m_testId = testId; m_ddsConnector42 = std::make_shared(domainId, IDL::PartitionType::Exercise, exerciseId); m_ddsConnector42->init(); m_ddsConnector42->initPublisherSubscriber(); m_pdmDts = ProjectDataManagement::Interface::Dts::create(m_ddsConnector42); bRet &= m_pdmDts->enableChargeType(); m_ppmDts = ParticipantManagement::Interface::Dts::create(m_ddsConnector42); bRet &= m_ppmDts->enableParticipantPosition(); bRet &= m_ppmDts->enableParticipant(); bRet &= m_ppmDts->enableDynamicParticipantData(); bRet &= m_ppmDts->enableType(); m_aesDts = AreaEffectSimulation::Interface::Dts::create(m_ddsConnector42); bRet &= m_aesDts->enableExplosionSingle(); bRet &= m_aesDts->enableAesItemView(); bRet &= m_aesDts->enableTriggeredImpacts(); m_cesDtc = CentralEffectSimulation::Interface::Dtc::create(m_ddsConnector42); bRet &= m_cesDtc->enableAll(); m_cesFtc = CentralEffectSimulation::Interface::Ftc::create(m_ddsConnector42); bRet &= m_cesFtc->enableAll(); connect(m_cesDtc.get(), &CentralEffectSimulation::Interface::Dtc::participantEventChanged, this, &CesTestsGasPipe::onEventChanged); m_participants.resize(6); m_participants[0].participantId = 20; // inside m_participants[0].participantTypeId = equipmentTypeIdVehicle; m_participants[0].equipmentNumber = 60; m_participants[0].relX = -10; m_participants[0].relY = -10; m_participants[0].partyId = 2; m_participants[0].buildingId = 0; m_participants[0].roomId = 0; m_participants[1].participantId = 21; // inside m_participants[1].participantTypeId = equipmentTypeIdVehicle; m_participants[1].equipmentNumber = 61; m_participants[1].relX = 10; m_participants[1].relY = 10; m_participants[1].partyId = 2; m_participants[1].buildingId = 0; m_participants[1].roomId = 0; m_participants[2].participantId = 22; // inside m_participants[2].participantTypeId = equipmentTypeIdSoldier; m_participants[2].equipmentNumber = 62; m_participants[2].relX = -10; m_participants[2].relY = -30; m_participants[2].partyId = 3; m_participants[2].buildingId = 0; m_participants[2].roomId = 0; m_participants[3].participantId = 23; // inside m_participants[3].participantTypeId = equipmentTypeIdSoldier; m_participants[3].equipmentNumber = 63; m_participants[3].relX = -10; m_participants[3].relY = -1; m_participants[3].partyId = 3; m_participants[3].buildingId = 0; m_participants[3].roomId = 0; m_participants[4].participantId = 24; // outside m_participants[4].participantTypeId = equipmentTypeIdVehicle; m_participants[4].equipmentNumber = 64; m_participants[4].relX = 30; m_participants[4].relY = 30; m_participants[4].partyId = 2; m_participants[4].buildingId = 0; m_participants[4].roomId = 0; m_participants[5].participantId = 25; // outside m_participants[5].participantTypeId = equipmentTypeIdVehicle; m_participants[5].equipmentNumber = 65; m_participants[5].relX = -30; m_participants[5].relY = -30; m_participants[5].partyId = 2; m_participants[5].buildingId = 0; m_participants[5].roomId = 0; return bRet; } void CesTestsGasPipe::startTest() { INFO_LOG(m_logger) << "startTest m_testId=" << m_testId; if (m_testId <= 1) // 1 SMART { m_explosionSingle = m_refPos.geographic(5, 5); QTimer::singleShot(0, this, &CesTestsGasPipe::tryCreateParticipant); QTimer::singleShot(20, this, &CesTestsGasPipe::tryCreateParticipant); QTimer::singleShot(40, this, &CesTestsGasPipe::tryCreateParticipant); QTimer::singleShot(60, this, &CesTestsGasPipe::tryCreateParticipant); QTimer::singleShot(80, this, &CesTestsGasPipe::tryCreateParticipant); QTimer::singleShot(100, this, &CesTestsGasPipe::tryCreateParticipant); QTimer::singleShot(250, this, &CesTestsGasPipe::tryCreateParticipantPosition); QTimer::singleShot(500, this, &CesTestsGasPipe::tryCreateParticipantPosition); QTimer::singleShot(1000, this, &CesTestsGasPipe::tryCreateParticipantPosition); QTimer::singleShot(1500, this, &CesTestsGasPipe::tryCreateParticipantPosition); QTimer::singleShot(2000, this, &CesTestsGasPipe::tryCreateParticipantPosition); QTimer::singleShot(2500, this, &CesTestsGasPipe::tryCreateParticipantPosition); QTimer::singleShot(3000, this, &CesTestsGasPipe::tryCreateTypeVehicle); QTimer::singleShot(3500, this, &CesTestsGasPipe::tryCreateTypeSoldier); QTimer::singleShot(4000, this, &CesTestsGasPipe::tryCreateChargeType); QTimer::singleShot(4500, this, &CesTestsGasPipe::tryCreateAesItemViewGasPipe); QTimer::singleShot(6000, this, &CesTestsGasPipe::checkParticipantEvent); } else { ERROR_LOG(m_logger) << "Unknown test id = " << m_testId; failExit(); } QTimer::singleShot(8000, this, &CesTestsGasPipe::failExit); } // ///////////////////////////////////////////////////// /// \brief CesTestsSmart::tryCreateDynamicParticipantData /// void CesTestsGasPipe::tryCreateDynamicParticipantData() { ParticipantManagement::DynamicParticipantData dp; const qint64 time = QDateTime::currentMSecsSinceEpoch(); const rti::core::int64 esTime = static_cast(time); ParticipantManagement::StateInformation si; si.stateTime(esTime); si.vulnerabilityState(ProjectDataManagement::VulnerabilityState_def::CatastrophicKill); dp.participantId(m_participants[m_DynamicParticipantIndex].participantId); dp.stateHistory().push_back(si); dp.sampleTime(esTime); m_DynamicParticipantIndex++; DEBUG_LOG(m_logger) << "Publishing DynamicParticipantData"; if (!m_ppmDts->publish(dp)) { ERROR_LOG(m_logger) << "Error requesting create ParticipantPosition"; failExit(); } } // ///////////////////////////////////////////////////// /// \brief CesTestsSmart::tryCreateParticipantPosition /// void CesTestsGasPipe::tryCreateParticipantPosition() { ParticipantManagement::ParticipantPosition pp; const qint64 time = QDateTime::currentMSecsSinceEpoch(); const rti::core::int64 posTime = static_cast(time); QPointF posF = m_refPos.geographic(m_participants[m_participantIndex].relX, m_participants[m_participantIndex].relY); const Core::GeoPosition pos(Core::GeoPosition(posF.x(), posF.y(), 0)); pp.buildingId(m_participants[m_participantIndex].buildingId); pp.participantId(m_participants[m_participantIndex].participantId); pp.participantTypeId(m_participants[m_participantIndex].participantTypeId); pp.partyId(m_participants[m_participantIndex].partyId); pp.roomId(m_participants[m_participantIndex].roomId); m_participantIndex++; pp.sampleTime(posTime); pp.pos(pos); DEBUG_LOG(m_logger) << "Publishing ParticipantPosition"; if (!m_ppmDts->publish(pp)) { ERROR_LOG(m_logger) << "Error requesting create ParticipantPosition"; failExit(); } } // ///////////////////////////////////////////////////// /// \brief CesTestsSmart::tryCreateParticipant /// void CesTestsGasPipe::tryCreateParticipant() { ParticipantManagement::Participant pt; pt.id(m_id); pt.equipmentNumber(m_equipmentNumber); DEBUG_LOG(m_logger) << "Publishing Participant"; if (!m_ppmDts->publish(pt)) { ERROR_LOG(m_logger) << "Error requesting create Participant"; failExit(); } m_id++; m_equipmentNumber++; } void CesTestsGasPipe::checkParticipantEvent() { INFO_LOG(m_logger) << "checkParicipantEvent"; m_cesDtc->waitForHistoricalDataParticipantEvent(); switch (m_testId) { case 1: if ( m_countEventGasPipe == 2) { ExitSuccess(); } break; default: // nothing failExit(); break; } } // ///////////////////////////////////////////////////// /// \brief CesTestsSmart::tryCreateTypeVehicle /// void CesTestsGasPipe::tryCreateTypeVehicle() { ParticipantManagement::Type ty; ty.id(35); ty.typeClass(ParticipantManagement::TypeClass::inner_enum::GroundVehicle); ty.equipmentTypeId(35); ty.symbol("1001"); ty.name("HMMWV Utility"); DEBUG_LOG(m_logger) << "Publishing Type"; if (!m_ppmDts->publish(ty)) { ERROR_LOG(m_logger) << "Error requesting create Type"; failExit(); } } // ///////////////////////////////////////////////////// /// \brief CesTestsSmart::tryCreateType /// void CesTestsGasPipe::tryCreateTypeSoldier() { ParticipantManagement::Type ty; ty.id(11); ty.typeClass(ParticipantManagement::TypeClass::inner_enum::Human); ty.equipmentTypeId(30); ty.symbol("1001"); ty.name("Soldier"); DEBUG_LOG(m_logger) << "Publishing Type"; if (!m_ppmDts->publish(ty)) { ERROR_LOG(m_logger) << "Error requesting create Type"; failExit(); } } static void setPos(std::vector &cont, const QPointF &pos) { cont.emplace_back(Core::GeoPosition(pos.x(), pos.y(), 0.0)); } void CesTestsGasPipe::tryCreateAesItemViewGasPipe() { INFO_LOG(m_logger) << "trying to send AesItemView AtExplosionAreaSingleExplosions"; AreaEffectSimulation::AesItemView iv; iv.effectStateId(AreaEffectSimulation::AesEffectState_def::EsActivated); iv.aesItemId(m_aesItemId); iv.id(m_aesItemId); iv.aesTypeId(AreaEffectSimulation::AesType::AtGasPipe); iv.partyId(5); QPointF bl = m_refPos.geographic(-10, -10); QPointF tr = m_refPos.geographic(30, 30); iv.boundingBoxBottomLeft(Core::GeoPosition2D(bl.x(), bl.y())); iv.boundingBoxTopRight(Core::GeoPosition2D(tr.x(), tr.y())); iv.chargeStruct().chargeTypeId(m_chargeTypeId); iv.sampleTime(QDateTime::currentMSecsSinceEpoch()); iv.effectStart ( QDateTime::currentMSecsSinceEpoch() + 2000); setPos(iv.form(), m_refPos.geographic(-10, -10)); setPos(iv.form(), m_refPos.geographic(-10, 30)); setPos(iv.form(), m_refPos.geographic( 10, 30)); setPos(iv.form(), m_refPos.geographic( 10, -10)); DEBUG_LOG(m_logger) << "Publishing AesItemView"; if (!m_aesDts->publish(iv)) { ERROR_LOG(m_logger) << "Error requesting create AesItemViewSingleExplosions"; failExit(); } } void CesTestsGasPipe::tryCreateChargeType() { DEBUG_LOG(m_logger) << "Publishing ChargeType"; ProjectDataManagement::ChargeType ct; ct.id(m_chargeTypeId); ct.properties("{\"impactRadius\":25,\"impactEdgeLength\":50,\"isSmart\":true,\"searchRadius\":150}"); if (!m_pdmDts->publish(ct)) { ERROR_LOG(m_logger) << "Error publish ChargeType"; failExit(); } } void CesTestsGasPipe::onEventChanged(const CentralEffectSimulation::ParticipantEvent &eventData, DataModification modType) { DEBUG_LOG(m_logger) << "onParticipantEventChanged participantId=" << eventData.participantId() << " eventType=" << eventData.eventTypeId(); if (modType == DataModification::eRemoved || modType == DataModification::eModified) return; if (eventData.eventTypeId() == ProjectDataManagement::EventType_def::HitGasPipe) { m_countEventGasPipe ++; DEBUG_LOG(m_logger) << "m_countEventGasPipe=" << m_countEventGasPipe; } } Core::FunctionReplyObject CesTestsGasPipe::fillFro(int participantId, bool bSuccess) const { if (bSuccess) return Core::FunctionReplyObject(participantId); return Core::FunctionReplyObject(participantId, tr_lts("dds", "Error sending telegram to tetra")); } void CesTestsGasPipe::failExit() { DEBUG_LOG(m_logger) << "FailExit"; m_bTestsSuccessful = false; QTimer::singleShot(50, qApp, QCoreApplication::quit); } void CesTestsGasPipe::ExitSuccess() { DEBUG_LOG(m_logger) << "ExitSuccess"; m_bTestsSuccessful = true; QTimer::singleShot(200, qApp, &QCoreApplication::quit); } } // ------------------------------------------------------------------ class CmdLineParser : public LtsCommandLineParser::LtsCommandLineParser { public: CmdLineParser() : LtsCommandLineParser() { addOption({ QStringList() << QLatin1String("t") << QLatin1String("testId") , QLatin1String("TestId.") , QLatin1String("Default: 0 (all tests)") , QLatin1String("0") }); addOption({ QStringList() << QLatin1String("a") << QLatin1String("trainingAreaId") , QLatin1String("TrainingAreaId.") , QLatin1String("Default: 0 (Unknown)") , QLatin1String("0") }); } int testId() const { return isSet(QLatin1String("t")) ? value(QLatin1String("t")).toInt() : -1; } int trainingAreaId() const { return isSet(QLatin1String("a")) ? value(QLatin1String("a")).toInt() : -1; } }; // ------------------------------------------------------------------ int main(int argc, char **argv) { NGLCoreApplication app(argc, argv); app.createLogger("CES", "log4cxx_ces.props"); CmdLineParser options; if (!options.init()) return -1; int iRet = -1; { std::unique_ptr cesTests(new CentralEffectSimulation::CesTestsGasPipe); if (!cesTests->init(options.domainId(), options.exerciseId(), options.testId())) return iRet; cesTests->startTest(); STARTUP_LOG(app.baseLogger()); app.exec(); iRet = cesTests->testsSuccessful() ? 0 : 1; fprintf(stderr, "%d\n", iRet); DEBUG_LOG(app.baseLogger()) << "** TEST result = " << iRet; SHUTDOWN_LOG(app.baseLogger()); } return iRet; }