BluetoothGatt.hpp Example File
bluetoothgatt/src/BluetoothGatt.hpp
#ifndef BLUETOOTHGATT_HPP
#define BLUETOOTHGATT_HPP
#include <QObject>
#include <bb/cascades/ArrayDataModel>
#include <btgatt.h>
#include <btle.h>
#include <btdevice.h>
class CharacteristicsEditor;
class BluetoothGatt : public QObject
{
Q_OBJECT
Q_PROPERTY(QString activeDevice READ activeDevice WRITE setActiveDevice NOTIFY activeDeviceChanged)
Q_PROPERTY(QString activeService READ activeService WRITE setActiveService NOTIFY activeServiceChanged)
Q_PROPERTY(QString activeCharacteristic READ activeCharacteristic WRITE setActiveCharacteristic NOTIFY activeCharacteristicChanged)
Q_PROPERTY(bb::cascades::DataModel* devicesModel READ devicesModel CONSTANT)
Q_PROPERTY(bb::cascades::DataModel* servicesModel READ servicesModel CONSTANT)
Q_PROPERTY(bb::cascades::DataModel* characteristicsModel READ characteristicsModel CONSTANT)
Q_PROPERTY(CharacteristicsEditor* editor READ editor CONSTANT)
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
public:
BluetoothGatt(QObject *parent = 0);
virtual ~BluetoothGatt();
void gattServiceConnected(const QString &bdaddr, const QString &service, int instance, int err, uint16_t connInt, uint16_t latency, uint16_t superTimeout );
void processBluetoothEvent(const int event, void *data);
Q_SIGNALS:
void activeDeviceChanged();
void activeServiceChanged();
void activeCharacteristicChanged();
void errorMessageChanged();
void bluetoothEvent(const int event, void *data);
public slots:
void viewCharacteristics(int row);
void viewCharacteristicsEditor(int row);
void viewServices(int row);
void refreshDevices();
void disconnectServices();
void resetEditor();
void resetCharacteristicsList();
void handleBluetoothEvent(const int event, void *data);
void handleCharacteristicNotificationsEnabledChanged(bool);
private:
QString activeDevice() const;
void setActiveDevice(const QString&);
QString activeDeviceName() const;
void setActiveDeviceName(const QString&);
QString activeService() const;
void setActiveService(const QString&);
QString activeCharacteristic() const;
void setActiveCharacteristic(const QString&);
bb::cascades::DataModel* devicesModel() const;
bb::cascades::DataModel* servicesModel() const;
bb::cascades::DataModel* characteristicsModel() const;
CharacteristicsEditor* editor() const;
QString errorMessage() const;
void setErrorMessage(const QString &errorMessage);
void gattServiceDisconnected(const QString &deviceAddress, const QString &uuid, int instance, int reason);
void gattNotification(int instance, uint16_t handle, const uint8_t *val, uint16_t len);
QString m_activeDevice;
QString m_activeDeviceName;
QString m_activeService;
QString m_activeCharacteristic;
bb::cascades::ArrayDataModel *m_devices;
bb::cascades::ArrayDataModel *m_services;
bb::cascades::ArrayDataModel *m_characteristics;
bt_gatt_callbacks_t m_gatt_cb;
int m_gattInstance;
bt_gatt_characteristic_t *m_characteristicList;
bt_gatt_characteristic_t *m_characteristicStruct;
int m_characteristicListSize;
CharacteristicsEditor *m_editor;
QString m_errorMessage;
};
#endif