mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-01 07:03:24 +00:00
b7057c414f
Handle credits. Do not just ask for maximum credits all the time as this will stop the download. Also do not let the credits go back to 0 (while this might work, this is not tested). Getting back the 0 credits stops the download, and even when it can be restarted, it is less efficient (and not needed). Notice also that it takes some time before a grant request is honoured. During testing I saw reception of up to 25 packets between request and grant. So a lower bound for the request of 32 packets seems resonable. One aspect the Telit/Stollmann TIO puzzeled me. Sections 4.1 and 4.2 both talk about credits, but my hyphothesis is that there are two credits counters in play. One for traffic either way. This commit only deals with credits granted by Subsurface to the OSTC to send data. Credits granted by the OSTC to allow Subsurface to send new commands is NOT part of this commit, and is seemingly not needed in our scenario. As we only send new commands to the OSTC when a previous one is finished (per HW's interface spec), the OSTC does not run out of credits to receive commands. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
61 lines
2 KiB
C++
61 lines
2 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#ifndef QT_BLE_H
|
|
#define QT_BLE_H
|
|
|
|
#include <QVector>
|
|
#include <QLowEnergyController>
|
|
#include <QEventLoop>
|
|
|
|
#define HW_OSTC_BLE_DATA_RX 0
|
|
#define HW_OSTC_BLE_DATA_TX 1
|
|
#define HW_OSTC_BLE_CREDITS_RX 2
|
|
#define HW_OSTC_BLE_CREDITS_TX 3
|
|
|
|
class BLEObject : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
BLEObject(QLowEnergyController *c, dc_user_device_t *);
|
|
~BLEObject();
|
|
dc_status_t write(const void* data, size_t size, size_t *actual);
|
|
dc_status_t read(void* data, size_t size, size_t *actual);
|
|
|
|
//TODO: need better mode of selecting the desired service than below
|
|
inline QLowEnergyService *preferredService()
|
|
{ return services.isEmpty() ? nullptr : services[0]; }
|
|
|
|
public slots:
|
|
void addService(const QBluetoothUuid &newService);
|
|
void serviceStateChanged(QLowEnergyService::ServiceState s);
|
|
void characteristcStateChanged(const QLowEnergyCharacteristic &c, const QByteArray &value);
|
|
void characteristicWritten(const QLowEnergyCharacteristic &c, const QByteArray &value);
|
|
void writeCompleted(const QLowEnergyDescriptor &d, const QByteArray &value);
|
|
dc_status_t setupHwTerminalIo(QList<QLowEnergyCharacteristic>);
|
|
dc_status_t setHwCredit(unsigned int c);
|
|
private:
|
|
QVector<QLowEnergyService *> services;
|
|
|
|
QLowEnergyController *controller = nullptr;
|
|
QList<QByteArray> receivedPackets;
|
|
bool isCharacteristicWritten;
|
|
dc_user_device_t *device;
|
|
unsigned int hw_credit = 0;
|
|
|
|
QList<QUuid> hwAllCharacteristics = {
|
|
"{00000001-0000-1000-8000-008025000000}", // HW_OSTC_BLE_DATA_RX
|
|
"{00000002-0000-1000-8000-008025000000}", // HW_OSTC_BLE_DATA_TX
|
|
"{00000003-0000-1000-8000-008025000000}", // HW_OSTC_BLE_CREDITS_RX
|
|
"{00000004-0000-1000-8000-008025000000}" // HW_OSTC_BLE_CREDITS_TX
|
|
};
|
|
};
|
|
|
|
|
|
extern "C" {
|
|
dc_status_t qt_ble_open(dc_custom_io_t *io, dc_context_t *context, const char *name);
|
|
dc_status_t qt_ble_read(dc_custom_io_t *io, void* data, size_t size, size_t *actual);
|
|
dc_status_t qt_ble_write(dc_custom_io_t *io, const void* data, size_t size, size_t *actual);
|
|
dc_status_t qt_ble_close(dc_custom_io_t *io);
|
|
}
|
|
|
|
#endif
|