* @brief Set the operation mode */
| 244 | * @brief Set the operation mode |
| 245 | */ |
| 246 | API::CommandResponse API::Handlers::DashboardHandler::setOperationMode(const QString& id, |
| 247 | const QJsonObject& params) |
| 248 | { |
| 249 | if (!params.contains(QStringLiteral("mode"))) { |
| 250 | return CommandResponse::makeError( |
| 251 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: mode")); |
| 252 | } |
| 253 | |
| 254 | const int mode = params.value(QStringLiteral("mode")).toInt(); |
| 255 | if (mode < 0 || mode > 2) { |
| 256 | return CommandResponse::makeError( |
| 257 | id, |
| 258 | ErrorCode::InvalidParam, |
| 259 | QStringLiteral( |
| 260 | "Invalid mode: %1. Valid range: 0-2 (0=ProjectFile, 1=ConsoleOnly, 2=QuickPlot)") |
| 261 | .arg(mode)); |
| 262 | } |
| 263 | |
| 264 | const auto operationMode = static_cast<SerialStudio::OperationMode>(mode); |
| 265 | AppState::instance().setOperationMode(operationMode); |
| 266 | |
| 267 | QJsonObject result; |
| 268 | result[QStringLiteral("mode")] = mode; |
| 269 | |
| 270 | const QStringList modeNames = { |
| 271 | QStringLiteral("ProjectFile"), QStringLiteral("ConsoleOnly"), QStringLiteral("QuickPlot")}; |
| 272 | result[QStringLiteral("modeName")] = modeNames[mode]; |
| 273 | |
| 274 | return CommandResponse::makeSuccess(id, result); |
| 275 | } |
| 276 | |
| 277 | //-------------------------------------------------------------------------------------------------- |
| 278 | // Getters |
no test coverage detected