* @brief Set RTU stop bits */
| 491 | * @brief Set RTU stop bits |
| 492 | */ |
| 493 | API::CommandResponse API::Handlers::ModbusHandler::setStopBitsIndex(const QString& id, |
| 494 | const QJsonObject& params) |
| 495 | { |
| 496 | if (!params.contains(QStringLiteral("stopBitsIndex"))) { |
| 497 | return CommandResponse::makeError( |
| 498 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: stopBitsIndex")); |
| 499 | } |
| 500 | |
| 501 | const int stopBitsIndex = params.value(QStringLiteral("stopBitsIndex")).toInt(); |
| 502 | auto* modbus = IO::ConnectionManager::instance().modbus(); |
| 503 | const auto& stopBitsList = modbus->stopBitsList(); |
| 504 | |
| 505 | if (stopBitsIndex < 0 || stopBitsIndex >= stopBitsList.count()) { |
| 506 | return CommandResponse::makeError(id, |
| 507 | ErrorCode::InvalidParam, |
| 508 | QStringLiteral("Invalid stopBitsIndex: %1. Valid range: 0-%2") |
| 509 | .arg(stopBitsIndex) |
| 510 | .arg(stopBitsList.count() - 1)); |
| 511 | } |
| 512 | |
| 513 | modbus->setStopBitsIndex(static_cast<quint8>(stopBitsIndex)); |
| 514 | |
| 515 | QJsonObject result; |
| 516 | result[QStringLiteral("stopBitsIndex")] = stopBitsIndex; |
| 517 | result[QStringLiteral("stopBitsValue")] = stopBitsList.at(stopBitsIndex); |
| 518 | return CommandResponse::makeSuccess(id, result); |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * @brief Add a register group |
nothing calls this directly
no test coverage detected