* @brief Select the active IN endpoint. */
| 154 | * @brief Select the active IN endpoint. |
| 155 | */ |
| 156 | API::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. |
nothing calls this directly
no test coverage detected