* @brief Set RTU parity */
| 429 | * @brief Set RTU parity |
| 430 | */ |
| 431 | API::CommandResponse API::Handlers::ModbusHandler::setParityIndex(const QString& id, |
| 432 | const QJsonObject& params) |
| 433 | { |
| 434 | if (!params.contains(QStringLiteral("parityIndex"))) { |
| 435 | return CommandResponse::makeError( |
| 436 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: parityIndex")); |
| 437 | } |
| 438 | |
| 439 | const int parityIndex = params.value(QStringLiteral("parityIndex")).toInt(); |
| 440 | auto* modbus = IO::ConnectionManager::instance().modbus(); |
| 441 | const auto& parityList = modbus->parityList(); |
| 442 | |
| 443 | if (parityIndex < 0 || parityIndex >= parityList.count()) { |
| 444 | return CommandResponse::makeError(id, |
| 445 | ErrorCode::InvalidParam, |
| 446 | QStringLiteral("Invalid parityIndex: %1. Valid range: 0-%2") |
| 447 | .arg(parityIndex) |
| 448 | .arg(parityList.count() - 1)); |
| 449 | } |
| 450 | |
| 451 | modbus->setParityIndex(static_cast<quint8>(parityIndex)); |
| 452 | |
| 453 | QJsonObject result; |
| 454 | result[QStringLiteral("parityIndex")] = parityIndex; |
| 455 | result[QStringLiteral("parityName")] = parityList.at(parityIndex); |
| 456 | return CommandResponse::makeSuccess(id, result); |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * @brief Set RTU data bits |
nothing calls this directly
no test coverage detected