* @brief Set TCP port */
| 346 | * @brief Set TCP port |
| 347 | */ |
| 348 | API::CommandResponse API::Handlers::ModbusHandler::setPort(const QString& id, |
| 349 | const QJsonObject& params) |
| 350 | { |
| 351 | if (!params.contains(QStringLiteral("port"))) { |
| 352 | return CommandResponse::makeError( |
| 353 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: port")); |
| 354 | } |
| 355 | |
| 356 | const int port = params.value(QStringLiteral("port")).toInt(); |
| 357 | |
| 358 | if (port < 1 || port > 65535) { |
| 359 | return CommandResponse::makeError( |
| 360 | id, |
| 361 | ErrorCode::InvalidParam, |
| 362 | QStringLiteral("Invalid port: %1. Valid range: 1-65535").arg(port)); |
| 363 | } |
| 364 | |
| 365 | IO::ConnectionManager::instance().modbus()->setPort(static_cast<quint16>(port)); |
| 366 | |
| 367 | QJsonObject result; |
| 368 | result[QStringLiteral("port")] = port; |
| 369 | return CommandResponse::makeSuccess(id, result); |
| 370 | } |
| 371 | |
| 372 | /** |
| 373 | * @brief Set RTU serial port by index |
no test coverage detected