Commit 3558e53c authored by Projects's avatar Projects Committed by Grzegorz Daniluk

GUI demo: display more data statistics

parent 3b322b93
...@@ -23,6 +23,16 @@ ...@@ -23,6 +23,16 @@
#include <QStatusBar> #include <QStatusBar>
#include "controller.h" #include "controller.h"
// Register custom type for Qt signals
static struct registerMetatypes {
registerMetatypes()
{
qRegisterMetaType<nanoFIP::DataStatusMap>("nanoFIP::DataStatusMap");
qRegisterMetaType<mstrfip_data_status>("mstrfip_data_status");
}
} _registerMetatypes;
DiotHardware::DiotHardware(int address, int slots_nr) DiotHardware::DiotHardware(int address, int slots_nr)
{ {
// Configure MasterFIP // Configure MasterFIP
...@@ -46,8 +56,9 @@ DiotHardware::DiotHardware(int address, int slots_nr) ...@@ -46,8 +56,9 @@ DiotHardware::DiotHardware(int address, int slots_nr)
crate->AddVariables(cycle->GetPeriodicVarWindow()); crate->AddVariables(cycle->GetPeriodicVarWindow());
crate->SetConsVarCb([&](nanoFIP &nf, mstrfip_data *data) { crate->SetConsVarCb([&](nanoFIP &nf, mstrfip_data *data) {
emit StatusChanged(data->status); emit StatusChanged(data->status, nf.GetDataStats());
// No more updates if the data is invalid
if(data->status != MSTRFIP_DATA_OK) if(data->status != MSTRFIP_DATA_OK)
return; return;
...@@ -292,6 +303,20 @@ DiotDiag::DiotDiag(QWidget* parent, const DiotHardware& hw) ...@@ -292,6 +303,20 @@ DiotDiag::DiotDiag(QWidget* parent, const DiotHardware& hw)
voltBox->setTitle("Voltages"); voltBox->setTitle("Voltages");
voltBox->setLayout(voltLayout); voltBox->setLayout(voltLayout);
statsLayout->addWidget(voltBox); statsLayout->addWidget(voltBox);
// Data statistics
QGroupBox *statBox = new QGroupBox(this);
QVBoxLayout *statLayout = new QVBoxLayout();
for(const auto& statType : hw.GetCrate()->GetDataStats()) {
auto statWidget = new QLabel(QString("%1: 0")
.arg(QString::fromStdString(nanoFIP::GetDataStatDesc(statType.first))));
statLayout->addWidget(statWidget);
stat_lbl.push_back(statWidget);
}
statBox->setTitle("Data statistics");
statBox->setLayout(statLayout);
statsLayout->addWidget(statBox);
mainLayout->addLayout(statsLayout, 1); mainLayout->addLayout(statsLayout, 1);
statusBar = new QStatusBar(this); statusBar = new QStatusBar(this);
...@@ -328,7 +353,8 @@ void DiotDiag::UpdateVoltage(unsigned int volt, bool state) ...@@ -328,7 +353,8 @@ void DiotDiag::UpdateVoltage(unsigned int volt, bool state)
} }
void DiotDiag::UpdateStatus(int status) void DiotDiag::UpdateStatus(mstrfip_data_status status,
const nanoFIP::DataStatusMap& stats)
{ {
qDebug() << "status: " << status; qDebug() << "status: " << status;
...@@ -359,6 +385,13 @@ void DiotDiag::UpdateStatus(int status) ...@@ -359,6 +385,13 @@ void DiotDiag::UpdateStatus(int status)
statusBar->setStyleSheet("color: red"); statusBar->setStyleSheet("color: red");
parentWidget()->setEnabled(false); parentWidget()->setEnabled(false);
} }
for( const auto& stat : stats )
{
stat_lbl[static_cast<int>(stat.first)]->setText(QString("%1: %2")
.arg(QString::fromStdString(nanoFIP::GetDataStatDesc(stat.first)))
.arg(stat.second));
}
} }
......
...@@ -107,9 +107,11 @@ signals: ...@@ -107,9 +107,11 @@ signals:
/** /**
* Signal emitted to update the data status. * Signal emitted to update the data status.
* @param status is the new data status. * @param status is the new data status.
* @param stats contains statistics.
* @see enum mstrfip_data_status * @see enum mstrfip_data_status
*/ */
void StatusChanged(int status); void StatusChanged(mstrfip_data_status status,
const nanoFIP::DataStatusMap& stats);
private: private:
std::unique_ptr<MasterFIP> mfip; std::unique_ptr<MasterFIP> mfip;
...@@ -208,7 +210,7 @@ public slots: ...@@ -208,7 +210,7 @@ public slots:
void UpdateVoltage(unsigned int volt, bool state); void UpdateVoltage(unsigned int volt, bool state);
void UpdateStatus(int status); void UpdateStatus(mstrfip_data_status status, const nanoFIP::DataStatusMap& stats);
private: private:
// Helper function to update labels // Helper function to update labels
...@@ -218,6 +220,7 @@ private: ...@@ -218,6 +220,7 @@ private:
std::vector<QLabel*> fan_lbl; std::vector<QLabel*> fan_lbl;
std::vector<QLabel*> temp_lbl; std::vector<QLabel*> temp_lbl;
std::vector<QLabel*> volt_lbl; std::vector<QLabel*> volt_lbl;
std::vector<QLabel*> stat_lbl;
QStatusBar* statusBar; QStatusBar* statusBar;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment