* @brief Writes to a UUID-resolved characteristic for split read/write devices. */
| 593 | * @brief Writes to a UUID-resolved characteristic for split read/write devices. |
| 594 | */ |
| 595 | qint64 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. |
no test coverage detected