Skip to content
Snippets Groups Projects
Verified Commit 6c81109f authored by Tobias Triffterer's avatar Tobias Triffterer :house_with_garden:
Browse files

Take over Data from updateExperimentState Command

This new method enables the ExperimentState class to update its
properties when new data has arrived via the updateExperimentState
command.
parent 0a5939b4
No related branches found
No related tags found
No related merge requests found
Pipeline #2935 passed with stage
in 20 seconds
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
* *
**/ **/
#include <stdexcept>
#include "experimentstate.h" #include "experimentstate.h"
using namespace Fp311Online; using namespace Fp311Online;
...@@ -64,3 +66,68 @@ Protocol::Command ExperimentState::getStateCommand() const ...@@ -64,3 +66,68 @@ Protocol::Command ExperimentState::getStateCommand() const
QString() // Token will be added by class that requested the Command object QString() // Token will be added by class that requested the Command object
); );
} }
void ExperimentState::updateFromCommand(const Protocol::Command& command)
{
if (command.action != Protocol::Action::updateExperimentState)
{
logError(QStringLiteral("Command instance passed to ExperimentState::updateFromCommand is not of type updateExperimentState."));
return;
}
if (command.arguments[QStringLiteral("adcstate")] == QStringLiteral("running"))
adcState = AdcState::Running;
else if (command.arguments[QStringLiteral("adcstate")] == QStringLiteral("stopped"))
adcState = AdcState::Stopped;
else
logError(QStringLiteral("Invalid value for argument \"adcstate\" of updateExperimentState command."));
if (command.arguments[QStringLiteral("beamhole")] == QStringLiteral("closed"))
beamHoleState = BeamHoleState::Closed;
else if (command.arguments[QStringLiteral("beamhole")] == QStringLiteral("open"))
beamHoleState = BeamHoleState::Open;
else if (command.arguments[QStringLiteral("beamhole")] == QStringLiteral("goldfoil"))
beamHoleState = BeamHoleState::GoldFoil;
else
logError(QStringLiteral("Invalid value for argument \"beamhole\" of updateExperimentState command."));
try {
bool ok = false;
pressure = command.arguments[QStringLiteral("pressurehPa")].toDouble(&ok);
if (!ok)
logError(QStringLiteral("Error converting the \"pressure\" string in the updateExperimentState command into a numeral."));
}
catch(PressureHectoPascal::BoundaryExceeded& e) {
logError(QStringLiteral("\"pressure\" value in the updateExperimentState command out of range: ") + QString::fromUtf8(e.what()));
}
try {
bool ok = false;
targetPosition = command.arguments[QStringLiteral("targetposition")].toDouble(&ok);
if (!ok)
logError(QStringLiteral("Error converting the \"targetposition\" string in the updateExperimentState command into a numeral."));
}
catch(TargetPositionMilliMeter::BoundaryExceeded& e) {
logError(QStringLiteral("\"targetposition\" value in the updateExperimentState command out of range: ") + QString::fromUtf8(e.what()));
}
try {
bool ok = false;
adcThreshold = static_cast<AdcConversion::valueType>(command.arguments[QStringLiteral("adcthreshold")].toUInt(&ok));
if (!ok)
logError(QStringLiteral("Error converting the \"adcthreshold\" string in the updateExperimentState command into a numeral."));
}
catch(AdcConversion::BoundaryExceeded& e) {
logError(QStringLiteral("\"adcthreshold\" value in the updateExperimentState command out of range: ") + QString::fromUtf8(e.what()));
}
try {
bool ok = false;
vacuumValve = static_cast<VacuumValveOpening::valueType>(command.arguments[QStringLiteral("vacuumvalve")].toUInt(&ok));
if (!ok)
logError(QStringLiteral("Error converting the \"vacuumvalve\" string in the updateExperimentState command into a numeral."));
}
catch(VacuumValveOpening::BoundaryExceeded& e) {
logError(QStringLiteral("\"vacuumvalve\" value in the updateExperimentState command out of range: ") + QString::fromUtf8(e.what()));
}
}
...@@ -71,6 +71,7 @@ public: ...@@ -71,6 +71,7 @@ public:
static PressureTorr convertHectoPascalToTorr(const PressureHectoPascal& pressure); static PressureTorr convertHectoPascalToTorr(const PressureHectoPascal& pressure);
Protocol::Command getStateCommand() const; Protocol::Command getStateCommand() const;
void updateFromCommand(const Protocol::Command& command);
ExperimentState() = default; ExperimentState() = default;
ExperimentState(const uint64_t experimentId); ExperimentState(const uint64_t experimentId);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment