* @brief Set flow control */
| 349 | * @brief Set flow control |
| 350 | */ |
| 351 | API::CommandResponse API::Handlers::UARTHandler::setFlowControl(const QString& id, |
| 352 | const QJsonObject& params) |
| 353 | { |
| 354 | if (!params.contains(QStringLiteral("flowControlIndex"))) { |
| 355 | return CommandResponse::makeError( |
| 356 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: flowControlIndex")); |
| 357 | } |
| 358 | |
| 359 | const int flowControlIndex = params.value(QStringLiteral("flowControlIndex")).toInt(); |
| 360 | const auto& flowControlList = IO::ConnectionManager::instance().uart()->flowControlList(); |
| 361 | |
| 362 | if (flowControlIndex < 0 || flowControlIndex >= flowControlList.count()) { |
| 363 | return CommandResponse::makeError( |
| 364 | id, |
| 365 | ErrorCode::InvalidParam, |
| 366 | QStringLiteral("Invalid flowControlIndex: %1. Valid range: 0-%2") |
| 367 | .arg(flowControlIndex) |
| 368 | .arg(flowControlList.count() - 1)); |
| 369 | } |
| 370 | |
| 371 | auto* uart = IO::ConnectionManager::instance().uart(); |
| 372 | QMetaObject::invokeMethod( |
| 373 | uart, |
| 374 | [uart, flowControlIndex]() { uart->setFlowControl(static_cast<quint8>(flowControlIndex)); }, |
| 375 | Qt::AutoConnection); |
| 376 | |
| 377 | QJsonObject result; |
| 378 | result[QStringLiteral("flowControlIndex")] = flowControlIndex; |
| 379 | result[QStringLiteral("flowControlName")] = flowControlList.at(flowControlIndex); |
| 380 | return CommandResponse::makeSuccess(id, result); |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * @brief Enable or disable DTR signal |
nothing calls this directly
no test coverage detected