diff --git a/src/experimentstate.cpp b/src/experimentstate.cpp index c107795f3d6c598cc2bd752277900367a0aa25ea..a7d9b4161f8812776a83898404913cc247fc9e27 100644 --- a/src/experimentstate.cpp +++ b/src/experimentstate.cpp @@ -34,5 +34,33 @@ ExperimentState::ExperimentState(const uint64_t experimentId) ExperimentState::PressureTorr ExperimentState::convertHectoPascalToTorr(const PressureHectoPascal& pressure) { - return pressure*76000.0/101325.0; + return pressure * 76000.0 / 101325.0; +} + +Protocol::Command ExperimentState::getStateCommand() const +{ + const QString adcstate = (adcState == AdcState::Running) ? QStringLiteral("running") : QStringLiteral("stopped"); + const QString beamhole = [this]() -> QString { + switch (beamHoleState) { + case BeamHoleState::Closed: + default: + return QStringLiteral("closed"); + case BeamHoleState::Open: + return QStringLiteral("open"); + case BeamHoleState::GoldFoil: + return QStringLiteral("goldfoil"); } + }(); + + return Protocol::Command( + Protocol::Action::updateExperimentState, + Protocol::Command::Arguments { + std::make_pair(QStringLiteral("adcstate"), adcstate), + std::make_pair(QStringLiteral("beamhole"), beamhole), + std::make_pair(QStringLiteral("pressurehPa"), QString::number(pressure)), + std::make_pair(QStringLiteral("targetposition"), QString::number(targetPosition)), + std::make_pair(QStringLiteral("adcthreshold"), QString::number(adcThreshold)), + std::make_pair(QStringLiteral("vacuumvalve"), QString::number(vacuumValve)) + }, + QString() // Token will be added by class that requested the Command object + ); } diff --git a/src/experimentstate.h b/src/experimentstate.h index c72f266bb243810f704fdd159dd2b91d9739ee2a..a4dfa79a8003c3c46204864175c6358bde5d1409 100644 --- a/src/experimentstate.h +++ b/src/experimentstate.h @@ -30,6 +30,7 @@ #include <cinttypes> #include "boundednumeral.h" +#include "command.h" #include "fp311online_export.h" namespace Fp311Online @@ -68,6 +69,8 @@ public: static PressureTorr convertHectoPascalToTorr(const PressureHectoPascal& pressure); + Protocol::Command getStateCommand() const; + ExperimentState() = default; ExperimentState(const uint64_t experimentId); ~ExperimentState() = default;