* @brief Remove a register group by index */
| 576 | * @brief Remove a register group by index |
| 577 | */ |
| 578 | API::CommandResponse API::Handlers::ModbusHandler::removeRegisterGroup(const QString& id, |
| 579 | const QJsonObject& params) |
| 580 | { |
| 581 | if (!params.contains(QStringLiteral("groupIndex"))) { |
| 582 | return CommandResponse::makeError( |
| 583 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: groupIndex")); |
| 584 | } |
| 585 | |
| 586 | const int groupIndex = params.value(QStringLiteral("groupIndex")).toInt(); |
| 587 | auto* modbus = IO::ConnectionManager::instance().modbus(); |
| 588 | |
| 589 | if (groupIndex < 0 || groupIndex >= modbus->registerGroupCount()) { |
| 590 | return CommandResponse::makeError(id, |
| 591 | ErrorCode::InvalidParam, |
| 592 | QStringLiteral("Invalid groupIndex: %1. Valid range: 0-%2") |
| 593 | .arg(groupIndex) |
| 594 | .arg(modbus->registerGroupCount() - 1)); |
| 595 | } |
| 596 | |
| 597 | modbus->removeRegisterGroup(groupIndex); |
| 598 | |
| 599 | QJsonObject result; |
| 600 | result[QStringLiteral("groupIndex")] = groupIndex; |
| 601 | result[QStringLiteral("removed")] = true; |
| 602 | return CommandResponse::makeSuccess(id, result); |
| 603 | } |
| 604 | |
| 605 | /** |
| 606 | * @brief Clear all register groups |
nothing calls this directly
no test coverage detected