From 1742cd9270fd753731e9da772ead194f3b2dd0d3 Mon Sep 17 00:00:00 2001 From: Tobias Triffterer <tobias@ep1.ruhr-uni-bochum.de> Date: Mon, 26 Apr 2021 21:30:51 +0200 Subject: [PATCH] Add Parser for fillHistogram Command As all commands that contain arguments, a dedicated parser method is added for this one, too. --- src/command.cpp | 17 ++++++++++++++++- src/command.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/command.cpp b/src/command.cpp index e400e0e..84ace41 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -79,6 +79,8 @@ Command Command::fromString(const QString& source) return parseUpdateExperimentState(rootobj); case Action::setTargetState: return parseSetTargetState(rootobj); + case Action::fillHistogram: + return parseFillHistogram(rootobj); case Action::sendHistogramUpdate: case Action::moveTargetCloser: case Action::moveTargetFarther: @@ -93,7 +95,6 @@ Command Command::fromString(const QString& source) // Not yet implemented: case Action::queryServerInformation: case Action::updateHistogram: - case Action::fillHistogram: return Command(); default: return Command(); @@ -228,6 +229,20 @@ Protocol::Command Protocol::Command::parseSetTargetState(const QJsonObject& inpu ); } +Protocol::Command Protocol::Command::parseFillHistogram(const QJsonObject& input) +{ + if (!input.keys().contains(QStringLiteral("adcchannels")) || !input.value(QStringLiteral("adcchannels")).isString()) { + logError(QStringLiteral("fillHistogram command does not contain adcchannels.")); + return Command(); + } + + return Command( + Action::fillHistogram, + Arguments{std::make_pair(QStringLiteral("adcchannels"), input.value(QStringLiteral("adcchannels")).toString())}, + input.value(QStringLiteral("token")).toString() + ); +} + QString Command::toString() const { if (action == Action::invalid) diff --git a/src/command.h b/src/command.h index d6e9586..e83a266 100644 --- a/src/command.h +++ b/src/command.h @@ -74,6 +74,7 @@ private: static Command parseError(const QJsonObject& input); static Command parseUpdateExperimentState(const QJsonObject& input); static Command parseSetTargetState(const QJsonObject& input); + static Command parseFillHistogram(const QJsonObject& input); static QString getActionString(const Action action); }; -- GitLab