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

Method selectDevice

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

* @brief Select BLE device by index */

Source from the content-addressed store, hash-verified

197 * @brief Select BLE device by index
198 */
199API::CommandResponse API::Handlers::BluetoothLEHandler::selectDevice(const QString& id,
200 const QJsonObject& params)
201{
202 if (!params.contains(QStringLiteral("deviceIndex"))) {
203 return CommandResponse::makeError(
204 id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: deviceIndex"));
205 }
206
207 const int deviceIndex = params.value(QStringLiteral("deviceIndex")).toInt();
208 auto* ble = IO::ConnectionManager::instance().bluetoothLE();
209
210 if (deviceIndex < 0 || deviceIndex >= ble->deviceCount()) {
211 return CommandResponse::makeError(id,
212 ErrorCode::InvalidParam,
213 QStringLiteral("Invalid deviceIndex: %1. Valid range: 0-%2")
214 .arg(deviceIndex)
215 .arg(ble->deviceCount() - 1));
216 }
217
218 ble->selectDevice(deviceIndex + 1);
219
220 QJsonObject result;
221 result[QStringLiteral("deviceIndex")] = deviceIndex;
222 const auto& deviceNames = ble->deviceNames();
223 if (deviceIndex + 1 < deviceNames.count())
224 result[QStringLiteral("deviceName")] = deviceNames.at(deviceIndex + 1);
225
226 return CommandResponse::makeSuccess(id, result);
227}
228
229/**
230 * @brief Select BLE service by index

Callers

nothing calls this directly

Calls 6

bluetoothLEMethod · 0.80
deviceCountMethod · 0.80
deviceNamesMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected