* @brief Select BLE service by index */
| 230 | * @brief Select BLE service by index |
| 231 | */ |
| 232 | API::CommandResponse API::Handlers::BluetoothLEHandler::selectService(const QString& id, |
| 233 | const QJsonObject& params) |
| 234 | { |
| 235 | if (!params.contains(QStringLiteral("serviceIndex"))) { |
| 236 | return CommandResponse::makeError( |
| 237 | id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: serviceIndex")); |
| 238 | } |
| 239 | |
| 240 | const int serviceIndex = params.value(QStringLiteral("serviceIndex")).toInt(); |
| 241 | auto* ble = IO::ConnectionManager::instance().connectedBluetoothLE(); |
| 242 | const auto& serviceNames = ble->serviceNames(); |
| 243 | |
| 244 | if (serviceIndex < 0 || serviceIndex >= serviceNames.count()) { |
| 245 | return CommandResponse::makeError(id, |
| 246 | ErrorCode::InvalidParam, |
| 247 | QStringLiteral("Invalid serviceIndex: %1. Valid range: 0-%2") |
| 248 | .arg(serviceIndex) |
| 249 | .arg(serviceNames.count() - 1)); |
| 250 | } |
| 251 | |
| 252 | ble->selectService(serviceIndex + 1); |
| 253 | |
| 254 | QJsonObject result; |
| 255 | result[QStringLiteral("serviceIndex")] = serviceIndex; |
| 256 | if (serviceIndex + 1 < serviceNames.count()) |
| 257 | result[QStringLiteral("serviceName")] = serviceNames.at(serviceIndex + 1); |
| 258 | |
| 259 | return CommandResponse::makeSuccess(id, result); |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * @brief Select a BLE service by UUID |
nothing calls this directly
no test coverage detected