/** * Msg Function Topic Module Test * $Id$ * $HeadURL$ * $Author$ */ #include "ces_tests_geo_pairing.h" #include "CentralEffectSimulation/ces_dtc.h" #include "CentralEffectSimulation/ces_ftc.h" #include #include #include #include #include /* ---------------------------------------------------------------------------------- * HOW TO RUN THE TESTS (example) * ---------------------------------------------------------------------------------- * 0. Preconditions: * load BT56 (BUILD) * make db * Start services: (SV) * ./svcCentralEffectSimulation -e 42 * ./cesTestsGeopairing -t 1 -e 42 // Mortar * ./cesTestsGeopairing -t 2 -e 42 // IGLA * ./cesTestsGeopairing -t 3 -e 42 // IGLA Damage States * ./cesTestsGeopairing -t 4 -e 42 // MK19 Area Fire */ namespace CentralEffectSimulation { CesTestsGeopairing::CesTestsGeopairing(QObject *parent) : QObject(parent) , m_bTestsSuccessful(true) , m_housePos(LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32UMD8000090000"))) , m_logger(getLogger("CesTestsGeopairing")) , m_testId(0) {} CesTestsGeopairing::~CesTestsGeopairing() {} bool CesTestsGeopairing::init(int domainId, int exerciseId, int testId) { bool bRet = true; 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_ppmDts = ParticipantManagement::Interface::Dts::create(m_ddsConnector42); bRet &= m_ppmDts->enableParticipantPosition(); bRet &= m_ppmDts->enableParticipant(); bRet &= m_ppmDts->enableDynamicParticipantData(); m_mdmDts = MeteoDataManagement::Interface::Dts::create(m_ddsConnector42); bRet &= m_mdmDts->enableAll(); m_tabDts = TrainingAreaBase::Interface::Dts::create(m_ddsConnector42); bRet &= m_tabDts->enableGeopairingData(); m_cesDtc = CentralEffectSimulation::Interface::Dtc::create(m_ddsConnector42); bRet &= m_cesDtc->enableAll(); m_cesFtc = CentralEffectSimulation::Interface::Ftc::create(m_ddsConnector42); bRet &= m_cesFtc->enableAll(); m_aesDtc = AreaEffectSimulation::Interface::Dtc::create(m_ddsConnector42); bRet &= m_aesDtc->enableAll(); return bRet; } void CesTestsGeopairing::startTest() { INFO_LOG(m_logger) << "startTest m_testId=" << m_testId; switch (m_testId) { case 1: { QTimer::singleShot(0, this, &CesTestsGeopairing::tryCreateMeteoData); QTimer::singleShot(500, this, &CesTestsGeopairing::tryCreateGeopairingData); QTimer::singleShot(1000, this, &CesTestsGeopairing::checkGeopairing); break; } case 2: { INFO_LOG(m_logger) << "Geopairing IGLA"; QTimer::singleShot(0, this, &CesTestsGeopairing::tryCreateMeteoData); QTimer::singleShot(250, this, &CesTestsGeopairing::tryCreateSoldierPosition); QTimer::singleShot(500, this, &CesTestsGeopairing::tryCreateAircraftPosition); QTimer::singleShot(750, this, &CesTestsGeopairing::tryCreateGeopairingDataIGLA); QTimer::singleShot(1000, this, &CesTestsGeopairing::checkGeopairing); break; } case 3: { INFO_LOG(m_logger) << "Geopairing IGLA Damage States"; QTimer::singleShot(0, this, &CesTestsGeopairing::tryCreateMeteoData); QTimer::singleShot(250, this, &CesTestsGeopairing::tryCreateSoldierPosition); QTimer::singleShot(500, this, &CesTestsGeopairing::tryCreateAircraftPosition); QTimer::singleShot(750, this, &CesTestsGeopairing::tryCreateGeopairingDataIGLA); QTimer::singleShot(1000, this, &CesTestsGeopairing::checkGeopairing); break; } case 4: // MK 19 { INFO_LOG(m_logger) << "Geopairing MK 19"; QTimer::singleShot(0, this, &CesTestsGeopairing::tryCreateMeteoData); QTimer::singleShot(250, this, &CesTestsGeopairing::tryCreateSoldierPosition); QTimer::singleShot(500, this, &CesTestsGeopairing::tryCreateAircraftPosition); QTimer::singleShot(750, this, &CesTestsGeopairing::tryCreateGeopairingDataMK19); QTimer::singleShot(1000, this, &CesTestsGeopairing::checkGeopairing); break; } default: { ERROR_LOG(m_logger) << "Unknown test id = " << m_testId; failExit(); } } QTimer::singleShot(6000, this, &CesTestsGeopairing::failExit); } // ///////////////////////////////////////////////////// /// \brief CesTestsGeopairing::tryCreateGeopairingData /// void CesTestsGeopairing::tryCreateMeteoData() { MeteoDataManagement::MeteoData md; md.id(1); md.windSpeed(0.0); md.windDirection(0.0); md.temperature(20.0); md.pressure(1013); DEBUG_LOG(m_logger) << "Publishing MeteoData"; if (!m_mdmDts->publish(md)) { ERROR_LOG(m_logger) << "Error requesting create MeteoData"; failExit(); } } // ///////////////////////////////////////////////////// /// \brief CesTestsGeopairing::tryCreateParticipantPosition /// void CesTestsGeopairing::tryCreateSoldierPosition() { ParticipantManagement::ParticipantPosition pp; const qint64 time = QDateTime::currentMSecsSinceEpoch(); const rti::core::int64 posTime = static_cast(time); double lon = 0.15530400; double lat = 0.92601500; pp.participantId(5); pp.participantTypeId(55); pp.pos().lon(lon); pp.pos().lat(lat); pp.partyId(2); pp.roomId(0); pp.sampleTime(posTime); DEBUG_LOG(m_logger) << "Publishing ParticipantPosition"; if (!m_ppmDts->publish(pp)) { ERROR_LOG(m_logger) << "Error requesting create ParticipantPosition"; failExit(); } } // ///////////////////////////////////////////////////// /// \brief CesTestsGeopairing::tryCreateAircraftPosition /// void CesTestsGeopairing::tryCreateAircraftPosition() { ParticipantManagement::ParticipantPosition pp; const qint64 time = QDateTime::currentMSecsSinceEpoch(); const rti::core::int64 posTime = static_cast(time); double lon = 0.15488; double lat = 0.925742; pp.participantId(61); pp.participantTypeId(130); pp.pos().lon(lon); pp.pos().lat(lat); pp.partyId(2); pp.roomId(0); pp.sampleTime(posTime); DEBUG_LOG(m_logger) << "Publishing ParticipantPosition"; if (!m_ppmDts->publish(pp)) { ERROR_LOG(m_logger) << "Error requesting create ParticipantPosition"; failExit(); } } // ///////////////////////////////////////////////////// /// \brief CesTestsGeopairing::tryCreateGeopairingData /// void CesTestsGeopairing::tryCreateGeopairingData() { TrainingAreaBase::GeopairingData gd; const qint64 time = QDateTime::currentMSecsSinceEpoch(); const rti::core::int64 posTime = static_cast(time); gd.payload().resize(18); // Fire_Report: TimerTick=58908 AmmuniationType=4 Azimut=79,7 Elevation=67,1 Temperatur=25 RoundsAmm1=0 RoundsAmm2=7 // E3 01 1C E6 04 9F 02 00 00 1D 03 00 00 19 00 00 00 07 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 /*gd.payload()[0] = 0xE3; gd.payload()[1] = 0x01; // GeoPairing Mortar gd.payload()[2] = 0x1C; // Time gd.payload()[3] = 0xE6; // Time gd.payload()[4] = 0x04; // Ammunition gd.payload()[5] = 0x9F; // Elevation gd.payload()[6] = 0x02; // Elevation gd.payload()[7] = 0x00; // Elevation gd.payload()[8] = 0x00; // Elevation gd.payload()[9] = 0x1D; // Azimuth gd.payload()[10] = 0x03; // Azimuth gd.payload()[11] = 0x00; // Azimuth gd.payload()[12] = 0x00; // Azimuth gd.payload()[13] = 0x19; // Temperature gd.payload()[14] = 0x00; // Time To Detonation gd.payload()[15] = 0x00; // Time To Detonation gd.payload()[16] = 0x00; // Weapon secific gd.payload()[17] = 0x07; // */ gd.payload()[0] = 0xE3; gd.payload()[1] = 0x01; gd.payload()[2] = 0xe5; gd.payload()[3] = 0x96; gd.payload()[4] = 0x12; gd.payload()[5] = 0x75; gd.payload()[6] = 0x03; gd.payload()[7] = 0x00; gd.payload()[8] = 0x00; gd.payload()[9] = 0x0e; gd.payload()[10] = 0x0d; gd.payload()[11] = 0x00; gd.payload()[12] = 0x00; gd.payload()[13] = 0x24; gd.payload()[14] = 0x00; gd.payload()[15] = 0x00; gd.payload()[16] = 0x00; gd.payload()[17] = 0x00; gd.sampleTime(posTime); gd.equipmentNumber(1001); QPointF posF = m_housePos.geographic(10,10); const Core::GeoPosition pos(Core::GeoPosition(posF.x(), posF.y(), 0)); gd.position(pos); DEBUG_LOG(m_logger) << "Publishing GeopairingData"; if (!m_tabDts->publish(gd)) { ERROR_LOG(m_logger) << "Error requesting create GeopairingData"; failExit(); } } // ///////////////////////////////////////////////////// /// \brief CesTestsGeopairing::tryCreateGeopairingDataIGLA /// void CesTestsGeopairing::tryCreateGeopairingDataIGLA() { TrainingAreaBase::GeopairingData gd; const qint64 time = QDateTime::currentMSecsSinceEpoch(); const rti::core::int64 posTime = static_cast(time); gd.payload().resize(18); // Original aus UAE LogViewer Script /*gd.payload()[0] = 0xE3; gd.payload()[1] = 0x03; // IGLA gd.payload()[2] = 0x1c; gd.payload()[3] = 0xe6; gd.payload()[4] = 0x04; gd.payload()[5] = 0x32; gd.payload()[6] = 0x00; gd.payload()[7] = 0x00; gd.payload()[8] = 0x00; gd.payload()[9] = 0x5a; gd.payload()[10] = 0x01; gd.payload()[11] = 0x00; gd.payload()[12] = 0x00; gd.payload()[13] = 0x19; gd.payload()[14] = 0x00; gd.payload()[15] = 0x00; gd.payload()[16] = 0x00; gd.payload()[17] = 0x00;*/ // Daten, wie bei Test1. Sollte ja dann im Zielbereich liegen. /* gd.payload()[0] = 0xE3; gd.payload()[1] = 0x03; // IGLA gd.payload()[2] = 0xe5; gd.payload()[3] = 0x96; gd.payload()[4] = 0x12; gd.payload()[5] = 0x75; gd.payload()[6] = 0x03; gd.payload()[7] = 0x00; gd.payload()[8] = 0x00; gd.payload()[9] = 0x0e; gd.payload()[10] = 0x0d; gd.payload()[11] = 0x00; gd.payload()[12] = 0x00; gd.payload()[13] = 0x24; gd.payload()[14] = 0x00; gd.payload()[15] = 0x00; gd.payload()[16] = 0x00; gd.payload()[17] = 0x00; */ // Daten, wie bei Test1. Sollte ja dann im Zielbereich liegen. gd.payload()[0] = 0xE3; gd.payload()[1] = 0x03; // IGLA gd.payload()[2] = 0x1c; gd.payload()[3] = 0xe6; gd.payload()[4] = 0x04; gd.payload()[5] = 0x32; gd.payload()[6] = 0x00; gd.payload()[7] = 0x00; gd.payload()[8] = 0x00; gd.payload()[9] = 0x00; gd.payload()[10] = 0x00; gd.payload()[11] = 0x00; gd.payload()[12] = 0x00; gd.payload()[13] = 0x19; gd.payload()[14] = 0x00; gd.payload()[15] = 0x00; gd.payload()[16] = 0x02; // Button Change over point pressed gd.payload()[17] = 0x00; gd.sampleTime(posTime); gd.equipmentNumber(1001); double lon = 0.15530364; double lat = 0.92601523; gd.position().lon(lon); gd.position().lat(lat); DEBUG_LOG(m_logger) << "Publishing GeopairingData"; if (!m_tabDts->publish(gd)) { ERROR_LOG(m_logger) << "Error requesting create GeopairingData"; failExit(); } } // ///////////////////////////////////////////////////// /// \brief CesTestsGeopairing::tryCreateGeopairingDataIGLA /// void CesTestsGeopairing::tryCreateGeopairingDataMK19() { TrainingAreaBase::GeopairingData gd; const qint64 time = QDateTime::currentMSecsSinceEpoch(); const rti::core::int64 posTime = static_cast(time); gd.payload().resize(18); gd.payload()[0] = 0xE3; gd.payload()[1] = 0x05; // MK 19 gd.payload()[2] = 0x1c; gd.payload()[3] = 0xe6; gd.payload()[4] = 0x04; gd.payload()[5] = 0x32; gd.payload()[6] = 0x00; gd.payload()[7] = 0x00; gd.payload()[8] = 0x00; gd.payload()[9] = 0x00; gd.payload()[10] = 0x00; gd.payload()[11] = 0x00; gd.payload()[12] = 0x00; gd.payload()[13] = 0x19; gd.payload()[14] = 0x00; gd.payload()[15] = 0x00; gd.payload()[16] = 0x02; // Button Change over point pressed gd.payload()[17] = 0x00; gd.sampleTime(posTime); gd.equipmentNumber(1001); double lon = 0.15530364; double lat = 0.92601523; gd.position().lon(lon); gd.position().lat(lat); DEBUG_LOG(m_logger) << "Publishing GeopairingData"; if (!m_tabDts->publish(gd)) { ERROR_LOG(m_logger) << "Error requesting create GeopairingData"; failExit(); } } void CesTestsGeopairing::checkGeopairing() { INFO_LOG(m_logger) << "checkMessageOnDds"; m_aesDtc->waitForHistoricalDataExplosionSingle(); QMap < int ,AreaEffectSimulation::ExplosionSingle> explosionSingles = m_aesDtc->explosionSingles(); INFO_LOG(m_logger) << "explosionSingles.size()" << explosionSingles.size(); AreaEffectSimulation::ExplosionSingle explosionSingle = explosionSingles.last(); DEBUG_LOG(m_logger) << "explosionSingle.lat=" << explosionSingle.impactPosition().lat() << " lon=" << explosionSingle.impactPosition().lon(); switch (m_testId) { case 1: { if ( (explosionSingle.impactPosition().lat() > 0.9 && explosionSingle.impactPosition().lat() < 1.0) && (explosionSingle.impactPosition().lon() > 0.1 && explosionSingle.impactPosition().lon() < 0.2)) { ExitSuccess(); return; } break; } } // end switch failExit(); } void CesTestsGeopairing::failExit() { DEBUG_LOG(m_logger) << "FailExit"; m_bTestsSuccessful = false; QTimer::singleShot(50, qApp, &QCoreApplication::quit); } void CesTestsGeopairing::ExitSuccess() { DEBUG_LOG(m_logger) << "ExitSuccess"; m_bTestsSuccessful = true; QTimer::singleShot(50, 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::CesTestsGeopairing); 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; }