Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,396 @@
|
||||
/**
|
||||
* Msg Function Topic Module Test
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include "ces_tests_booby_trap.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 &
|
||||
* ./cesTestsBoobyTrap -t 1 -e 42 // Anstarten des Modul-Tests
|
||||
*/
|
||||
|
||||
namespace CentralEffectSimulation
|
||||
{
|
||||
|
||||
CesTestsBoobyTrap::CesTestsBoobyTrap(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_bTestsSuccessful(true)
|
||||
//, m_refPos(LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32UMD8000090000")))
|
||||
, m_refPos(LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32UMD9387781202")))
|
||||
, m_logger(getLogger("CesTest"))
|
||||
, m_testId(0)
|
||||
, m_participantIndex(0)
|
||||
, m_id(20)
|
||||
, m_equipmentNumber(60)
|
||||
, m_DynamicParticipantIndex(0)
|
||||
, m_aesItemId(5)
|
||||
, m_chargeTypeId(252) // Verdeckte Ladung
|
||||
, m_countEventBoobyTrap(0)
|
||||
{}
|
||||
|
||||
CesTestsBoobyTrap::~CesTestsBoobyTrap()
|
||||
{}
|
||||
|
||||
bool CesTestsBoobyTrap::init(int domainId, int exerciseId, int testId)
|
||||
{
|
||||
bool bRet = true;
|
||||
int equipmentTypeIdVehicle = 27;
|
||||
int equipmentTypeIdSoldier = 55; // 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->enableBoobyTrap();
|
||||
bRet &= m_aesDts->enableAesItemView();
|
||||
|
||||
m_cesDtc = CentralEffectSimulation::Interface::Dtc::create(m_ddsConnector42);
|
||||
bRet &= m_cesDtc->enableAll();
|
||||
bRet &= m_cesDtc->enableParticipantEvent();
|
||||
|
||||
m_cesFtc = CentralEffectSimulation::Interface::Ftc::create(m_ddsConnector42);
|
||||
bRet &= m_cesFtc->enableAll();
|
||||
|
||||
connect(m_cesDtc.get(), &CentralEffectSimulation::Interface::Dtc::participantEventChanged,
|
||||
this, &CesTestsBoobyTrap::onEventChanged);
|
||||
|
||||
m_participants.resize(3);
|
||||
m_participants[0].participantId = 126; // Secondary
|
||||
m_participants[0].participantTypeId = equipmentTypeIdSoldier;
|
||||
m_participants[0].equipmentNumber = 1002;
|
||||
m_participants[0].relX = 3;
|
||||
m_participants[0].relY = -6;
|
||||
m_participants[0].partyId = 4;
|
||||
m_participants[0].buildingId = 0;
|
||||
m_participants[0].roomId = 0;
|
||||
|
||||
m_participants[1].participantId = 125; // inside Building
|
||||
m_participants[1].participantTypeId = equipmentTypeIdSoldier;
|
||||
m_participants[1].equipmentNumber = 1001;
|
||||
m_participants[1].relX = 0;
|
||||
m_participants[1].relY = 0;
|
||||
m_participants[1].partyId = 4;
|
||||
m_participants[1].buildingId = 301;
|
||||
m_participants[1].roomId = 126;
|
||||
|
||||
m_participants[2].participantId = 24; // inside BoobyTrap
|
||||
m_participants[2].participantTypeId = equipmentTypeIdVehicle;
|
||||
m_participants[2].equipmentNumber = 3803;
|
||||
m_participants[2].relX = 3;
|
||||
m_participants[2].relY = -6;
|
||||
m_participants[2].partyId = 2;
|
||||
m_participants[2].buildingId = 0;
|
||||
m_participants[2].roomId = 0;
|
||||
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
void CesTestsBoobyTrap::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(250, this, &CesTestsBoobyTrap::tryCreateParticipantPosition);
|
||||
QTimer::singleShot(500, this, &CesTestsBoobyTrap::tryCreateParticipantPosition);
|
||||
QTimer::singleShot(4500, this, &CesTestsBoobyTrap::tryCreateAesBoobyTrap);
|
||||
QTimer::singleShot(4500, this, &CesTestsBoobyTrap::tryCreateAesItemViewBoobyTrap);
|
||||
QTimer::singleShot(6000, this, &CesTestsBoobyTrap::tryCreateParticipantPosition);
|
||||
QTimer::singleShot(7500, this, &CesTestsBoobyTrap::tryCreateAesItemViewBoobyTrapSecondary);
|
||||
|
||||
QTimer::singleShot(8000, this, &CesTestsBoobyTrap::checkParticipantEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Unknown test id = " << m_testId;
|
||||
failExit();
|
||||
}
|
||||
QTimer::singleShot(8000, this, &CesTestsBoobyTrap::failExit);
|
||||
}
|
||||
|
||||
// /////////////////////////////////////////////////////
|
||||
/// \brief CesTestsSmart::tryCreateParticipantPosition
|
||||
///
|
||||
void CesTestsBoobyTrap::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[" << m_participantIndex << "]"
|
||||
<< " pos=" << posF.x() << "/" << posF.y();
|
||||
if (!m_ppmDts->publish(pp))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error requesting create ParticipantPosition";
|
||||
failExit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CesTestsBoobyTrap::checkParticipantEvent()
|
||||
{
|
||||
INFO_LOG(m_logger) << "checkParicipantEvent";
|
||||
m_cesDtc->waitForHistoricalDataParticipantEvent();
|
||||
|
||||
switch (m_testId)
|
||||
{
|
||||
case 1:
|
||||
if ( m_countEventBoobyTrap == 2)
|
||||
{
|
||||
INFO_LOG(m_logger) << "ExitSuccess";
|
||||
ExitSuccess();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// nothing
|
||||
failExit();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void setPos(std::vector<Core::GeoPosition> &cont, const QPointF &pos)
|
||||
{
|
||||
cont.emplace_back(Core::GeoPosition(pos.x(), pos.y(), 0.0));
|
||||
}
|
||||
|
||||
void CesTestsBoobyTrap::tryCreateAesItemViewBoobyTrap()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to send AesItemView tryCreateAesItemViewBoobyTrap";
|
||||
|
||||
AreaEffectSimulation::AesItemView iv;
|
||||
iv.effectStateId(AreaEffectSimulation::AesEffectState_def::EsActivated);
|
||||
|
||||
iv.aesItemId(m_aesItemId);
|
||||
iv.id(m_aesItemId);
|
||||
iv.aesTypeId(AreaEffectSimulation::AesType::AtBoobyTrap);
|
||||
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 tryCreateAesItemViewBoobyTrap";
|
||||
failExit();
|
||||
}
|
||||
}
|
||||
|
||||
void CesTestsBoobyTrap::tryCreateAesBoobyTrap()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to send AesItemView tryCreateAesBoobyTrap";
|
||||
|
||||
AreaEffectSimulation::BoobyTrap iv;
|
||||
iv.effectStateId(AreaEffectSimulation::AesEffectState_def::EsActivated);
|
||||
|
||||
iv.id(m_aesItemId);
|
||||
iv.partyId(5);
|
||||
QPointF bl = m_refPos.geographic(10, 10);
|
||||
iv.impactPosition(Core::GeoPosition2D(bl.x(), bl.y()));
|
||||
iv.chargeStruct().chargeTypeId(m_chargeTypeId);
|
||||
iv.sampleTime(QDateTime::currentMSecsSinceEpoch());
|
||||
iv.isCentral(true);
|
||||
iv.impactRadius(10.0);
|
||||
iv.triggerRadius(2.0);
|
||||
iv.centralAngle(90.0);
|
||||
iv.effectDuration(3600000);
|
||||
|
||||
iv.effectStart ( QDateTime::currentMSecsSinceEpoch() + 2000);
|
||||
|
||||
|
||||
DEBUG_LOG(m_logger) << "Publishing AesItemView";
|
||||
if (!m_aesDts->publish(iv))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error requesting create tryCreateBoobyTrap";
|
||||
failExit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CesTestsBoobyTrap::tryCreateAesItemViewBoobyTrapSecondary()
|
||||
{
|
||||
INFO_LOG(m_logger) << "trying to send AesItemView tryCreateAesItemViewBoobyTrapSecondary";
|
||||
|
||||
AreaEffectSimulation::AesItemView iv;
|
||||
iv.effectStateId(AreaEffectSimulation::AesEffectState_def::EsActivated);
|
||||
|
||||
iv.aesItemId(m_aesItemId);
|
||||
iv.id(m_aesItemId+1);
|
||||
iv.aesTypeId(AreaEffectSimulation::AesType::AtBoobyTrapSecondary);
|
||||
iv.partyId(5);
|
||||
QPointF bl = m_refPos.geographic(-20, -20);
|
||||
QPointF tr = m_refPos.geographic(40, 40);
|
||||
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(-20, -20));
|
||||
setPos(iv.form(), m_refPos.geographic(-20, 20));
|
||||
setPos(iv.form(), m_refPos.geographic( 50, 50));
|
||||
setPos(iv.form(), m_refPos.geographic( 50, -20));
|
||||
|
||||
DEBUG_LOG(m_logger) << "Publishing AesItemView";
|
||||
if (!m_aesDts->publish(iv))
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Error requesting create AesItemViewBoobyTrapSecondary";
|
||||
failExit();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CesTestsBoobyTrap::onEventChanged(const CentralEffectSimulation::ParticipantEvent &eventData, DataModification modType)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onParticipantEventChanged participantId=" << eventData.participantId()
|
||||
<< " eventType=" << eventData.eventTypeId()
|
||||
<< " aesItemId=" << eventData.aesItemId();
|
||||
if (modType == DataModification::eRemoved ||
|
||||
modType == DataModification::eModified)
|
||||
return;
|
||||
if (eventData.eventTypeId() == ProjectDataManagement::EventType_def::HitMine)
|
||||
{
|
||||
m_countEventBoobyTrap ++;
|
||||
DEBUG_LOG(m_logger) << "m_countEventBoobyTrap=" << m_countEventBoobyTrap
|
||||
<< " eventData.aesItemId()=" << eventData.aesItemId()
|
||||
<< " eventData.participantId()=" << eventData.participantId();
|
||||
}
|
||||
}
|
||||
|
||||
Core::FunctionReplyObject CesTestsBoobyTrap::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 CesTestsBoobyTrap::failExit()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "FailExit";
|
||||
m_bTestsSuccessful = false;
|
||||
QTimer::singleShot(200, qApp, QCoreApplication::quit);
|
||||
}
|
||||
|
||||
void CesTestsBoobyTrap::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::CesTestsBoobyTrap> cesTests(new CentralEffectSimulation::CesTestsBoobyTrap);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user