Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Services/CentralEffectSimulation/ModuleTests/ces_tests_smart.cpp
T

524 lines
18 KiB
C++
Executable File

/**
* Msg Function Topic Module Test
* $Id$
* $HeadURL$
* $Author$
*/
#include "ces_tests_smart.h"
#include "CentralEffectSimulation/ces_dtc.h"
#include "CentralEffectSimulation/ces_ftc.h"
#include <TrainingAreaBase/tab_fts.h>
#include <nglapplication/nglcoreapplication.h>
#include <LtsCommandLineParser/LtsCommandLineParser.h>
#include <QtCore/QTimer>
#include <QtCore/QDateTime>
#include <QtGui/QPolygonF>
#include <QtCore/QDateTime>
/* ----------------------------------------------------------------------------------
* HOW TO RUN THE TESTS (example)
* ----------------------------------------------------------------------------------
* 0. Preconditions:
* make db
* Start services: (SV)
* ./svcCentralEffectSimulation -e 42 &
* ./cesTestsSmart -t 1 -e 42 // Smart Single Explosion
*/
namespace CentralEffectSimulation
{
CesTestsSmart::CesTestsSmart(QObject *parent)
: QObject(parent)
, TrainingAreaBase::Interface::Fts::SendCesHitRequestHandler(nullptr)
, m_bTestsSuccessful(true)
, m_housePos(LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32UMD8000090000")))
, m_logger(getLogger("CesTestsSmart"))
, m_testId(0)
, m_participantIndex(0)
, m_DynamicParticipantIndex(0)
, m_originatorParticipantId(30)
, m_aesItemId(5)
, m_buildingId(0)
, m_roomId(0)
, m_chargeTypeId(374) // SMART
{}
CesTestsSmart::~CesTestsSmart()
{}
bool CesTestsSmart::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_buildingId = 0; // ism_main_structure_element:id
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();
m_tabFts = TrainingAreaBase::Interface::Fts::create(m_ddsConnector42);
m_tabFts->enableAll();
m_participants.resize(6);
m_participants[0].participantId = 20;
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 = m_buildingId;
m_participants[0].roomId = m_roomId;
m_participants[1].participantId = 21;
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 = m_buildingId;
m_participants[1].roomId = m_roomId;
m_participants[2].participantId = 22;
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 = m_buildingId;
m_participants[2].roomId = m_roomId;
m_participants[3].participantId = 23;
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 = m_buildingId;
m_participants[3].roomId = m_roomId;
m_participants[4].participantId = 24;
m_participants[4].participantTypeId = equipmentTypeIdVehicle;
m_participants[4].equipmentNumber = 64;
m_participants[4].relX = 10;
m_participants[4].relY = 30;
m_participants[4].partyId = 2;
m_participants[4].buildingId = m_buildingId;
m_participants[4].roomId = m_roomId;
m_participants[5].participantId = 25;
m_participants[5].participantTypeId = equipmentTypeIdVehicle;
m_participants[5].equipmentNumber = 65;
m_participants[5].relX = 1;
m_participants[5].relY = 3;
m_participants[5].partyId = 2;
m_participants[5].buildingId = m_buildingId;
m_participants[5].roomId = m_roomId;
return bRet;
}
void CesTestsSmart::startTest()
{
INFO_LOG(m_logger) << "startTest m_testId=" << m_testId;
if (m_testId <= 1) // 1 SMART
{
m_explosionSingle = m_housePos.geographic(5, 5);
QTimer::singleShot(0, this, &CesTestsSmart::tryCreateParticipant);
QTimer::singleShot(250, this, &CesTestsSmart::tryCreateParticipantPosition);
QTimer::singleShot(500, this, &CesTestsSmart::tryCreateParticipantPosition);
QTimer::singleShot(1000, this, &CesTestsSmart::tryCreateParticipantPosition);
QTimer::singleShot(1500, this, &CesTestsSmart::tryCreateParticipantPosition);
QTimer::singleShot(2000, this, &CesTestsSmart::tryCreateParticipantPosition);
QTimer::singleShot(2500, this, &CesTestsSmart::tryCreateParticipantPosition);
QTimer::singleShot(3000, this, &CesTestsSmart::tryCreateTypeVehicle);
QTimer::singleShot(3500, this, &CesTestsSmart::tryCreateTypeSoldier);
QTimer::singleShot(4000, this, &CesTestsSmart::tryCreateChargeType);
QTimer::singleShot(4500, this, &CesTestsSmart::tryCreateAesItemViewSingleExplosion);
QTimer::singleShot(5000, this, &CesTestsSmart::tryCreatePrepareExplosionSingle);
QTimer::singleShot(5500, this, &CesTestsSmart::tryCreateExplosionSingle);
QTimer::singleShot(6000, this, &CesTestsSmart::checkParticipantEvent);
}
else
{
ERROR_LOG(m_logger) << "Unknown test id = " << m_testId;
failExit();
}
QTimer::singleShot(8000, this, &CesTestsSmart::failExit);
}
// /////////////////////////////////////////////////////
/// \brief CesTestsSmart::tryCreateDynamicParticipantData
///
void CesTestsSmart::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 CesTestsSmart::tryCreateParticipantPosition()
{
ParticipantManagement::ParticipantPosition pp;
const qint64 time = QDateTime::currentMSecsSinceEpoch();
const rti::core::int64 posTime = static_cast<rti::core::int64>(time);
QPointF posF = m_housePos.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 CesTestsSmart::tryCreateParticipant()
{
ParticipantManagement::Participant pt;
pt.id(21);
pt.equipmentNumber(61);
DEBUG_LOG(m_logger) << "Publishing Participant";
if (!m_ppmDts->publish(pt))
{
ERROR_LOG(m_logger) << "Error requesting create Participant";
failExit();
}
}
void CesTestsSmart::checkParticipantEvent()
{
INFO_LOG(m_logger) << "checkParicipantEvent m_cesDtc->participantEvents().size() =" << m_cesDtc->participantEvents().size();
m_cesDtc->waitForHistoricalDataParticipantEvent();
CentralEffectSimulation::ParticipantEvent participantEvent0 = m_cesDtc->participantEvent(0);
CentralEffectSimulation::ParticipantEvent participantEvent1 = m_cesDtc->participantEvent(1);
for ( int i = 0; i < m_cesDtc->participantEvents().size(); i++)
{
CentralEffectSimulation::ParticipantEvent participantEvent = m_cesDtc->participantEvent(i);
INFO_LOG(m_logger) << "Recived ParicipantEvent equipmentNumber:"<<participantEvent.equipmentNumber()
<< " eventType="<<participantEvent.eventTypeId();
}
switch (m_testId)
{
case 1:
if ( participantEvent0.eventTypeId()==ProjectDataManagement::EventType::HitEffectSimulation
&& participantEvent1.eventTypeId()==ProjectDataManagement::EventType::HitEffectSimulation)
{
ExitSuccess();
}
break;
default:
// nothing
ERROR_LOG(m_logger) << "Error checkParticipantEvent";
failExit();
break;
}
}
// /////////////////////////////////////////////////////
/// \brief CesTestsSmart::tryCreateTypeVehicle
///
void CesTestsSmart::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 CesTestsSmart::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 CesTestsSmart::tryCreateAesItemViewSingleExplosion()
{
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::AtExplosionAreaSingleExplosions);
iv.partyId(5);
QPointF bl = m_housePos.geographic(-10, -10);
QPointF tr = m_housePos.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_housePos.geographic(-10, -10));
setPos(iv.form(), m_housePos.geographic(0, 0));
setPos(iv.form(), m_housePos.geographic(5, 5));
setPos(iv.form(), m_housePos.geographic(-10, 10));
setPos(iv.form(), m_housePos.geographic(-10, 20));
setPos(iv.form(), m_housePos.geographic(-10, 30));
DEBUG_LOG(m_logger) << "Publishing AesItemView";
if (!m_aesDts->publish(iv))
{
ERROR_LOG(m_logger) << "Error requesting create AesItemViewSingleExplosions";
failExit();
}
}
void CesTestsSmart::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 CesTestsSmart::tryCreatePrepareExplosionSingle()
{
INFO_LOG(m_logger) << "trying to send ExplosionSingle";
AreaEffectSimulation::ExplosionSingle es;
const qint64 time = QDateTime::currentMSecsSinceEpoch();
const rti::core::int64 esTime = static_cast<rti::core::int64>(time);
es.id(m_aesItemId);
es.participantId(m_originatorParticipantId); // In ddsview <not set>
es.effectStateId(AreaEffectSimulation::AesEffectState_def::EsPrepared);
es.name("Smart tryCreatePrepareExplosionSingle");
es.impactPosition(Core::GeoPosition2D(m_explosionSingle.x(), m_explosionSingle.y()));
es.sampleTime(esTime);
es.chargeStruct().chargeTypeId(m_chargeTypeId);
es.isCentral(true);
es.effectStart ( QDateTime::currentMSecsSinceEpoch() + 2000);
DEBUG_LOG(m_logger) << "Publishing ExplosionSingle";
if (!m_aesDts->publish(es))
{
ERROR_LOG(m_logger) << "Error publish ExplosionArea";
failExit();
}
}
void CesTestsSmart::tryCreateExplosionSingle()
{
INFO_LOG(m_logger) << "trying to send ExplosionSingle";
AreaEffectSimulation::ExplosionSingle es;
const qint64 time = QDateTime::currentMSecsSinceEpoch();
const rti::core::int64 esTime = static_cast<rti::core::int64>(time);
es.id(m_aesItemId);
es.name("Smart tryCreateExplosionSingle");
es.participantId(m_originatorParticipantId); // In ddsview <not set>
es.effectStateId(AreaEffectSimulation::AesEffectState_def::EsActivated);
es.effectStart ( QDateTime::currentMSecsSinceEpoch() + 2000);
es.isCentral(true);
es.impactPosition(Core::GeoPosition2D(m_explosionSingle.x(), m_explosionSingle.y()));
es.sampleTime(esTime);
es.chargeStruct().chargeTypeId(m_chargeTypeId);
DEBUG_LOG(m_logger) << "Publishing ExplosionSingle";
if (!m_aesDts->publish(es))
{
ERROR_LOG(m_logger) << "Error publish ExplosionArea";
failExit();
}
}
Core::FunctionReplyObject CesTestsSmart::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 CesTestsSmart::onSendCesHitRequest(const rti::core::SampleIdentity &cookie,
const TrainingAreaBase::SendCesHitRequest &request)
{
// debug und co
qint64 msecs = (qint64) request.effectTime();
QDateTime dateTime;
dateTime.setMSecsSinceEpoch(msecs);
DEBUG_LOG(m_logger) << "onSendCesHitRequest" << "\n"
<< " request.aesId() = " << request.aesId() << "\n"
<< " request.chargeTypeId() = " << request.chargeTypeId() << "\n"
<< " request.equipmentNumber() = " << request.equipmentNumber() << "\n"
<< " request.originatorEquipmentNumber() = " << request.originatorEquipmentNumber() << "\n"
<< " request.originatorPosition() = " << request.position() << "\n"
<< " request.effectTime()= " << request.effectTime() << " "
<< dateTime.toString(QStringLiteral("dd.MM.yy - hh:mm:ss.zzz")) << "\n"
<< " request.remainEffectPercent() = " << request.remainEffectPercent();
m_tabFts->sendCesHitReply(cookie, Core::FunctionReplyObject(request.equipmentNumber()));
ExitSuccess();
}
void CesTestsSmart::failExit()
{
DEBUG_LOG(m_logger) << "FailExit";
m_bTestsSuccessful = false;
QTimer::singleShot(50, qApp, QCoreApplication::quit);
}
void CesTestsSmart::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::CesTestsSmart> cesTests(new CentralEffectSimulation::CesTestsSmart);
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;
}