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

Method writeCharacteristic

app/src/IO/Drivers/BluetoothLE.cpp:595–630  ·  view source on GitHub ↗

* @brief Writes to a UUID-resolved characteristic for split read/write devices. */

Source from the content-addressed store, hash-verified

593 * @brief Writes to a UUID-resolved characteristic for split read/write devices.
594 */
595qint64 IO::Drivers::BluetoothLE::writeCharacteristic(const QString& uuid, const QByteArray& data)
596{
597 const QBluetoothUuid target = bleUuidFromString(uuid);
598 if (target.isNull()) {
599 qWarning() << "BLE writeCharacteristic: invalid UUID" << uuid;
600 return 0;
601 }
602
603 QLowEnergyService* service = m_service;
604 if (!service) {
605 for (auto* inst : std::as_const(s_instances))
606 if (inst != this && inst->m_deviceIndex == m_deviceIndex && inst->m_service) {
607 service = inst->m_service;
608 break;
609 }
610 }
611
612 if (!service) {
613 qWarning() << "BLE writeCharacteristic: no active service for the selected device";
614 return 0;
615 }
616
617 const auto characteristic = service->characteristic(target);
618 if (!characteristic.isValid()) {
619 qWarning() << "BLE writeCharacteristic: characteristic" << uuid << "not found in service";
620 return 0;
621 }
622
623 const auto props = characteristic.properties();
624 const auto mode = (props & QLowEnergyCharacteristic::WriteNoResponse)
625 ? QLowEnergyService::WriteWithoutResponse
626 : QLowEnergyService::WriteWithResponse;
627
628 service->writeCharacteristic(characteristic, data, mode);
629 return data.length();
630}
631
632/**
633 * @brief Opens a connection to a Bluetooth LE device.

Callers 1

writeMethod · 0.45

Calls 3

bleUuidFromStringFunction · 0.85
lengthMethod · 0.80
isValidMethod · 0.45

Tested by

no test coverage detected