416 lines
13 KiB
C++
Executable File
416 lines
13 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)
|
|
, m_logger(getLogger("TgtTests"))
|
|
{}
|
|
|
|
// ------------------------------------------------------------------
|
|
bool TgtTests::init(int domainId, int testId, int operatorId, int shootbackAreaId)
|
|
{
|
|
INFO_LOG(m_logger) << "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(m_logger) << "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(m_logger) << "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(m_logger) << "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(m_logger) << "Error requesting remove Shootback Area";
|
|
failExit();
|
|
}
|
|
|
|
}
|
|
|
|
// ------------------------------------------------------------------
|
|
void TgtTests::tryRequestTechnicalState()
|
|
{
|
|
INFO_LOG(m_logger) << "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(m_logger) << "Error requesting create data";
|
|
failExit();
|
|
}
|
|
} // tryRequestTechnicalState
|
|
|
|
// ------------------------------------------------------------------
|
|
void TgtTests::tryConfigureTargetMode()
|
|
{
|
|
INFO_LOG(m_logger) << "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(m_logger) << "Error requesting create data";
|
|
failExit();
|
|
}
|
|
} // tryConfigureTargetMode
|
|
|
|
// ------------------------------------------------------------------
|
|
void TgtTests::tryConfigureTargetWeapon()
|
|
{
|
|
INFO_LOG(m_logger) << "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(m_logger) << "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(m_logger) << "Error publish targetData";
|
|
failExit();
|
|
}
|
|
}
|
|
|
|
// ------------------------------------------------------------------
|
|
void TgtTests::tryCreateParticipant()
|
|
{
|
|
INFO_LOG(m_logger) << "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(m_logger) << "Publishing Participant";
|
|
if (!m_dtsPpm->publish(participant))
|
|
{
|
|
ERROR_LOG(m_logger) << "Error publish Participant";
|
|
failExit();
|
|
}
|
|
m_participantIndex++;
|
|
} // tryCreateParticipant
|
|
|
|
|
|
// ------------------------------------------------------------------
|
|
void TgtTests::onShootbackAreaModifyReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
INFO_LOG(m_logger) << "onShootbackAreaModifyReply on id " << replyObject.id()
|
|
<< " and error = " << replyObject.error();
|
|
if (replyObject.error())
|
|
{
|
|
ERROR_LOG(m_logger) << "Error onShoobackAreaModifyReply - aborting";
|
|
failExit();
|
|
}
|
|
|
|
ExitSuccess();
|
|
|
|
} // onShoobackAreaModifyReply
|
|
|
|
// ------------------------------------------------------------------
|
|
void TgtTests::onShootbackAreaRemoveReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
INFO_LOG(m_logger) << "onShootbackAreaModifyReply on id " << replyObject.id()
|
|
<< " and error = " << replyObject.error();
|
|
if (replyObject.error())
|
|
{
|
|
ERROR_LOG(m_logger) << "Error onShootbackAreaRemoveReply - aborting";
|
|
failExit();
|
|
}
|
|
|
|
ExitSuccess();
|
|
} // onShootbackAreaRemoveReply
|
|
|
|
// ------------------------------------------------------------------
|
|
void TgtTests::onConfigureTargetReply(const Core::FunctionReplyObject &replyObject)
|
|
{
|
|
INFO_LOG(m_logger) << "onConfigureTargetReply, error = " << replyObject.error();
|
|
if (replyObject.error())
|
|
{
|
|
ERROR_LOG(m_logger) << "Error ConfigureTargets - aborting";
|
|
failExit();
|
|
}
|
|
} // onConfigureTargetReply
|
|
|
|
// ------------------------------------------------------------------
|
|
void TgtTests::checkAlarm()
|
|
{
|
|
INFO_LOG(m_logger) << "checkAlarm";
|
|
m_dtcTgt->waitForHistoricalDataTargetConfig();
|
|
//qint32 id = 0;
|
|
/*TargetManagement::Notification notification = m_dtcTgt->notification(id);
|
|
INFO_LOG(m_logger) << "Recived TargetManagement::Notification: " << notification
|
|
<< " testId: " << m_testId;
|
|
|
|
switch (m_testId)
|
|
{
|
|
case 1:
|
|
case 2:
|
|
case 3:
|
|
INFO_LOG(m_logger) << "ExitSuccess";
|
|
ExitSuccess();
|
|
break;
|
|
default:
|
|
// nothing
|
|
INFO_LOG(m_logger) << "failExit";
|
|
failExit();
|
|
break;
|
|
}*/
|
|
}
|
|
|
|
// ------------------------------------------------------------------
|
|
void TgtTests::failExit()
|
|
{
|
|
m_bTestsSuccessful = false;
|
|
QTimer::singleShot(0, qApp, &QCoreApplication::quit);
|
|
} // failExit
|
|
|
|
// ------------------------------------------------------------------
|
|
void TgtTests::ExitSuccess()
|
|
{
|
|
DEBUG_LOG(m_logger) << "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
|
|
|