* @brief Connect to the configured device */
| 245 | * @brief Connect to the configured device |
| 246 | */ |
| 247 | API::CommandResponse API::Handlers::IOManagerHandler::connect(const QString& id, |
| 248 | const QJsonObject& params) |
| 249 | { |
| 250 | Q_UNUSED(params) |
| 251 | |
| 252 | auto& manager = IO::ConnectionManager::instance(); |
| 253 | |
| 254 | if (manager.isConnected()) { |
| 255 | return CommandResponse::makeError( |
| 256 | id, ErrorCode::ExecutionError, QStringLiteral("Already connected")); |
| 257 | } |
| 258 | |
| 259 | if (!manager.configurationOk()) { |
| 260 | return CommandResponse::makeError( |
| 261 | id, ErrorCode::ExecutionError, QStringLiteral("Device configuration is invalid")); |
| 262 | } |
| 263 | |
| 264 | manager.connectDevice(); |
| 265 | |
| 266 | QJsonObject result; |
| 267 | result[QStringLiteral("connected")] = manager.isConnected(); |
| 268 | return CommandResponse::makeSuccess(id, result); |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * @brief Disconnect from the current device |
nothing calls this directly
no test coverage detected