Index: sources/bluetooth/BluetoothInterface.h =================================================================== diff -u -r93cb2e56782aa64aafb2b69ec526a5e49ffdf1c7 -r093155324dda47cba65693b72a2d1b0290d0c29a --- sources/bluetooth/BluetoothInterface.h (.../BluetoothInterface.h) (revision 93cb2e56782aa64aafb2b69ec526a5e49ffdf1c7) +++ sources/bluetooth/BluetoothInterface.h (.../BluetoothInterface.h) (revision 093155324dda47cba65693b72a2d1b0290d0c29a) @@ -22,6 +22,7 @@ // Project #include "main.h" // Doxygen : do not remove #include "MBluetooth.h" +#include "MUIBloodPressureData.h" // Define #define _BluetoothInterface Bluetooth::BluetoothInterface::I() @@ -34,8 +35,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,42 +53,34 @@ typedef QMap< QBluetoothUuid::ServiceClassUuid, QLowEnergyService *> ServiceMap; QThread *_thread = nullptr; - bool _init = false; + bool _init = false ; + bool _isValid = false ; + const QByteArray _bloodPressureNotifyValue = QByteArray::fromHex("0100"); + 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 ; + quint8 _tempBatt = 0 ; - bool _connectionActive = false ; + bool _reconnectionActive = false ; const quint16 _interval = 1000 ; // the interface timer base interval in mSec + public: - // 19 total bytes - struct MeasurementData { - uint8_t flags; // 1 byte - uint16_t systolic; // 2 bytes - uint16_t diastolic; // 2 bytes - uint16_t mean_arterial_pressure_value; // 2 bytes - uint16_t year; // 2 bytes - uint8_t month; // 1 byte - uint8_t day; // 1 byte - uint8_t hour; // 1 byte - uint8_t minute; // 1 byte - uint8_t second; // 1 byte - uint16_t pulse_rate; // 2 bytes - uint8_t user_id; // 1 byte - uint16_t measurement_status; // 2 bytes - }; + bool isValid( ) const { return _isValid ; } + void valid(bool vValid) { _isValid = vValid; } + void mimic(quint16 vSystolic , + quint16 vDiastolic , + quint16 vPulseRate ); protected: void timerEvent(QTimerEvent *event) override; @@ -94,6 +89,8 @@ bool init(); bool init(QThread &vThread); + void doNotifyStatePOSTError(); + private slots: void quit(); @@ -116,15 +113,20 @@ void onDeviceError ( QLowEnergyController::Error vError ); void onServiceCharacteristicChanged (const QLowEnergyCharacteristic &vCharacteristic , const QByteArray &vValue ); - void onServiceCharacteristicRead (const QLowEnergyCharacteristic &vCharacteristic , const QByteArray &vValue ) { qDebug() << " ..... Service Charc R:" << vCharacteristic .name() << vValue; } - void onServiceCharacteristicWritten (const QLowEnergyCharacteristic &vCharacteristic , const QByteArray &vValue ) { qDebug() << " ..... Service Charc W:" << vCharacteristic .name() << vValue; } - void onServiceDescriptorRead (const QLowEnergyDescriptor &vDescriptor , const QByteArray &vValue ) { qDebug() << " ..... Service Descr R:" << vDescriptor .name() << vValue; } - void onServiceDescriptorWritten (const QLowEnergyDescriptor &vDescriptor , const QByteArray &vValue ) { qDebug() << " ..... Service Descr W:" << vDescriptor .name() << vValue; } + void onServiceCharacteristicRead (const QLowEnergyCharacteristic &vCharacteristic , const QByteArray &vValue ); + void onServiceCharacteristicWritten (const QLowEnergyCharacteristic &vCharacteristic , const QByteArray &vValue ); + void onServiceDescriptorRead (const QLowEnergyDescriptor &vDescriptor , const QByteArray &vValue ); + void onServiceDescriptorWritten (const QLowEnergyDescriptor &vDescriptor , const QByteArray &vValue ); void onServiceError ( QLowEnergyService::ServiceError vError ); void onServiceStateChanged ( QLowEnergyService::ServiceState vState ); + void onDeviceSelect (const BluetoothDeviceData &vDevice); + private: + bool startScan (); + bool stopScan (); + void initConnections (); void initConnectionsDevice (); void initConnectionsService (QLowEnergyService *vService); @@ -141,23 +143,35 @@ void quitServices (); bool isLocalValid (); + bool isAgentValid (); bool isInfoValid (); bool isDeviceValid (); - // bool isServiceValid (QLowEnergyService *vService); - bool isDetailValid (const QLowEnergyCharacteristic &vDetail); - bool isDeviceSupported ( const QString &vName ); + bool isDeviceSupported (const QString &vName ); - bool connectToDevice (); + bool connectToDevice (); + bool reconnectToDevice (); void discoverServices (); void discoverServicesDetails(); + void enableNotify (); + void requestMeasurements (); + void requestInformation (); + void requestBattery (); + void printCharacteristics (QLowEnergyService *vService); - void notifyStateChange(const BluetoothData &vData); + void notifyStateChange (const BluetoothData &vData); + void notifyBloodPressure (const MUIBloodPressure &vModel); + void interpretBloodPressure (const QByteArray &vData); + void interpretInformation (); + void interpretBattery (const QByteArray &vData); - void parseMeasurement (const QByteArray &byteArray); + signals: - void didStateChange(const BluetoothData &vData); + void didStateChange (const BluetoothData &vData); + void didActionReceive (const UIBloodPressureData &vData); + void didDeviceChange (const BluetoothDeviceData &vDevice); + void didDeviceSelect (const BluetoothDeviceData &vDevice); - SAFE_CALL(start ) - SAFE_CALL(doScan) + SAFE_CALL(doStart) + SAFE_CALL(doScan ) }; }