* @brief Set TCP host address */
| 321 | * @brief Set TCP host address |
| 322 | */ |
| 323 | API::CommandResponse API::Handlers::ModbusHandler::setHost(const QString& id, |
| 324 | const QJsonObject& params) |
| 325 | { |
| 326 | if (!params.contains(QStringLiteral("host"))) { |
| 327 | return CommandResponse::makeError( |
| 328 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: host")); |
| 329 | } |
| 330 | |
| 331 | const QString host = params.value(QStringLiteral("host")).toString(); |
| 332 | |
| 333 | if (host.isEmpty()) { |
| 334 | return CommandResponse::makeError( |
| 335 | id, ErrorCode::InvalidParam, QStringLiteral("Host cannot be empty")); |
| 336 | } |
| 337 | |
| 338 | IO::ConnectionManager::instance().modbus()->setHost(host); |
| 339 | |
| 340 | QJsonObject result; |
| 341 | result[QStringLiteral("host")] = host; |
| 342 | return CommandResponse::makeSuccess(id, result); |
| 343 | } |
| 344 | |
| 345 | /** |
| 346 | * @brief Set TCP port |