MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / removeRegisterGroup

Method removeRegisterGroup

app/src/API/Handlers/ModbusHandler.cpp:578–603  ·  view source on GitHub ↗

* @brief Remove a register group by index */

Source from the content-addressed store, hash-verified

576 * @brief Remove a register group by index
577 */
578API::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

Callers

nothing calls this directly

Calls 4

modbusMethod · 0.80
registerGroupCountMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected