Commit 3c9f7be1 authored by Gertulla, Janis Luca's avatar Gertulla, Janis Luca
Browse files

Visual overhaul, division of locking and triggering.

parent e8f8f1b3
......@@ -22,7 +22,6 @@ SOURCES += \
main.cpp \
overlaytab.cpp \
settingstab.cpp \
valuestab.cpp \
window.cpp
HEADERS += \
......@@ -31,14 +30,12 @@ HEADERS += \
lib.h \
overlaytab.h \
settingstab.h \
valuestab.h \
window.h
FORMS += \
graphtab.ui \
overlaytab.ui \
settingstab.ui \
valuestab.ui \
window.ui
# Default rules for deployment.
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.13.1, 2020-10-20T18:33:28. -->
<!-- Written by QtCreator 4.13.1, 2020-10-21T12:23:44. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......@@ -280,6 +280,11 @@
<value type="QString" key="Analyzer.Perf.SampleMode">-F</value>
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
<value type="int" key="Analyzer.Perf.StackSize">4096</value>
<value type="bool" key="Analyzer.QmlProfiler.AggregateTraces">false</value>
<value type="bool" key="Analyzer.QmlProfiler.FlushEnabled">false</value>
<value type="uint" key="Analyzer.QmlProfiler.FlushInterval">0</value>
<value type="QString" key="Analyzer.QmlProfiler.LastTraceFile"></value>
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
......
......@@ -44,6 +44,23 @@ void read_int16(uint8_t **buf, int16_t *x)
(*buf)++;
}
void write_uint16(uint8_t **buf, uint16_t x)
{
**buf = (uint8_t) (x >> 8);
(*buf)++;
**buf = (uint8_t) (x & 0xFF);
(*buf)++;
}
void read_uint16(uint8_t **buf, uint16_t *x)
{
*x = 0;
*x |= **buf << 8;
(*buf)++;
*x |= **buf;
(*buf)++;
}
void write_bools(uint8_t **buf, bool b1, bool b2, bool b3, bool b4, bool b5, bool b6, bool b7, bool b8)
{
**buf = (b1 << 7) | (b2 << 6) | (b3 << 5) | (b4 << 4) | (b5 << 3) | (b6 << 2) | (b7 << 1) | (b8 << 0);
......@@ -146,20 +163,32 @@ void Client::handleData()
else if(msgHeader == MsgState) // state change
{
if(msgLen != 2) emit log("invalid state length!");
if(msgLen != 22) emit log("invalid state length!");
PlcState newStat;
read_bools(p, &newStat.override, &newStat.linked,
&newStat.pGratActive, &newStat.pMcpActive, &newStat.pVvActive,
&newStat.tDetActive, &newStat.tDpsActive,
&newStat.tGratActive, &newStat.tDetActive,
nullptr);
read_bools(p, &newStat.vTdetOpen, &newStat.vDetOpen, &newStat.vFoilOpen, &newStat.vDpsOpen,
&newStat.hvmcpHigh, &newStat.rbeamlineHigh,
&newStat.pumpEnabled,
nullptr,
nullptr);
read_int16(p, &newStat.pGratLock);
read_int16(p, &newStat.pGratTrigger);
read_int16(p, &newStat.pMcpLock);
read_int16(p, &newStat.pMcpTrigger);
read_int16(p, &newStat.pVvLock);
read_int16(p, &newStat.pVvTrigger);
read_int16(p, &newStat.tGratLock);
read_int16(p, &newStat.tGratTrigger);
read_int16(p, &newStat.tDetLock);
read_int16(p, &newStat.tDetTrigger);
emit newState(newStat);
}
......@@ -172,8 +201,8 @@ void Client::handleData()
read_int16(p, &newMeas.pMcp);
read_int16(p, &newMeas.pVv);
read_int16(p, &newMeas.tGrat);
read_int16(p, &newMeas.tDet);
read_int16(p, &newMeas.tDps);
read_bools(p, &newMeas.vTdetHigh, &newMeas.vDetHigh, &newMeas.vFoilHigh, &newMeas.vDpsHigh,
&newMeas.vTdetLow, &newMeas.vDetLow, &newMeas.vFoilLow, &newMeas.vDpsLow);
......@@ -191,48 +220,35 @@ void Client::handleData()
void Client::onSendState(PlcState &state)
{
uint8_t data[4];
uint8_t data[24];
uint8_t *l = data;
uint8_t **p = &l;
// data[0] = 0x01; // PlcState
// data[1] = 0x02; // Length = 2;
// data[2] |= (state.override & 1) << 7;
// data[2] |= (state.linked & 1) << 6;
// data[2] |= (state.pGratActive & 1) << 5;
// data[2] |= (state.pMcpActive & 1) << 4;
// data[2] |= (state.pVvActive & 1) << 3;
// data[2] |= (state.tDetActive & 1) << 2;
// data[2] |= (state.tDpsActive & 1) << 1;
// data[3] |= (state.vTdetOpen & 1) << 7;
// data[3] |= (state.vDetOpen & 1) << 6;
// data[3] |= (state.vFoilOpen & 1) << 5;
// data[3] |= (state.vDpsOpen & 1) << 4;
// data[3] |= (state.hvmcpHigh & 1) << 3;
// data[3] |= (state.rbeamlineHigh & 1)<< 2;
// data[3] |= (state.pumpEnabled & 1) << 1;
write_byte(p, 1);
write_byte(p, 2);
write_byte(p, 22);
write_bools(p, state.override, state.linked,
state.pGratActive, state.pMcpActive, state.pVvActive,
state.tDetActive, state.tDpsActive,
state.tGratActive, state.tDetActive,
0);
write_bools(p, state.vTdetOpen, state.vDetOpen, state.vFoilOpen, state.vDpsOpen,
state.hvmcpHigh, state.rbeamlineHigh,
state.pumpEnabled,
0,
0);
write((const char *) data, 4);
write_int16(p, state.pGratLock);
write_int16(p, state.pGratTrigger);
write_int16(p, state.pMcpLock);
write_int16(p, state.pMcpTrigger);
write_int16(p, state.pVvLock);
write_int16(p, state.pVvTrigger);
write_int16(p, state.tGratLock);
write_int16(p, state.tGratTrigger);
write_int16(p, state.tDetLock);
write_int16(p, state.tDetTrigger);
write((const char *) data, 24);
}
void Client::onNewConfig(Config &newConfig)
......
......@@ -3,12 +3,11 @@
GraphTab::GraphTab(QWidget *parent) :
QWidget(parent),
ui(new Ui::GraphTab)
ui(std::make_unique<Ui::GraphTab>())
{
ui->setupUi(this);
}
GraphTab::~GraphTab()
{
delete ui;
}
......@@ -2,6 +2,7 @@
#define GRAPHTAB_H
#include <QWidget>
#include <memory>
namespace Ui {
class GraphTab;
......@@ -16,7 +17,7 @@ public:
~GraphTab();
private:
Ui::GraphTab *ui;
std::unique_ptr<Ui::GraphTab> ui;
};
#endif // GRAPHTAB_H
......@@ -13,6 +13,37 @@
<property name="windowTitle">
<string>Form</string>
</property>
<property name="styleSheet">
<string notr="true">background-color: #333;
colof: #fff;</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>480</x>
<y>440</y>
<width>701</width>
<height>101</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>12</pointsize>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">background-color: #333;
color: #fff;</string>
</property>
<property name="text">
<string>TO BE IMPLEMENTED IN EARLY NOVEMBER!!!</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</widget>
<resources/>
<connections/>
......
......@@ -9,8 +9,8 @@ PlcState::PlcState()
pMcpActive = true;
pVvActive = true;
tGratActive = true;
tDetActive = true;
tDpsActive = true;
vTdetOpen = false;
vDetOpen = false;
......@@ -20,7 +20,21 @@ PlcState::PlcState()
hvmcpHigh = false;
rbeamlineHigh = true;
pumpEnabled = false;
pGratLock = 563;
pGratTrigger = 618;
pMcpLock = 332;
pMcpTrigger = 409;
pVvLock = 563;
pVvTrigger = 618;
tGratLock = 870;
tGratTrigger = 818;
tDetLock = 870;
tDetTrigger = 818;
}
PlcState::PlcState(PlcState &other)
......@@ -32,8 +46,8 @@ PlcState::PlcState(PlcState &other)
pMcpActive = other.pMcpActive;
pVvActive = other.pVvActive;
tGratActive = other.tGratActive;
tDetActive = other.tDetActive;
tDpsActive = other.tDpsActive;
vTdetOpen = other.vTdetOpen;
vDetOpen = other.vDetOpen;
......@@ -43,8 +57,21 @@ PlcState::PlcState(PlcState &other)
hvmcpHigh = other.hvmcpHigh;
rbeamlineHigh = other.rbeamlineHigh;
pumpEnabled = other.pumpEnabled;
pGratLock = other.pGratLock;
pGratTrigger = other.pGratTrigger;
pMcpLock = other.pMcpLock;
pMcpTrigger = other.pMcpTrigger;
pVvLock = other.pVvLock;
pVvTrigger = other.pVvTrigger;
tGratLock = other.tGratLock;
tGratTrigger = other.tGratTrigger;
tDetLock = other.tDetLock;
tDetTrigger = other.tDetTrigger;
}
PlcState::PlcState(PlcState &&other)
......@@ -56,8 +83,8 @@ PlcState::PlcState(PlcState &&other)
pMcpActive = other.pMcpActive;
pVvActive = other.pVvActive;
tGratActive = other.tGratActive;
tDetActive = other.tDetActive;
tDpsActive = other.tDpsActive;
vTdetOpen = other.vTdetOpen;
vDetOpen = other.vDetOpen;
......@@ -67,8 +94,21 @@ PlcState::PlcState(PlcState &&other)
hvmcpHigh = other.hvmcpHigh;
rbeamlineHigh = other.rbeamlineHigh;
pumpEnabled = other.pumpEnabled;
pGratLock = other.pGratLock;
pGratTrigger = other.pGratTrigger;
pMcpLock = other.pMcpLock;
pMcpTrigger = other.pMcpTrigger;
pVvLock = other.pVvLock;
pVvTrigger = other.pVvTrigger;
tGratLock = other.tGratLock;
tGratTrigger = other.tGratTrigger;
tDetLock = other.tDetLock;
tDetTrigger = other.tDetTrigger;
}
PlcState::PlcState(PlcState *other) : PlcState()
......@@ -82,8 +122,8 @@ PlcState::PlcState(PlcState *other) : PlcState()
this->pMcpActive = other->pMcpActive;
this->pVvActive = other->pVvActive;
this->tGratActive = other->tGratActive;
this->tDetActive = other->tDetActive;
this->tDpsActive = other->tDpsActive;
this->vTdetOpen = other->vTdetOpen;
this->vDetOpen = other->vDetOpen;
......@@ -93,7 +133,21 @@ PlcState::PlcState(PlcState *other) : PlcState()
this->hvmcpHigh = other->hvmcpHigh;
this->rbeamlineHigh = other->rbeamlineHigh;
this->pumpEnabled = other->pumpEnabled;
this->pGratLock = other->pGratLock;
this->pGratTrigger = other->pGratTrigger;
this->pMcpLock = other->pMcpLock;
this->pMcpTrigger = other->pMcpTrigger;
this->pVvLock = other->pVvLock;
this->pVvTrigger = other->pVvTrigger;
this->tGratLock = other->tGratLock;
this->tGratTrigger = other->tGratTrigger;
this->tDetLock = other->tDetLock;
this->tDetTrigger = other->tDetTrigger;
}
}
......@@ -106,8 +160,8 @@ void PlcState::operator=(PlcState &other)
this->pMcpActive = other.pMcpActive;
this->pVvActive = other.pVvActive;
this->tGratActive = other.tGratActive;
this->tDetActive = other.tDetActive;
this->tDpsActive = other.tDpsActive;
this->vTdetOpen = other.vTdetOpen;
this->vDetOpen = other.vDetOpen;
......@@ -117,45 +171,83 @@ void PlcState::operator=(PlcState &other)
this->hvmcpHigh = other.hvmcpHigh;
this->rbeamlineHigh = other.rbeamlineHigh;
this->pumpEnabled = other.pumpEnabled;
this->pGratLock = other.pGratLock;
this->pGratTrigger = other.pGratTrigger;
this->pMcpLock = other.pMcpLock;
this->pMcpTrigger = other.pMcpTrigger;
this->pVvLock = other.pVvLock;
this->pVvTrigger = other.pVvTrigger;
this->tGratLock = other.tGratLock;
this->tGratTrigger = other.tGratTrigger;
this->tDetLock = other.tDetLock;
this->tDetTrigger = other.tDetTrigger;
}
Config::Config() // default
{
this->networkIP = "169.254.170.12";
this->networkPort = 5000;
this->networkPlcIP = "169.254.170.12";
this->networkPlcPort = 5000;
this->networkPumpIP = "127.0.0.1";
this->networkPumpPort = 1313;
this->pumpAutostop = false;
this->displayModeDynamic = 0;
this->pressureUnitType = 1; // mBar
this->pressureUnit = 1; // mBar
this->gaugeTypeGrat = 0; // PBR
this->gaugeTypeMcp = 0; // PBR
this->gaugeTypeVv = 3; // TPR
this->gaugeTypeGrat = 0; // PBR
this->gaugeTypeMcp = 0; // PBR
this->gaugeTypeVv = 3; // TPR
}
Config::Config(Config &other)
{
this->networkIP = other.networkIP;
this->networkPort = other.networkPort;
this->networkPlcIP = other.networkPlcIP;
this->networkPlcPort = other.networkPlcPort;
this->displayModeDynamic = other.displayModeDynamic;
this->pressureUnitType = other.pressureUnitType;
this->networkPumpIP = other.networkPumpIP;
this->networkPumpPort = other.networkPumpPort;
this->gaugeTypeGrat = other.gaugeTypeGrat;
this->gaugeTypeMcp = other.gaugeTypeMcp;
this->gaugeTypeVv = other.gaugeTypeVv;
this->pumpAutostop = other.pumpAutostop;
this->pressureUnit = other.pressureUnit;
this->gaugeTypeGrat = other.gaugeTypeGrat;
this->gaugeTypeMcp = other.gaugeTypeMcp;
this->gaugeTypeVv = other.gaugeTypeVv;
}
Config::Config(Config &&other)
{
this->networkPlcIP = other.networkPlcIP;
this->networkPlcPort = other.networkPlcPort;
this->networkPumpIP = other.networkPumpIP;
this->networkPumpPort = other.networkPumpPort;
this->pumpAutostop = other.pumpAutostop;
this->pressureUnit = other.pressureUnit;
this->gaugeTypeGrat = other.gaugeTypeGrat;
this->gaugeTypeMcp = other.gaugeTypeMcp;
this->gaugeTypeVv = other.gaugeTypeVv;
}
Config::Config(Config *other) : Config()
{
if(other != nullptr)
{
this->networkIP = other->networkIP;
this->networkPort = other->networkPort;
this->networkPlcIP = other->networkPlcIP;
this->networkPlcPort = other->networkPlcPort;
this->displayModeDynamic = other->displayModeDynamic;
this->pressureUnitType = other->pressureUnitType;
this->pressureUnit = other->pressureUnit;
this->gaugeTypeGrat = other->gaugeTypeGrat;
this->gaugeTypeMcp = other->gaugeTypeMcp;
......@@ -165,15 +257,19 @@ Config::Config(Config *other) : Config()
void Config::operator=(Config &other)
{
this->networkIP = other.networkIP;
this->networkPort = other.networkPort;
this->networkPlcIP = other.networkPlcIP;
this->networkPlcPort = other.networkPlcPort;
this->networkPumpIP = other.networkPumpIP;
this->networkPumpPort = other.networkPumpPort;
this->displayModeDynamic = other.displayModeDynamic;
this->pressureUnitType = other.pressureUnitType;
this->pumpAutostop = other.pumpAutostop;
this->gaugeTypeGrat = other.gaugeTypeGrat;
this->gaugeTypeMcp = other.gaugeTypeMcp;
this->gaugeTypeVv = other.gaugeTypeVv;
this->pressureUnit = other.pressureUnit;
this->gaugeTypeGrat = other.gaugeTypeGrat;
this->gaugeTypeMcp = other.gaugeTypeMcp;
this->gaugeTypeVv = other.gaugeTypeVv;
}
......@@ -184,7 +280,7 @@ void PlcMeasurement::operator=(PlcMeasurement &other)
this->pMcp = other.pMcp;
this->pVv = other.pVv;
this->tDps = other.tDps;
this->tGrat = other.tGrat;
this->tDet = other.tDet;
this->vTdetHigh = other.vTdetHigh;
......@@ -203,16 +299,34 @@ qreal pressureFromReading(int16_t measure, int type){
case 0: // PBR
return qPow(10, 1.333 * baseVal - 10.33);
case 1: // PKR
return qPow(10, 1.667 * baseVal - 11.33);
return qPow(10, 1.666 * baseVal - 11.33);
case 2: // IKR
return qPow(10, 1.250 * baseVal - 12.75);
case 3:
case 3: // TPR
return qPow(10, 1.000 * baseVal - 05.50);
default:
return NAN; // something went terribly wrong in UI or Settings
}
}
int16_t readingFromPressure(qreal pressure, int type)
{
qreal l = qLn(pressure) / qLn(10.0);
switch(type) {
case 0: // PBR
return ((l + 10.33) / 1.333) * 1023.0 / 10.0;
case 1: // PKR
return ((l + 11.33) / 1.666) * 1023.0 / 10.0;
case 2: // IKR
return ((l + 12.75) / 1.250) * 1023.0 / 10.0;
case 3: // TPR
return ((l + 05.50) / 1.000) * 1023.0 / 10.0;
default:
return -1; // ...
}
}
QString unitFromConfig(int value)
{
switch(value)
......@@ -227,7 +341,7 @@ QString unitFromConfig(int value)
case 7: return "µTorr";
case 8: return "nTorr";
default: return "<undefined>";
default: return "<err>";
}
}
......@@ -252,5 +366,5 @@ qreal factorFromConfig(int value)
void setValue(QLabel *w, qreal value)
{
w->setText(QString::number(value, 'g', 3));
w->setText(QString::number(value, 'e', 2));
}
......@@ -14,18 +14,25 @@ enum MsgType
struct Config
{
QString networkIP;
int networkPort;
QString networkPlcIP;
int networkPlcPort;
QString networkPumpIP;
int networkPumpPort;
bool pumpAutostop;
int displayModeDynamic;
int pressureUnitType;
int gaugeTypeGrat;
int gaugeTypeMcp;
int gaugeTypeVv;
int pressureUnit;
Config();
Config(Config &other);
Config(Config &&other);
Config(Config *other);
void operator=(Config &other);
};
......@@ -35,14 +42,11 @@ struct PlcState
{
bool override = false;
bool linked = true;
bool pGratActive = true;
bool pMcpActive = true;
bool pVvActive = true;
bool tDetActive = true;
bool tDpsActive = true;
bool tGratActive = true;
bool vTdetOpen = false;
bool vDetOpen = false;
......@@ -52,7 +56,18 @@ struct PlcState
bool hvmcpHigh = false;
bool rbeamlineHigh = true;
bool pumpEnabled = false;
int16_t pGratLock;
int16_t pGratTrigger;
int16_t pMcpLock;