/*! * \copyright * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file BluetoothInterface.h * \author (last) Behrouz NematiPour * \author (original) Behrouz NematiPour * \date (last) 22-Aug-2021 * \date (original) 22-Aug-2021 */ #pragma once // Qt #include #include #include #include #include // Project #include "main.h" // Doxygen : do not remove #include "MBluetooth.h" // Define #define _BluetoothInterface Bluetooth::BluetoothInterface::I() // forward declarations class tst_initializations; // namespace namespace Bluetooth { using namespace Model; /*! * \brief The MessageAcknowModel class * \details The wrapper class of the AcknowModel which does the thread handling. */ class BluetoothInterface : public QObject { Q_OBJECT // Singleton SINGLETON(BluetoothInterface) // friends friend class ::tst_initializations; typedef QMap< QBluetoothUuid::ServiceClassUuid, QLowEnergyService *> ServiceMap; QThread *_thread = nullptr; bool _init = false; QStringList _supportedDeviceKeywords { "BP7000", "BLEsmart", "BLESmart" }; // Regarding to Omron Documents. QBluetoothLocalDevice *_local = nullptr ; QBluetoothDeviceDiscoveryAgent *_agent = nullptr ; QLowEnergyController *_device = nullptr ; QLowEnergyService *_serviceDeviceInformation = nullptr ; QLowEnergyService *_serviceCurrentTime = nullptr ; QLowEnergyService *_serviceBloodPressure = nullptr ; QLowEnergyService *_serviceBattery = nullptr ; QBluetoothDeviceInfo _info ; MBluetooth _model ; MBluetooth::InterfaceStates _state ; bool _bpRead = false ; const quint16 _interval = 1000 ; // the interface timer base interval in mSec protected: void timerEvent(QTimerEvent *event) override; public slots: bool init(); bool init(QThread &vThread); private slots: void quit(); // Local Device Slots void onLocalPairingFinish (const QBluetoothAddress &vAddress, QBluetoothLocalDevice::Pairing vPairing ); void onLocalPairingDisplayConfirmation (const QBluetoothAddress &vAddress, const QString &vPin ); void onLocalPairingDisplayPinCode (const QBluetoothAddress &vAddress, const QString &vPin ); void onLocalDeviceConnect (const QBluetoothAddress &vAddress ); void onLocalDeviceDisconnect (const QBluetoothAddress &vAddress ); void onLocalError ( QBluetoothLocalDevice::Error vError ); // Discovery Agent Slots void onAgentDiscoverDevice (const QBluetoothDeviceInfo & vDevice ); void onAgentDiscoverFinish (); void onAgentDiscoverCancel (); void onAgentDiscoverError ( QBluetoothDeviceDiscoveryAgent::Error vError ); // Device Slots void onDeviceConnect ( ); void onDeviceDisconnect ( ); void onDeviceError ( QLowEnergyController::Error vError ); void onDeviceStateChanged ( QLowEnergyController::ControllerState vState ); void onDeviceConnectionUpdated (const QLowEnergyConnectionParameters & vParameters ); private: void initConnections(); void initThread(QThread &vThread); void quitThread(); bool discoverStart (); bool discoverFinish (); bool isLocalValid (); bool isInfoValid (); bool isDeviceValid (); bool isDeviceSupported( const QString &vName ); bool initDevice (); void resetDevice (); bool connectToDevice(); bool discoverServices(); void notifyStateChange(const BluetoothData &vData); signals: void didStateChange(const BluetoothData &vData); SAFE_CALL(start ) SAFE_CALL(doScan) }; }