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

@@ -0,0 +1,32 @@
#
# monitoring of the target areas
# $Id$
# $HeadURL$
# $Author$
#
SET(SRCS
plugin.cpp
plugin.h
handler_participant_borderline.cpp
handler_participant_borderline.h
handler_simulated_movement.cpp
handler_simulated_movement.h
simulation_movement.cpp
simulation_movement.h
# logger.cpp
# logger.h
)
NGL_ADD_LIBRARY(AAR SV cesPluginBasic MODULE ${SRCS})
NGL_TARGET_LINK_LIBRARIES(cesPluginBasic
Qt5::Network
Qt5::Widgets
cesPluginInterface
ngldb
svcCesDDSCommon
# ProjectConfig
)
NGL_INSTALL_TARGET(cesPluginBasic)
@@ -0,0 +1,212 @@
/**
* Handler for player data
* $Id$
* $HeadURL$
* $Author$
* Created by gr, SLSE, 2017-02-20
*/
#include "handler_participant_borderline.h"
#include <QLineF>
#include <QTimer>
#include <LtsCoordTrans/lts_coord_trans.h>
namespace CentralEffectSimulationBasic
{
HandlerParticipantBorderline::HandlerParticipantBorderline(const std::shared_ptr<CentralEffectSimulation::DdsHandler> &ddsHandler,
const std::shared_ptr<CentralEffectSimulation::HandlerParticipant> &participantHandler,
QObject *parent)
: QObject(parent)
, m_ddsHandler(ddsHandler)
, m_handlerParticipant(participantHandler)
, m_logger(CentralEffectSimulation::getLogger("Plugin.Basic.HandlerParticipantBorderline"))
{
INFO_LOG(m_logger) << "HandlerParticipantBorderline::HandlerParticipantBorderline";
} // end of ctor()
//-----------------------------------------------------------------------------
HandlerParticipantBorderline::~HandlerParticipantBorderline()
{
} // end of dtor()
//-----------------------------------------------------------------------------
bool HandlerParticipantBorderline::init()
{
INFO_LOG(m_logger) << "HandlerParticipantBorderline::init";
auto dtcAes = m_ddsHandler->dtcAes();
dtcAes->waitForHistoricalDataBorderline(1000);
connect(dtcAes.get(), &AreaEffectSimulation::Interface::Dtc::borderlineChanged,
this, &HandlerParticipantBorderline::onBorderlineChanged);
connect(m_handlerParticipant.get(), &CentralEffectSimulation::HandlerParticipant::newIndoorPosition,
this, &HandlerParticipantBorderline::onParticipantPositionChanged);
connect(m_handlerParticipant.get(), &CentralEffectSimulation::HandlerParticipant::newOutdoorPosition,
this, &HandlerParticipantBorderline::onParticipantPositionChanged);
// Get 'static' data for all Borderlines
{
auto cb = [this](const AreaEffectSimulation::Borderline & fa)
{
onBorderlineChanged(fa, DataModification::eAdded);
};
if (!dtcAes->borderlines(cb))
return false;
}
INFO_LOG(m_logger) << "HandlerParticipantBorderline::init() finished. ";
return true;
} // end of init()
//-----------------------------------------------------------------------------
void HandlerParticipantBorderline::onBorderlineChanged(const AreaEffectSimulation::Borderline &data, DataModification modType)
{
switch (modType)
{
case DataModification::eRemoved:
DEBUG_LOG(m_logger) << " remove Borderline- data.id()=" << data.id();
m_borderlines.remove(data.id());
break;
case DataModification::eAdded:
case DataModification::eModified:
{
const AreaEffectSimulation::AesEffectState &effectState = data.effectStateId();
switch (effectState.underlying())
{
case AreaEffectSimulation::AesEffectState_def::EsReceived:
case AreaEffectSimulation::AesEffectState_def::EsFired:
case AreaEffectSimulation::AesEffectState_def::EsCreated:
case AreaEffectSimulation::AesEffectState_def::EsPrepared:
case AreaEffectSimulation::AesEffectState_def::EsActivated:
{
BorderlineUtm borderline(data);
DEBUG_LOG(m_logger) << "m_borderlines.insert id=" << data.id();
m_borderlines.insert(data.id(), borderline);
break;
}
case AreaEffectSimulation::AesEffectState_def::EsRemoved:
case AreaEffectSimulation::AesEffectState_def::EsExpired:
case AreaEffectSimulation::AesEffectState_def::EsPaused:
m_borderlines.remove(data.id());
break;
case AreaEffectSimulation::AesEffectState_def::EsUnknown:
case AreaEffectSimulation::AesEffectState_def::EsError:
break;
}
break;
}
}
}
bool HandlerParticipantBorderline::intersect(const QPolygonF &polygonf, const QLineF &linef) const
{
DEBUG_LOG(m_logger) << "line to check: " << CentralEffectSimulation::debug(linef.p1()) << " - " << CentralEffectSimulation::debug(linef.p2());
QPointF a = polygonf.first();
for (const QPointF &b : polygonf)
{
const QLineF segment(a, b);
DEBUG_LOG(m_logger) << "segment:" << CentralEffectSimulation::debug(a) << " - " << CentralEffectSimulation::debug(b);
if (QLineF::BoundedIntersection == linef.intersect(segment, nullptr))
return true;
a = b;
}
return false;
}
void HandlerParticipantBorderline::onParticipantPositionChanged(const CentralEffectSimulation::HandlerParticipant::CesParticipantData &partPos)
{
// Bounding Box von der Linie
DEBUG_LOG(m_logger) << "ParicipantStep "
<< " participantId=" << partPos.participantId()
<< " participantTypeId=" << partPos.participantTypeId()
<< " Anzahl Borderlines=" << m_borderlines.size();
for (const BorderlineUtm &borderline : qAsConst(m_borderlines))
{
DEBUG_LOG(m_logger) << "borderline id = " << borderline.id
<< ", Box bottomLeft = " << CentralEffectSimulation::debug(borderline.boundingBox.bottomLeft())
<< ", topRight = " << CentralEffectSimulation::debug(borderline.boundingBox.topRight());
const QPolygonF utmStepPoly = m_handlerParticipant->getParticipantStep(partPos.participantId(), borderline.zone);
if (utmStepPoly.size() < 2)
continue;
// Intersection von Polygon und Line: Polygon = Borderline, Line from last Participant pos to actual participant pos
const QLineF utmStep(utmStepPoly[0], utmStepPoly[1]);
const bool result = intersect(borderline.points, utmStep);
DEBUG_LOG(m_logger) << "result intersection = " << result;
if (result)
{
if (borderline.operatorId <= 0)
sendParticipantEvent(borderline, partPos, ProjectDataManagement::EventType_def::CrossGlobalBorderline);
else
sendParticipantEvent(borderline, partPos, ProjectDataManagement::EventType_def::CrossLocalBorderline);
}
}
} // end of onParticipantPositionChanged()
//-----------------------------------------------------------------------------
// ///////////////////////////////////
// P D M (ProjectDataManagement)
// ///////////////////////////////////
// Search for corresponding aesItemView
// Check for all participants wheter he is in the explosion area
void HandlerParticipantBorderline::sendParticipantEvent(const BorderlineUtm &borderline,
const CentralEffectSimulation::HandlerParticipant::CesParticipantData &participantPosition,
const ProjectDataManagement::EventType eventType)
{
ParticipantManagement::TypeClass typeClass = m_handlerParticipant->typeClassFromTypeId(participantPosition.participantTypeId());
if (typeClass == ParticipantManagement::TypeClass_def::Unit ||
typeClass == ParticipantManagement::TypeClass_def::SupportUnit ||
typeClass == ParticipantManagement::TypeClass_def::SupportEntity ||
typeClass == ParticipantManagement::TypeClass_def::Unknown)
return;
int equipmentNumber = m_ddsHandler->participantId2EquipNo(participantPosition.participantId());
if (equipmentNumber <= 0)
return;
CentralEffectSimulation::ParticipantEvent pe;
DEBUG_LOG(m_logger) << "sendParticipantEvent participantId=" << participantPosition.participantId()
<< " lat= " << participantPosition.pos().lat()
<< " lon= " << participantPosition.pos().lon()
<< " equipmentNumber=" << equipmentNumber
<< " eventType=" << eventType;
pe.id(m_ddsHandler->getParticipantEventId());
pe.eventTypeId(eventType);
pe.participantId(participantPosition.participantId());
pe.eventTime(participantPosition.sampleTime());
pe.aesItemId(borderline.id);
pe.partyId(participantPosition.partyId());
pe.aesName(borderline.name.toStdString());
pe.equipmentNumber(equipmentNumber);
pe.position(participantPosition.pos());
m_ddsHandler->dtsCes()->publish(pe);
qint64 id = pe.id();
QTimer::singleShot(1 * 60 * 1000, this, [id, this]() { m_ddsHandler->dtsCes()->removeParticipantEventByKey(id); });
}
HandlerParticipantBorderline::BorderlineUtm::BorderlineUtm(const AreaEffectSimulation::Borderline &bl)
: id(bl.id())
, operatorId(bl.operatorId())
, partyId(bl.partyId().is_set() ? bl.partyId().get() : -1)
, name(QString::fromStdString(bl.name()))
{
points.reserve(bl.segments().size());
for (const Core::GeoPosition2D &pointGeo : bl.segments())
points.push_back(CentralEffectSimulation::geographic2Utm(pointGeo, &zone));
boundingBox = points.boundingRect();
// build Polygon:
}
} // namespace CentralEffectSimulationBasic
@@ -0,0 +1,86 @@
/**
* Handler for player data
* $Id$
* $HeadURL$
* $Author$
* Created by gr, SLSE, 2017-02-20
*/
#pragma once
#include <CentralEffectSimulation/logger.h>
#include <AreaEffectSimulation/aes_dtc.h>
#include <CentralEffectSimulation/dds_handler.h>
#include <CentralEffectSimulation/handler_participant.h>
#include <QHash>
#include <QRectF>
#include <QPolygonF>
// AES-Handling for participants
namespace CentralEffectSimulationBasic
{
class HandlerParticipantBorderline final
: public QObject
{
Q_OBJECT
struct BorderlineUtm
{
int id = 0;
int zone = -1;
int32_t operatorId = 0;
int32_t partyId = -1;
QPolygonF points;
QRectF boundingBox;
QString name;
BorderlineUtm() = default;
explicit BorderlineUtm(const AreaEffectSimulation::Borderline &bl);
};
public:
HandlerParticipantBorderline(const std::shared_ptr<CentralEffectSimulation::DdsHandler> &ddsHandler,
const std::shared_ptr<CentralEffectSimulation::HandlerParticipant> &participantHandler,
QObject *parent = nullptr);
~HandlerParticipantBorderline();
/**
* Initialize the handler to manage information from player management
*/
bool init();
private Q_SLOTS:
/**
* Handle the signals from 'ParticipantHandler'
*/
void onParticipantPositionChanged(const CentralEffectSimulation::HandlerParticipant::CesParticipantData &partPos);
/**
* Handle the signals from 'AES'
*/
void onBorderlineChanged(const AreaEffectSimulation::Borderline &data, DataModification modType);
private: // methoden
void sendParticipantEvent(const BorderlineUtm &borderline,
const CentralEffectSimulation::HandlerParticipant::CesParticipantData &participantPosition,
const ProjectDataManagement::EventType eventType);
bool intersect(const QPolygonF &polygonf, const QLineF &linef) const;
private: // attributes
std::shared_ptr<CentralEffectSimulation::DdsHandler> m_ddsHandler; ///< Pointer to VOM DDS handler
std::shared_ptr<CentralEffectSimulation::HandlerParticipant> m_handlerParticipant;
// AES-Values
QHash<int, BorderlineUtm> m_borderlines; // key = aesItemId
CentralEffectSimulation::LOGGER_T &m_logger; ///< Interface to the Logging-Facility
};
} // namespace CentralEffectSimulationBasic
@@ -0,0 +1,310 @@
/**
* Handler for player data
* $Id$
* $HeadURL$
* $Author$
* Created by gr, SLSE, 2017-02-20
*/
#include "handler_simulated_movement.h"
#include <CentralEffectSimulation/handler_participant.h>
#include <QTimer>
#include <LtsCoordTrans/lts_coord_trans.h>
#include <ngldb/dbtransaction.h>
namespace CentralEffectSimulationBasic
{
HandlerSimulatedMovement::HandlerSimulatedMovement(const std::shared_ptr<CentralEffectSimulation::DdsHandler> &ddsHandler,
const std::shared_ptr<CentralEffectSimulation::HandlerParticipant> &participantHandler,
const std::shared_ptr<CentralEffectSimulation::DatabaseInterface> &db,
QObject *parent)
: QObject(parent)
, SimulatedMovementModifyRequestHandler(ddsHandler->ftsCes())
, SimulatedMovementRemoveRequestHandler(ddsHandler->ftsCes())
, SimulatedMovementRemoveByParticipantIdRequestHandler(ddsHandler->ftsCes())
, m_ddsHandler(ddsHandler)
, m_handlerParticipant(participantHandler)
, m_db(db)
, m_jumpToStart(false)
, m_logger(CentralEffectSimulation::getLogger("Plugin.Basic.HandlerSimulatedMovement"))
{
} // end of ctor()
//-----------------------------------------------------------------------------
HandlerSimulatedMovement::~HandlerSimulatedMovement()
{
qDeleteAll(m_simulationMovements);
} // end of dtor()
//-----------------------------------------------------------------------------
bool HandlerSimulatedMovement::init()
{
if (!loadSimulatedMovementFromDb())
return false;
return true;
} // end of init()
bool HandlerSimulatedMovement::loadSimulatedMovementFromDb()
{
QVector<CentralEffectSimulation::Database::CesSimulatedMovement> simMoveVec;
if (!m_db->select(simMoveVec))
{
ERROR_LOG(m_logger) << "Error reading data from database 'CesSimulatedMovement'";
return false;
}
DEBUG_LOG(m_logger) << "loadSimulatedMovementFromDb size =" << simMoveVec.size();
QVector<CentralEffectSimulation::Database::CesSimulatedMovementSegment> simMoveSegVec;
if (!m_db->select(simMoveSegVec))
{
ERROR_LOG(m_logger) << "Error reading data from database 'CesSimulatedMovementSegment'";
return false;
}
DEBUG_LOG(m_logger) << "loadSimulatedMovementSegmentsFromDb size =" << simMoveSegVec.size();
// add to internal buffer
for (const CentralEffectSimulation::Database::CesSimulatedMovement &data : qAsConst(simMoveVec))
{
CentralEffectSimulation::SimulatedMovement request;
request.id(data.id);
request.name(data.name.toStdString());
request.startTime(data.startTime);
request.participantId(data.participantId);
request.repeat(data.repeat);
request.nextPoint(data.nextpoint);
DEBUG_LOG(m_logger) << "Loading SimulatedMovement: " << request;
QMap <int, CentralEffectSimulation::Database::CesSimulatedMovementSegment> segDbMap; // QMap to get it sorted
for (const CentralEffectSimulation::Database::CesSimulatedMovementSegment &segData : qAsConst(simMoveSegVec))
{
if (segData.simulatedMovementId == data.id)
segDbMap.insert(segData.positionIndex, segData);
}
request.segments().reserve(segDbMap.size());
CentralEffectSimulation::SimulatedMovementSegment seg;
for (const CentralEffectSimulation::Database::CesSimulatedMovementSegment &segDb : qAsConst(segDbMap))
{
seg.delay(segDb.delay);
seg.name(segDb.name.toStdString());
seg.speed(segDb.speed);
seg.position(Core::GeoPosition2D(segDb.position.x(),
segDb.position.y()));
request.segments().push_back(seg);
}
SimulationMovement *sm = new SimulationMovement(m_ddsHandler, m_db, m_handlerParticipant, request);
m_simulationMovements.insert(sm->id(), sm);
publishSimulatedMovement(request);
}
return true;
}
Core::FunctionReplyObject HandlerSimulatedMovement::insertInDb(const CentralEffectSimulation::SimulatedMovement &request)
{
CentralEffectSimulation::Database::CesSimulatedMovement newSimulatedMovement = SimulationMovement::toDb(request);
DBTransaction trans(m_db->database());
if (m_simulationMovements.contains(request.id()))
newSimulatedMovement.nextpoint = m_simulationMovements.value(request.id())->getNextPoint();
else // new Simulation
newSimulatedMovement.nextpoint = 1;
if (!m_db->insert(newSimulatedMovement))
return Core::FunctionReplyObject(0, tr_lts("dds", "Error adding 'CesSimulatedMovement' to database"));
DEBUG_LOG(m_logger) << "newSimulatedMovement.id = " << newSimulatedMovement.id;
CentralEffectSimulation::Database::CesSimulatedMovementSegment newSegment;
newSegment.simulatedMovementId = newSimulatedMovement.id;
for (const CentralEffectSimulation::SimulatedMovementSegment &seg : request.segments())
{
newSegment.id = 0; // insert
newSegment.delay = seg.delay();
newSegment.speed = seg.speed();
newSegment.name = QString::fromStdString(seg.name());
newSegment.position = QPointF(seg.position().lon(), seg.position().lat());
if (!m_db->insert(newSegment))
return Core::FunctionReplyObject(0, tr_lts("dds", "Error adding 'CesSimulatedMovementSegment' to database"));
++newSegment.positionIndex;
}
trans.commit();
DEBUG_LOG(m_logger) << "newSimulatedMovement.id=" << newSimulatedMovement.id << " request.id=" << request.id();
return Core::FunctionReplyObject(newSimulatedMovement.id);
} // end of insertInDb
Core::FunctionReplyObject HandlerSimulatedMovement::updateDb(const CentralEffectSimulation::SimulatedMovement &request)
{
CentralEffectSimulation::Database::CesSimulatedMovement newSimulatedMovement(SimulationMovement::toDb(request));
if (!m_db->update(newSimulatedMovement))
return Core::FunctionReplyObject(0, tr_lts("dds", "Error update 'CesSimulatedMovement' to database"));
DEBUG_LOG(m_logger) << "newSimulatedMovement.id = " << newSimulatedMovement.id;
// First remove all participant-segments
m_db->removeCesSimulatedMovementSegmentBySimulatedMovementId(newSimulatedMovement.id);
// Insert new segments:
CentralEffectSimulation::Database::CesSimulatedMovementSegment newSegment;
newSegment.simulatedMovementId = newSimulatedMovement.id;
for (const CentralEffectSimulation::SimulatedMovementSegment &seg : request.segments())
{
newSegment.id = 0; // insert
newSegment.delay = seg.delay();
newSegment.speed = seg.speed();
newSegment.name = QString::fromStdString(seg.name());
newSegment.position = QPointF(seg.position().lon(), seg.position().lat());
if (!m_db->insert(newSegment))
return Core::FunctionReplyObject(0, tr_lts("dds", "Error adding 'CesSimulatedMovementSegment' to database"));
++newSegment.positionIndex;
}
DEBUG_LOG(m_logger) << "newSimulatedMovement.id=" << newSimulatedMovement.id << " request.id=" << request.id();
return Core::FunctionReplyObject(newSimulatedMovement.id);
} // end of updateDb
Core::FunctionReplyObject HandlerSimulatedMovement::removeFromDb(const int32_t id)
{
DEBUG_LOG(m_logger) << "removeFromDb: id=" << id;
if (!m_db->removeCesSimulatedMovement(id))
return Core::FunctionReplyObject(0, tr_lts("dds", "Error remove 'CesSimulatedMovement' from database"));
return Core::FunctionReplyObject(id);
}
void HandlerSimulatedMovement::publishSimulatedMovement(const CentralEffectSimulation::SimulatedMovement &request)
{
INFO_LOG(m_logger) << "publishSimulatedMovement: " << request;
m_ddsHandler->dtsCes()->publish(request);
}
void HandlerSimulatedMovement::setParticipantAsSimulated(const int &participantId, const bool isSimulated)
{
if (participantId <= 0)
return;
ParticipantManagement::SetAsSimulated req(participantId,isSimulated);
if (!m_ddsHandler->ftcPpm()->setAsSimulatedRequest(req, this))
ERROR_LOG(m_logger) << "Error modify participant data participantId=" << participantId;
}
void HandlerSimulatedMovement::onModifyParticipantDataReply(const Core::FunctionReplyObject &replyObject)
{
if (replyObject.error())
WARNING_LOG(m_logger) << "onModifyParticipantDataReply: " << replyObject();
}
void HandlerSimulatedMovement::onSetAsSimulatedReply(const Core::FunctionReplyObject &replyObject)
{
if (replyObject.error())
WARNING_LOG(m_logger) << "onSetAsSimulatedReply: " << replyObject();
}
void HandlerSimulatedMovement::onSimulatedMovementModifyRequest(const rti::core::SampleIdentity &cookie,
const CentralEffectSimulation::SimulatedMovement &request)
{
DEBUG_LOG(m_logger) << "onSimulatedMovementModifyRequest: " << request;
m_jumpToStart = request.jumpToStart();
// we allow a modify with requestId = 0 and participantId != 0
SimulationMovement *sm = findSimulationMovement(request.id(), request.participantId());
if (sm)
sm->setSimulatedMovementRequest(request);
else
sm = new SimulationMovement(m_ddsHandler, m_db, m_handlerParticipant, request);
// New Route
if (request.jumpToStart())
{
DEBUG_LOG(m_logger) << "sm->setJump(true)";
sm->setJump(true);
}
Core::FunctionReplyObject reply = request.id() > 0
? updateDb(sm->simMovementData())
: insertInDb(sm->simMovementData());
sm->setId(reply.id());
m_simulationMovements[sm->id()] = sm;
publishSimulatedMovement(request);
setParticipantAsSimulated(request.participantId(), true);
DEBUG_LOG(m_logger) << "simulatedMovementModifyReply id=" << reply.id();
m_ddsHandler->ftsCes()->simulatedMovementModifyReply(cookie, reply);
} // end onSimulatedMovementModifyRequest
Core::FunctionReplyObject HandlerSimulatedMovement::removeSimulatedMovement(int32_t ddsId)
{
DEBUG_LOG(m_logger) << "removeSimulatedMovement with id " << ddsId << ", " << m_simulationMovements.size();
if (ddsId <= 0)
return Core::FunctionReplyObject(0, tr_lts("dds", "remove participant simulation "));
auto reply = removeFromDb(ddsId);
if (reply.error())
return reply;
int participantId = -1;
auto it = m_simulationMovements.find(ddsId);
if (it != m_simulationMovements.end())
{
participantId = it.value()->participantId();
delete it.value();
m_simulationMovements.erase(it);
}
if (participantId == -1)
WARNING_LOG(m_logger) << "Could not find movement simulation with id " << ddsId << ", " << m_simulationMovements.size();
setParticipantAsSimulated(participantId, false);
return reply;
}
void HandlerSimulatedMovement::onSimulatedMovementRemoveRequest(const rti::core::SampleIdentity &cookie,
const Core::RemoveElementRequest &request)
{
Core::FunctionReplyObject reply = removeSimulatedMovement(request.id());
if (reply.error())
WARNING_LOG(m_logger) << reply();
m_ddsHandler->ftsCes()->simulatedMovementRemoveReply(cookie, reply);
} // end onSimulatedMovementRemoveRequest
void HandlerSimulatedMovement::onSimulatedMovementRemoveByParticipantIdRequest(const rti::core::SampleIdentity &cookie,
const CentralEffectSimulation::SimulatedMovementRemoveByParticipantId &request)
{
DEBUG_LOG(m_logger) << "onSimulatedMovementRemoveByParticipantIdRequest: " << request;
int id = 0;
for (const SimulationMovement *simMovement : qAsConst(m_simulationMovements))
{
if (simMovement->participantId() == request.participantId())
{
id = simMovement->id();
break;
}
}
Core::FunctionReplyObject reply = removeSimulatedMovement(id);
if (reply.error())
WARNING_LOG(m_logger) << reply();
m_ddsHandler->ftsCes()->simulatedMovementRemoveByParticipantIdReply(cookie, reply);
}
SimulationMovement *HandlerSimulatedMovement::findSimulationMovement(int id, int participantId)
{
if (id)
return m_simulationMovements.value(id);
for (SimulationMovement *s : qAsConst(m_simulationMovements))
{
if (s->participantId() == participantId)
return s;
}
return nullptr;
}
} // namespace CentralEffectSimulationBasic
@@ -0,0 +1,84 @@
/**
* Handler for player data
* $Id$
* $HeadURL$
* $Author$
* Created by gr, SLSE, 2017-02-20
*/
#pragma once
#include "simulation_movement.h"
#include <CentralEffectSimulation/logger.h>
#include <CentralEffectSimulation/dds_handler.h>
#include <CentralEffectSimulation/ces_dts.h>
#include <CentralEffectSimulation/ces_fts.h>
#include <CentralEffectSimulation/ces_db.h>
#include <ParticipantManagement/ppm_ftc.h>
#include <CentralEffectSimulation/handler_participant.h>
#include <QHash>
// Simulated movement for participants
namespace CentralEffectSimulationBasic
{
class HandlerSimulatedMovement final
: public QObject
, protected CentralEffectSimulation::Interface::Fts::SimulatedMovementModifyRequestHandler
, protected CentralEffectSimulation::Interface::Fts::SimulatedMovementRemoveRequestHandler
, protected CentralEffectSimulation::Interface::Fts::SimulatedMovementRemoveByParticipantIdRequestHandler
, protected ParticipantManagement::Interface::Ftc::ModifyParticipantDataReplyHandler
, protected ParticipantManagement::Interface::Ftc::SetAsSimulatedReplyHandler
{
Q_OBJECT
public:
explicit HandlerSimulatedMovement(const std::shared_ptr<CentralEffectSimulation::DdsHandler> &ddsHandler,
const std::shared_ptr<CentralEffectSimulation::HandlerParticipant> &participantHandler,
const std::shared_ptr<CentralEffectSimulation::DatabaseInterface> &db,
QObject *parent = nullptr);
~HandlerSimulatedMovement();
/**
* Initialize the handler to manage information from player management
*/
bool init();
void onModifyParticipantDataReply(const Core::FunctionReplyObject &replyObject) override final;
void onSetAsSimulatedReply(const Core::FunctionReplyObject &replyObject) override final;
private: // methoden
bool loadSimulatedMovementFromDb();
void onSimulatedMovementModifyRequest(const rti::core::SampleIdentity &cookie,
const CentralEffectSimulation::SimulatedMovement &request) override;
void onSimulatedMovementRemoveRequest(const rti::core::SampleIdentity &cookie,
const Core::RemoveElementRequest &request) override;
void onSimulatedMovementRemoveByParticipantIdRequest(const rti::core::SampleIdentity &cookie,
const CentralEffectSimulation::SimulatedMovementRemoveByParticipantId &request) override;
Core::FunctionReplyObject insertInDb(const CentralEffectSimulation::SimulatedMovement &request);
Core::FunctionReplyObject updateDb(const CentralEffectSimulation::SimulatedMovement &request);
Core::FunctionReplyObject removeFromDb(const int32_t id);
void publishSimulatedMovement(const CentralEffectSimulation::SimulatedMovement &request);
void setParticipantAsSimulated(const int &participantId, const bool isSimulated);
Core::FunctionReplyObject removeSimulatedMovement(int32_t ddsId);
SimulationMovement *findSimulationMovement(int id, int participantId);
private: // attributes
std::shared_ptr<CentralEffectSimulation::DdsHandler> m_ddsHandler; ///< Pointer to VOM DDS handler
std::shared_ptr<CentralEffectSimulation::HandlerParticipant> m_handlerParticipant;
std::shared_ptr<CentralEffectSimulation::DatabaseInterface> m_db;
// Input-values for simulation
QHash<int, SimulationMovement *> m_simulationMovements; // Key = SimulationMovement.id
int m_jumpToStart;
CentralEffectSimulation::LOGGER_T &m_logger; ///< Interface to the Logging-Facility
};
} // namespace CentralEffectSimulationBasic
@@ -0,0 +1,95 @@
/**
* Plugin CentralEffectSimulation Basic
* $Id$
* $HeadURL$
* $Author$
* Created by Gerlinde Rudolphus, SLTE, 2016-04-14
*/
#include "plugin.h"
#include "logger.h"
namespace CentralEffectSimulationBasic
{
std::shared_ptr<CentralEffectSimulation::Plugin::Interface> CentralEffectSimulationBasicPlugin::createInterface(CentralEffectSimulation::Plugin::DataProvider *pdp,
const std::shared_ptr<DDSConnector::DdsConnector> &dDSConnector,
NGL::Settings *settings,
CentralEffectSimulation::MainHandler *mainHandler)
{
return std::make_shared<CesBasicInterfaceImpl>(pdp, dDSConnector, settings, mainHandler);
}
CesBasicInterfaceImpl::CesBasicInterfaceImpl(CentralEffectSimulation::Plugin::DataProvider *pdp,
const std::shared_ptr<DDSConnector::DdsConnector> &dDSConnector,
NGL::Settings *settings,
CentralEffectSimulation::MainHandler *mainHandler)
: m_pdp(pdp)
, m_ddsConnector(dDSConnector)
, m_mainHandler(mainHandler)
, m_ddsHandler(m_mainHandler->dds())
, m_db(m_mainHandler->db())
, m_handlerParticipant(m_mainHandler->handlerParticipant())
, m_logger(CentralEffectSimulation::getLogger("Plugin.Basic.CesBasicInterfaceImpl"))
{
Q_UNUSED(settings)
}
CesBasicInterfaceImpl::~CesBasicInterfaceImpl()
{
m_handlerParticipantBorderline.reset();
m_handlerSimulatedMovement.reset();
}
bool CesBasicInterfaceImpl::init(int domainId, int exerciseId)
{
m_domainId = domainId;
m_exerciseId = exerciseId;
INFO_LOG(m_logger) << "CesBasicInterfaceImpl::init()"
<< " m_domainId=" << m_domainId
<< " m_exerciseId=" << m_exerciseId;
// initialize handlerParticipantBorderline
m_handlerParticipantBorderline = std::make_shared<HandlerParticipantBorderline>(m_ddsHandler,
m_handlerParticipant,
this);
if (!m_handlerParticipantBorderline->init())
{
ERROR_LOG(m_logger) << "Initialisation HandlerParticipantBorderline failed.";
return false;
}
// initialize handlerSimulatedMovement
m_handlerSimulatedMovement = std::make_shared<HandlerSimulatedMovement>(m_ddsHandler,
m_handlerParticipant,
m_db,
this);
if (!m_handlerSimulatedMovement->init())
{
ERROR_LOG(m_logger) << "Initialisation m_handlerSimulatedMovement failed.";
return false;
}
INFO_LOG(m_logger) << "CentralEffectSimulationBasicInterfaceImpl::init() return true";
return true;
}
QString CesBasicInterfaceImpl::echo(const QString &message)
{
QString ret(QStringLiteral("<<<< %1 >>>> CesBasicInterfaceImpl::echo").arg(message));
INFO_LOG(m_logger) << "CesBasicInterfaceImpl::echo return:" << ret;
DEBUG_LOG(m_logger) << "DEBUG: CesBasicInterfaceImpl::echo return:" << ret;
return ret;
}
} //namespace CentralEffectSimulationBasic
@@ -0,0 +1,84 @@
/**
* Plugin CentralEffectSimulation Basic
* $Id$
* $HeadURL$
* $Author$
* Created by Gerlinde Rudolphus, SLTE, 2016-04-14
*/
#pragma once
#include "handler_participant_borderline.h"
#include "handler_simulated_movement.h"
#include <CentralEffectSimulation/logger.h>
#include <CentralEffectSimulation/ces_plugin_interface.h>
#include <CentralEffectSimulation/main_handler.h>
#include <CentralEffectSimulation/dds_handler.h>
#include <QObject>
//namespace NGLDB
//{
//template <typename DB> class DbServiceHandler;
//}
namespace CentralEffectSimulationBasic
{
//using DbHandler = NGLDB::DbServiceHandler<CentralEffectSimulation::DatabaseInterface>;
class CentralEffectSimulationBasicPlugin : public QObject, public CentralEffectSimulation::Plugin::Plugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "special:3:ces.CentralEffectSimulationBasicPlugin")
Q_INTERFACES(CentralEffectSimulation::Plugin::Plugin)
public:
CentralEffectSimulationBasicPlugin() = default;
~CentralEffectSimulationBasicPlugin() = default;
std::shared_ptr<CentralEffectSimulation::Plugin::Interface> createInterface(CentralEffectSimulation::Plugin::DataProvider *pdp,
const std::shared_ptr<DDSConnector::DdsConnector> &dDSConnector,
NGL::Settings *settings,
CentralEffectSimulation::MainHandler *mainHandler) override;
};
class CesBasicInterfaceImpl final : public CentralEffectSimulation::Plugin::Interface
{
Q_OBJECT
public:
CesBasicInterfaceImpl(CentralEffectSimulation::Plugin::DataProvider *pdp,
const std::shared_ptr<DDSConnector::DdsConnector> &dDSConnector,
NGL::Settings *settings,
CentralEffectSimulation::MainHandler *mainHandler);
~CesBasicInterfaceImpl();
//bool init();
const char *name() const override { return "CentralEffectSimulationBasic"; }
QString echo(const QString &message) override;
private Q_SLOTS:
bool init(int domainId, int exerciseId) override;
private:
private:
CentralEffectSimulation::Plugin::DataProvider *m_pdp{nullptr};
std::shared_ptr<DDSConnector::DdsConnector> m_ddsConnector;
CentralEffectSimulation::MainHandler *m_mainHandler{nullptr};
std::shared_ptr<CentralEffectSimulation::DdsHandler> m_ddsHandler;
std::shared_ptr<CentralEffectSimulation::DatabaseInterface> m_db;
std::shared_ptr<CentralEffectSimulation::HandlerParticipant> m_handlerParticipant; ///< Pointer to handler for all participants
std::shared_ptr<HandlerParticipantBorderline> m_handlerParticipantBorderline; ///< Pointer to handler for check participants cross Borderline
std::shared_ptr<HandlerSimulatedMovement> m_handlerSimulatedMovement; ///< Pointer to handler for Simulated Movement
NGL::INGLLogger &m_logger;
int m_domainId = 0;
int m_exerciseId = 0;
};
} // namespace CentralEffectSimulationBasic
@@ -0,0 +1,320 @@
/**
* Simulation for Movement
* $Id$
* $HeadURL$
* $Author$
* Created by gr, SLSE, 2017-12-13
*/
#include "simulation_movement.h"
#include <LtsCoordTrans/lts_coord_trans.h>
#include <QDateTime>
namespace CentralEffectSimulationBasic
{
SimulationMovement::SimulationMovement(const std::shared_ptr<CentralEffectSimulation::DdsHandler> &ddsHandler,
const std::shared_ptr<CentralEffectSimulation::DatabaseInterface> &db,
const std::shared_ptr<CentralEffectSimulation::HandlerParticipant> &participantHandler,
const CentralEffectSimulation::SimulatedMovement &sml,
QObject *parent)
: QObject(parent)
, m_ddsHandler(ddsHandler)
, m_db(db)
, m_handlerParticipant(participantHandler)
, m_moveTime(1)
, m_actSegment()
, m_newPos()
, m_simStart(true)
, m_zone(-1)
, m_segTimer(new QTimer(this))
, m_moveTimer(new QTimer(this))
, m_simMovement(sml)
, m_logger(CentralEffectSimulation::getLogger("Plugin.Basic.SimulationMovement"))
{
m_segTimer->setSingleShot(true);
connect(m_segTimer, &QTimer::timeout, this, &SimulationMovement::startNewSegment);
m_moveTimer->setSingleShot(true);
connect(m_moveTimer, &QTimer::timeout, this, &SimulationMovement::move);
setSimulatedMovementRequest(sml);
}
SimulationMovement::~SimulationMovement()
{
DEBUG_LOG(m_logger) << "Delete SimulatedMovement "
<< " id=" << m_simMovement.id()
<< " participantId= " << m_simMovement.participantId();
m_ddsHandler->dtsCes()->removeSimulatedMovementByKey(m_simMovement.id());
m_segTimer->stop();
m_moveTimer->stop();
}
void SimulationMovement::setSimulatedMovementRequest(const CentralEffectSimulation::SimulatedMovement &sml)
{
int nextPoint = m_simMovement.nextPoint();
m_simMovement = sml;
m_simMovement.nextPoint(nextPoint);
m_moveTime = 1;
m_segTimer->stop();
m_moveTimer->stop();
m_points.clear();
m_segSpeed.clear();
m_segDelay.clear();
m_points.reserve(sml.segments().size());
m_segSpeed.reserve(sml.segments().size());
m_segDelay.reserve(sml.segments().size());
for (const CentralEffectSimulation::SimulatedMovementSegment &point : sml.segments())
{
const Core::GeoPosition2D &pointGeo = point.position();
m_points.push_back(m_zone == -1 ? CentralEffectSimulation::geographic2Utm(pointGeo, &m_zone) : CentralEffectSimulation::geographic2Utm(pointGeo, m_zone));
DEBUG_LOG(m_logger) << "pointGeo lat=" << pointGeo.lat() << " lon=" << pointGeo.lon()
<< " point lat=" << point.position().lat() << " lon=" << point.position().lon()
<< " utmPoint=" << CentralEffectSimulation::debug(m_points.last());
m_segSpeed.append(point.speed());
m_segDelay.append(point.delay());
}
// Only start simulation in future
DEBUG_LOG(m_logger) << "m_startTime - QDateTime::currentMSecsSinceEpoch()=" << m_simMovement.startTime() - QDateTime::currentMSecsSinceEpoch()
<< " m_startTime=" << m_simMovement.startTime()
<< " currentTime=" << QDateTime::currentMSecsSinceEpoch()
<< " m_nextPoint=" << m_simMovement.nextPoint();
if (m_simMovement.nextPoint() > 0 && m_points.size() > m_simMovement.nextPoint())
m_newPos = m_points[m_simMovement.nextPoint()].toPoint();
if (m_simMovement.startTime() - QDateTime::currentMSecsSinceEpoch() > 0)
m_moveTimer->start(m_simMovement.startTime() - QDateTime::currentMSecsSinceEpoch());
else
{
DEBUG_LOG(m_logger) << "Service-Start";
m_moveTimer->start(10); // Service-Start
}
}
void SimulationMovement::updateNextPointInDb()
{
if (m_simMovement.id() <= 0)
{
WARNING_LOG(m_logger) << "Internal error - id not set!";
return;
}
CentralEffectSimulation::Database::CesSimulatedMovement dbSim = toDb(m_simMovement);
m_db->update(dbSim);
}
void SimulationMovement::startNewSegment()
{
DEBUG_LOG(m_logger) << "simulate participantId = " << m_simMovement.participantId()
<< " m_nextPoint = " << m_simMovement.nextPoint();
m_moveTime = 1;
if (m_simMovement.nextPoint() < m_points.size())
{
QPointF p1;
// Next segment
const CentralEffectSimulation::HandlerParticipant::CesParticipantData pos = m_handlerParticipant->position(m_simMovement.participantId());
if (pos.participantId() == m_simMovement.participantId())
{
p1 = CentralEffectSimulation::geographic2Utm(pos.pos(), m_zone);
DEBUG_LOG(m_logger) << "Next segment ParticipantPosition =" << CentralEffectSimulation::debug(p1);
}
else
{
if (m_simStart) // Wait for participantPosition
{
INFO_LOG(m_logger) << "Wait for participant position participantId =" << m_simMovement.participantId();
m_segTimer->start(1000);
return;
}
if (m_simMovement.nextPoint() > 0)
{
p1 = m_points.at(m_simMovement.participantId() - 1);
DEBUG_LOG(m_logger) << "nextPoint>0 (" << m_simMovement.nextPoint() << ") ParticipantPosition =" << CentralEffectSimulation::debug(p1);
}
else
{
p1 = m_points.at(m_points.size() - 1);
DEBUG_LOG(m_logger) << "nextPoint=" << m_simMovement.nextPoint() << " ParticipantPosition =" << CentralEffectSimulation::debug(p1);
}
}
const QPointF &p2 = m_points.at(m_simMovement.nextPoint());
m_actSegment.setPoints(p1, p2);
int curDelay = m_segDelay.at(m_simMovement.nextPoint());
DEBUG_LOG(m_logger) << "New Segment: p1 = " << CentralEffectSimulation::debug(p1) << " p2=" << CentralEffectSimulation::debug(p2)
<< " delay =" << curDelay;
m_moveTimer->start(curDelay);
}
else
{
if (m_simMovement.repeat())
{
m_simMovement.nextPoint(0);
m_moveTimer->start(m_segDelay.at(m_simMovement.nextPoint()));
}
else
m_simMovement.nextPoint(-1); // Invalid value
}
}
void SimulationMovement::setJump(bool jump)
{
DEBUG_LOG(m_logger) << "Jump";
if (jump)
{
m_simMovement.nextPoint(1);
m_newPos = m_points.at(0);
m_actSegment.setPoints(m_newPos,
m_points.at(m_simMovement.nextPoint()));
m_moveTime = 1;
m_simStart = false;
publishNewPos();
DEBUG_LOG(m_logger) << "Jump done";
}
}
void SimulationMovement::publishSimulatedMovement()
{
DEBUG_LOG(m_logger) << " m_nextPoint= " << m_simMovement.nextPoint();
m_ddsHandler->dtsCes()->publish(m_simMovement);
}
void SimulationMovement::publishNewPos()
{
TrainingAreaBase::EquipmentPosition participantPos;
LtsCoordTrans::UtmCoordinate utmPos;
utmPos.zone = m_zone;
utmPos.northp = true;
utmPos.x = m_newPos.x();
utmPos.y = m_newPos.y();
const QPointF posGeo = utmPos.geographic();
DEBUG_LOG(m_logger) << "participantPos zone=" << utmPos.zone
<< " northp=" << utmPos.northp
<< " x=" << utmPos.x
<< " y=" << utmPos.y;
const Core::GeoPosition pos(Core::GeoPosition(posGeo.x(), posGeo.y(), 0));
participantPos.equipmentNumber(-m_simMovement.participantId()); // negative - treat as participantId
participantPos.sampleTime(m_ddsHandler->currentPartitionTime());
participantPos.position().position(pos);
participantPos.position().reportingSource(Core::PositionReportingSource::MovementSimulation);
m_ddsHandler->dtsTab()->publish(participantPos);
}
void SimulationMovement::move()
{
DEBUG_LOG(m_logger) << "move";
if (m_simMovement.nextPoint() < 0)
{
DEBUG_LOG(m_logger) << "move next point < 0";
return;
}
const CentralEffectSimulation::HandlerParticipant::CesParticipantData partPos = m_handlerParticipant->position(m_simMovement.participantId());
const QPointF participantPosUtm = CentralEffectSimulation::geographic2Utm(partPos.pos(), m_zone);
if (partPos.participantId() != m_simMovement.participantId())
{
DEBUG_LOG(m_logger) << "move no ParticipantId=" << m_simMovement.participantId();
m_moveTimer->start(1000);
return;
}
if (!partPos.positionValid)
{
DEBUG_LOG(m_logger) << "move no ParticipantId=" << m_simMovement.participantId();
m_moveTimer->start(1000);
return;
}
DEBUG_LOG(m_logger) << " pos=" << CentralEffectSimulation::debug(participantPosUtm);
QLineF step = m_actSegment;
if (m_simStart)
{
m_actSegment.setPoints(participantPosUtm,
m_points.at(m_simMovement.nextPoint()));
step = m_actSegment;
DEBUG_LOG(m_logger) << "m_simStart set m_actSegment"
<< " p1: " << CentralEffectSimulation::debug(m_actSegment.p1())
<< " p2: " << CentralEffectSimulation::debug(m_actSegment.p2());
m_simStart = false;
}
if (m_segSpeed[m_simMovement.nextPoint()] <= 0.0)
{
DEBUG_LOG(m_logger) << "move next point < 0";
return;
}
m_newPos = m_points[m_simMovement.nextPoint()];
step.setLength(m_segSpeed[m_simMovement.nextPoint()] * m_moveTime);
m_moveTime++;
// ready criterion
if (step.length() >= m_actSegment.length() + 0.1 ||
step.length() < 0.1) // 0.1 Magic Number but 10 cm distance to Point is arrived
{
DEBUG_LOG(m_logger) << "move ready step.length()=" << step.length()
<< " m_actSegment.length()=" << m_actSegment.length();
m_simMovement.nextPoint(m_simMovement.nextPoint() + 1);
if (m_simMovement.nextPoint() >= m_points.size())
{
if (m_simMovement.repeat())
m_simMovement.nextPoint(0);
else
{
m_simMovement.nextPoint(-1); // Invalid value
return;
}
}
updateNextPointInDb();
DEBUG_LOG(m_logger) << "ready move participantId = " << m_simMovement.participantId()
<< " m_nextPoint =" << m_simMovement.nextPoint()
<< " newPos =" << m_newPos.x() << "/" << m_newPos.y()
<< " m_moveTime=" << m_moveTime
<< " length=" << m_segSpeed[m_simMovement.nextPoint()] * m_moveTime
<< " step.length=" << step.length()
<< " m_segSpeed[m_nextPoint]=" << m_segSpeed[m_simMovement.nextPoint()]
<< " m_moveTime=" << m_moveTime
<< " m_actSegment.length=" << m_actSegment.length()
<< " m_zone=" << m_zone;
publishNewPos();
startNewSegment();
publishSimulatedMovement();
return;
}
m_newPos = step.p2();
DEBUG_LOG(m_logger) << "move participantId = " << m_simMovement.participantId()
<< " m_nextPoint =" << m_simMovement.nextPoint()
<< " newPos =" << m_newPos.x() << "/" << m_newPos.y()
<< " m_moveTime=" << m_moveTime
<< " length=" << m_segSpeed[m_simMovement.nextPoint()] * m_moveTime
<< " step.length=" << step.length()
<< " m_speed=" << m_segSpeed[m_simMovement.nextPoint()]
<< " m_moveTime=" << m_moveTime
<< " m_actSegment.length=" << m_actSegment.length()
<< " m_zone=" << m_zone;
publishNewPos();
m_moveTimer->start(1000); // Calculate new position each second
}
CentralEffectSimulation::Database::CesSimulatedMovement SimulationMovement::toDb(const CentralEffectSimulation::SimulatedMovement &ddsSimMovement)
{
CentralEffectSimulation::Database::CesSimulatedMovement ret;
ret.id = ddsSimMovement.id();
ret.name = QString::fromStdString(ddsSimMovement.name());
ret.startTime = ddsSimMovement.startTime();
ret.participantId = ddsSimMovement.participantId();
ret.repeat = ddsSimMovement.repeat();
ret.nextpoint = ddsSimMovement.nextPoint();
return ret;
}
}
@@ -0,0 +1,75 @@
/**
* Simulation for Movement
* $Id$
* $HeadURL$
* $Author$
* Created by gr, SLSE, 2017-12-13
*/
#pragma once
#include <CentralEffectSimulation/logger.h>
#include <CentralEffectSimulation/dds_handler.h>
#include <CentralEffectSimulation/handler_participant.h>
#include <CentralEffectSimulation/ces_db.h>
#include <QLineF>
#include <QObject>
#include <QTimer>
namespace CentralEffectSimulationBasic
{
class SimulationMovement : public QObject
{
Q_OBJECT
public:
SimulationMovement(const std::shared_ptr<CentralEffectSimulation::DdsHandler> &ddsHandler,
const std::shared_ptr<CentralEffectSimulation::DatabaseInterface> &db,
const std::shared_ptr<CentralEffectSimulation::HandlerParticipant> &participantHandler,
const CentralEffectSimulation::SimulatedMovement &sml,
QObject *parent = nullptr);
~SimulationMovement();
void setSimulatedMovementRequest(const CentralEffectSimulation::SimulatedMovement &sml);
int id() const { return m_simMovement.id(); }
void setId(int id) { m_simMovement.id(id); }
int participantId() const { return m_simMovement.participantId(); }
void setJump(bool jump);
void setnextPoint(int nextPoint) { m_simMovement.nextPoint(nextPoint); }
int getNextPoint() const { return m_simMovement.nextPoint(); }
void publishSimulatedMovement();
const CentralEffectSimulation::SimulatedMovement &simMovementData() const { return m_simMovement; }
static CentralEffectSimulation::Database::CesSimulatedMovement toDb(const CentralEffectSimulation::SimulatedMovement &ddsSimMovement);
protected Q_SLOTS:
void publishNewPos();
void startNewSegment();
void move();
protected:
void updateNextPointInDb();
private:
std::shared_ptr<CentralEffectSimulation::DdsHandler> m_ddsHandler; ///< Pointer to VOM DDS handler
std::shared_ptr<CentralEffectSimulation::DatabaseInterface> m_db;
std::shared_ptr<CentralEffectSimulation::HandlerParticipant> m_handlerParticipant;
// Input Data
QVector<QPointF> m_points;
QVector<double> m_segSpeed;
QVector<int> m_segDelay;
// Dynamic Data
int m_moveTime; /// Time starts for each segment new
QLineF m_actSegment;
QPointF m_newPos;
bool m_simStart; /// Start of simulation
int m_zone;
QTimer *m_segTimer;
QTimer *m_moveTimer;
CentralEffectSimulation::SimulatedMovement m_simMovement;
CentralEffectSimulation::LOGGER_T &m_logger; ///< Interface to the Logging-Facility
};
}