Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

@@ -0,0 +1,490 @@
/**
* Msg Function Topic Module Test
* $Id$
* $HeadURL$
* $Author$
*/
#include "ces_tests_mine_areas.h"
#include "CentralEffectSimulation/ces_dtc.h"
#include "CentralEffectSimulation/ces_ftc.h"
#include <nglapplication/nglcoreapplication.h>
#include <LtsCommandLineParser/LtsCommandLineParser.h>
#include <QTimer>
#include <QDateTime>
#include <QPolygonF>
#include <QDateTime>
/* ----------------------------------------------------------------------------------
* HOW TO RUN THE TESTS (example)
* ----------------------------------------------------------------------------------
* 0. Preconditions:
* make test-db
* Start services: (SV)
* ./svcCentralEffectSimulation -e 42 &
* ./CesTestsMineAreas -t 1 -e 42 // Mine Area Tests
*
* Was soll getestet werden?
* - 1) Betreten einer Minensperre und auslösen einer Mine
* Teilnehmer geht in das Minensperre und betritt oder überquert mindestens eine Mine
* Reaktion: - Ausloesen einer Mine mit MineTriggerRequest und Anzeige auf der Karte
* - Event betreten Minensperre
* - CES-Hit ueber TAB den Teilnehmer
* - 2) Bewegung innerhalb einer Minensperre
* Teilnehmer ist im Minensperre und liefert eine neue Position innerhalb der Minensperre auf einer andern Mine
* Reaktion: - Ausloesen einer Mine mit MineTriggerRequest und Anzeige auf der Karte
* - CES-Hit ueber TAB den Teilnehmer
* - 3) Teilnehmer verlässt die Minensperre mit ueberquerung einer scharfen Mine
* Reaktion: - Ausloesen einer Mine mit MineTriggerRequest und Anzeige auf der Karte
* - Event verlassen Minensperre
* - CES-Hit ueber TAB den Teilnehmer
* - 4) Teilnehmer springt über eine Minensperre
* Reaktion: - Ausloesen einer Mine mit MineTriggerRequest und Anzeige auf der Karte
* - Event betreten Minensperre
* - Event verlassen Minensperre
* - CES-Hit ueber TAB den Teilnehmer
* - 5) Teilnehmer liefert neue Position außerhalb der Minensperre und hat noch Minen in der gespeicherten Liste
* Reaktion: - Ausloesen einer Mine mit MineTriggerRequest und Anzeige auf der Karte
* - CES-Hit ueber TAB den Teilnehmer
* - 6) Teilnehmer liefert neue Position außerhalb der Minensperre und hat noch Minen in der gespeicherten Liste
* ist aber im Zustand Catastorphic Kill
* Reaktion: - keine
* - 7) Teilnehmer liefert neue Position innerhalb der Minensperre und hat noch Minen in der gespeicherten Liste
* ist aber im Zustand Catastorphic Kill
* Reaktion: - keine
* - 8) Teilnehmer liefert neue Position außerhalb der Minensperre und hat noch Minen in der gespeicherten Liste,
* die outdated sind (siehe settings CES_MINE_AREAS/PeriodStoredMinesOutdated)
* Reaktion: - keine
* - 9) Minengasse: Verlegen einer Minengasse
* Teilnehmer überquert Minensperre ueber eine Minengasse
* Reaktion: - Event betreten Minensperre
* - Event verlassen Minensperre
*
*/
namespace CentralEffectSimulation
{
CesTestsMineAreas::CesTestsMineAreas(QObject *parent)
: QObject(parent)
, m_bTestsSuccessful(true)
, m_refPos(LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32UMD8000090000")))
, m_logger(getLogger("CesTestMineAreas"))
, m_testId(0)
, m_participantIndex(0)
, m_id(20)
, m_equipmentNumber(60)
, m_DynamicParticipantIndex(0)
, m_aesItemId(5)
, m_chargeTypeId(374) // SMART
, m_countEventMineAreas(0)
{}
CesTestsMineAreas::~CesTestsMineAreas()
{}
bool CesTestsMineAreas::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<DDSConnector::DdsConnector>(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, &CesTestsMineAreas::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 CesTestsMineAreas::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, &CesTestsMineAreas::tryCreateParticipant);
QTimer::singleShot(20, this, &CesTestsMineAreas::tryCreateParticipant);
QTimer::singleShot(40, this, &CesTestsMineAreas::tryCreateParticipant);
QTimer::singleShot(60, this, &CesTestsMineAreas::tryCreateParticipant);
QTimer::singleShot(80, this, &CesTestsMineAreas::tryCreateParticipant);
QTimer::singleShot(100, this, &CesTestsMineAreas::tryCreateParticipant);
QTimer::singleShot(250, this, &CesTestsMineAreas::tryCreateParticipantPosition);
QTimer::singleShot(500, this, &CesTestsMineAreas::tryCreateParticipantPosition);
QTimer::singleShot(1000, this, &CesTestsMineAreas::tryCreateParticipantPosition);
QTimer::singleShot(1500, this, &CesTestsMineAreas::tryCreateParticipantPosition);
QTimer::singleShot(2000, this, &CesTestsMineAreas::tryCreateParticipantPosition);
QTimer::singleShot(2500, this, &CesTestsMineAreas::tryCreateParticipantPosition);
QTimer::singleShot(3000, this, &CesTestsMineAreas::tryCreateTypeVehicle);
QTimer::singleShot(3500, this, &CesTestsMineAreas::tryCreateTypeSoldier);
QTimer::singleShot(4000, this, &CesTestsMineAreas::tryCreateChargeType);
QTimer::singleShot(4500, this, &CesTestsMineAreas::tryCreateAesItemViewMineArea);
QTimer::singleShot(6000, this, &CesTestsMineAreas::checkParticipantEvent);
}
else
{
ERROR_LOG(m_logger) << "Unknown test id = " << m_testId;
failExit();
}
QTimer::singleShot(8000, this, &CesTestsMineAreas::failExit);
}
// /////////////////////////////////////////////////////
/// \brief CesTestsSmart::tryCreateDynamicParticipantData
///
void CesTestsMineAreas::tryCreateDynamicParticipantData()
{
ParticipantManagement::DynamicParticipantData dp;
const qint64 time = QDateTime::currentMSecsSinceEpoch();
const rti::core::int64 esTime = static_cast<rti::core::int64>(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 CesTestsMineAreas::tryCreateParticipantPosition()
{
ParticipantManagement::ParticipantPosition pp;
const qint64 time = QDateTime::currentMSecsSinceEpoch();
const rti::core::int64 posTime = static_cast<rti::core::int64>(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 CesTestsMineAreas::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 CesTestsMineAreas::checkParticipantEvent()
{
INFO_LOG(m_logger) << "checkParicipantEvent";
m_cesDtc->waitForHistoricalDataParticipantEvent();
switch (m_testId)
{
case 1:
if ( m_countEventMineAreas == 2)
{
ExitSuccess();
}
break;
default:
// nothing
failExit();
break;
}
}
// /////////////////////////////////////////////////////
/// \brief CesTestsSmart::tryCreateTypeVehicle
///
void CesTestsMineAreas::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 CesTestsMineAreas::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<Core::GeoPosition> &cont, const QPointF &pos)
{
cont.emplace_back(Core::GeoPosition(pos.x(), pos.y(), 0.0));
}
void CesTestsMineAreas::tryCreateAesItemViewMineArea()
{
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::AtMineArea);
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 CesTestsMineAreas::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 CesTestsMineAreas::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_countEventMineAreas ++;
DEBUG_LOG(m_logger) << "m_countEventMineAreas=" << m_countEventMineAreas;
}
}
Core::FunctionReplyObject CesTestsMineAreas::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 CesTestsMineAreas::failExit()
{
DEBUG_LOG(m_logger) << "FailExit";
m_bTestsSuccessful = false;
QTimer::singleShot(50, qApp, QCoreApplication::quit);
}
void CesTestsMineAreas::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<CentralEffectSimulation::CesTestsMineAreas> cesTests(new CentralEffectSimulation::CesTestsMineAreas);
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;
}