Commit 71f1f8f9 authored by Projects's avatar Projects Committed by Grzegorz Daniluk

GUI demo: display data status

parent 23e450ab
......@@ -20,6 +20,7 @@
#include <QtWidgets/QGroupBox>
#include <QBoxLayout>
#include <QLabel>
#include <QStatusBar>
#include "controller.h"
DiotHardware::DiotHardware(int address, int slots_nr)
......@@ -45,6 +46,11 @@ DiotHardware::DiotHardware(int address, int slots_nr)
crate->AddVariables(cycle->GetPeriodicVarWindow());
crate->SetConsVarCb([&](nanoFIP &nf, mstrfip_data *data) {
emit StatusChanged(data->status);
if(data->status != MSTRFIP_DATA_OK)
return;
// Report the crate state
DIOT_Crate* crate = static_cast<DIOT_Crate*>(&nf);
......@@ -247,7 +253,8 @@ DiotDiag::DiotDiag(QWidget* parent, DiotHardware& hw)
: QFrame(parent)
{
DIOT_Crate* crate = hw.GetCrate();
QHBoxLayout *mainLayout = new QHBoxLayout();
QVBoxLayout *mainLayout = new QVBoxLayout();
QHBoxLayout *statsLayout = new QHBoxLayout();
// Fans
QGroupBox *fanBox = new QGroupBox(this);
......@@ -259,7 +266,7 @@ DiotDiag::DiotDiag(QWidget* parent, DiotHardware& hw)
}
fanBox->setTitle("Fans");
fanBox->setLayout(fanLayout);
mainLayout->addWidget(fanBox);
statsLayout->addWidget(fanBox);
// Temperature sensors
QGroupBox *tempBox = new QGroupBox(this);
......@@ -271,7 +278,7 @@ DiotDiag::DiotDiag(QWidget* parent, DiotHardware& hw)
}
tempBox->setTitle("Temperature");
tempBox->setLayout(tempLayout);
mainLayout->addWidget(tempBox);
statsLayout->addWidget(tempBox);
// Voltages
QGroupBox *voltBox = new QGroupBox(this);
......@@ -284,7 +291,11 @@ DiotDiag::DiotDiag(QWidget* parent, DiotHardware& hw)
}
voltBox->setTitle("Voltages");
voltBox->setLayout(voltLayout);
mainLayout->addWidget(voltBox);
statsLayout->addWidget(voltBox);
mainLayout->addLayout(statsLayout, 1);
statusBar = new QStatusBar(this);
mainLayout->addWidget(statusBar);
setLayout(mainLayout);
......@@ -294,6 +305,8 @@ DiotDiag::DiotDiag(QWidget* parent, DiotHardware& hw)
this, &DiotDiag::UpdateTemperature);
QObject::connect(&hw, &DiotHardware::VoltageChanged,
this, &DiotDiag::UpdateVoltage);
QObject::connect(&hw, &DiotHardware::StatusChanged,
this, &DiotDiag::UpdateStatus);
}
......@@ -315,6 +328,36 @@ void DiotDiag::UpdateVoltage(unsigned int volt, bool state)
}
void DiotDiag::UpdateStatus(int status)
{
qDebug() << "status: " << status;
switch(status)
{
case MSTRFIP_DATA_OK:
statusBar->showMessage("Status: data OK");
break;
case MSTRFIP_DATA_FRAME_ERROR:
statusBar->showMessage("Status: frame error");
break;
case MSTRFIP_DATA_PAYLOAD_ERROR:
statusBar->showMessage("Status: payload error");
break;
case MSTRFIP_DATA_NOT_RECEIVED:
statusBar->showMessage("Status: data not received");
break;
}
if(status == MSTRFIP_DATA_OK)
statusBar->setStyleSheet("color: green");
else
statusBar->setStyleSheet("color: red");
}
void DiotDiag::updateLabel(std::vector<QLabel*> labels, unsigned int idx,
bool state, const QString& desc, int val)
{
......
......@@ -30,6 +30,7 @@
class DiotIOController;
class QLabel;
class QPushButton;
class QStatusBar;
/**
* Class representing the DIOT crate hardware in the Qt world.
......@@ -103,6 +104,13 @@ signals:
*/
void VoltageChanged(unsigned int volt, bool state);
/**
* Signal emitted to update the data status.
* @param status is the new data status.
* @see enum mstrfip_data_status
*/
void StatusChanged(int status);
private:
std::unique_ptr<MasterFIP> mfip;
std::unique_ptr<CycleSimple> cycle;
......@@ -200,6 +208,8 @@ public slots:
void UpdateVoltage(unsigned int volt, bool state);
void UpdateStatus(int status);
private:
// Helper function to update labels
void updateLabel(std::vector<QLabel*> labels,
......@@ -208,6 +218,7 @@ private:
std::vector<QLabel*> fan_lbl;
std::vector<QLabel*> temp_lbl;
std::vector<QLabel*> volt_lbl;
QStatusBar* statusBar;
};
#endif /* CONTROLLER_H */
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