251 lines
7.5 KiB
C++
Executable File
251 lines
7.5 KiB
C++
Executable File
/**
|
|
* Handler for the HMI language
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* created by Philipp Dassow 2017-07-20
|
|
*/
|
|
|
|
#include "object_ied.h"
|
|
|
|
#include <gim.hpp>
|
|
|
|
#include "dds_handler.h"
|
|
#include "logger.h"
|
|
|
|
namespace GuezIedManagement
|
|
{
|
|
|
|
ObjectIed::ObjectIed(const std::shared_ptr<DdsHandler> &ddsHandler,
|
|
const std::shared_ptr<DatabaseInterface> &db,
|
|
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc,
|
|
QObject *parent)
|
|
: QObject(parent)
|
|
, m_ddsHandler(ddsHandler)
|
|
, m_db(db)
|
|
, m_ppmDtc(ppmDtc)
|
|
, m_logger(getLogger("ObjectIed"))
|
|
{
|
|
}
|
|
|
|
ObjectIed::~ObjectIed()
|
|
{
|
|
m_ddsHandler->dts()->removeIedByKey(m_data.id);
|
|
}
|
|
|
|
Core::FunctionReplyObject ObjectIed::createObject(const Database::GimIed &data)
|
|
{
|
|
m_data = data;
|
|
if (m_data.id <= 0)
|
|
{
|
|
if(!m_db->insert(m_data))
|
|
{
|
|
return Core::FunctionReplyObject(0, tr_lts("dds", "Error inserting IED-data into database"));
|
|
}
|
|
|
|
// Id is serial -> will be generated by db => inside m_data after db-insert
|
|
DEBUG_LOG(m_logger) << "New IED-Id: " << m_data.id;
|
|
}
|
|
|
|
INFO_LOG(m_logger) << "Ied created sucessfully.";
|
|
|
|
// Publish Data via DTS
|
|
onPublishData();
|
|
|
|
return Core::FunctionReplyObject(m_data.id);
|
|
}
|
|
|
|
Core::FunctionReplyObject ObjectIed::updateDefinition(const Database::GimIed &data)
|
|
{
|
|
assignBaseData(data);
|
|
m_data.typeId = data.typeId;
|
|
m_data.remoteTrigger = data.remoteTrigger;
|
|
m_data.tautWireTrigger = data.tautWireTrigger;
|
|
m_data.lightBarrierTrigger = data.lightBarrierTrigger;
|
|
m_data.switchTrigger = data.switchTrigger;
|
|
m_data.explosiveForce = data.explosiveForce;
|
|
m_data.symbol = data.symbol;
|
|
assignPairingState(data);
|
|
|
|
return updateObject();
|
|
}
|
|
|
|
Core::FunctionReplyObject ObjectIed::updateState(const Database::GimIed &data)
|
|
{
|
|
assignBaseData(data);
|
|
m_data.batterywarnings = data.batterywarnings;
|
|
m_data.electronicsErrorStateId = data.electronicsErrorStateId;
|
|
m_data.pyrotechnics1ErrorStateId = data.pyrotechnics1ErrorStateId;
|
|
m_data.pyrotechnics2ErrorStateId = data.pyrotechnics2ErrorStateId;
|
|
m_data.pyrotechnics3ErrorStateId = data.pyrotechnics3ErrorStateId;
|
|
|
|
return updateObject();
|
|
}
|
|
|
|
Core::FunctionReplyObject ObjectIed::updatePairingState(const Database::GimIed &data)
|
|
{
|
|
assignPairingState(data);
|
|
|
|
return updateObject();
|
|
}
|
|
|
|
Core::FunctionReplyObject ObjectIed::removeObject()
|
|
{
|
|
if (!m_db->removeGimIed(m_data.id))
|
|
return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "IED with id %1 can not be removed from DB")).arg(m_data.id);
|
|
|
|
if (!m_ddsHandler->dts()->removeIedByKey(m_data.id))
|
|
return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "IED with id %1 can not be removed from DDS")).arg(m_data.id);
|
|
|
|
return Core::FunctionReplyObject(m_data.id);
|
|
}
|
|
|
|
void ObjectIed::setPosition(int64_t sampleTime, const Core::GeoPosition &pos)
|
|
{
|
|
setPosition(IedPosition(m_data.id,
|
|
"IedPosition",
|
|
false,
|
|
true,
|
|
sampleTime,
|
|
pos));
|
|
}
|
|
|
|
void ObjectIed::setPosition(const IedPosition &position)
|
|
{
|
|
m_position = position;
|
|
publishPosition();
|
|
}
|
|
|
|
void ObjectIed::onPublishData()
|
|
{
|
|
GuezIedManagement::Ied ddsData;
|
|
|
|
ddsData.id(m_data.id);
|
|
ddsData.equipmentNumber(m_data.equipmentNumber);
|
|
ddsData.type(IedType(m_data.typeId));
|
|
ddsData.remoteTrigger(m_data.remoteTrigger);
|
|
ddsData.switchTrigger(m_data.switchTrigger);
|
|
ddsData.lightBarrierTrigger(m_data.lightBarrierTrigger);
|
|
ddsData.tautWireTrigger(m_data.tautWireTrigger);
|
|
ddsData.explosiveForce(m_data.explosiveForce);
|
|
ddsData.partyId(m_data.partyId);
|
|
ddsData.pairingState(IedPairingState(m_data.pairingStateId));
|
|
|
|
switch(ddsData.pairingState().underlying())
|
|
{
|
|
case IedPairingState_def::PairedToParticipant:
|
|
{
|
|
ddsData.pairedParticipantId().set(m_data.pairedParticipantId.toInt());
|
|
connect(m_ppmDtc.get(), &ParticipantManagement::Interface::Dtc::participantPositionChanged, this, &ObjectIed::onParticipantPositionChanged, Qt::UniqueConnection);
|
|
break;
|
|
}
|
|
case IedPairingState_def::PairedToOps:
|
|
{
|
|
ddsData.pairedOpsId().set(m_data.pairedOpsId.toInt());
|
|
//todo: connect to ISM for OPS-Position
|
|
disconnect(m_ppmDtc.get(), &ParticipantManagement::Interface::Dtc::participantPositionChanged, this, &ObjectIed::onParticipantPositionChanged);
|
|
break;
|
|
}
|
|
case IedPairingState_def::NotPaired:
|
|
{
|
|
disconnect(m_ppmDtc.get(), &ParticipantManagement::Interface::Dtc::participantPositionChanged, this, &ObjectIed::onParticipantPositionChanged);
|
|
//todo: disconnect from ISM for OPS-Position
|
|
break;
|
|
}
|
|
}
|
|
|
|
ddsData.tacticalState(IedTacticalState(m_data.tacticalStateId));
|
|
ddsData.pyrotechnics(m_data.pyrotechnics);
|
|
ddsData.batteryWarnings(m_data.batterywarnings);
|
|
ddsData.electronicsError(IedError(m_data.electronicsErrorStateId));
|
|
ddsData.pyrotechnics1Error(IedError(m_data.pyrotechnics1ErrorStateId));
|
|
ddsData.pyrotechnics2Error(IedError(m_data.pyrotechnics2ErrorStateId));
|
|
ddsData.pyrotechnics3Error(IedError(m_data.pyrotechnics3ErrorStateId));
|
|
ddsData.symbol(m_data.symbol.toStdString());
|
|
ddsData.sampleTime(m_data.sampleTime);
|
|
|
|
INFO_LOG(m_logger) << "Publish IED-data to dds (" << m_data.id << ") ...";
|
|
|
|
if (!m_ddsHandler->dts()->publish(ddsData))
|
|
ERROR_LOG(m_logger) << "Error publishing IED-data to dds";
|
|
}
|
|
|
|
void ObjectIed::onParticipantPositionChanged(const ParticipantManagement::ParticipantPosition &data, DataModification modType)
|
|
{
|
|
if (modType != DataModification::eAdded && modType != DataModification::eModified)
|
|
return;
|
|
|
|
if (data.participantId() == m_data.pairedParticipantId.toInt())
|
|
setPosition(data.sampleTime(), data.pos());
|
|
}
|
|
|
|
void ObjectIed::assignBaseData(const Database::GimIed &data)
|
|
{
|
|
m_data.equipmentNumber = data.equipmentNumber;
|
|
m_data.tacticalStateId = data.tacticalStateId;
|
|
m_data.pyrotechnics = data.pyrotechnics;
|
|
m_data.sampleTime = data.sampleTime;
|
|
}
|
|
|
|
void ObjectIed::assignPairingState(const Database::GimIed &data)
|
|
{
|
|
m_data.pairedParticipantId = data.pairedParticipantId;
|
|
m_data.pairedOpsId = data.pairedOpsId;
|
|
m_data.partyId = data.partyId;
|
|
|
|
switch(data.pairingStateId.underlying())
|
|
{
|
|
case IedPairingState_def::PairedToParticipant:
|
|
{
|
|
ParticipantManagement::ParticipantPosition position = m_ppmDtc->participantPosition(m_data.pairedParticipantId.toInt());
|
|
setPosition(position.sampleTime(), position.pos());
|
|
break;
|
|
}
|
|
case IedPairingState_def::PairedToOps:
|
|
{
|
|
// todo get Ops-Position
|
|
break;
|
|
}
|
|
case IedPairingState_def::NotPaired:
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
m_data.pairingStateId = data.pairingStateId;
|
|
}
|
|
|
|
Core::FunctionReplyObject ObjectIed::updateObject()
|
|
{
|
|
if (!isValid())
|
|
return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "Trying to update an already removed IED object"));
|
|
|
|
INFO_LOG(m_logger) << "Trying to updateObject IedData with id = " << m_data.id;
|
|
|
|
if (!m_db->update(m_data))
|
|
{
|
|
ERROR_LOG(m_logger) << "Failed to update IedData with id = " << m_data.id;
|
|
return Core::FunctionReplyObject(m_data.id, tr_lts("dds", "Error updating IED-data with id %1 in database")).arg(m_data.id);
|
|
}
|
|
|
|
INFO_LOG(m_logger) << "IED-Data changed sucessfully.";
|
|
|
|
// Publish Data via DTS
|
|
onPublishData();
|
|
|
|
return Core::FunctionReplyObject(m_data.id);
|
|
}
|
|
|
|
void ObjectIed::publishPosition()
|
|
{
|
|
if (!m_ddsHandler->dts()->publish(m_position))
|
|
ERROR_LOG(m_logger) << "Error publishing IED-position to dds";
|
|
}
|
|
|
|
bool ObjectIed::isValid() const
|
|
{
|
|
return m_data.id > 0;
|
|
}
|
|
|
|
} // Namespace GuezIedManagement
|