* @brief Set Modbus slave address */
| 269 | * @brief Set Modbus slave address |
| 270 | */ |
| 271 | API::CommandResponse API::Handlers::ModbusHandler::setSlaveAddress(const QString& id, |
| 272 | const QJsonObject& params) |
| 273 | { |
| 274 | if (!params.contains(QStringLiteral("address"))) { |
| 275 | return CommandResponse::makeError( |
| 276 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: address")); |
| 277 | } |
| 278 | |
| 279 | const int address = params.value(QStringLiteral("address")).toInt(); |
| 280 | |
| 281 | if (address < 1 || address > 247) { |
| 282 | return CommandResponse::makeError( |
| 283 | id, |
| 284 | ErrorCode::InvalidParam, |
| 285 | QStringLiteral("Invalid address: %1. Valid range: 1-247").arg(address)); |
| 286 | } |
| 287 | |
| 288 | IO::ConnectionManager::instance().modbus()->setSlaveAddress(static_cast<quint8>(address)); |
| 289 | |
| 290 | QJsonObject result; |
| 291 | result[QStringLiteral("address")] = address; |
| 292 | return CommandResponse::makeSuccess(id, result); |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * @brief Set polling interval in milliseconds |