* @brief Select the active OUT endpoint. */
| 185 | * @brief Select the active OUT endpoint. |
| 186 | */ |
| 187 | API::CommandResponse API::Handlers::USBHandler::setOutEndpointIndex(const QString& id, |
| 188 | const QJsonObject& params) |
| 189 | { |
| 190 | if (!params.contains(QStringLiteral("endpointIndex"))) { |
| 191 | return CommandResponse::makeError( |
| 192 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: endpointIndex")); |
| 193 | } |
| 194 | |
| 195 | const int ep_index = params.value(QStringLiteral("endpointIndex")).toInt(); |
| 196 | const auto& endpoints = IO::ConnectionManager::instance().usb()->outEndpointList(); |
| 197 | |
| 198 | if (ep_index < 0 || ep_index >= endpoints.count()) { |
| 199 | return CommandResponse::makeError( |
| 200 | id, |
| 201 | ErrorCode::InvalidParam, |
| 202 | QString(QStringLiteral("Invalid endpointIndex: %1. Valid range: 0-%2")) |
| 203 | .arg(ep_index) |
| 204 | .arg(endpoints.count() - 1)); |
| 205 | } |
| 206 | |
| 207 | IO::ConnectionManager::instance().usb()->setOutEndpointIndex(ep_index); |
| 208 | |
| 209 | QJsonObject result; |
| 210 | result[QStringLiteral("endpointIndex")] = ep_index; |
| 211 | result[QStringLiteral("endpointName")] = endpoints.at(ep_index); |
| 212 | return CommandResponse::makeSuccess(id, result); |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * @brief Set the ISO transfer packet size. |
nothing calls this directly
no test coverage detected