Index: sources/bluetooth/BluetoothInterface.h =================================================================== diff -u -rf11dd9cd2c07f96d9d939d70ed9c4ce2edef2a9d -re4a0e2fc4c7ae0cbce0d670772276bf7f5ff3845 --- sources/bluetooth/BluetoothInterface.h (.../BluetoothInterface.h) (revision f11dd9cd2c07f96d9d939d70ed9c4ce2edef2a9d) +++ sources/bluetooth/BluetoothInterface.h (.../BluetoothInterface.h) (revision e4a0e2fc4c7ae0cbce0d670772276bf7f5ff3845) @@ -34,8 +34,10 @@ using namespace Model; /*! - * \brief The MessageAcknowModel class - * \details The wrapper class of the AcknowModel which does the thread handling. + * \brief The Bluetooth Controller class + * \details The wrapper class of the Bluetooth which does the thread handling. + * \warning In the Bluetooth interface it checks about the Bluetooth POST to avoid creating threads, objects. + * The validity of the Bluetooth interface has to be always checked before use. */ class BluetoothInterface : public QObject { @@ -50,25 +52,26 @@ typedef QMap< QBluetoothUuid::ServiceClassUuid, QLowEnergyService *> ServiceMap; QThread *_thread = nullptr; - bool _init = false; + bool _init = false ; + bool _isValid = false ; + const char *_invalidLocalAddress = "00:00:00:00:00:00"; QStringList _supportedDeviceKeywords { "BP7000", "BLEsmart", "BLESmart" }; // Regarding to Omron Documents. QBluetoothLocalDevice *_local = nullptr ; QBluetoothDeviceDiscoveryAgent *_agent = nullptr ; QLowEnergyController *_device = nullptr ; - // QList _services ; - QLowEnergyService *_serviceDeviceInformation = nullptr ; QLowEnergyService *_serviceCurrentTime = nullptr ; QLowEnergyService *_serviceBloodPressure = nullptr ; QLowEnergyService *_serviceBattery = nullptr ; QBluetoothDeviceInfo _temp ; - bool _reconnectionActive = false ; + bool _reconnectionActive = false ; const quint16 _interval = 1000 ; // the interface timer base interval in mSec + public: // 19 total bytes struct MeasurementData { @@ -87,6 +90,9 @@ uint16_t measurement_status; // 2 bytes }; + bool isValid( ) const { return _isValid ; } + void valid(bool vValid) { _isValid = vValid; } + protected: void timerEvent(QTimerEvent *event) override; @@ -141,6 +147,7 @@ void quitServices (); bool isLocalValid (); + bool isAgentValid (); bool isInfoValid (); bool isDeviceValid (); // bool isServiceValid (QLowEnergyService *vService); @@ -151,14 +158,23 @@ bool reconnectToDevice (); void discoverServices (); void discoverServicesDetails(); + void enableNotify (); + void readMeasurements (); + void readInformation (); + void printCharacteristics (QLowEnergyService *vService); void notifyStateChange(const BluetoothData &vData); void parseMeasurement (const QByteArray &byteArray); signals: void didStateChange(const BluetoothData &vData); - SAFE_CALL(start ) - SAFE_CALL(doScan) + SAFE_CALL(doStart ) + SAFE_CALL(doScan ) + SAFE_CALL(doConnectToDevice ) + SAFE_CALL(doDiscoverServices ) + SAFE_CALL(doEnableNotify ) + SAFE_CALL(doReadMeasurements ) + SAFE_CALL(doReadInformation ) }; }