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

Method selectService

app/src/API/Handlers/BluetoothLEHandler.cpp:232–260  ·  view source on GitHub ↗

* @brief Select BLE service by index */

Source from the content-addressed store, hash-verified

230 * @brief Select BLE service by index
231 */
232API::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

Callers

nothing calls this directly

Calls 5

connectedBluetoothLEMethod · 0.80
serviceNamesMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected