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

Method setInEndpointIndex

app/src/API/Handlers/USBHandler.cpp:156–182  ·  view source on GitHub ↗

* @brief Select the active IN endpoint. */

Source from the content-addressed store, hash-verified

154 * @brief Select the active IN endpoint.
155 */
156API::CommandResponse API::Handlers::USBHandler::setInEndpointIndex(const QString& id,
157 const QJsonObject& params)
158{
159 if (!params.contains(QStringLiteral("endpointIndex"))) {
160 return CommandResponse::makeError(
161 id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: endpointIndex"));
162 }
163
164 const int ep_index = params.value(QStringLiteral("endpointIndex")).toInt();
165 const auto& endpoints = IO::ConnectionManager::instance().usb()->inEndpointList();
166
167 if (ep_index < 0 || ep_index >= endpoints.count()) {
168 return CommandResponse::makeError(
169 id,
170 ErrorCode::InvalidParam,
171 QString(QStringLiteral("Invalid endpointIndex: %1. Valid range: 0-%2"))
172 .arg(ep_index)
173 .arg(endpoints.count() - 1));
174 }
175
176 IO::ConnectionManager::instance().usb()->setInEndpointIndex(ep_index);
177
178 QJsonObject result;
179 result[QStringLiteral("endpointIndex")] = ep_index;
180 result[QStringLiteral("endpointName")] = endpoints.at(ep_index);
181 return CommandResponse::makeSuccess(id, result);
182}
183
184/**
185 * @brief Select the active OUT endpoint.

Callers

nothing calls this directly

Calls 5

inEndpointListMethod · 0.80
usbMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected