Index: denali.pro.user =================================================================== diff -u -r3779eaac00ecfa03d5b0405171ab68a0e0ff5538 -r47c8f13876317ba36500400f894d96c9bce9eb17 --- denali.pro.user (.../denali.pro.user) (revision 3779eaac00ecfa03d5b0405171ab68a0e0ff5538) +++ denali.pro.user (.../denali.pro.user) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -1,14 +1,14 @@ - + EnvironmentId {67370740-e20f-4fc6-be45-6652e866a8bf} ProjectExplorer.Project.ActiveTarget - 1 + 0 ProjectExplorer.Project.EditorSettings @@ -86,311 +86,6 @@ ProjectExplorer.Project.Target.0 - Qt 5.12.5 (iMX8) - Qt 5.12.5 (iMX8) - {5d6458ef-f917-4aef-a092-c77bbe106149} - 0 - 0 - 0 - - /home/denali/Projects/tmp/build/denali-Qt_5_12_5_iMX8-Debug - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Debug - Debug - Qt4ProjectManager.Qt4BuildConfiguration - 2 - true - - - /home/denali/Projects/tmp/build/denali-Qt_5_12_5_iMX8-Release - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Release - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - - /home/denali/Projects/tmp/build/denali-Qt_5_12_5_iMX8-Profile - - - true - qmake - - QtProjectManager.QMakeBuildStep - false - - false - false - false - - - true - Make - - Qt4ProjectManager.MakeStep - - false - - - false - - 2 - Build - Build - ProjectExplorer.BuildSteps.Build - - - - true - Make - - Qt4ProjectManager.MakeStep - - true - clean - - false - - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Profile - Profile - Qt4ProjectManager.Qt4BuildConfiguration - 0 - true - - 3 - - - - true - Check for free disk space - - RemoteLinux.CheckForFreeDiskSpaceStep - - - - - / - 5242880 - - - - - true - Kill current application instance - - RemoteLinux.KillAppStep - - - - - - - - - true - Deploy files via rsync - - RemoteLinux.RsyncDeployStep - - - - - - - -av - false - - 3 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy to Remote Linux Host - - DeployToGenericLinux - - 1 - - - dwarf - - cpu-cycles - - - 250 - -F - true - 4096 - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - kcachegrind - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - 1 - - - denali (on Generic Linux Device (iMX8))2 - RemoteLinuxRunConfiguration:/home/denali/Projects/application/denali.pro - 1 - - false - -u -a - 3768 - false - true - false - false - true - false - - - :0 - - 1 - - - - ProjectExplorer.Project.Target.1 - Desktop Qt 5.12.5 GCC 64bit Desktop Qt 5.12.5 GCC 64bit qt.qt5.5125.gcc_64_kit @@ -422,7 +117,17 @@ false - 2 + + true + -b --tag denali >> denali + + sha256sum + %{buildDir} + Custom Process Step + + ProjectExplorer.ProcessStep + + 3 Build Build ProjectExplorer.BuildSteps.Build @@ -478,7 +183,16 @@ false - 2 + + true + -b --tag denali >> denali + sha256sum + %{buildDir} + Custom Process Step + + ProjectExplorer.ProcessStep + + 3 Build Build ProjectExplorer.BuildSteps.Build @@ -1481,7 +1195,7 @@ denali Qt4ProjectManager.Qt4RunConfiguration:/home/denali/Projects/application/denali.pro - --disable-timeout -l + --disable-timeout -l -m -a 3768 false true @@ -1496,6 +1210,330 @@ + ProjectExplorer.Project.Target.1 + + Qt 5.12.5 (iMX8) + Qt 5.12.5 (iMX8) + {5d6458ef-f917-4aef-a092-c77bbe106149} + 0 + 0 + 0 + + /home/denali/Projects/tmp/build/denali-Qt_5_12_5_iMX8-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + + true + -b --tag denali >> denali + + sha256sum + %{buildDir} + Custom Process Step + + ProjectExplorer.ProcessStep + + 3 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + /home/denali/Projects/tmp/build/denali-Qt_5_12_5_iMX8-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + + true + -b --tag denali >> denali + sha256sum + %{buildDir} + Custom Process Step + + ProjectExplorer.ProcessStep + + 3 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + /home/denali/Projects/tmp/build/denali-Qt_5_12_5_iMX8-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + + true + Check for free disk space + + RemoteLinux.CheckForFreeDiskSpaceStep + + + + + / + 5242880 + + + + + true + Kill current application instance + + RemoteLinux.KillAppStep + + + + + + + + + true + Deploy files via rsync + + RemoteLinux.RsyncDeployStep + + + + + + + -av + false + + 3 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy to Remote Linux Host + + DeployToGenericLinux + + 1 + + + dwarf + + cpu-cycles + + + 250 + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 1 + + + denali (on Generic Linux Device (iMX8))2 + RemoteLinuxRunConfiguration:/home/denali/Projects/application/denali.pro + 1 + + false + -u -l -a + 3768 + false + true + false + false + false + false + + + :0 + + 1 + + + ProjectExplorer.Project.TargetCount 2 Index: scripts/bluetooth_paired_clear.sh =================================================================== diff -u --- scripts/bluetooth_paired_clear.sh (revision 0) +++ scripts/bluetooth_paired_clear.sh (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -0,0 +1,39 @@ +#!/bin/sh +########################################################################### +# +# 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 bluetooth_reset.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 30-Aug-2021 +# @author (original) Behrouz NematiPour +# @date (original) 30-Aug-2021 +# +############################################################################ + +# @details +# This file is called by UI Software to removed all the currnelty paired or cached devices. +# This is done before each scan to clean up and start a fresh scan. + +DEVICES=$(echo "devices" | bluetoothctl | grep ^Device | cut -b 8-25) +if [ ! -z "$DEVICES" ]; then + for device in $DEVICES; do + if [ ! -z "$device" ]; then + echo "remove $device" | bluetoothctl + fi + done +fi + +PAIRED_DEVICES=$(echo "paired-devices" | bluetoothctl | grep ^Device | cut -b 8-25) +if [ ! -z "$PAIRED_DEVICES" ]; then + for paired_device in $PAIRED_DEVICES; do + if [ ! -z "$paired_device" ]; then + echo "remove $paired_device" | bluetoothctl + fi + done +fi + Index: scripts/bluetooth_paired_query.sh =================================================================== diff -u --- scripts/bluetooth_paired_query.sh (revision 0) +++ scripts/bluetooth_paired_query.sh (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -0,0 +1,30 @@ +#!/bin/sh +########################################################################### +# +# 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 bluetooth_reset.sh +# +# @author (last) Behrouz NematiPour +# @date (last) 30-Aug-2021 +# @author (original) Behrouz NematiPour +# @date (original) 30-Aug-2021 +# +############################################################################ + +# @details +# This file is called by UI Software to query the Blood Pressure paired Bluetooth device. +# There should be only one device paired at a time regarding our design. +# The returned value is the devive mac address and the name assigned to it in the system. + +#test code +#PAIRED_DEVICE_INFO="28:FF:B2:78:5B:BF BP7000" +#PAIRED_DEVICE_INFO="" + +#PAIRED_DEVICE_INFO=$(echo "paired-devices" | bluetoothctl | grep ^Device | cut -b 8-125) + +echo $PAIRED_DEVICE_INFO + Fisheye: Tag 47c8f13876317ba36500400f894d96c9bce9eb17 refers to a dead (removed) revision in file `scripts/bluetooth_remove_paired.sh'. Fisheye: No comparison available. Pass `N' to diff? Index: sources/bluetooth/BluetoothInterface.cpp =================================================================== diff -u -r3e64d98e243484505a44d99b13826097cb6b01eb -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/bluetooth/BluetoothInterface.cpp (.../BluetoothInterface.cpp) (revision 3e64d98e243484505a44d99b13826097cb6b01eb) +++ sources/bluetooth/BluetoothInterface.cpp (.../BluetoothInterface.cpp) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -20,6 +20,7 @@ #include // Project +#include "ApplicationController.h" #include "Logger.h" // namespace @@ -295,6 +296,10 @@ connect(this , SIGNAL(didDeviceSelect (BluetoothDeviceData )), this , SLOT( onDeviceSelect (BluetoothDeviceData ))); + + connect(&_ApplicationController, SIGNAL(didAttributeResponse(const DeviceBluetoothPairedQueryResponseData &)), + this , SLOT( onAttributeResponse(const DeviceBluetoothPairedQueryResponseData &))); + } /*! @@ -515,6 +520,30 @@ connectToDevice(); } +void BluetoothInterface::onAttributeResponse(const DeviceBluetoothPairedQueryResponseData &vData) +{ + // Notify the View that it is a new scan so clean up the list, and update screen status. + NOTIFY_SCAN_START + + // create a device info with the given paired device information + // to simulate the device discovered slot call + QBluetoothDeviceInfo info(QBluetoothAddress(vData.mAddr), vData.mName, 0); + info.setCoreConfigurations(QBluetoothDeviceInfo::LowEnergyCoreConfiguration); + onAgentDiscoverDevice(info); + + // since it is only one paired device, the device discovery finish is called to process the device. + onAgentDiscoverFinish(); + + // try to call to the device for the first time to make the device and initialize it. + BluetoothDeviceData data; + data.addr = vData.mAddr; + data.name = vData.mName; + onDeviceSelect(data); + + // set the flag for the re-connection timer. + _reconnectionActive = true; +} + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~ Remote Device Slots // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Index: sources/bluetooth/BluetoothInterface.h =================================================================== diff -u -r9ae3b0d6624904693329309aaf8ff02784c17184 -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/bluetooth/BluetoothInterface.h (.../BluetoothInterface.h) (revision 9ae3b0d6624904693329309aaf8ff02784c17184) +++ sources/bluetooth/BluetoothInterface.h (.../BluetoothInterface.h) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -23,6 +23,7 @@ #include "main.h" // Doxygen : do not remove #include "MBluetooth.h" #include "MUIBloodPressureData.h" +#include "DeviceModels.h" // Define #define _BluetoothInterface Bluetooth::BluetoothInterface::I() @@ -120,6 +121,8 @@ void onDeviceSelect (const BluetoothDeviceData &vDevice); + void onAttributeResponse (const DeviceBluetoothPairedQueryResponseData &vData); + private: bool startScan (); bool stopScan (); @@ -167,7 +170,7 @@ void didDeviceChange (const BluetoothDeviceData &vDevice); void didDeviceSelect (const BluetoothDeviceData &vDevice); - SAFE_CALL(doStart) - SAFE_CALL(doScan ) + SAFE_CALL(doStart) // start the bluetooth adapter. + SAFE_CALL(doScan ) // scan for devices. }; } Index: sources/device/DeviceController.cpp =================================================================== diff -u -rb7c9de054c6b7a1ca4bac9fbb0ec5d4ac06620a9 -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision b7c9de054c6b7a1ca4bac9fbb0ec5d4ac06620a9) +++ sources/device/DeviceController.cpp (.../DeviceController.cpp) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -430,7 +430,7 @@ QString src = (vError > DeviceError::eDevice_Scripts_Error_Start ? MAbstract::unitText(MAbstract::Unit_Enum::eUI) : MAbstract::unitText(MAbstract::Unit_Enum::eDV)) + ","; vModel._data.mAccepted = false ; vModel._data.mReason = vError ; - vModel._data.mMessage = DeviceError::deviceErrorText(vError) + QString(" [%1]").arg(vError); + vModel._data.mMessage = DeviceError::deviceErrorText(vError, vError); LOG_EVENT(src + vModel._data.mMessage + " " + vExtraLogInfo); emit didAttributeResponse(vModel._data); return true; @@ -499,6 +499,7 @@ */ void DeviceController::onProcessBrightnessExitCode(int vExitCode, QProcess::ExitStatus) { + // TODO: Move this into the model. _deviceBrightnessResponse._data.mBrightnessPercent = _deviceBrightnessRequest._data.mBrightness_old * 10; // set to old value in case of error if ( ! checkError(static_cast(vExitCode), _deviceBrightnessResponse, _deviceBrightnessResponse.toString()) ) { // has no error if (_deviceBrightnessRequest._data.mRead) { @@ -541,17 +542,49 @@ void DeviceController::onProcessBluetoothPairedResetExitCode(int vExitCode, QProcess::ExitStatus vStatus) { - DeviceBluetoothPairedResetResponseData data; - data.mAccepted = vStatus == QProcess::NormalExit; - data.mReason = vExitCode; - QString msg; - if (data.mAccepted) msg = tr("Removed previously paired devices."); - else msg = tr("Unsuccessful removal of previously paired devices."); - data.mMessage = msg; - didAttributeResponse(data); - LOG_DEBUG(msg); + // TODO: review the usage and definition of this object _deviceBluetoothPairedResetResponse. do we need it any more? + MDeviceBluetoothPairedResetResponse model; + QByteArray deviceInfo; + if ( vStatus ) vExitCode = Device::DeviceError::eDevice_Scripts_Error_Status; + else deviceInfo = _processBluetoothPairedReset.readAll(); + model.fromByteArray( deviceInfo, &vExitCode ); + LOG_EVENT_UI(model.data().mMessage); + didAttributeResponse(model.data()); } + +void DeviceController::onAttributeRequest(const DeviceBluetoothPairedQueryRequestData &) +{ + // ----- check that script exists. + QString script; + if ( checkError( DeviceError::checkScript(script, Bluetooth_Paired_Query), _deviceBluetoothPairedQueryResponse, script) ) + return; + + // ----- check if the process is not running + if ( _processBluetoothPairedQuery.state() != QProcess::NotRunning ) { + checkError(DeviceError::eDevice_Scripts_Error_IsRunning, _deviceBluetoothPairedQueryResponse); + return; + } + + // ----- run the process + TimedProcess *timedProcess = new TimedProcess(&_processBluetoothPairedQuery, script, 1000); + timedProcess->start(); +} + +void DeviceController::onProcessBluetoothPairedQueryExitCode(int vExitCode, QProcess::ExitStatus vStatus) +{ + // The Exit code in this script is not used and is not used. + // any other checking is done by UI Software at the moment this script is called. + // The only thing matters is the pared device info in text and it will be empty string if error happens. + MDeviceBluetoothPairedQueryResponse model; + QByteArray deviceInfo; + if ( vStatus ) vExitCode = Device::DeviceError::eDevice_Scripts_Error_Status; + else deviceInfo = _processBluetoothPairedQuery.readAll(); + model.fromByteArray( deviceInfo, &vExitCode ); + didAttributeResponse(model.data()); + LOG_EVENT_UI(model.data().mMessage); +} + /*! * \brief DeviceController::doScreenshot * \details emit the screenshot signal to run that in Device controller thread @@ -581,12 +614,12 @@ { if ( ! QFileInfo::exists(vFile)) { if ( ! FileHandler::write(vFile, "", false) ) { - LOG_DEBUG(DeviceError::deviceErrorText(DeviceError::eDevice_Watch_Error_NotFound)); + LOG_DEBUG(DeviceError::deviceErrorText(DeviceError::eDevice_Watch_Error_NotFound, 0)); return; } } if ( ! _fileSystemWatcher.addPath(vFile) ) { - LOG_DEBUG(DeviceError::deviceErrorText(DeviceError::eDevice_Watch_Error_NotAdded)); + LOG_DEBUG(DeviceError::deviceErrorText(DeviceError::eDevice_Watch_Error_NotAdded, 0)); } } Index: sources/device/DeviceError.cpp =================================================================== diff -u -r9ae3b0d6624904693329309aaf8ff02784c17184 -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/device/DeviceError.cpp (.../DeviceError.cpp) (revision 9ae3b0d6624904693329309aaf8ff02784c17184) +++ sources/device/DeviceError.cpp (.../DeviceError.cpp) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -27,13 +27,22 @@ using namespace Device; const char *DeviceError::Scripts_Error_Text[] = { - QT_TR_NOOP("The device script file is not found."), - QT_TR_NOOP("The device script file is not executable."), - QT_TR_NOOP("The request is already in progress."), - QT_TR_NOOP("The requested value is out of range."), - QT_TR_NOOP("The requested value is incorrect."), - QT_TR_NOOP("The response value is incorrect."), - QT_TR_NOOP("The watch file is not found."), + QT_TR_NOOP("The device script abnormal exit." ), // eDevice_Scripts_Error_Status + QT_TR_NOOP("The device script file is not found." ), // eDevice_Scripts_Error_NotFound + QT_TR_NOOP("The device script file is not executable." ), // eDevice_Scripts_Error_NotExecutable + QT_TR_NOOP("The request is already in progress." ), // eDevice_Scripts_Error_IsRunning + QT_TR_NOOP("The requested value is out of range." ), // eDevice_Scripts_Error_OutOfRange + QT_TR_NOOP("The requested value is incorrect." ), // eDevice_Scripts_Error_Incorrect_Req + QT_TR_NOOP("The response value is incorrect." ), // eDevice_Scripts_Error_Incorrect_Rsp + + QT_TR_NOOP("The watch file is not found." ), // eDevice_Watch_Error_NotFound + QT_TR_NOOP("The watch file cannot be added." ), // eDevice_Watch_Error_NotAdded + + QT_TR_NOOP("The Bluetooth cuff pair clear error." ), // eDevice_BCuff_Error_Reset + + QT_TR_NOOP("The Bluetooth cuff pair query error." ), // eDevice_BCuff_Error_Query + QT_TR_NOOP("The Bluetooth cuff pair query empty." ), // eDevice_BCuff_Error_Query_Empty + QT_TR_NOOP("The Bluetooth cuff pair invalid address." ), // eDevice_BCuff_Error_Query_Addr }; /*! @@ -49,21 +58,22 @@ DeviceError::Scripts_Error_Enum err = DeviceError::eDevice_OK; vScript = _scriptsFolder + vShellScript; QFileInfo info(vScript); - if ( ! info.exists () ) { err = DeviceError::eDevice_Scripts_Error_NotFound ; goto lOut; } - if ( ! info.isExecutable() ) { err = DeviceError::eDevice_Scripts_Error_NotExecutable ; goto lOut; } + if ( ! info.exists () ) { err = DeviceError::eDevice_Scripts_Error_NotFound ; goto lOut; } + if ( ! info.isExecutable() ) { err = DeviceError::eDevice_Scripts_Error_NotExecutable ; goto lOut; } lOut: return err; } -QString DeviceError::deviceErrorText(DeviceError::Scripts_Error_Enum vError) { +QString DeviceError::deviceErrorText(DeviceError::Scripts_Error_Enum vError, int vExitCode) { QString message; int idx = vError - eDevice_Scripts_Error_Start - 1; - int len = sizeof Scripts_Error_Text / sizeof Scripts_Error_Text[0]; - if (idx > len) { message = QObject::tr("Device error no text defined [%1]").arg(vError); goto lOut; } + int len = (sizeof Scripts_Error_Text / sizeof Scripts_Error_Text[0]); + qDebug() << len << idx; + if (idx >= len) { message = QObject::tr("Unknown device error %2 [%1]").arg(vExitCode).arg(vError); goto lOut; } if (eDevice_Scripts_Error_Start < vError && vError < eDevice_Error_End) { - message = QObject::tr(Scripts_Error_Text[idx]); goto lOut; } + message = QObject::tr(Scripts_Error_Text[idx]) + (vExitCode ? QString(" [%1]").arg(vExitCode) : ""); goto lOut; } - message = QObject::tr("Device error"); + message = QObject::tr("Device error [%1]").arg(vExitCode); lOut: return message; } Index: sources/device/DeviceError.h =================================================================== diff -u -re8262d170bb94046ddb767074a31530bdf4a2319 -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/device/DeviceError.h (.../DeviceError.h) (revision e8262d170bb94046ddb767074a31530bdf4a2319) +++ sources/device/DeviceError.h (.../DeviceError.h) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -40,8 +40,11 @@ enum Scripts_Error_Enum { eDevice_OK = 0 , + // The scripts can use the exit code of each commands they execute and the assumption is most of Linux commands exit codes are less than 1000. + // so any error less that 1000 will be identified as device error eDevice_Scripts_Error_Start = 1000 , // the script itself in system starts from 0 so give it enough gap + eDevice_Scripts_Error_Status , eDevice_Scripts_Error_NotFound , eDevice_Scripts_Error_NotExecutable , eDevice_Scripts_Error_IsRunning , @@ -52,12 +55,18 @@ eDevice_Watch_Error_NotFound , eDevice_Watch_Error_NotAdded , + eDevice_BCuff_Error_Reset , + + eDevice_BCuff_Error_Query , + eDevice_BCuff_Error_Query_Empty , + eDevice_BCuff_Error_Query_Addr , + eDevice_Error_End }; Q_ENUM(Scripts_Error_Enum) - static QString deviceErrorText( DeviceError::Scripts_Error_Enum vError ); + static QString deviceErrorText( DeviceError::Scripts_Error_Enum vError , int vExitCode ); static Scripts_Error_Enum checkScript(QString &vScript, const QString &vShellScript); }; } Index: sources/device/DeviceGlobals.h =================================================================== diff -u -r76aef158f5b9cdcecfa6003a72fe35b32c88eac2 -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/device/DeviceGlobals.h (.../DeviceGlobals.h) (revision 76aef158f5b9cdcecfa6003a72fe35b32c88eac2) +++ sources/device/DeviceGlobals.h (.../DeviceGlobals.h) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -64,7 +64,7 @@ void vATTRIBUTE##Changed (const vTYPE & v##vATTRIBUTE ); \ private : \ /*! \ - * \brief VDevice::bluetoothPairedResetRequest \ + * \brief VDevice::Request \ * \details The slot which will be called in case \ * the attribute value has been updated in the QML. \ * The updated value is wrapped in the corresponding model \ @@ -173,35 +173,43 @@ #define DEVICE_DEV_PARENT_LIST \ DEVICE_DEV_PARENT ( Brightness ) \ DEVICE_DEV_PARENT ( BluetoothPairedReset ) \ + DEVICE_DEV_PARENT ( BluetoothPairedQuery ) \ #define DEVICE_DEV_INIT_CONNECTIONS_LIST \ DEVICE_DEV_INIT_CONNECTIONS ( Brightness ) \ DEVICE_DEV_INIT_CONNECTIONS ( BluetoothPairedReset ) \ + DEVICE_DEV_INIT_CONNECTIONS ( BluetoothPairedQuery ) \ #define DEVICE_DEV_DEFINITION_LIST \ DEVICE_DEV_DEFINITION ( Brightness ) \ DEVICE_DEV_DEFINITION ( BluetoothPairedReset ) \ + DEVICE_DEV_DEFINITION ( BluetoothPairedQuery ) \ /* ---------------------------- APP */ #define DEVICE_APP_INIT_CONNECTIONS_LIST \ DEVICE_APP_INIT_CONNECTIONS ( Brightness ) \ DEVICE_APP_INIT_CONNECTIONS ( BluetoothPairedReset ) \ + DEVICE_APP_INIT_CONNECTIONS ( BluetoothPairedQuery ) \ #define DEVICE_APP_BRIDGE_DEFINITION_LIST \ DEVICE_APP_BRIDGE_DEFINITION( Brightness ) \ DEVICE_APP_BRIDGE_DEFINITION( BluetoothPairedReset ) \ + DEVICE_APP_BRIDGE_DEFINITION( BluetoothPairedQuery ) \ /* ---------------------------- GUI */ #define DEVICE_GUI_BRIDGE_DEFINITION_LIST \ DEVICE_GUI_BRIDGE_DEFINITION( Brightness ) \ DEVICE_GUI_BRIDGE_DEFINITION( BluetoothPairedReset ) \ + DEVICE_GUI_BRIDGE_DEFINITION( BluetoothPairedQuery ) \ #define DEVICE_GUI_INIT_CONNECTIONS_LIST \ DEVICE_GUI_INIT_CONNECTIONS ( Brightness ) \ DEVICE_GUI_INIT_CONNECTIONS ( BluetoothPairedReset ) \ + DEVICE_GUI_INIT_CONNECTIONS ( BluetoothPairedQuery ) \ /* ---------------------------- VIEW */ #define DEVICE_VIEW_INIT_CONNECTIONS_LIST \ DEVICE_VIEW_INIT_CONNECTIONS( Brightness ) \ DEVICE_VIEW_INIT_CONNECTIONS( BluetoothPairedReset ) \ + DEVICE_VIEW_INIT_CONNECTIONS( BluetoothPairedQuery ) \ Index: sources/device/DeviceModels.cpp =================================================================== diff -u -r61f16c988a159401c92730b4cbfca5085c77222f -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision 61f16c988a159401c92730b4cbfca5085c77222f) +++ sources/device/DeviceModels.cpp (.../DeviceModels.cpp) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -14,13 +14,103 @@ */ #include "DeviceModels.h" +// Qt +#include + +// Project +#include "DeviceError.h" + using namespace Model; /*! - * \brief MAdjustChemicalConfirmResponse::data - * \details Provides model's Data from the received messages data values - * \return Data + * \brief MDeviceBluetoothPairedResetResponse::fromByteArray + * \details Checks the response and sets up the mode data. + * \param vExitCode - Passed script exit code + * \return true if passed. */ -DeviceBrightnessResponseData MDeviceBrightnessResponse::data() const { - return _data; +bool MDeviceBluetoothPairedResetResponse::fromByteArray(const QByteArray &, int *vExitCode) +{ + // initialize data + int error = 0; + _data.mAccepted = false; + + // check if the vExitCode passed and it has a value other than zero + if ( vExitCode && *vExitCode ){ _data.mReason = Device::DeviceError::eDevice_BCuff_Error_Reset; error = *vExitCode; } + else _data.mReason = Device::DeviceError::eDevice_OK; + + // if vExitCode is not zero go to error since the data is no longer valid + if ( _data.mReason ) goto lError; // non-zero Exit code + + // Now everything is good to extract the data + _data.mAccepted = true; + _data.mMessage = QObject::tr("Removed previously paired device(s)."); goto lOut ; // normal return + +lError: + _data.mMessage = Device::DeviceError::deviceErrorText(static_cast(_data.mReason), error); + +lOut: + return _data.mAccepted; } + +/*! + * \brief MDeviceBluetoothPairedQueryResponse::fromByteArray + * \details Checks the script returned value and + * converts the returning paired device information from the process into the response model. + * \param vByteArray - Passed script response data + * \param vExitCode - Passed script exit code + * \return true if passed value is valid for conversion. + */ +bool MDeviceBluetoothPairedQueryResponse::fromByteArray(const QByteArray &vByteArray, int *vExitCode) +{ + // initialize data + QRegularExpression regX("^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$"); + QRegularExpressionValidator validator(regX); + int pos = 0; + + QStringList deviceInfo; + QString info = vByteArray.simplified().trimmed(); + int count = 0; + int error = 0; + _data.mAccepted = false; + _data.mAddr = ""; + _data.mName = ""; + _data.mInfo = deviceInfo; + + // check if the vExitCode passed and it has a value other than zero + if ( vExitCode && *vExitCode ){ _data.mReason = Device::DeviceError::eDevice_BCuff_Error_Query; error = *vExitCode; } + else _data.mReason = Device::DeviceError::eDevice_OK; + + // if vExitCode is not zero go to error since the data is no longer valid + if ( _data.mReason ) goto lError; // non-zero Exit code + + + // no paired device was found + if ( info.isEmpty() ) { + _data.mReason = Device::DeviceError::eDevice_BCuff_Error_Query_Empty; goto lError; // empty response + } + + deviceInfo = info.split(SEPARATOR); + count = deviceInfo.count(); + if ( count ) { + if ( count != LEN_COUNT) { + _data.mReason = Device::DeviceError::eDevice_Scripts_Error_Incorrect_Rsp; goto lError; // incorrect response, length + } + } + + if ( validator.validate(deviceInfo[eAddr], pos) != QValidator::Acceptable) { + _data.mReason = Device::DeviceError::eDevice_BCuff_Error_Query_Addr; goto lError; // incorrect response, address invalid + } + + // Now everything is good to extract the data + _data.mAccepted = true; + _data.mAddr = deviceInfo[eAddr]; + _data.mName = deviceInfo[eName]; + _data.mInfo = deviceInfo; + _data.mMessage = QObject::tr("Paired BCuff Query %1 %2").arg(_data.mAddr).arg(_data.mName); goto lOut ; // normal return + +lError: + _data.mMessage = Device::DeviceError::deviceErrorText(static_cast(_data.mReason), error); + +lOut: + return _data.mAccepted; +} Index: sources/device/DeviceModels.h =================================================================== diff -u -re8262d170bb94046ddb767074a31530bdf4a2319 -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/device/DeviceModels.h (.../DeviceModels.h) (revision e8262d170bb94046ddb767074a31530bdf4a2319) +++ sources/device/DeviceModels.h (.../DeviceModels.h) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -122,9 +122,10 @@ QVariantList parameters () const override { return { _data.mBrightnessPercent }; } QString infoText () const override { return QString("DeviceBrightness") ; } - Data data () const; + Data data () const { return _data; } }; +// ---------- MDeviceBluetoothPaired 'Reset' ---------- // /*! * \brief The MDeviceBluetoothPairedResetRequest class * \details The model for the bluetooth pared removal script call. @@ -147,11 +148,50 @@ public: struct Data : MDeviceResponseBase::Data { } _data; - QVariantList parameters () const override { return { }; } - QString infoText () const override { return QString("DeviceBluetoothPairedReset") ; } - Data data () const; + QVariantList parameters ( ) const override { return { }; } + QString infoText ( ) const override { return QString("DeviceBluetoothPairedReset") ; } + Data data ( ) const { return _data; } + bool fromByteArray(const QByteArray &vByteArray, int *vExitCode = nullptr) override; }; +// ---------- MDeviceBluetoothPaired 'Query' ---------- // +/*! + * \brief The MDeviceBluetoothPairedQueryRequest class + * \details The model for the bluetooth pared removal script call. + */ +class MDeviceBluetoothPairedQueryRequest : public MDeviceRequestBase { +public: + struct Data { + } _data; + + QString toString() { + return MDeviceRequestBase::toString("DeviceBluetoothPairedQuery", { }); + } +}; + +/*! + * \brief The MDeviceBluetoothPairedQueryResponse class + * \details The model for the bluetooth pared removal script call returned value / response. + */ +class MDeviceBluetoothPairedQueryResponse : public MDeviceResponseBase { +public: + static const quint8 LEN_COUNT = 2; + static const char SEPARATOR = ' '; + enum { + eAddr, + eName, + }; + struct Data : MDeviceResponseBase::Data { + QString mAddr = ""; // Paired device address + QString mName = ""; // Paired device name + QStringList mInfo = {}; // combination of the {mAddr, mName} to be used in QML/GUI side. + } _data; + QVariantList parameters ( ) const override { return { }; } + QString infoText ( ) const override { return QString("DeviceBluetoothPairedQuery"); } + Data data ( ) const { return _data; } + bool fromByteArray(const QByteArray &vByteArray, int *vExitCode = nullptr) override; +}; + } @@ -161,3 +201,6 @@ typedef Model::MDeviceBluetoothPairedResetRequest ::Data DeviceBluetoothPairedResetRequestData ; typedef Model::MDeviceBluetoothPairedResetResponse::Data DeviceBluetoothPairedResetResponseData; + +typedef Model::MDeviceBluetoothPairedQueryRequest ::Data DeviceBluetoothPairedQueryRequestData ; +typedef Model::MDeviceBluetoothPairedQueryResponse::Data DeviceBluetoothPairedQueryResponseData; Index: sources/device/DeviceView.cpp =================================================================== diff -u -re2dc7bd9995a3bb410aa472a1f95c1cc9ba3136d -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/device/DeviceView.cpp (.../DeviceView.cpp) (revision e2dc7bd9995a3bb410aa472a1f95c1cc9ba3136d) +++ sources/device/DeviceView.cpp (.../DeviceView.cpp) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -43,19 +43,6 @@ emit didAttributeRequest(data); } -/*! - * \brief VDevice::onAttributeResponse - * \param vData - * - * HERE Request 100 - * _GuiController doAttributeRequest - * _ApplicationController onAttributeRequest - * _DeviceController onAttributeRequest - * _ApplicationController onAttributeResponse - * _GuiController onAttributeResponse - * HERE Response 100 - * - */ void VDevice::onAttributeResponse(const DeviceBrightnessResponseData &vData) { // DEBUG : qDebug() << "HERE Response" << vData.mBrightnessPercent; if ( vData.mAccepted ) { @@ -75,27 +62,19 @@ response(true); } -// -------------------------------- -// developer implementation section -// -------------------------------- - void VDevice::doInitBluetoothPairedReset() { - // DEBUG : - qDebug() << "HERE Init"; + // DEBUG : qDebug() << "HERE Init"; DeviceBluetoothPairedResetRequestData data; emit didAttributeRequest(data); } void VDevice::bluetoothPairedResetRequest(const quint8 &) { - // DEBUG : - qDebug() << "HERE Request"; - // DeviceBluetoothPairedResetRequestData data; - // emit didAttributeRequest(data); + // DEBUG : qDebug() << "HERE Request"; + // Nothing to be done here. This property will not be assigned. } void VDevice::onAttributeResponse(const DeviceBluetoothPairedResetResponseData &vData) { - // DEBUG : - qDebug() << "HERE Response" << vData.mAccepted << vData.mReason << vData.mMessage; + // DEBUG : qDebug() << "HERE Response" << vData.mAccepted << vData.mReason << vData.mMessage; // this has to be called to let Gui to set to old value that device controller provided. status(vData.mMessage); @@ -107,3 +86,26 @@ response(true); } +void VDevice::doInitBluetoothPairedQuery() { + // DEBUG : qDebug() << "HERE Init"; + DeviceBluetoothPairedQueryRequestData data; + emit didAttributeRequest(data); +} + +void VDevice::bluetoothPairedQueryRequest(const QStringList &) { + // DEBUG : qDebug() << "HERE Request"; + // Nothing to be done here. This property will not be assigned. +} + +void VDevice::onAttributeResponse(const DeviceBluetoothPairedQueryResponseData &vData) { + // DEBUG : qDebug() << "HERE Response" << vData.mAccepted << vData.mReason << vData.mMessage; + // this has to be called to let Gui to set to old value that device controller provided. + status(vData.mMessage); + + accepted(vData.mAccepted); + reason (vData.mReason ); + + // has to be the last one + emit bluetoothPairedQueryChanged(vData.mInfo); + response(true); +} Index: sources/device/DeviceView.h =================================================================== diff -u -rb7c9de054c6b7a1ca4bac9fbb0ec5d4ac06620a9 -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/device/DeviceView.h (.../DeviceView.h) (revision b7c9de054c6b7a1ca4bac9fbb0ec5d4ac06620a9) +++ sources/device/DeviceView.h (.../DeviceView.h) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -36,15 +36,16 @@ class VDevice : public QObject { Q_OBJECT - TRIGGER ( bool , response , true) + TRIGGER ( bool , response , true) - PROPERTY ( bool , accepted , 0) - TRIGGER ( quint32 , reason , 0) - PROPERTY ( QString , status , "") + PROPERTY ( bool , accepted , 0) + TRIGGER ( quint32 , reason , 0) + PROPERTY ( QString , status , "") - ATTRIBUTE ( quint8 , brightness , 0, Brightness ) + ATTRIBUTE ( quint8 , brightness , 0, Brightness ) - ATTRIBUTE ( quint8 , bluetoothPairedReset, 0, BluetoothPairedReset ) + ATTRIBUTE ( quint8 , bluetoothPairedReset, 0, BluetoothPairedReset ) + ATTRIBUTE ( QStringList , bluetoothPairedQuery, {}, BluetoothPairedQuery ) VIEW_DEC_CLASS(VDevice) }; Index: sources/gui/qml/main.qml =================================================================== diff -u -r161d1431cc3507cd430f54af6aa47dab5145d472 -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/gui/qml/main.qml (.../main.qml) (revision 161d1431cc3507cd430f54af6aa47dab5145d472) +++ sources/gui/qml/main.qml (.../main.qml) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -262,14 +262,14 @@ anchors { top : parent.top left : parent.left - leftMargin : 450 + leftMargin : 500 } horizontalAlignment : Text.Alignleft verticalAlignment : Text.AlignBottom height : 15 text : vNetwork.ethernetIP - font.pixelSize: 14 + font.pixelSize: 15 } Text { // TEST : Current Date/Time Index: sources/gui/qml/pages/MainStack.qml =================================================================== diff -u -r3e64d98e243484505a44d99b13826097cb6b01eb -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/gui/qml/pages/MainStack.qml (.../MainStack.qml) (revision 3e64d98e243484505a44d99b13826097cb6b01eb) +++ sources/gui/qml/pages/MainStack.qml (.../MainStack.qml) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -34,8 +34,12 @@ * is selected from the main menu. */ StackItem { id : _root - stackView.initialItem : _initialModeScreen + // DEBUG: this property can mostly be used for debugging to get pass the initial screen + property var initialItem: _initialModeScreen // _mainHome + + stackView.initialItem : _root.initialItem + function doSettingsDisinfect() { _mainMenu.currentIndex = 0 page( _disinfectStack ) @@ -126,7 +130,7 @@ Connections { target: vHDOperationMode // onFaultChanged : { page( _faultModeScreen , vfault )} // may needed later. onServiceChanged : { page( _serviceModeScreen , vservice )} - onInitChanged : { page( _initialModeScreen , vinit ) + onInitChanged : { page( _root.initialItem , vinit ) if ( vinit ) vHDPOSTData.reset() // better to reset on vinit = true because the rest makes the screen animation to run } Index: sources/gui/qml/pages/settings/SettingsBluetoothCuff.qml =================================================================== diff -u -r2b90169339a65399c03c31d1a40adffee87e7719 -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/gui/qml/pages/settings/SettingsBluetoothCuff.qml (.../SettingsBluetoothCuff.qml) (revision 2b90169339a65399c03c31d1a40adffee87e7719) +++ sources/gui/qml/pages/settings/SettingsBluetoothCuff.qml (.../SettingsBluetoothCuff.qml) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -117,6 +117,7 @@ vDevice.doInitBluetoothPairedReset() } } + Connections { target: vDevice onBluetoothPairedResetChanged : { // DEBUG: console.debug("bluetoothPairedReset", vbluetoothPairedReset, vDevice.accepted, vDevice.reason, vDevice.status) @@ -135,4 +136,7 @@ // done : _delegate.stepDone } notificationText : vBluetooth.notification || vDevice.status + Component.onCompleted : { + vDevice.doInitBluetoothPairedQuery() + } } Index: sources/model/MModel.h =================================================================== diff -u -rb7c9de054c6b7a1ca4bac9fbb0ec5d4ac06620a9 -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/model/MModel.h (.../MModel.h) (revision b7c9de054c6b7a1ca4bac9fbb0ec5d4ac06620a9) +++ sources/model/MModel.h (.../MModel.h) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -266,6 +266,8 @@ REGISTER_METATYPE( UIBloodPressureData ) \ REGISTER_METATYPE( DeviceBluetoothPairedResetRequestData ) \ REGISTER_METATYPE( DeviceBluetoothPairedResetResponseData ) \ + REGISTER_METATYPE( DeviceBluetoothPairedQueryRequestData ) \ + REGISTER_METATYPE( DeviceBluetoothPairedQueryResponseData ) \ /* Settings */ \ REGISTER_METATYPE( SettingsData ) \ REGISTER_METATYPE( WifiNetworkData ) \ Index: sources/storage/StorageGlobals.cpp =================================================================== diff -u -rb7c9de054c6b7a1ca4bac9fbb0ec5d4ac06620a9 -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/storage/StorageGlobals.cpp (.../StorageGlobals.cpp) (revision b7c9de054c6b7a1ca4bac9fbb0ec5d4ac06620a9) +++ sources/storage/StorageGlobals.cpp (.../StorageGlobals.cpp) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -115,5 +115,6 @@ const char *Brightness_Get = "brightness_get.sh"; // Bluetooth - const char *Bluetooth_Paired_Reset = "bluetooth_remove_paired.sh"; + const char *Bluetooth_Paired_Reset = "bluetooth_paired_clear.sh"; + const char *Bluetooth_Paired_Query = "bluetooth_paired_query.sh"; } Index: sources/storage/StorageGlobals.h =================================================================== diff -u -rb7c9de054c6b7a1ca4bac9fbb0ec5d4ac06620a9 -r47c8f13876317ba36500400f894d96c9bce9eb17 --- sources/storage/StorageGlobals.h (.../StorageGlobals.h) (revision b7c9de054c6b7a1ca4bac9fbb0ec5d4ac06620a9) +++ sources/storage/StorageGlobals.h (.../StorageGlobals.h) (revision 47c8f13876317ba36500400f894d96c9bce9eb17) @@ -84,4 +84,5 @@ // Bluetooth extern const char *Bluetooth_Paired_Reset; + extern const char *Bluetooth_Paired_Query; }