265 lines
7.6 KiB
C++
Executable File
265 lines
7.6 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* GUI Plugin for ParticipantManagement - ParticipantBiteDialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Patric Karwat, SLSE, 2016-06-13
|
|
*/
|
|
|
|
#include "participant_bite_dialog.h"
|
|
#include "ui_participant_bite_dialog.h"
|
|
#include <ngltools/ngltools_dtg.h>
|
|
|
|
#include <QJsonObject>
|
|
#include <QJsonArray>
|
|
|
|
|
|
namespace ParticipantManagement
|
|
{
|
|
ParticipantBiteDialog::ParticipantBiteDialog(int ddsId, QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
|
, m_ddsId(ddsId)
|
|
, m_eqipNr(-1)
|
|
, m_fromDetailData(false)
|
|
, m_dtc(nullptr)
|
|
, m_ftc(nullptr)
|
|
, m_requestHelper(nullptr)
|
|
, m_layout(nullptr)
|
|
, m_ui(new Ui::ParticipantBiteDialog)
|
|
, m_logger(getLogger("ParticipantBiteDialog"))
|
|
, m_ccsMap()
|
|
, m_bctMap()
|
|
{
|
|
m_ui->setupUi(this);
|
|
setUnchangeable();
|
|
}
|
|
|
|
ParticipantBiteDialog::~ParticipantBiteDialog()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
void ParticipantBiteDialog::retranslate()
|
|
{
|
|
QString id(tr("<UNKNOWN>"));
|
|
if (m_eqipNr > 0)
|
|
id = QString::number(m_eqipNr);
|
|
|
|
translate(m_ui, id, false, tr("BITE Participant"));
|
|
}
|
|
|
|
bool ParticipantBiteDialog::init(const std::shared_ptr<Interface::Dtc> &dtc,
|
|
const std::shared_ptr<Interface::Ftc> &ftc,
|
|
const std::shared_ptr<ProjectDataManagement::Interface::Dtc> &pdmDtc,
|
|
bool bBiteWithSelfTest,
|
|
const QJsonObject &detailData)
|
|
{
|
|
m_dtc = dtc;
|
|
m_ftc = ftc;
|
|
m_pdmDtc = pdmDtc;
|
|
|
|
if (!m_dtc || !m_ftc || !pdmDtc)
|
|
return false;
|
|
|
|
m_ccsMap = pdmDtc->canComponentStrings();
|
|
m_bctMap = pdmDtc->biteComponentTexts();
|
|
|
|
if (detailData.isEmpty())
|
|
{
|
|
Participant participant = m_dtc->participant(m_ddsId);
|
|
if (participant.equipmentNumber().is_set())
|
|
m_eqipNr = participant.equipmentNumber().get();
|
|
|
|
//start a new request
|
|
connect(m_dtc.get(), &Interface::Dtc::biteChanged, this, &ParticipantBiteDialog::onBiteChanged);
|
|
CallBiteRequest req(bBiteWithSelfTest, {m_ddsId});
|
|
|
|
if (!m_requestHelper)
|
|
m_requestHelper = new LtsUtils::RequestHelper(this);
|
|
m_requestHelper->startSingleRequest([req, this]()
|
|
{
|
|
return m_ftc->callBiteRequest(req, this);
|
|
});
|
|
|
|
//we may show old values when the timestamp is set.
|
|
}
|
|
else // take Bite from the apple, uh, the detail data
|
|
{
|
|
m_fromDetailData = true;
|
|
|
|
const QJsonArray biteErrors(detailData[QStringLiteral("BiteErrors")].toArray());
|
|
|
|
Bite bite;
|
|
bite.batteryState(detailData[QStringLiteral("BatteryState")].toInt());
|
|
bite.biteState(detailData[QStringLiteral("BiteState")].toInt());
|
|
bite.configState(detailData[QStringLiteral("ConfigState")].toInt());
|
|
|
|
BiteError biteError;
|
|
bite.biteErrors().reserve(biteErrors.size());
|
|
for (const QJsonValue &biteErrorValue : biteErrors)
|
|
{
|
|
const QJsonObject biteErrorObject(biteErrorValue.toObject());
|
|
biteError.errorNumber(biteErrorObject[QStringLiteral("ErrorNo")].toInt());
|
|
biteError.canDeviceNumber(biteErrorObject[QStringLiteral("CanDeviceNumber")].toInt());
|
|
biteError.subdeviceNumber(biteErrorObject[QStringLiteral("SubdeviceNumber")].toInt());
|
|
biteError.uniqueId(biteErrorObject[QStringLiteral("UniqueId")].toInt());
|
|
|
|
bite.biteErrors().push_back(biteError);
|
|
}
|
|
onBiteChanged(bite);
|
|
}
|
|
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
//private
|
|
|
|
int ParticipantBiteDialog::checkArguments(bool available, bool statusOk, qint64 bitValue, int i)
|
|
{
|
|
QString name;
|
|
for (const ProjectDataManagement::CanComponentString &ccs : qAsConst(m_ccsMap))
|
|
{
|
|
if (ccs.bitMask() == bitValue)
|
|
{
|
|
name = m_pdmDtc->trCanComponentStringName(ccs.id());
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (available)
|
|
{
|
|
addLabel(name, i, 0);
|
|
if (statusOk)
|
|
{
|
|
addLabel(tr("Ok"), i, 1, LabelType::Ok);
|
|
}
|
|
else
|
|
{
|
|
addLabel(tr("Error"), i, 1, LabelType::Error);
|
|
}
|
|
i++;
|
|
}
|
|
else if (statusOk)
|
|
{
|
|
addLabel(name, i, 0);
|
|
addLabel(tr("Communication error"), i, 1, LabelType::Error);
|
|
i++;
|
|
}
|
|
return i;
|
|
}
|
|
|
|
int ParticipantBiteDialog::checkArgument(bool bError, const QString &name, int i)
|
|
{
|
|
if (bError)
|
|
{
|
|
addLabel(name, i, 0, LabelType::Error);
|
|
i++;
|
|
}
|
|
return i;
|
|
}
|
|
|
|
void ParticipantBiteDialog::addLabel(const QString &text, int row, int column, LabelType labelType)
|
|
{
|
|
QLabel *label = new QLabel(text);
|
|
|
|
if (labelType == LabelType::Error)
|
|
label->setStyleSheet(QLatin1String("color: rgb(255, 0, 0);font: bold;"));
|
|
else if (labelType == LabelType::Ok)
|
|
label->setStyleSheet(QLatin1String("color: rgb(0, 139, 0);font: bold;"));
|
|
|
|
m_layout->addWidget(label, row, column);
|
|
m_internalWidgets += label;
|
|
}
|
|
|
|
|
|
//private Slots
|
|
void ParticipantBiteDialog::onBiteChanged(const Bite &bite)
|
|
{
|
|
if (bite.equipmentNumber() != m_eqipNr && !m_fromDetailData)
|
|
return;
|
|
|
|
m_ui->lblLastChange->setText(DTG::toStringMSec(bite.sampleTime()));
|
|
delete m_ui->scrollAreaWidgetContents->layout();
|
|
m_layout = new QGridLayout(m_ui->scrollAreaWidgetContents);
|
|
|
|
qDeleteAll(m_internalWidgets);
|
|
m_internalWidgets.clear();
|
|
|
|
int row = 0;
|
|
|
|
for (int it = 0 ; it < 32; it++)
|
|
{
|
|
quint32 bitValue = 1U << it;
|
|
row = checkArguments(((bite.biteState() & bitValue) == bitValue),
|
|
((bite.configState() & bitValue) == bitValue), bitValue, row);
|
|
}
|
|
|
|
row = checkArgument(bite.configError() != 0, tr("Configcheck error", "BITE CAN"), row);
|
|
if (row > 0)
|
|
m_layout->addItem(new QSpacerItem(10, 10, QSizePolicy::Fixed, QSizePolicy::Fixed), row++, 0);
|
|
row = checkArgument(bite.batteryState() != 0, tr("Battery Warning", "BITE CAN"), row);
|
|
m_layout->addItem(new QSpacerItem(10, 10, QSizePolicy::Fixed, QSizePolicy::Fixed), row++, 0);
|
|
|
|
for (const auto &bitEr : bite.biteErrors())
|
|
{
|
|
QLabel *labl = nullptr;
|
|
if (bitEr.subdeviceNumber() != 0)
|
|
labl = new QLabel(tr("Error: %1 \nComponent: %2 \nSubdev: %3 \nUId: %4 ")
|
|
.arg(getErrorString(bitEr),
|
|
getCanDeviceName(bitEr.canDeviceNumber()),
|
|
getSubDeviceName(bitEr.subdeviceNumber()))
|
|
.arg(QString::number( bitEr.uniqueId(), 16 ).toUpper()));
|
|
// .arg(bitEr.uniqueId()));
|
|
else if (bitEr.canDeviceNumber() != 0)
|
|
labl = new QLabel(tr("Error: %1 \nComponent: %2")
|
|
.arg(getErrorString(bitEr),
|
|
getCanDeviceName(bitEr.canDeviceNumber())));
|
|
|
|
if (labl)
|
|
{
|
|
m_layout->addWidget(labl , row++, 0);
|
|
m_internalWidgets.append(labl);
|
|
}
|
|
}
|
|
|
|
m_layout->addItem(new QSpacerItem(10, 10, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding), row, 0);
|
|
}
|
|
|
|
QString ParticipantBiteDialog::getErrorString(const ParticipantManagement::BiteError &error) const
|
|
{
|
|
const bool subDevice = (error.subdeviceNumber() != 0);
|
|
for (const ProjectDataManagement::BiteComponentText &bct : m_bctMap)
|
|
{
|
|
if (((subDevice && bct.subDeviceId() == error.subdeviceNumber()) ||
|
|
(bct.canDeviceId() == error.canDeviceNumber())) &&
|
|
(bct.errorNumber() == error.errorNumber()))
|
|
return m_pdmDtc->trBiteComponentTextName(bct.id());
|
|
}
|
|
return tr("Unknown (%1)").arg(error.errorNumber());
|
|
}
|
|
|
|
QString ParticipantBiteDialog::getCanDeviceName(int id) const
|
|
{
|
|
for (const ProjectDataManagement::CanComponentString &ccs : m_ccsMap)
|
|
{
|
|
if (ccs.canDeviceId() == id)
|
|
return m_pdmDtc->trCanComponentStringName(ccs.id());
|
|
}
|
|
return tr("Unknown (%1)").arg(id);
|
|
}
|
|
|
|
QString ParticipantBiteDialog::getSubDeviceName(int id) const
|
|
{
|
|
for (const ProjectDataManagement::CanComponentString &ccs : m_ccsMap)
|
|
{
|
|
if (ccs.subDeviceId() == id)
|
|
return m_pdmDtc->trCanComponentStringName(ccs.id());
|
|
}
|
|
return tr("Unknown (%1)").arg(id);
|
|
}
|
|
|
|
} // namespace ParticipantManagement
|