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

Method setPluginIndex

app/src/API/Handlers/CANBusHandler.cpp:110–136  ·  view source on GitHub ↗

* @brief Select CAN plugin by index */

Source from the content-addressed store, hash-verified

108 * @brief Select CAN plugin by index
109 */
110API::CommandResponse API::Handlers::CANBusHandler::setPluginIndex(const QString& id,
111 const QJsonObject& params)
112{
113 if (!params.contains(QStringLiteral("pluginIndex"))) {
114 return CommandResponse::makeError(
115 id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: pluginIndex"));
116 }
117
118 const int pluginIndex = params.value(QStringLiteral("pluginIndex")).toInt();
119 auto* canbus = IO::ConnectionManager::instance().canBus();
120 const auto& pluginList = canbus->pluginList();
121
122 if (pluginIndex < 0 || pluginIndex >= pluginList.count()) {
123 return CommandResponse::makeError(id,
124 ErrorCode::InvalidParam,
125 QStringLiteral("Invalid pluginIndex: %1. Valid range: 0-%2")
126 .arg(pluginIndex)
127 .arg(pluginList.count() - 1));
128 }
129
130 canbus->setPluginIndex(static_cast<quint8>(pluginIndex));
131
132 QJsonObject result;
133 result[QStringLiteral("pluginIndex")] = pluginIndex;
134 result[QStringLiteral("pluginName")] = pluginList.at(pluginIndex);
135 return CommandResponse::makeSuccess(id, result);
136}
137
138/**
139 * @brief Select CAN interface by index

Callers

nothing calls this directly

Calls 5

canBusMethod · 0.80
pluginListMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected