Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Services/TargetManagement/ModuleTests/tgt_tests.cpp
T
torstenandCopilot b774f4035c Qt6 Migration: DDS-Stubs, Logger-Fixes, Export-Header Korrekturen
- NGL_ADD_LIBRARY2: 87 CMakeLists.txt konvertiert für Export-Header Generierung
- 44 Export-Header Include-Pfade korrigiert (_export.h)
- 81 DDS-Stub-Header generiert (*_dtc.h, *_fts.h, *_dts.h, *_ftc.h)
- INGLLogger: Duplikat gelöscht, m_logger Member entfernt, variadische Makros
- Q_FUNC_INFO Redefinition behoben (Qt6 definiert bereits)
- FATAL_LOG Makro hinzugefügt
- InfrastructureManagement DDS-Stubs (ism.hpp, ism_enums.hpp, ism_ftc.h)
- FilterManagement DDS-Stubs (flt_ftc.h, flt_dts.h)
- AreaEffectSimulation DDS-Stubs (aes.hpp, aes_enums.hpp)
- SymbolAppearance Klasse vollständig definiert mit content() Methode
- BuildingComponentFilter Klasse definiert mit Copy-Konstruktor
- Ftc Factory: nullptr Return (abstract class)
- AesFilter Klasse in aes.hpp hinzugefügt
- Dtc Klasse in ppm.hpp mit participantChanged Signal
- AesType Enum: alle 15 At* Werte definiert
- AesEffectState_def: EsReceived hinzugefügt
- DataModification Enum: eAdded/eModified/eRemoved
- function_reply_object.h → core_types.h Include-Pfad (72 Dateien)
- Enum-Class-Streaming Template-Operator in INGLLogger.h
- ism_mounting_point.h: QImage → QtGui/QImage, QGuiApplication/QScreen
- ism_data_plugin_interface.h: QSet Include, Include-Reihenfolge
- QRegExp → QRegularExpression in tpm_js_parser.cpp
- .underlying() Aufrufe zu direktem Enum-Vergleich korrigiert
- Include-Pfade: aes.hpp in symbol_appearance_settings_impl.h und aes_display_filter_impl.h

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-08-19 06:06:24 +02:00

415 lines
12 KiB
C++
Executable File

/**
* Msg Function Topic Module Test
* $Id$
* $HeadURL$
* $Author$
*/
#include "tgt_tests.h"
#include <nglapplication/nglcoreapplication.h>
#include <LtsCommandLineParser/LtsCommandLineParser.h>
#include <QTimer>
#include <QDateTime>
#include <QJsonObject>
#include <QJsonDocument>
/* ----------------------------------------------------------------------------------
* Ablauf:
* ----------------------------------------------------------------------------------
* Anzeigen der Konfiguration am Arbeitsplatz
- Teilnehmerfenster eines Targets enthält Bedienfeld zum Konfigurieren der Targets
- Bei der Anwahl des Fensters wird die aktuelle Konfiguration vom Target abgefragt.
- Das Bedienfenster sendet den Request configureTargetRequest
- Der Service TargetManager empfaengt den Request und sendet ans TAB SendTargetDataRequest.
- TAB sendet den Response an das Target Management.
- TAB sendet die Konfigurationsdaten an das TargetManagement. (TAB::TargetData)
- Das TargetManagement sendet sie an das Plugin weiter. (TGT::TargetConfig)
- Das Plugin zeigt die Konfiguration an und gibt nun die Auswahl von Waffe und Mode frei
- Fuer den Mode und die Waffe werden je ein Request vom Plugin an das TargetManagement geschickt.
- Das TargetManagement leitet es an TAB weiter.
- TAB leitet es weiter und im Gutfall kommt die Antwort vom Target TrainingAreaBase::TargetData
- Der Service Target Management empfaengt es und sendet an den Arbeitsplatz den Data-Topic
TargetManagement::Target Config
- Der Arbeitsplatz zeigt die Konfiguration an.
*
*/
/* ----------------------------------------------------------------------------------
* HOW TO RUN THE TESTS
* ----------------------------------------------------------------------------------
*
* Preconditions: Nothing
*
* Start services: (SV)
* ./svcTargetManagement -e 42
* ./tgtTests -t 1 -e 42 // Configure Target RequestTechnicalState
* ./tgtTests -t 2 -e 42 -o 14 // Add ShootbackArea
* ./tgtTests -t 3 -e 42 -s 1 -o 14 // Update ShootbackArea with id 1
* ./tgtTests -t 4 -e 42 -s 1 -o 14 // Remove ShootbackArea with id 1
*/
// ------------------------------------------------------------------
namespace TargetManagement
{
TgtTests::TgtTests(QObject *parent)
: QObject(parent)
{}
// ------------------------------------------------------------------
bool TgtTests::init(int domainId, int testId, int operatorId, int shootbackAreaId)
{
INFO_LOG() << "init begin";
m_testId = testId;
m_operatorId = operatorId;
m_participantIndex = 0;
m_shootbackAreaId = shootbackAreaId;
m_ddsConnector.reset(new DDSConnector::DdsConnector(domainId, IDL::PartitionType::Any));
if (!m_ddsConnector->init())
return false;
m_ddsConnector->initPublisherSubscriber();
m_ftcTgt = TargetManagement::Interface::Ftc::create(m_ddsConnector);
bool bRet = m_ftcTgt->enableAll();
m_dtcTgt = TargetManagement::Interface::Dtc::create(m_ddsConnector);
bRet &= m_dtcTgt->enableAll();
m_dtsPpm = ParticipantManagement::Interface::Dts::create(m_ddsConnector);
bRet &= m_dtsPpm->enableAll();
m_dtsTab = TrainingAreaBase::Interface::Dts::create(m_ddsConnector);
bRet &= m_dtsTab->enableAll();
return bRet;
} // init
// ------------------------------------------------------------------
void TgtTests::startTest()
{
INFO_LOG() << "startTest m_testId=" << m_testId;
if (m_testId == 1) // Send FTC ConfigureAlarms and EEM Event
{
QTimer::singleShot(0, this, &TgtTests::tryCreateParticipant);
QTimer::singleShot(100, this, &TgtTests::tryRequestTechnicalState);
QTimer::singleShot(200, this, &TgtTests::tryConfigureTargetMode);
QTimer::singleShot(400, this, &TgtTests::tryConfigureTargetWeapon);
QTimer::singleShot(600, this, &TgtTests::tryCreateTargetData);
QTimer::singleShot(800, this, &TgtTests::checkAlarm);
}
else if (m_testId == 2) // Create ShootbackArea
{
QTimer::singleShot(0, this, &TgtTests::tryCreateShootbackArea);
}
else if (m_testId == 3) // Update ShootbackArea
{
QTimer::singleShot(0, this, &TgtTests::tryUpdateShootbackArea);
}
else if (m_testId == 4) // Remove ShootbackArea
{
QTimer::singleShot(0, this, &TgtTests::tryRemoveShootbackArea);
}
QTimer::singleShot(5000, this, &TgtTests::failExit);
} // startTest
// ------------------------------------------------------------------
void TgtTests::tryCreateShootbackArea()
{
ShootbackAreaModifyRequest request;
request.id(0); // force create
request.name("Test ShootbackArea");
double lon = 0.15530364;
double lat = 0.92601523;
request.position().lon(lon);
request.position().lat(lat);
request.width(100);
request.height(100);
if (!m_ftcTgt->shootbackAreaModifyRequest(request, this))
{
ERROR_LOG() << "Error requesting create Shootback Area";
failExit();
}
}
// ------------------------------------------------------------------
void TgtTests::tryUpdateShootbackArea()
{
ShootbackAreaModifyRequest request;
request.id(m_shootbackAreaId); // update specific id
request.name("Test ShootbackArea Updated");
if (!m_ftcTgt->shootbackAreaModifyRequest(request, this))
{
ERROR_LOG() << "Error requesting modify Shootback Area";
failExit();
}
}
// ------------------------------------------------------------------
void TgtTests::tryRemoveShootbackArea()
{
ShootbackAreaRemoveRequest request;
request.id(m_shootbackAreaId); // remove specific id
if (!m_ftcTgt->shootbackAreaRemoveRequest(request, this))
{
ERROR_LOG() << "Error requesting remove Shootback Area";
failExit();
}
}
// ------------------------------------------------------------------
void TgtTests::tryRequestTechnicalState()
{
INFO_LOG() << "trying to send createRequest Operator Message";
ConfigureTargetRequest request;
request.id(0);
request.participantId(5);
request.tgtCommand(TargetManagement::TgtCommand_def::RequestTechnicalState);
if (!m_ftcTgt->configureTargetRequest(request, this))
{
ERROR_LOG() << "Error requesting create data";
failExit();
}
} // tryRequestTechnicalState
// ------------------------------------------------------------------
void TgtTests::tryConfigureTargetMode()
{
INFO_LOG() << "trying to send createRequest Operator Message";
ConfigureTargetRequest request;
request.id(0);
request.participantId(5);
TargetManagement::Mode mode = TargetManagement::Mode_def::ShootBack;
request.tgtCommand(TargetManagement::TgtCommand_def::SetMode);
request.mode(mode);
if (!m_ftcTgt->configureTargetRequest(request, this))
{
ERROR_LOG() << "Error requesting create data";
failExit();
}
} // tryConfigureTargetMode
// ------------------------------------------------------------------
void TgtTests::tryConfigureTargetWeapon()
{
INFO_LOG() << "trying to send createRequest Operator Message";
ConfigureTargetRequest request;
request.id(0);
request.participantId(5);
request.tgtCommand(TargetManagement::TgtCommand_def::SetWeapon);
request.weapon(1); // AK47
if (!m_ftcTgt->configureTargetRequest(request, this))
{
ERROR_LOG() << "Error requesting create data";
failExit();
}
} // tryConfigureTargetWeapon
// Response from Target
// ------------------------------------------------------------------
void TgtTests::tryCreateTargetData()
{
TrainingAreaBase::TargetData targetData;
targetData.equipmentNumber(1001);
// Shoot Back - AK 47
targetData.payload() = {0x65, 0x01, 0x01, 0xae, 0xff, 0x00 };
if (!m_dtsTab->publish(targetData))
{
ERROR_LOG() << "Error publish targetData";
failExit();
}
}
// ------------------------------------------------------------------
void TgtTests::tryCreateParticipant()
{
INFO_LOG() << "trying to create Participant index = " << m_participantIndex;
ParticipantManagement::Participant participant;
participant.id(5);
participant.superiorId(0);
participant.inferiorIds().resize(2);
participant.inferiorIds().at(0) = 2;
participant.inferiorIds().at(1) = 3;
participant.partyId(5);
participant.equipmentNumber(1001);
DEBUG_LOG() << "Publishing Participant";
if (!m_dtsPpm->publish(participant))
{
ERROR_LOG() << "Error publish Participant";
failExit();
}
m_participantIndex++;
} // tryCreateParticipant
// ------------------------------------------------------------------
void TgtTests::onShootbackAreaModifyReply(const Core::FunctionReplyObject &replyObject)
{
INFO_LOG() << "onShootbackAreaModifyReply on id " << replyObject.id()
<< " and error = " << replyObject.error();
if (replyObject.error())
{
ERROR_LOG() << "Error onShoobackAreaModifyReply - aborting";
failExit();
}
ExitSuccess();
} // onShoobackAreaModifyReply
// ------------------------------------------------------------------
void TgtTests::onShootbackAreaRemoveReply(const Core::FunctionReplyObject &replyObject)
{
INFO_LOG() << "onShootbackAreaModifyReply on id " << replyObject.id()
<< " and error = " << replyObject.error();
if (replyObject.error())
{
ERROR_LOG() << "Error onShootbackAreaRemoveReply - aborting";
failExit();
}
ExitSuccess();
} // onShootbackAreaRemoveReply
// ------------------------------------------------------------------
void TgtTests::onConfigureTargetReply(const Core::FunctionReplyObject &replyObject)
{
INFO_LOG() << "onConfigureTargetReply, error = " << replyObject.error();
if (replyObject.error())
{
ERROR_LOG() << "Error ConfigureTargets - aborting";
failExit();
}
} // onConfigureTargetReply
// ------------------------------------------------------------------
void TgtTests::checkAlarm()
{
INFO_LOG() << "checkAlarm";
m_dtcTgt->waitForHistoricalDataTargetConfig();
//qint32 id = 0;
/*TargetManagement::Notification notification = m_dtcTgt->notification(id);
INFO_LOG() << "Recived TargetManagement::Notification: " << notification
<< " testId: " << m_testId;
switch (m_testId)
{
case 1:
case 2:
case 3:
INFO_LOG() << "ExitSuccess";
ExitSuccess();
break;
default:
// nothing
INFO_LOG() << "failExit";
failExit();
break;
}*/
}
// ------------------------------------------------------------------
void TgtTests::failExit()
{
m_bTestsSuccessful = false;
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // failExit
// ------------------------------------------------------------------
void TgtTests::ExitSuccess()
{
DEBUG_LOG() << "SUCCESS";
m_bTestsSuccessful = true;
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
} // ExitSuccess
} // namespace
// ------------------------------------------------------------------
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("o") << QLatin1String("operatorId")
, QLatin1String("OperatorId")
, QLatin1String("Default: 10")
, QLatin1String("10")
});
addOption({ QStringList() << QLatin1String("s") << QLatin1String("shootbackAreaId")
, QLatin1String("shootbackAreaId")
, QLatin1String("Default: 0")
, QLatin1String("0")
});
}
int testId() const { return isSet(QLatin1String("t")) ? value(QLatin1String("t")).toInt() : 0; }
int operatorId() const { return isSet(QLatin1String("o")) ? value(QLatin1String("o")).toInt() : 10; }
int shootbackAreaId() const { return isSet(QLatin1String("s")) ? value(QLatin1String("s")).toInt() : 0; }
};
// ------------------------------------------------------------------
int main(int argc, char **argv)
{
NGLCoreApplication app(argc, argv);
app.createLogger("TGT", "log4cxx_tgt.props");
CmdLineParser options;
if (!options.init())
return -1;
int iRet = -1;
{
std::unique_ptr<TargetManagement::TgtTests> tgtTests(new TargetManagement::TgtTests);
if (!tgtTests->init(options.domainId(), options.testId(), options.operatorId(), options.shootbackAreaId()))
return iRet;
tgtTests->startTest();
STARTUP_LOG(app.baseLogger());
app.exec();
iRet = tgtTests->testsSuccessful() ? 0 : 1;
fprintf(stderr, "%d\n", iRet);
SHUTDOWN_LOG(app.baseLogger());
}
return iRet;
} // main