* @brief Write raw data to the connected device */
| 343 | * @brief Write raw data to the connected device |
| 344 | */ |
| 345 | API::CommandResponse API::Handlers::IOManagerHandler::writeData(const QString& id, |
| 346 | const QJsonObject& params) |
| 347 | { |
| 348 | if (!params.contains(QStringLiteral("data"))) { |
| 349 | return CommandResponse::makeError( |
| 350 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: data")); |
| 351 | } |
| 352 | |
| 353 | const QString dataStr = params.value(QStringLiteral("data")).toString(); |
| 354 | const QByteArray data = QByteArray::fromBase64(dataStr.toUtf8()); |
| 355 | |
| 356 | if (data.isEmpty() && !dataStr.isEmpty()) { |
| 357 | return CommandResponse::makeError( |
| 358 | id, ErrorCode::InvalidParam, QStringLiteral("Invalid base64 data")); |
| 359 | } |
| 360 | |
| 361 | auto& manager = IO::ConnectionManager::instance(); |
| 362 | if (!manager.isConnected()) { |
| 363 | return CommandResponse::makeError( |
| 364 | id, ErrorCode::ExecutionError, QStringLiteral("Not connected")); |
| 365 | } |
| 366 | |
| 367 | const qint64 bytesWritten = manager.writeData(data); |
| 368 | |
| 369 | QJsonObject result; |
| 370 | result[QStringLiteral("bytesWritten")] = bytesWritten; |
| 371 | return CommandResponse::makeSuccess(id, result); |
| 372 | } |
| 373 | |
| 374 | //-------------------------------------------------------------------------------------------------- |
| 375 | // Getters |
no test coverage detected