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

+216
View File
@@ -0,0 +1,216 @@
/**
* Msg Function Topic Module Test
* $Id: ces_tests_gas_pipe.cpp 53032 2021-03-08 14:20:54Z diers $
* $HeadURL: svn://slssvn/TDS/branches/product/features/3dws_devel/Lts/Services/FeedGeoJson/ModuleTests/ces_tests_gas_pipe.cpp $
* $Author: diers $
*/
#include "feedGeoJson.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)
* ./svcFeedGeoJson -e 42 &
* ./cesTestsGasPipe -t 1 -e 42 // Gas Pipe explosion
*/
namespace FeedGeoJson
{
FeedGeoJson::FeedGeoJson(QObject *parent)
: QObject(parent)
, m_bTestsSuccessful(true)
, m_refPos(LtsCoordTrans::UtmCoordinate::fromMgrs(QStringLiteral("32UMD8000090000")))
, m_logger(getLogger("CesTestGasPipe"))
{}
FeedGeoJson::~FeedGeoJson()
{}
bool FeedGeoJson::init(const int domainId, const int exerciseId, WebSocketServer &webSocketServer)
{
m_websocketServer = &webSocketServer;
bool bRet = true;
INFO_LOG(m_logger) << "init begin";
m_ddsConnector42 = std::make_shared<DDSConnector::DdsConnector>(domainId, IDL::PartitionType::Exercise, exerciseId);
m_ddsConnector42->init();
m_ddsConnector42->initPublisherSubscriber();
m_pdmDtc = ProjectDataManagement::Interface::Dtc::create(m_ddsConnector42);
bRet &= m_pdmDtc->enableChargeType();
m_ppmDtc = ParticipantManagement::Interface::Dtc::create(m_ddsConnector42);
bRet &= m_ppmDtc->enableParticipantPosition();
bRet &= m_ppmDtc->enableParticipant();
bRet &= m_ppmDtc->enableDynamicParticipantData();
bRet &= m_ppmDtc->enableType();
m_aesDtc = AreaEffectSimulation::Interface::Dtc::create(m_ddsConnector42);
bRet &= m_aesDtc->enableExplosionSingle();
bRet &= m_aesDtc->enableAesItemView();
bRet &= m_aesDtc->enableTriggeredImpacts();
connect(m_ppmDtc.get(), &ParticipantManagement::Interface::Dtc::participantPositionChanged,
this, &FeedGeoJson::onParticipantPositionChanged);
NOTICE_LOG(m_logger) << "END init";
return bRet;
}
QString FeedGeoJson::getGeoJsonPosition(const ParticipantManagement::ParticipantPosition &data)
{
NOTICE_LOG(m_logger) << "sendPositionToGeoJson participantId=" << data.participantId();
QString message = QStringLiteral("{ 'type': 'FeatureCollection',\
'features': [\
{ 'type': 'Feature',\
'geometry': {'type': 'Point', 'coordinates': [102.0, 0.5]},\
'properties': {'prop0': 'value0'}\
},\
{ 'type': 'Feature',\
'geometry': {\
'type': 'LineString',\
'coordinates': [\
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]\
]\
},\
'properties': {\
'prop0': 'value0',\
'prop1': 0.0\
}¸\
},\
{ 'type': 'Feature',\
'geometry': {\
'type': 'Polygon',\
'coordinates': [\
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],\
[100.0, 1.0], [100.0, 0.0] ]\
]\
},\
'properties': {\
'prop0': 'value0',\
'prop1': {'this': 'that'}\
}\
}\
]\
}");
return message;
}
void FeedGeoJson::onParticipantPositionChanged(const ParticipantManagement::ParticipantPosition &data, DataModification modType)
{
NOTICE_LOG(m_logger) << "onParticipantPositionChanged: " << data;
DEBUG_LOG(m_logger) << "onParticipantPositionChanged: " << data;
if (modType == DataModification::eRemoved)
{
DEBUG_LOG(m_logger) << "m_participantsOutsideMap.remove participantId: " << data.participantId();
//m_participantsOutsideMap.remove(data.participantId());
}
else
{
DEBUG_LOG(m_logger) << "Handle ParticipantPosition";
QString posGeoJson = getGeoJsonPosition(data);
m_websocketServer->sendMessage(posGeoJson);
}
}
void FeedGeoJson::onDynamicParticipantDataChanged(const ParticipantManagement::DynamicParticipantData &data, DataModification modType)
{
DEBUG_LOG(m_logger) << "onDynamicParticipantDataChanged";
if (modType == DataModification::eRemoved)
return;
}
void FeedGeoJson::failExit()
{
DEBUG_LOG(m_logger) << "FailExit";
m_bTestsSuccessful = false;
QTimer::singleShot(50, qApp, QCoreApplication::quit);
}
void FeedGeoJson::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("p") << QLatin1String("websocket port")
, QLatin1String("Port")
, QLatin1String("Default: 12345 (all tests)")
, QLatin1String("12345")
});
}
int exerciseId() const { return isSet(QLatin1String("e")) ? value(QLatin1String("e")).toInt() : -1; }
int port() const { return isSet(QLatin1String("p")) ? value(QLatin1String("p")).toInt() : -1; }
};
// ------------------------------------------------------------------
int main(int argc, char **argv)
{
NGLCoreApplication app(argc, argv);
app.createLogger("FGJ", "log4cxx_fgj.props");
fprintf(stderr, "Start Feed GeoJson Service\n");
CmdLineParser options;
if (!options.init())
{
fprintf(stderr, "no exercise ID abailable\n ./feedGeoJson -e <exerciseId>\n");
return -1;
}
fprintf(stderr, "./feedGeoJson -e %d -p %d (exerciseId=%d, Websocket Port=%d)\n", options.exerciseId(),options.port(), options.exerciseId(),options.port());
WebSocketServer webSocketServer(options.port()); // Listening on port 12345
int iRet = -1;
{
std::unique_ptr<FeedGeoJson::FeedGeoJson> cesTests(new FeedGeoJson::FeedGeoJson);
if (!cesTests->init(options.domainId(), options.exerciseId(), webSocketServer))
return iRet;
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;
}