diff options
author | Jan Mulder <jlmulder@xs4all.nl> | 2017-07-03 21:21:02 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-07-04 23:46:07 +0900 |
commit | d6b17fef08a6597582c4ea980ed3c7fcba410e43 (patch) | |
tree | e55861e3ff9caa0629b9fda1150c79da17ace876 /core/qt-ble.cpp | |
parent | 6031692a39820c0b5466d558e913272edabeb92a (diff) | |
download | subsurface-d6b17fef08a6597582c4ea980ed3c7fcba410e43.tar.gz |
OSTC over BLE: filter and track OSTC credit traffic
1) As the OSTC sends data to the BLE central role (the SSRF client) over 2
characteristics, we have to filter the administrative credit data from
the actual dive data that it received. The characteristcStateChanged
function is adapted for this.
2) We have to be sure that the Terminal Client I/O is fully defined during
opening the connecton to the OSTC. From 6d505b24f0c15 we can see
that the last step in setting up the terminal interface is the grant
of credits. This is done by writing to the proper (the only one, with
id = 0x2902) descriptor of the credits RX characteristic. The here
added slot is triggered on the completion of write of credits marking
the final stage of the setup.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
Diffstat (limited to 'core/qt-ble.cpp')
-rw-r--r-- | core/qt-ble.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp index 3d29c2550..5d4e35d54 100644 --- a/core/qt-ble.cpp +++ b/core/qt-ble.cpp @@ -57,9 +57,28 @@ void BLEObject::serviceStateChanged(QLowEnergyService::ServiceState s) void BLEObject::characteristcStateChanged(const QLowEnergyCharacteristic &c, const QByteArray &value) { - Q_UNUSED(c) + if (device_is_hw(device)) { + if (c.uuid() == hwAllCharacteristics[HW_OSTC_BLE_DATA_TX]) { + receivedPackets.append(value); + } else { + qDebug() << "ignore packet from" << c.uuid() << value.toHex(); + } + } else { + receivedPackets.append(value); + } + //qDebug() << ".. incoming packet count" << receivedPackets.length(); +} - receivedPackets.append(value); +void BLEObject::characteristicWritten(const QLowEnergyCharacteristic &c, const QByteArray &value) +{ + if (device_is_hw(device)) { + if (c.uuid() == hwAllCharacteristics[HW_OSTC_BLE_CREDITS_RX]) { + qDebug() << "HW_OSTC_BLE_CREDITS_RX confirmed" << c.uuid() << value.toHex(); + isCharacteristicWritten = true; + } + } else { + qDebug() << "BLEObject::characteristicWritten not supposed to fire. Now HW only function"; + } } void BLEObject::writeCompleted(const QLowEnergyDescriptor &d, const QByteArray &value) @@ -67,7 +86,7 @@ void BLEObject::writeCompleted(const QLowEnergyDescriptor &d, const QByteArray & Q_UNUSED(d) Q_UNUSED(value) - qDebug() << "BLE write completed"; + qDebug() << "BLE write completed on" << d.name() << d.value(); } void BLEObject::addService(const QBluetoothUuid &newService) @@ -95,6 +114,7 @@ void BLEObject::addService(const QBluetoothUuid &newService) services.append(service); connect(service, &QLowEnergyService::stateChanged, this, &BLEObject::serviceStateChanged); connect(service, &QLowEnergyService::characteristicChanged, this, &BLEObject::characteristcStateChanged); + connect(service, &QLowEnergyService::characteristicWritten, this, &BLEObject::characteristicWritten); connect(service, &QLowEnergyService::descriptorWritten, this, &BLEObject::writeCompleted); service->discoverDetails(); } |