Index: sources/bluetooth/BluetoothInterface.cpp =================================================================== diff -u -re4a0e2fc4c7ae0cbce0d670772276bf7f5ff3845 -raa8f2c87c14c68d1fda6da2540d47144990a596c --- sources/bluetooth/BluetoothInterface.cpp (.../BluetoothInterface.cpp) (revision e4a0e2fc4c7ae0cbce0d670772276bf7f5ff3845) +++ sources/bluetooth/BluetoothInterface.cpp (.../BluetoothInterface.cpp) (revision aa8f2c87c14c68d1fda6da2540d47144990a596c) @@ -1,4 +1,4 @@ - /*! +/*! * \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 @@ -43,12 +43,12 @@ */ bool BluetoothInterface::init() { - if ( ! _isValid ) return false; if ( _init ) return false; _init = true; // runs in BluetoothInterface thread - initConnections(); + // REMINDER:initConnections(); has been removed from here to the ondoStart, + // since the _local, _agent objects are created there. LOG_DEBUG("UI," + tr("%1 Initialized").arg(metaObject()->className())); return true; @@ -150,10 +150,13 @@ } // coco end +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // +// ~~~~~~~~~~ THREAD SAFE state change notifications.~~~~~~~~~~ // +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // #define NOTIFY_IDLE notifyStateChange(MBluetooth(MBluetooth::eIS_Idle )); #define NOTIFY_CLOSE notifyStateChange(MBluetooth(MBluetooth::eIS_Close )); -// ~~~~~~~~~~~ Local +// ~~~~~~~~~~ Local #define NOTIFY_LOCAL_INIT notifyStateChange(MBluetooth(MBluetooth::eIS_Local_Init , \ _local->address().toString() , \ _local->name(),0,1 )); @@ -165,7 +168,7 @@ #define NOTIFY_LOCAL_ERROR_OFF notifyStateChange(MBluetooth(MBluetooth::eIS_Local_Error_Off )); #define NOTIFY_LOCAL_ERROR_INVALID notifyStateChange(MBluetooth(MBluetooth::eIS_Local_Error_Invalid )); #define NOTIFY_LOCAL_DISCONNECT notifyStateChange(MBluetooth(MBluetooth::eIS_Local_Disconnect , vAddress.toString()) ); -// ~~~~~~~~~~~ Scan +// ~~~~~~~~~~ Scan #define NOTIFY_SCAN_DISCOVER notifyStateChange(MBluetooth(MBluetooth::eIS_Scan_Discover , \ vInfo.address().toString() , \ vInfo.name(), "" , \ @@ -185,7 +188,7 @@ #define NOTIFY_SCAN_NOTFOUND notifyStateChange(MBluetooth(MBluetooth::eIS_Scan_NotFound ,"", "" )); #define NOTIFY_SCAN_STOP notifyStateChange(MBluetooth(MBluetooth::eIS_Scan_Stop )); #define NOTIFY_SCAN_DONE notifyStateChange(MBluetooth(MBluetooth::eIS_Scan_Done )); -// ~~~~~~~~~ Device +// ~~~~~~~~~~ Device #define NOTIFY_DEVICE_INIT_ERROR notifyStateChange(MBluetooth(MBluetooth::eIS_Device_Error_Init )); #define NOTIFY_DEVICE_INIT notifyStateChange(MBluetooth(MBluetooth::eIS_Device_Init , \ _device->remoteAddress().toString() , \ @@ -206,7 +209,7 @@ #define NOTIFY_DEVICE_DISCONNECT notifyStateChange(MBluetooth(MBluetooth::eIS_Device_Disconnect , \ _device->remoteAddress().toString() , \ _device->remoteName() )); - +// ~~~~~~~~~~ Service #define NOTIFY_SERVICE_START notifyStateChange(MBluetooth(MBluetooth::eIS_Service_Start )); #define NOTIFY_SERVICE_DISCOVER notifyStateChange(MBluetooth(MBluetooth::eIS_Service_Discover )); #define NOTIFY_SERVICE_DETAILS(vS) notifyStateChange(MBluetooth(MBluetooth::eIS_Service_Detail , \ @@ -222,7 +225,7 @@ service->serviceUuid().toString() , \ service->serviceName() )); #define NOTIFY_SERVICE_DONE notifyStateChange(MBluetooth(MBluetooth::eIS_Service_Done )); - +// ~~~~~~~~~~ Details/Characteristics #define NOTIFY_DETAILS_ERROR notifyStateChange(MBluetooth(MBluetooth::eIS_Service_Detail_Error , \ _device->remoteAddress().toString() , \ _device->remoteName(), "" , \ @@ -282,17 +285,21 @@ service->serviceUuid().toString() , \ service->serviceName() )); - -/* -#define NOTIFY_SERVICE_DISCOVER notifyStateChange(MBluetooth(MBluetooth::eIS_Service_Discover , \ - _service->serviceUuid().toString() , \ - _service->serviceName() )); -*/ - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~ Public interface to initialize and start the scan // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /*! + * \brief BluetoothInterface::doNotifyStatePOSTError + * \details The public slot for public notification on POST error, + * since the POST is done by ApplicationPOST class, + * and it needs to notify the BluetoothInterface about the failure. + */ +void BluetoothInterface::doNotifyStatePOSTError() +{ + NOTIFY_LOCAL_ERROR_POST +} + +/*! * \brief BluetoothInterface::ondoStart * \details the thread safe slot to be called when the public function start is called. * initializes the local Bluetooth device _local and setups up the interface. @@ -313,10 +320,11 @@ return; } - _agent = new QBluetoothDeviceDiscoveryAgent (this); _local->powerOn(); + _agent = new QBluetoothDeviceDiscoveryAgent (this); quitDevice(); _agent->setLowEnergyDiscoveryTimeout(5000); + initConnections(); NOTIFY_LOCAL_INIT NOTIFY_IDLE } @@ -565,6 +573,12 @@ void BluetoothInterface::onServiceCharacteristicRead (const QLowEnergyCharacteristic &vCharacteristic, const QByteArray &vValue) { QLowEnergyService *service = reinterpret_cast(sender()); NOTIFY_DETAILS_READ + // By document reading shall occur here (onServiceCharacteristicRead) but seems it only happens onServiceCharacteristicChanged. + // Did not seem to cause any issue having one read here in case the value has been passed in here. + if (vCharacteristic.uuid() == QBluetoothUuid(QBluetoothUuid::BloodPressureMeasurement)) + { + interpretBloodPressure(vValue); + } } void BluetoothInterface::onServiceCharacteristicWritten (const QLowEnergyCharacteristic &vCharacteristic, const QByteArray &vValue) { QLowEnergyService *service = reinterpret_cast(sender()); @@ -573,45 +587,20 @@ void BluetoothInterface::onServiceCharacteristicChanged (const QLowEnergyCharacteristic &vCharacteristic, const QByteArray &vValue) { QLowEnergyService *service = reinterpret_cast(sender()); NOTIFY_DETAILS_CHANGE + // ManufacturerNameString : OMRONHEALTHCARE + // ModelNumberString : BP7000 if (vCharacteristic.uuid() == QBluetoothUuid(QBluetoothUuid::BloodPressureMeasurement)) { - parseMeasurement(vValue); + interpretBloodPressure(vValue); } } -void BluetoothInterface::parseMeasurement(const QByteArray &byteArray) +void BluetoothInterface::interpretBloodPressure(const QByteArray &vData) { - MeasurementData measurement; - const uchar *d = reinterpret_cast(byteArray.constData()); - - measurement.flags = *d; - measurement.systolic = d[1]; - measurement.diastolic = d[3]; - measurement.mean_arterial_pressure_value= d[5]; - measurement.year = d[7]; - measurement.month = d[9]; - measurement.day = d[10]; - measurement.hour = d[11]; - measurement.minute = d[12]; - measurement.second = d[13]; - measurement.pulse_rate = d[14]; - measurement.user_id = d[16]; - measurement.measurement_status = d[17]; - - qDebug() << measurement.flags - << measurement.systolic - << measurement.diastolic - << measurement.mean_arterial_pressure_value - << measurement.year - << measurement.month - << measurement.day - << measurement.hour - << measurement.minute - << measurement.second - << measurement.pulse_rate - << measurement.user_id - << measurement.measurement_status ; - // emit didReceiveBPMeasurement(measurement); + MUIBloodPressure model; + model.fromByteArray(vData); + emit didActionReceive(model.data()); + LOG_EVENT(model.toString()); } /*!