Index: denali.pro =================================================================== diff -u -r15de0cd12dad1ea5107c52e5ed89280bc9e29b1d -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- denali.pro (.../denali.pro) (revision 15de0cd12dad1ea5107c52e5ed89280bc9e29b1d) +++ denali.pro (.../denali.pro) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -51,6 +51,7 @@ sources/main.h \ sources/model/MDGDebugText.h \ sources/model/MHDDebugText.h \ + sources/storage/DriveWatcher.h \ sources/threads.h \ sources/maintimer.h \ sources/applicationpost.h \ @@ -133,7 +134,6 @@ \ # Storage sources/storage/storageglobals.h \ sources/storage/filehandler.h \ - sources/storage/usbwatcher.h \ sources/storage/logger.h \ \ # Utility sources/utility/crc.h \ @@ -149,6 +149,7 @@ main.cpp \ sources/model/MDGDebugText.cpp \ sources/model/MHDDebugText.cpp \ + sources/storage/DriveWatcher.cpp \ sources/threads.cpp \ sources/maintimer.cpp \ sources/applicationpost.cpp \ @@ -227,7 +228,6 @@ \ # Storage sources/storage/storageglobals.cpp \ sources/storage/filehandler.cpp \ - sources/storage/usbwatcher.cpp \ sources/storage/logger.cpp \ \ # Utility sources/utility/crc.cpp \ Index: main.cpp =================================================================== diff -u -r3453d86e870b126f49f9582321dbf58928c4f396 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- main.cpp (.../main.cpp) (revision 3453d86e870b126f49f9582321dbf58928c4f396) +++ main.cpp (.../main.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -38,7 +38,7 @@ #include "applicationcontroller.h" #include "guicontroller.h" #include "logger.h" -#include "usbwatcher.h" +#include "DriveWatcher.h" #include "threads.h" // kernel @@ -263,7 +263,7 @@ } //! - Initializing USB Watcher - _USBWatcher.init(Threads::_USBWatcher_Thread); + _DriveWatcher.init(Threads::_DriveWatcher_Thread); //! - Initializing CanBus Interface if (_CanInterface.init(Threads::_CanFrame_Thread)) { Index: sources/applicationcontroller.cpp =================================================================== diff -u -r90bcc276f2a879169fef20e9168711cf906c0e54 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision 90bcc276f2a879169fef20e9168711cf906c0e54) +++ sources/applicationcontroller.cpp (.../applicationcontroller.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -21,7 +21,7 @@ #include "guicontroller.h" #include "messagedispatcher.h" #include "logger.h" -#include "usbwatcher.h" +#include "DriveWatcher.h" #include "filehandler.h" /*! @@ -100,9 +100,9 @@ connect(&_GuiController , SIGNAL(didUSBDriveUmount()), this , SLOT( onUSBDriveUmount())); - connect(&_USBWatcher , SIGNAL(didUSBDriveMount ()), + connect(&_DriveWatcher , SIGNAL(didUSBDriveMount ()), this , SLOT( onUSBDriveMount ())); - connect(&_USBWatcher , SIGNAL(didUSBDriveRemove()), + connect(&_DriveWatcher , SIGNAL(didUSBDriveRemove()), this , SLOT( onUSBDriveRemove())); connect(&_GuiController , SIGNAL(didExportLog()), @@ -186,7 +186,7 @@ /*! * \brief ApplicationController::onUSBDriveMount - * \details This is the slot which connects to the _USBWatcher didUSBDriveMount signal + * \details This is the slot which connects to the _DriveWatcher didUSBDriveMount signal * and notifies the other classes (GuiController) by emitting its signal didUSBDriveMount */ void ApplicationController::onUSBDriveMount () @@ -200,7 +200,7 @@ /*! * \brief ApplicationController::onUSBDriveRemove * \details This is the slot which connects to the _GuiController didUSBDriveUmount signal - * and notifies the other classes (USBWatcher) by emitting its signal didUSBDriveUmount + * and notifies the other classes (DriveWatcher) by emitting its signal didUSBDriveUmount */ void ApplicationController::onUSBDriveUmount() { @@ -212,7 +212,7 @@ /*! * \brief ApplicationController::onUSBDriveRemove - * \details This is the slot which connects to the _USBWatcher didUSBDriveRemove signal + * \details This is the slot which connects to the _DriveWatcher didUSBDriveRemove signal * and notifies the other classes (GuiController) by emitting its signal didUSBDriveRemove */ void ApplicationController::onUSBDriveRemove() Index: sources/canbus/caninterface.cpp =================================================================== diff -u -r30f83b2813e68ae3c2806399bf808b642c215b67 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision 30f83b2813e68ae3c2806399bf808b642c215b67) +++ sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -187,7 +187,7 @@ // coco begin validated: Manually tested since required to disable and enable the canbus if (!_canDevice) { status(tr("Device Creation"), mError); - LOG_ERROR(status()); + LOG_DEBUG(status()); return false; } // coco end @@ -203,7 +203,7 @@ { if (!_canDevice->connectDevice()) { status(tr("Connection")); - LOG_ERROR(status()); + LOG_DEBUG(status()); delete _canDevice; _canDevice = nullptr; return false; @@ -365,7 +365,7 @@ case QCanBusDevice::ConfigurationError: case QCanBusDevice::UnknownError: _canStatus = _canDevice->errorString(); - LOG_ERROR(QString("%1 - %2").arg(_erFrameCount).arg(_canStatus)); + LOG_DEBUG(QString("%1 - %2").arg(_erFrameCount).arg(_canStatus)); break; default: Index: sources/canbus/frameinterface.cpp =================================================================== diff -u -r15de0cd12dad1ea5107c52e5ed89280bc9e29b1d -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/canbus/frameinterface.cpp (.../frameinterface.cpp) (revision 15de0cd12dad1ea5107c52e5ed89280bc9e29b1d) +++ sources/canbus/frameinterface.cpp (.../frameinterface.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -148,7 +148,7 @@ QCanBusFrame mFrame; mFrame.setFrameId(vCan_Id); if (vData.length() > Can::eLenCanFrame) { - LOG_ERROR(tr("Payload can't be larger than %1 bytes").arg(Can::eLenCanFrame)); + LOG_DEBUG(QString("Payload can't be larger than %1 bytes").arg(Can::eLenCanFrame)); return; } mFrame.setPayload(vData); @@ -222,7 +222,7 @@ ChannelGroup channelGroup = checkChannel(mFrameId, &ok); if (!ok) { - LOG_ERROR("Unexpected Channel\r\n" + + LOG_DEBUG("Unexpected Channel\r\n" + Format::toHexString(mFrameId, false, eLenChannelDigits) + " -- " + vFrame.payload().toHex(' ')); return; } @@ -327,7 +327,7 @@ Frame frame = Frame(vCan_Id, vData); // coco begin validated: has been manually tested by sending over 4000 frames and not received by anyother node. if (_txFrameList.count() >= _txFrameList_Max) { - LOG_ERROR(tr("Transmit buffer overflow of %1").arg(_txFrameList_Max)); + LOG_DEBUG(QString("Transmit buffer overflow of %1").arg(_txFrameList_Max)); return; // coco end } Index: sources/canbus/messageacknowmodel.cpp =================================================================== diff -u -rb798668f16ad0967ab97e96f5f9a2cdd821e899f -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/canbus/messageacknowmodel.cpp (.../messageacknowmodel.cpp) (revision b798668f16ad0967ab97e96f5f9a2cdd821e899f) +++ sources/canbus/messageacknowmodel.cpp (.../messageacknowmodel.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -191,5 +191,5 @@ _acknowList[vSequence]->deleteLater(); _acknowList.remove(vSequence); emit didFailedTransmit(vSequence); - LOG_ERROR( tr("Acknow retry failed for sequence %1").arg(vSequence) ); + LOG_DEBUG( QString("Acknow retry failed for sequence %1").arg(vSequence) ); } Index: sources/canbus/messagebuilder.cpp =================================================================== diff -u -r15de0cd12dad1ea5107c52e5ed89280bc9e29b1d -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/canbus/messagebuilder.cpp (.../messagebuilder.cpp) (revision 15de0cd12dad1ea5107c52e5ed89280bc9e29b1d) +++ sources/canbus/messagebuilder.cpp (.../messagebuilder.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -111,7 +111,7 @@ vPayload += mAction & 0xFF; // low byte } else { QString mHexString = Format::toHexString(vAction, false, eLenMessageIDDigits); - LOG_ERROR(tr("Incorrect Action ID '%1'").arg(mHexString)); + LOG_DEBUG(QString("Incorrect Action ID '%1'").arg(mHexString)); return false; } return true; @@ -140,7 +140,7 @@ if (vData.length() < len) { QString mHexMIdString = Format::toHexString(vAction, false, eLenMessageIDDigits); QString mHexDatString = vData.toHex('.').toUpper(); - LOG_ERROR(tr("Not enough data has been provided for the Message ID '%1'\r\n%2") + LOG_DEBUG(QString("Not enough data has been provided for the Message ID '%1'\r\n%2") .arg(mHexMIdString) .arg(mHexDatString) ); @@ -230,7 +230,7 @@ quint8 mBeenRead = 0; if ( ! checkCRC(crcData, mExpected, mBeenRead ) ) { // CRC is always next byte after Data static quint64 erCRC = 0; - LOG_ERROR(tr("%1 - CRC error, expected %2 but got %3 : %4") + LOG_DEBUG(QString("%1 - CRC error, expected %2 but got %3 : %4") .arg(++erCRC) .arg(Format::toHexString(mExpected, true, eLenCRCDigits)) .arg(Format::toHexString(mBeenRead, true, eLenCRCDigits)) @@ -265,7 +265,7 @@ vMessage.data = getData (mPayload, vMessage.length); vMessage.initialized = true; } else { // Expected Header but got pure data - LOG_ERROR(tr("Expected Header, got frame without Sync byte")); + LOG_DEBUG(QString("Expected Header, got frame without Sync byte")); printPayload(vPayload, false ,vCan_Id); return false; } @@ -355,7 +355,7 @@ { QByteArray headInfo; if (vPayload.length() < eLenHeaderInfo) { - LOG_ERROR("Incorrect Message Header"); + LOG_DEBUG("Incorrect Message Header"); return headInfo; } for (int i = 0; i < eLenHeaderInfo; i++) { Index: sources/canbus/messagedispatcher.cpp =================================================================== diff -u -r246bf68b01c9249f2a74dddbba67f49807937fa2 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/canbus/messagedispatcher.cpp (.../messagedispatcher.cpp) (revision 246bf68b01c9249f2a74dddbba67f49807937fa2) +++ sources/canbus/messagedispatcher.cpp (.../messagedispatcher.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -44,7 +44,7 @@ if ( _init ) return false; _init = true; - // runs in USBWatcher thread + // runs in DriveWatcher thread initConnections(); LOG_EVENT("UI," + tr("%1 Initialized").arg(metaObject()->className())); @@ -303,7 +303,7 @@ QByteArray mData; if (! _interpreter.interpretMessage(vActionId, vData, mData)) { - LOG_ERROR(tr("Incorrect Message, can't be interpreted, %1").arg(vActionId)); // TODO : LOGGINF IMPROVEMENT + LOG_DEBUG(QString("Incorrect Message, can't be interpreted, %1").arg(vActionId)); // TODO : LOGGINF IMPROVEMENT return; } @@ -320,7 +320,7 @@ } if ( ! _builder.buildFrames(vActionId, mData, frameList, mSequence) ) { - LOG_ERROR(tr("Incorrect Message can't be built")); // TODO : LOGGINF IMPROVEMENT + LOG_DEBUG(QString("Incorrect Message can't be built")); // TODO : LOGGINF IMPROVEMENT return; } if (mNeedsAcknow) { @@ -358,7 +358,7 @@ { if (vPayload.length() < eLenCanFrame) { // Each frame has to have exactly 8 (eLenCanFrame) bytes of data and not used bytes should be passed as 00. - LOG_ERROR(tr("Incorrect frame length. Exp:%1,got:%2").arg(eLenCanFrame).arg(vPayload.length())); + LOG_DEBUG(QString("Incorrect frame length. Exp:%1,got:%2").arg(eLenCanFrame).arg(vPayload.length())); return false; } if (! _builder.buildMessage(vPayload, _messageList[vCan_Id].last(), vCan_Id)) { Index: sources/canbus/messageinterpreter.cpp =================================================================== diff -u -r246bf68b01c9249f2a74dddbba67f49807937fa2 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/canbus/messageinterpreter.cpp (.../messageinterpreter.cpp) (revision 246bf68b01c9249f2a74dddbba67f49807937fa2) +++ sources/canbus/messageinterpreter.cpp (.../messageinterpreter.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -25,13 +25,13 @@ #define DEBUG_RECEIVE_SIGNAL(vID, vMODEL) // Debug() << #vID << #vMODEL; -// This define helps to prevent having multiple overloaded function for each model +// This define helps to prevent having multiple overloaded functions for each model #define EMIT_RECEIVE_SIGNAL(vID, vMODEL) { \ vMODEL mModel; \ ok = prepareData(vMessage, vID, mModel, vData); \ if ( ! ok ) return false; \ emit didActionReceive(mModel.data()); \ - LOG_BASIC(mModel.toString()); \ + logReceived(mModel); \ DEBUG_RECEIVE_SIGNAL(vID, vMODEL) \ } @@ -73,11 +73,11 @@ { QString mActionIdHexString = Format::toHexString(vMessage.actionId); if ( ! payloadLen.contains(vType) ) { - LOG_ERROR(tr("Undefined data length for received Message with ID '%1'").arg(mActionIdHexString)); + LOG_DEBUG(QString("Undefined data length for received Message with ID '%1'").arg(mActionIdHexString)); return false; } if ( vMessage.data.length() < payloadLen[vType] ) { - LOG_ERROR(tr("Incorrect data length for received Message with ID '%1'").arg(mActionIdHexString)); + LOG_DEBUG(QString("Incorrect data length for received Message with ID '%1'").arg(mActionIdHexString)); return false; } return true; @@ -87,7 +87,7 @@ { if (vData.count() == 0) { QString mActionIdHexString = Format::toHexString(vActionId); - LOG_ERROR(tr("Incorrect data for transmit Message with ID '%1'").arg(mActionIdHexString)); + LOG_DEBUG(QString("Incorrect data for transmit Message with ID '%1'").arg(mActionIdHexString)); return false; } return true; @@ -122,7 +122,7 @@ .arg(int(vMessage.can_id), 3, 16, QChar('0')) .arg(mActionIdHexString) .arg(QString(vMessage.data.toHex('.'))); - LOG_ERROR(logMessage); + LOG_DEBUG(logMessage); } /*! @@ -144,6 +144,23 @@ } /*! + * \brief MessageInterpreter::logReceived + * \details Regarding the type of message logs the message recived. + * \param vModel - the MAbstract model type + */ +void MessageInterpreter::logReceived(const Model::MAbstract &vModel) +{ + switch (vModel.typeText()) { + case Model::MAbstract::Type_Enum::eDatum: + LOG_DATUM(vModel.toString()); + break; + case Model::MAbstract::Type_Enum::eEvent: + LOG_EVENT(vModel.toString()); + break; + } +} + +/*! * \brief MessageInterpreter::interpretMessage * \details This method will be called * to interpret messages from UI regarding vActionId. @@ -220,7 +237,7 @@ default: QString mActionIdHexString = Format::toHexString(vActionId); - LOG_ERROR(mSenderID + tr("Unknown transmit Message with ID '%1'").arg(mActionIdHexString)); + LOG_DEBUG(mSenderID + tr("Unknown transmit Message with ID '%1'").arg(mActionIdHexString)); ok = false; break; Index: sources/canbus/messageinterpreter.h =================================================================== diff -u -r246bf68b01c9249f2a74dddbba67f49807937fa2 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/canbus/messageinterpreter.h (.../messageinterpreter.h) (revision 246bf68b01c9249f2a74dddbba67f49807937fa2) +++ sources/canbus/messageinterpreter.h (.../messageinterpreter.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -48,7 +48,8 @@ bool isDataLenValid (const Gui::GuiActionType &vActionId, const QVariantList &vData); void printUnhandled (const Message &vMessage ) const; - bool prepareData (const Message &vMessage, Gui::GuiActionType vID, Model::MAbstract &vModel, QVariantList &vData); + bool prepareData (const Message &vMessage, Gui::GuiActionType vID, Model::MAbstract &vModel, QVariantList &vData ); + void logReceived ( const Model::MAbstract &vModel ); bool interpretMessage_HD (const Message &vMessage, QVariantList &vData) __attribute_warn_unused_result__; bool interpretMessage_DG (const Message &vMessage, QVariantList &vData) __attribute_warn_unused_result__; Index: sources/gui/guiglobals.cpp =================================================================== diff -u -r15de0cd12dad1ea5107c52e5ed89280bc9e29b1d -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/gui/guiglobals.cpp (.../guiglobals.cpp) (revision 15de0cd12dad1ea5107c52e5ed89280bc9e29b1d) +++ sources/gui/guiglobals.cpp (.../guiglobals.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -105,7 +105,7 @@ } else if (vStatus == QQuickView::Error || vStatus == QQuickView::Null) { for (const auto &error : _viewer->errors()) { - LOG_ERROR(QObject::tr("Application Terminated: %1").arg(error.toString())); + LOG_DEBUG(QString("Application Terminated: %1").arg(error.toString())); } QCoreApplication::exit(-1); } Index: sources/model/MAbstract.h =================================================================== diff -u -r15de0cd12dad1ea5107c52e5ed89280bc9e29b1d -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/MAbstract.h (.../MAbstract.h) (revision 15de0cd12dad1ea5107c52e5ed89280bc9e29b1d) +++ sources/model/MAbstract.h (.../MAbstract.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -28,7 +28,7 @@ const char _delimiter = ','; quint8 _precision = 2; -protected: +public: enum class Type_Enum { eDatum, eEvent, Index: sources/model/dg/data/MDGDrainPumpData.h =================================================================== diff -u -r30f83b2813e68ae3c2806399bf808b642c215b67 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/dg/data/MDGDrainPumpData.h (.../MDGDrainPumpData.h) (revision 30f83b2813e68ae3c2806399bf808b642c215b67) +++ sources/model/dg/data/MDGDrainPumpData.h (.../MDGDrainPumpData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -31,9 +31,6 @@ friend class ::tst_models; // DG Drain Pump Data (U32) Set pt. RPM (U32) DAC value - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eDG ; } - QString infoText () const override { return QString("DrainPump"); } QVariantList parameters() const override; struct { @@ -42,6 +39,11 @@ } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum ; } + Unit_Enum unitText () const override { return Unit_Enum::eDG ; } + QString infoText () const override { return QString("DrainPump"); } + struct Data { quint32 mRPM = 0; /*!< Reservoir1 Prim value of type float extracted out */ quint32 mDAC = 0; /*!< Reservoir2 Bkup value of type float extracted out */ Index: sources/model/dg/data/MDGHeatersData.h =================================================================== diff -u -r90bcc276f2a879169fef20e9168711cf906c0e54 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/dg/data/MDGHeatersData.h (.../MDGHeatersData.h) (revision 90bcc276f2a879169fef20e9168711cf906c0e54) +++ sources/model/dg/data/MDGHeatersData.h (.../MDGHeatersData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -31,9 +31,6 @@ friend class ::tst_models; // Heaters Data (U32) mainPrimaryDC (U32) smallPrimaryDC (U32) trimmerDC - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eDG ; } - QString infoText () const override { return QString("Heaters"); } QVariantList parameters() const override; struct { @@ -43,6 +40,11 @@ } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum ; } + Unit_Enum unitText () const override { return Unit_Enum::eDG ; } + QString infoText () const override { return QString("Heaters"); } + struct Data { quint32 mMainPrimaryDC = 0; /*!< Reservoir1 Prim value of type float extracted out */ quint32 mSmallPrimaryDC = 0; /*!< Reservoir1 Bkup value of type float extracted out */ Index: sources/model/dg/data/MDGLoadCellReadingsData.h =================================================================== diff -u -r90bcc276f2a879169fef20e9168711cf906c0e54 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/dg/data/MDGLoadCellReadingsData.h (.../MDGLoadCellReadingsData.h) (revision 90bcc276f2a879169fef20e9168711cf906c0e54) +++ sources/model/dg/data/MDGLoadCellReadingsData.h (.../MDGLoadCellReadingsData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -31,9 +31,6 @@ friend class ::tst_models; // Load Cell Readings Data Rs1 Prim. (F32) Rs1 Bkup (F32) Rs2 Prim. (F32) Rs2 Bkup (F32) - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eDG ; } - QString infoText () const override { return QString("LoadCell"); } QVariantList parameters() const override; struct { @@ -44,6 +41,11 @@ } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum ; } + Unit_Enum unitText () const override { return Unit_Enum::eDG ; } + QString infoText () const override { return QString("LoadCell"); } + struct Data { float mReservoir1Prim = 0; /*!< Reservoir1 Prim value of type float extracted out */ float mReservoir1Bkup = 0; /*!< Reservoir1 Bkup value of type float extracted out */ Index: sources/model/dg/data/MDGOperationModeData.h =================================================================== diff -u -r90bcc276f2a879169fef20e9168711cf906c0e54 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/dg/data/MDGOperationModeData.h (.../MDGOperationModeData.h) (revision 90bcc276f2a879169fef20e9168711cf906c0e54) +++ sources/model/dg/data/MDGOperationModeData.h (.../MDGOperationModeData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -31,16 +31,18 @@ friend class ::tst_models; // DG Operation Mode (U32) DG Op Mode - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eDG ; } - QString infoText () const override { return QString("OpMode"); } QVariantList parameters() const override; struct { Types::U32 mOpMode ; } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum; } + Unit_Enum unitText () const override { return Unit_Enum::eDG ; } + QString infoText () const override { return QString("OpMode"); } + struct Data { quint32 mOpMode = 0; /*!< Reservoir1 Prim value of type float extracted out */ }; Index: sources/model/dg/data/MDGPressuresData.h =================================================================== diff -u -r90bcc276f2a879169fef20e9168711cf906c0e54 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/dg/data/MDGPressuresData.h (.../MDGPressuresData.h) (revision 90bcc276f2a879169fef20e9168711cf906c0e54) +++ sources/model/dg/data/MDGPressuresData.h (.../MDGPressuresData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -31,9 +31,6 @@ friend class ::tst_models; // DG Pressures Data (F32) RO inlet PSI (F32) RO outlet PSI (F32) Drain inlet PSI (F32) Drain outlet PSI - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eDG ; } - QString infoText () const override { return QString("Pressures"); } QVariantList parameters() const override; struct { @@ -44,6 +41,11 @@ } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum ; } + Unit_Enum unitText () const override { return Unit_Enum::eDG ; } + QString infoText () const override { return QString("Pressures"); } + struct Data { float mROInletPSI = 0; /*!< Reservoir1 Prim value of type float extracted out */ float mROOutletPSI = 0; /*!< Reservoir1 Bkup value of type float extracted out */ Index: sources/model/dg/data/MDGROPumpData.h =================================================================== diff -u -r90bcc276f2a879169fef20e9168711cf906c0e54 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/dg/data/MDGROPumpData.h (.../MDGROPumpData.h) (revision 90bcc276f2a879169fef20e9168711cf906c0e54) +++ sources/model/dg/data/MDGROPumpData.h (.../MDGROPumpData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -31,9 +31,6 @@ friend class ::tst_models; // DG RO Pump Data (U32) Set pt. pressure (F32) flow rate (F32) PWM - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eDG ; } - QString infoText () const override { return QString("ROPump"); } QVariantList parameters() const override; struct { @@ -43,6 +40,11 @@ } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum; } + Unit_Enum unitText () const override { return Unit_Enum::eDG ; } + QString infoText () const override { return QString("ROPump"); } + struct Data { quint32 mPressure = 0; /*!< ArterialPressure value of type float extracted out */ float mFlowRate = 0; /*!< VenousPressure value of type float extracted out */ Index: sources/model/dg/data/MDGReservoirData.h =================================================================== diff -u -r90bcc276f2a879169fef20e9168711cf906c0e54 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/dg/data/MDGReservoirData.h (.../MDGReservoirData.h) (revision 90bcc276f2a879169fef20e9168711cf906c0e54) +++ sources/model/dg/data/MDGReservoirData.h (.../MDGReservoirData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -31,9 +31,6 @@ friend class ::tst_models; // DG Reservoir Data (U32) active reservoir (U32) Fill to vol (mL) (U32) Drain to vol (mL) - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eDG ; } - QString infoText () const override { return QString("Reservoir"); } QVariantList parameters() const override; struct { @@ -43,6 +40,11 @@ } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum ; } + Unit_Enum unitText () const override { return Unit_Enum::eDG ; } + QString infoText () const override { return QString("Reservoir"); } + struct Data { quint32 mActiveReservoir = 0; quint32 mFillToVol = 0; Index: sources/model/dg/data/MDGTemperaturesData.h =================================================================== diff -u -r90bcc276f2a879169fef20e9168711cf906c0e54 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/dg/data/MDGTemperaturesData.h (.../MDGTemperaturesData.h) (revision 90bcc276f2a879169fef20e9168711cf906c0e54) +++ sources/model/dg/data/MDGTemperaturesData.h (.../MDGTemperaturesData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -34,9 +34,6 @@ // 2 - F32 Outlet primary heater 6 - F32 Inlet dialysate 10 - F32 Trimmer heater cold junction // 3 - F32 Conductivity sensor 1 7 - F32 Primary heater thermo-couple 11 - F32 Primary heater internal temperature // 4 - F32 Conductivity sensor 2 8 - F32 Trimmer heater thermo-couple 12 - F32 Trimmer heater internal temperature - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eDG ; } - QString infoText () const override { return QString("Temperatures"); } QVariantList parameters() const override; struct { @@ -55,6 +52,11 @@ } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum ; } + Unit_Enum unitText () const override { return Unit_Enum::eDG ; } + QString infoText () const override { return QString("Temperatures"); } + struct Data { float mInletPrimaryHeater = 0; ///< Inlet primary heaters temperature float mOutletPrimaryHeater = 0; ///< Outlet primary heaters temperature Index: sources/model/dg/data/MDGValvesStatesData.h =================================================================== diff -u -r90bcc276f2a879169fef20e9168711cf906c0e54 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/dg/data/MDGValvesStatesData.h (.../MDGValvesStatesData.h) (revision 90bcc276f2a879169fef20e9168711cf906c0e54) +++ sources/model/dg/data/MDGValvesStatesData.h (.../MDGValvesStatesData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -49,16 +49,18 @@ private: // DG Valves States (U16) Valves States - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eDG ; } - QString infoText () const override { return QString("ValvesStates"); } QVariantList parameters() const override; struct { Types::Flags mStates ; } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum ; } + Unit_Enum unitText () const override { return Unit_Enum::eDG ; } + QString infoText () const override { return QString("ValvesStates"); } + struct Data { QBitArray mStates ; }; Index: sources/model/hd/adjustment/MTreatmentAdjustBloodDialysateResponse.h =================================================================== diff -u -r30f83b2813e68ae3c2806399bf808b642c215b67 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/hd/adjustment/MTreatmentAdjustBloodDialysateResponse.h (.../MTreatmentAdjustBloodDialysateResponse.h) (revision 30f83b2813e68ae3c2806399bf808b642c215b67) +++ sources/model/hd/adjustment/MTreatmentAdjustBloodDialysateResponse.h (.../MTreatmentAdjustBloodDialysateResponse.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -30,9 +30,6 @@ // friends friend class ::tst_models; - Type_Enum typeText () const override { return Type_Enum::eEvent; } - Unit_Enum unitText () const override { return Unit_Enum::eHD ; } - QString infoText () const override { return QString("AdjustBloodDialisate"); } QVariantList parameters() const override; struct { @@ -43,6 +40,11 @@ } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eEvent ; } + Unit_Enum unitText () const override { return Unit_Enum::eHD ; } + QString infoText () const override { return QString("AdjustBloodDialisate"); } + struct Data { bool mAccepted = 0; /*!< Accepted value of type quint32 extracted out */ quint32 mReason = 0; /*!< Reason value of type quint32 extracted out */ Index: sources/model/hd/adjustment/MTreatmentAdjustDurationResponse.h =================================================================== diff -u -r30f83b2813e68ae3c2806399bf808b642c215b67 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/hd/adjustment/MTreatmentAdjustDurationResponse.h (.../MTreatmentAdjustDurationResponse.h) (revision 30f83b2813e68ae3c2806399bf808b642c215b67) +++ sources/model/hd/adjustment/MTreatmentAdjustDurationResponse.h (.../MTreatmentAdjustDurationResponse.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -30,19 +30,22 @@ // friends friend class ::tst_models; - Type_Enum typeText () const override { return Type_Enum::eEvent; } - Unit_Enum unitText () const override { return Unit_Enum::eHD ; } - QString infoText () const override { return QString("AdjustDuration"); } QVariantList parameters() const override; struct { + Types::U32 mAccepted ; Types::U32 mReason ; Types::U32 mDuration ; Types::F32 mUFVolume ; } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eEvent ; } + Unit_Enum unitText () const override { return Unit_Enum::eHD ; } + QString infoText () const override { return QString("AdjustDuration"); } + struct Data { bool mAccepted = 0; /*!< Accepted value of type quint32 extracted out */ quint32 mReason = 0; /*!< Reason value of type quint32 extracted out */ Index: sources/model/hd/adjustment/MTreatmentAdjustUltrafiltrationStateResponse.h =================================================================== diff -u -r30f83b2813e68ae3c2806399bf808b642c215b67 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/hd/adjustment/MTreatmentAdjustUltrafiltrationStateResponse.h (.../MTreatmentAdjustUltrafiltrationStateResponse.h) (revision 30f83b2813e68ae3c2806399bf808b642c215b67) +++ sources/model/hd/adjustment/MTreatmentAdjustUltrafiltrationStateResponse.h (.../MTreatmentAdjustUltrafiltrationStateResponse.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -30,16 +30,18 @@ // friends friend class ::tst_models; - Type_Enum typeText () const override { return Type_Enum::eEvent; } - Unit_Enum unitText () const override { return Unit_Enum::eHD ; } - QString infoText () const override { return QString("AdjustUFState"); } QVariantList parameters() const override; struct { Types::U08 mAccepted ; // IMPORTANT : This is a response to AcknowGeneric which has a data of 1 byte for the accepted/rejected. } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eEvent ; } + Unit_Enum unitText () const override { return Unit_Enum::eHD ; } + QString infoText () const override { return QString("AdjustUFState"); } + struct Data { bool mAccepted = 0; /*!< Accepted value of type quint32 extracted out */ }; Index: sources/model/hd/data/MHDOperationModeData.h =================================================================== diff -u -r15de0cd12dad1ea5107c52e5ed89280bc9e29b1d -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/hd/data/MHDOperationModeData.h (.../MHDOperationModeData.h) (revision 15de0cd12dad1ea5107c52e5ed89280bc9e29b1d) +++ sources/model/hd/data/MHDOperationModeData.h (.../MHDOperationModeData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -31,16 +31,18 @@ friend class ::tst_models; // HD Operation Mode (U32) HD Op Mode - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eHD ; } - QString infoText () const override { return QString("OpMode"); } QVariantList parameters() const override; struct { Types::U32 mOpMode ; } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum; } + Unit_Enum unitText () const override { return Unit_Enum::eHD ; } + QString infoText () const override { return QString("OpMode"); } + struct Data { quint32 mOpMode = 0; /*!< Reservoir1 Prim value of type float extracted out */ }; Index: sources/model/hd/data/MTreatmentFlowsData.h =================================================================== diff -u -r30f83b2813e68ae3c2806399bf808b642c215b67 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/hd/data/MTreatmentFlowsData.h (.../MTreatmentFlowsData.h) (revision 30f83b2813e68ae3c2806399bf808b642c215b67) +++ sources/model/hd/data/MTreatmentFlowsData.h (.../MTreatmentFlowsData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -28,8 +28,6 @@ */ class MFlow : public MAbstract { - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eHD ; } QVariantList parameters() const override; protected: @@ -44,6 +42,10 @@ } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum; } + Unit_Enum unitText () const override { return Unit_Enum::eHD ; } + MFlow () { } bool fromByteArray (const QByteArray &vByteArray , int *vIndex = nullptr) override; @@ -54,9 +56,9 @@ */ class MBloodFlow : public MFlow { +public: QString infoText () const override { return QString("BloodFlow"); } -public: struct Data { qint32 mFlowSetPoint = 0; /*!< vFlowSetPoint - Flow Set Point value of type signed int extracted out */ float mMeasuredFlow = 0; /*!< vMeasuredFlow - Measured Flow value of type float extracted out */ @@ -77,9 +79,9 @@ */ class MDialysateFlow : public MFlow { +public: QString infoText () const override { return QString("DialysateFlow"); } -public: struct Data { qint32 mFlowSetPoint = 0; /*!< vFlowSetPoint - Flow Set Point value of type signed int extracted out */ float mMeasuredFlow = 0; /*!< vMeasuredFlow - Measured Flow value of type float extracted out */ Index: sources/model/hd/data/MTreatmentOutletFlowData.h =================================================================== diff -u -r246bf68b01c9249f2a74dddbba67f49807937fa2 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/hd/data/MTreatmentOutletFlowData.h (.../MTreatmentOutletFlowData.h) (revision 246bf68b01c9249f2a74dddbba67f49807937fa2) +++ sources/model/hd/data/MTreatmentOutletFlowData.h (.../MTreatmentOutletFlowData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -24,9 +24,6 @@ class MOutletFlow : public MAbstract { - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eHD ; } - QString infoText () const override { return QString("OutletFlow"); } QVariantList parameters() const override; struct { @@ -40,6 +37,11 @@ } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum ; } + Unit_Enum unitText () const override { return Unit_Enum::eHD ; } + QString infoText () const override { return QString("OutletFlow"); } + struct Data { float mRefUFVol = 0; /*!< Reference UF Volume value of type float extracted out */ float mMeasUFVol = 0; /*!< Measured UF Volume value of type float extracted out */ Index: sources/model/hd/data/MTreatmentPressureOcclusionData.h =================================================================== diff -u -r30f83b2813e68ae3c2806399bf808b642c215b67 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/hd/data/MTreatmentPressureOcclusionData.h (.../MTreatmentPressureOcclusionData.h) (revision 30f83b2813e68ae3c2806399bf808b642c215b67) +++ sources/model/hd/data/MTreatmentPressureOcclusionData.h (.../MTreatmentPressureOcclusionData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -25,9 +25,6 @@ class MPressureOcclusion : public MAbstract { public: - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eHD ; } - QString infoText () const override { return QString("Pressure/Occlusion"); } QVariantList parameters() const override; struct { @@ -39,6 +36,11 @@ } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum ; } + Unit_Enum unitText () const override { return Unit_Enum::eHD ; } + QString infoText () const override { return QString("Pressure/Occlusion"); } + struct Data { float mArterialPressure = 0; /*!< ArterialPressure value of type float extracted out */ float mVenousPressure = 0; /*!< VenousPressure value of type float extracted out */ Index: sources/model/hd/data/MTreatmentRangesData.h =================================================================== diff -u -r30f83b2813e68ae3c2806399bf808b642c215b67 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/hd/data/MTreatmentRangesData.h (.../MTreatmentRangesData.h) (revision 30f83b2813e68ae3c2806399bf808b642c215b67) +++ sources/model/hd/data/MTreatmentRangesData.h (.../MTreatmentRangesData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -31,9 +31,6 @@ // friends friend class ::tst_models; - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eHD ; } - QString infoText () const override { return QString("TreatmentRanges"); } QVariantList parameters() const override; struct { @@ -46,6 +43,11 @@ } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum ; } + Unit_Enum unitText () const override { return Unit_Enum::eHD ; } + QString infoText () const override { return QString("TreatmentRanges"); } + struct Data { quint32 mDuration_Min = 0; /*!< mDuration_Min value of type U32 extracted out */ quint32 mDuration_Max = 0; /*!< mDuration_Max value of type U32 extracted out */ Index: sources/model/hd/data/MTreatmentStatesData.h =================================================================== diff -u -r15de0cd12dad1ea5107c52e5ed89280bc9e29b1d -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/hd/data/MTreatmentStatesData.h (.../MTreatmentStatesData.h) (revision 15de0cd12dad1ea5107c52e5ed89280bc9e29b1d) +++ sources/model/hd/data/MTreatmentStatesData.h (.../MTreatmentStatesData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -30,9 +30,6 @@ // friends friend class ::tst_models; - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eHD ; } - QString infoText () const override { return QString("TreatmentStates"); } QVariantList parameters() const override; struct { @@ -42,6 +39,11 @@ } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum ; } + Unit_Enum unitText () const override { return Unit_Enum::eHD ; } + QString infoText () const override { return QString("TreatmentStates"); } + struct Data { quint32 mSubMode = 0; /*!< Sub-Mode value of type quint32 extracted out */ quint32 mUFState = 0; /*!< UF State value of type quint32 extracted out */ Index: sources/model/hd/data/MTreatmentTimeData.h =================================================================== diff -u -r30f83b2813e68ae3c2806399bf808b642c215b67 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/model/hd/data/MTreatmentTimeData.h (.../MTreatmentTimeData.h) (revision 30f83b2813e68ae3c2806399bf808b642c215b67) +++ sources/model/hd/data/MTreatmentTimeData.h (.../MTreatmentTimeData.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -25,9 +25,6 @@ class MTreatmentTime : public MAbstract { - Type_Enum typeText () const override { return Type_Enum::eDatum; } - Unit_Enum unitText () const override { return Unit_Enum::eHD ; } - QString infoText () const override { return QString("TreamtmentTime"); } QVariantList parameters() const override; struct { @@ -37,6 +34,11 @@ } _data; public: + + Type_Enum typeText () const override { return Type_Enum::eDatum ; } + Unit_Enum unitText () const override { return Unit_Enum::eHD ; } + QString infoText () const override { return QString("TreamtmentTime"); } + struct Data { quint32 mTotal = 0; /*!< Total treatment time in sec */ quint32 mElapsed = 0; /*!< Elapsed treatment time in sec */ Index: sources/storage/DriveWatcher.cpp =================================================================== diff -u --- sources/storage/DriveWatcher.cpp (revision 0) +++ sources/storage/DriveWatcher.cpp (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -0,0 +1,352 @@ +/*! + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * \copyright + * 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 DriveWatcher.cpp + * \date 12/31/2019 + * \author Behrouz NematiPour + * + */ +#include "DriveWatcher.h" + +// Linux +#include +#include + +// Qt +#include +#include +#include + +// Project +#include "storageglobals.h" +#include "logger.h" +#include "applicationcontroller.h" + +// namespace +using namespace Storage; + +/*! + * \brief DriveWatcher::DriveWatcher + * \details Constructor + * \param parent - QObject parent owner object. + * Qt handles the children destruction by their parent objects life-cycle. + */ +DriveWatcher::DriveWatcher(QObject *parent) : QObject(parent) { } + +/*! + * \brief DriveWatcher::init + * \details Initializes the class by setting the connections and starting the timer + * \return False if it has been called before. + */ +bool DriveWatcher::init() +{ + if ( _init ) return false; + _init = true; + + // runs in DriveWatcher thread + initConnections(); + startTimer(_interval); + + return true; +} + +/*! + * \brief DriveWatcher::init + * \details Initialized the Class by calling the init() method first + * And initializes the thread vThread by calling initThread + * on success init(). + * \param vThread - the thread + * \return returns the return value of the init() method + */ +bool DriveWatcher::init(QThread &vThread) +{ + if ( ! init() ) return false; + initThread(vThread); + return true; +} + +/*! + * \brief DriveWatcher::quit + * \details quits the class + * Calls quitThread + */ +void DriveWatcher::quit() +{ + // coco begin validated: Application termination is not correctly done in coco!!! + // it has been tested and works perfectly fine in normal run. + quitThread(); // validated +} +// coco end + +/*! + * \brief DriveWatcher::initConnections + * \details Initializes the required signal/slot connection between this class and other objects + * to be able to communicate. + */ +void DriveWatcher::initConnections() +{ + connect(&_ApplicationController, SIGNAL(didUSBDriveUmount()), + this , SLOT( onUSBDriveUmount())); +} + +/*! + * \brief ApplicationController::initThread + * \details Moves this object into the thread vThread. + * And checks that this method is called from main thread. + * Also connects quitThread to application aboutToQuit. + * \param vThread - the thread + */ +void DriveWatcher::initThread(QThread &vThread) +{ + // runs in main thread + Q_ASSERT_X(QThread::currentThread() == qApp->thread() , __func__, "The Class initialization must be done in Main Thread" ); + _thread = &vThread; + _thread->setObjectName(QString("%1_Thread").arg(metaObject()->className())); + connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(quit())); + _thread->start(); + moveToThread(_thread); +} + +/*! + * \brief DriveWatcher::quitThread + * \details Moves this object to main thread to be handled by QApplicaiton + * And to be destroyed there. + */ +void DriveWatcher::quitThread() +{ + // coco begin validated: Application termination is not correctly done in coco!!! + // it has been tested and works perfectly fine in normal run. + + if ( ! _thread ) return; + + // runs in thread + moveToThread(qApp->thread()); // validated +} +// coco end + +/*! + * \brief DriveWatcher::usbSeek + * \details Tries to look for the available USB devices + * Starts from sda1 to sdz1. + * \note will only look for the first partition if there is any + * \param vDevice - Found device (/dev/sda1) + * \return true if a device found + */ +bool DriveWatcher::usbSeek(QString &vDevice) +{ + // coco begin validated: Needed User Interaction so tested manually + QString device = ""; + for (char a = 'a'; a <= 'z'; a++) { + device = QString("/dev/sd%1%2").arg(a).arg('1'); + if (QFileInfo::exists(device)) { + vDevice = device; + return true; // application is deciding on the first existing drive + } + } + vDevice = device; + return false; + // coco end +} + +/*! + * \brief DriveWatcher::driveSpaceCheck + * \param vPath - Device mount point + * \param vTotalBytes - Total volume size in bytes + * \param vAvailableBytes - Size (in bytes) available for the current user + * \param vPercent - The percentage of availabe spcae + * \return - The drive mounted and ready + * \note if device ejected manually system assumes it's still ready. + */ +bool DriveWatcher::driveSpaceCheck(const QString &vPath, qint64 &vTotalBytes, qint64 &vAvailableBytes) +{ + QStorageInfo storage(vPath); + bool isReady = storage.isReady(); + if (isReady) { + vTotalBytes = storage.bytesTotal(); + vAvailableBytes = storage.bytesAvailable(); + } + return isReady; +} + +/*! + * \brief DriveWatcher::timerEvent + * \details This event handler has been re-implemented in here + * to receive timer events for the object + * for the timer which has been set to _checkInterval + * Runs the usbCheck on interval + */ +void DriveWatcher::timerEvent(QTimerEvent *) +{ + usbCheck(); + sdcardSpaceCheck(); +} + +/*! + * \brief DriveWatcher::usbcheck + * \details Runs usbSeek to mount or umount or remove it + * regarding the state it's in. + */ +void DriveWatcher::usbCheck() +{ + // coco begin validated: Needed User Interaction so tested manually + QString device = ""; + if (usbSeek(device)) { + if (! _umounted ) { + usbMount(device); + } else { + usbUmount(USB_Mount_Point); + } + } else { + if ( ! _removed ) { + usbRemove(); + } + } + // coco end +} + +/*! + * \brief DriveWatcher::sdcardFreeSpaceCheck + * \details Checks the drivers for available free space. + */ +void DriveWatcher::sdcardSpaceCheck() +{ + // coco begin validated: Needed User Interaction so tested manually + + quint8 mPercent ; + + // OLd Info ; // Current info + static bool mOIsReady ; bool mCIsReady ; + static qint64 mOTotal ; qint64 mCTotal ; + static qint64 mOAvailable; qint64 mCAvailable; + + mCIsReady = driveSpaceCheck(Storage::SDCard_Base_Path_Name, mCTotal, mCAvailable); + if (mOIsReady == mCIsReady && + mOTotal == mCTotal && + mOAvailable == mCAvailable ) return; + + mOIsReady = mCIsReady ; + mOTotal = mCTotal ; + mOAvailable = mCAvailable ; + mPercent = (100 * mCAvailable) / mCTotal; + emit didSDCardSpaceChange(mCIsReady, mCTotal, mCAvailable, mPercent); + // coco end +} + +/*! + * \brief DriveWatcher::usbError + * \details Logs any error which has been happened + * On USB device vDevice + * \note When this method has been called error number will be read from errno variable, + * Which has been set by umount or mount. + * \param vDevice + */ +void DriveWatcher::usbError(const QString &vDevice) +{ + // coco begin validated: This needs user interaction to plug-in/out the USB device + // has been tested manually + QString error; + static QString lastError; + switch (errno) { + case EBUSY: + error = tr("%1 - Device or resource busy (%2)").arg(errno).arg(vDevice); + _mounted = true; + break; + + default: + error = tr("%1 - %2 (%3 , %4)").arg(errno).arg(strerror(errno)).arg(vDevice).arg(USB_Mount_Point); + break; + + } + if (error != lastError) { + LOG_DEBUG(error); + lastError = error; + } +} +// coco end + +/*! + * \brief DriveWatcher::onUSBDriveUmount + * \details This is the slot connected to the _ApplicationController's didUSBDriveUmount SIGNAL, + * To notify the USB drive detach. + */ +void DriveWatcher::onUSBDriveUmount() +{ + // coco begin validated: This needs user interaction to plug-in/out the USB device + // has been tested manually + _umounted = true; +} +// coco end + +/*! + * \brief DriveWatcher::usbMount + * \details Mounts the USB device vDevice + * \note Emits didUSBDriveMount signal + * \param vDevice - USB device to be mounted (eg. /dev/sda1) + * \return true on successful mount + */ +bool DriveWatcher::usbMount(const QString &vDevice) +{ + // coco begin validated: This needs user interaction to plug-in the USB device + // has been tested manually + bool ok; + _usbDrive = vDevice.toLatin1().constData(); + ok = ::mount(_usbDrive, USB_Mount_Point, USB_File_System,MS_SYNCHRONOUS , "") == 0; + if (ok) { + _mounted = true; + _removed = false; + LOG_EVENT(tr("USB flash drive %1 has been mounted on %2").arg(vDevice).arg(USB_Mount_Point)); + emit didUSBDriveMount(); + } else { + usbError(vDevice); + } + return ok; +} +// coco end + +/*! + * \brief DriveWatcher::usbUmount + * \details Unmounts the USB device vDevice + * \note Emits didUSBDriveUmount signal + * \param vDevice - USB device to be unmounted (eg. /dev/sda1) + * \return true on successful unmount + */ +bool DriveWatcher::usbUmount(const QString &vDevice) +{ + // coco begin validated: This needs user interaction to plug-out the USB device + // has been tested manually + bool ok; + ok = ::umount(vDevice.toLatin1().constData()) == 0; + if (ok) { + _mounted = false; + LOG_EVENT(tr("USB drive %2 unmounted").arg(vDevice)); + emit didUSBDriveUmount(); + } else { + // the error is irrelevant, commented out for now + //usbError(vDevice); + } + return ok; +} +// coco end + +/*! + * \brief DriveWatcher::usbRemove + * \details Removed the USB mount point + * So next time it is not mounted as next device. + * \note Emits didUSBDriveRemove signal + */ +void DriveWatcher::usbRemove() +{ + // coco begin validated: This needs user interaction to plug-out the USB device + // has been tested manually + usbUmount(USB_Mount_Point); + _umounted = false; + _removed = true; + LOG_EVENT(tr("USB drive removed")); + emit didUSBDriveRemove(); +} +// coco end Index: sources/storage/DriveWatcher.h =================================================================== diff -u --- sources/storage/DriveWatcher.h (revision 0) +++ sources/storage/DriveWatcher.h (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -0,0 +1,126 @@ +/*! + * + * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * \copyright + * 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 DriveWatcher.h + * \date 12/31/2019 + * \author Behrouz NematiPour + * + */ +#pragma once + +// Qt +#include + +// Project +#include "main.h" +#include "threads.h" + +// Define +#define _DriveWatcher Storage::DriveWatcher::I() + +// forward diclations +class tst_initializations; + +namespace Storage { + +/*! + * \brief The DriveWatcher class + * \details This class is to watch the USB device to be mounted if plugged in + * or to be unmounted if user through UI requests it. + * and will notify UI (user) on mounted and removed(No USB drive exists). + */ +class DriveWatcher : public QObject +{ + Q_OBJECT + + // friends + friend class ::tst_initializations; + + bool _mounted = false; + bool _umounted = false; + bool _removed = false; + const char *_usbDrive = ""; + const int _interval = 1000; // in ms + + QThread *_thread = nullptr; + bool _init = false; + +// Singleton +SINGLETON(DriveWatcher) + +public slots: + bool init(); + bool init(QThread &vThread); + +private slots: + void quit(); + +protected: + void timerEvent(QTimerEvent *) override; + +private: + void initConnections(); + + void initThread(QThread &vThread); + void quitThread(); + + bool usbSeek(QString &vDevice); + + bool driveSpaceCheck(const QString &vPath, qint64 &vTotalBytes, qint64 &vAvailableBytes); + +signals: + /*! + * \brief didUSBDriveMount + * \details notifies UI when USB device is available and has been mounted. + */ + void didUSBDriveMount (); + + /*! + * \brief didUSBDriveUmount + * \details notifies USB watcher on UI(user) request for USB umount. + */ + void didUSBDriveUmount(); + + /*! + * \brief didUSBDriveRemove + * \details notifies UI when USB device has been removed(not exists). + */ + void didUSBDriveRemove(); + + /*! + * \brief didSDCardFreeSpaceChange + * \param vReady - Device is mounted and ready + * \note if device ejected manually system assumes it's still ready. + * \param vTotal - Returns the total volume size in bytes. + * Returns -1 if QStorageInfo object is not valid + * \param vAvailable - Returns the size (in bytes) available for the current user. + * It returns the total size available if the user is the root user or a system administrator. + * This size can be less than or equal to the free size returned by bytesFree() function. + * Returns -1 if QStorageInfo object is not valid. + * \param vPercent - The percentage of availabe spcae. + * \note Will emitted if only one of the publishing paramter changes. + */ + void didSDCardSpaceChange(bool vReady, qint64 vTotal, qint64 vAvailable, quint8 vPercent); + +private slots: + // ----- usb + void usbCheck(); + + bool usbMount (const QString &vDevice); + bool usbUmount(const QString &vDevice); + void usbRemove(); + void usbError (const QString &vDevice); + + void onUSBDriveUmount(); + + // ----- sdcard + void sdcardSpaceCheck(); + +}; + +} Index: sources/storage/filehandler.cpp =================================================================== diff -u -rd04653f0fbf1ed98178b6c7094beb4ec226a777f -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/storage/filehandler.cpp (.../filehandler.cpp) (revision d04653f0fbf1ed98178b6c7094beb4ec226a777f) +++ sources/storage/filehandler.cpp (.../filehandler.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -20,6 +20,7 @@ #include #include #include + // Project #include "logger.h" @@ -48,7 +49,9 @@ QFile::Text | QFile::Append : QFile::Text | QFile::WriteOnly; if (! file.open(openMode)) { - errOut(QObject::tr("Can't open file for write (%1).Possible corrupted file system").arg(vFileName)); + QString msg = QString("Can't open file for write (%1).Possible corrupted file system").arg(vFileName); + errOut (msg); + LOG_DEBUG(msg); return false; } QTextStream out(&file); @@ -68,7 +71,9 @@ { QFile file(vFileName); if (! file.open(QFile::Text | QFile::ReadOnly)) { - errOut(QObject::tr("Can't open file for read (%1).Possible corrupted file system").arg(vFileName)); + QString msg = QString("Can't open file for read (%1).Possible corrupted file system").arg(vFileName); + errOut (msg); + LOG_DEBUG(msg); return false; } QTextStream in(&file); @@ -110,7 +115,6 @@ int FileHandler::removeFiles(const QStringList &vFolders, const QStringList &vNameFilter, const QDate &vDateOlderThan) { int countRemoved = 0; - QStringList removed; for (const auto &folder : vFolders) { QDir dir(folder); dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks); @@ -120,22 +124,40 @@ QDateTime fileTime = info.lastModified(); QString fileName = info.absoluteFilePath(); if (fileTime.isValid()) { - if (fileTime.date() < vDateOlderThan) { + if (fileTime.date() <= vDateOlderThan) { if (QFile::remove(fileName)) { - removed += fileName; ++countRemoved; + LOG_DEBUG(QString("%1 File(s) %2 removed").arg(countRemoved).arg(fileName)); } else { - LOG_ERROR(QString("Can't delete file : ") + fileName); + LOG_DEBUG(QString("Can't delete file : ") + fileName); } } } else { - LOG_ERROR(QString("Can't get last modified date of file : ") + fileName); + LOG_DEBUG(QString("Can't get last modified date of file : ") + fileName); } } } - - qDebug() << countRemoved << vDateOlderThan << removed; return countRemoved; } + +/*! + * \brief FileHandler::makeFolder + * \details Create the folder vFolder if it doesn't exist. + * \param vFolder - the folder to create + * \return true on successfull creation + */ +bool FileHandler::makeFolder(const QString &vFolder) +{ + QDir dir(vFolder); + if ( ! dir.exists(vFolder) ) { + if ( ! dir.mkpath(vFolder) ) { + QString msg = "Can't create folder " + vFolder; + qDebug() << msg; + LOG_DEBUG(msg); + return false; + } + } + return true; +} Index: sources/storage/filehandler.h =================================================================== diff -u -rd04653f0fbf1ed98178b6c7094beb4ec226a777f -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/storage/filehandler.h (.../filehandler.h) (revision d04653f0fbf1ed98178b6c7094beb4ec226a777f) +++ sources/storage/filehandler.h (.../filehandler.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -34,9 +34,9 @@ static bool write(const QString &vFileName, const QString &vContent, bool vAppend = true); static bool read (const QString &vFileName, QString &vContent); - static int copyFolder(const QString &vSource, const QString &vDestination); - + static int copyFolder (const QString &vSource, const QString &vDestination); static int removeFiles(const QStringList &vFolders, const QStringList &vNameFilter, const QDate &vDateOlderThan); + static bool makeFolder (const QString &vFolder); }; } Index: sources/storage/logger.cpp =================================================================== diff -u -rd04653f0fbf1ed98178b6c7094beb4ec226a777f -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/storage/logger.cpp (.../logger.cpp) (revision d04653f0fbf1ed98178b6c7094beb4ec226a777f) +++ sources/storage/logger.cpp (.../logger.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -22,6 +22,7 @@ #include // Project +#include "DriveWatcher.h" #include "threads.h" #include "storageglobals.h" #include "maintimer.h" @@ -37,7 +38,7 @@ * Qt handles the children destruction by their parent objects life-cycle. */ Logger::Logger(QObject *parent) : QObject(parent) { - _prefix = QFileInfo(qApp->applicationFilePath()).baseName(); + _logFileNamePrefix = QFileInfo(qApp->applicationFilePath()).baseName(); } /*! @@ -90,11 +91,6 @@ } // coco end -void Logger::onLog(const QString &vContent, LogType vLogType) -{ - log(vContent,vLogType); -} - /*! * \brief Logger::initConnections * \details Initializes the required signal/slot connection between this class and other objects @@ -106,7 +102,6 @@ connect(&_exportWatcher, SIGNAL(finished()), this , SLOT(onExport())); - connect(this, SIGNAL(didLog(QString,LogType)), this, SLOT( onLog(QString,LogType))); @@ -116,6 +111,9 @@ connect(&_removeOldLogsWatcher, SIGNAL(finished ()), this , SLOT(onRemoveOldLogs())); + + connect(&_DriveWatcher, SIGNAL( didSDCardSpaceChange(bool, qint64, qint64, quint8)), + this , SLOT( onSDCardSpaceChange(bool, qint64, qint64, quint8))); } /*! @@ -154,6 +152,11 @@ } // coco end +void Logger::onLog(const QString &vContent, LogType vLogType) +{ + log(vContent,vLogType); +} + /*! * \brief Logger::checkLogPath * \details Sets the log paths and creates them if didn't exist. @@ -181,10 +184,12 @@ { if (vUseApplicationDirPath) { _dir.setPath(qApp->applicationDirPath()); - LOG_EVENT(tr("Application path used for events logging (%1)").arg(_dir.path())); - } else { - _dir.setPath(Log_Base_Path_Name); + // Don't use LOG_XXXXX, At this moment Logger has not been initialized yet + qDebug() << QString("Application path used for events logging (%1)").arg(_dir.path()); } + else { + _dir.setPath(SDCard_Base_Path_Name); + } } /*! @@ -195,10 +200,9 @@ bool Logger::setLogPath() { bool ok = true; - if ( ! setLogPath(LogType::eLogBasic) ) ok = false; - if ( ! setLogPath(LogType::eLogEvent) ) ok = false; - if ( ! setLogPath(LogType::eLogError) ) ok = false; - if ( ! setLogPath(LogType::eLogDatum) ) ok = false; + if ( ok && ! setLogPath(LogType::eLogDebug) ) ok = false; + if ( ok && ! setLogPath(LogType::eLogEvent) ) ok = false; + if ( ok && ! setLogPath(LogType::eLogDatum) ) ok = false; return ok; } @@ -211,17 +215,18 @@ */ bool Logger::setLogPath(LogType vLogType) { - _logPathNames[vLogType] = _dir.path() + "/" + _logBasePathNames[vLogType]; - if ( ! _dir.exists(_logBasePathNames[vLogType]) ) { - if ( ! _dir.mkpath(_logBasePathNames[vLogType]) ) { - LOG_ERROR(tr("Can't create %1 log path (%2)") - .arg(_logTypeName [vLogType]) - .arg(_logPathNames[vLogType]) - ); - return false; - } + bool ok = false; + switch (vLogType) { + case LogType::eLogDebug: + _logPathNames[vLogType] = qApp->applicationDirPath() + "/" + _logBasePathNames[vLogType]; + break; + + default: + _logPathNames[vLogType] = _dir.path() + "/" + _logBasePathNames[vLogType]; + break; } - return true; + ok = FileHandler::makeFolder(_logPathNames[vLogType]); + return ok; } /*! @@ -235,18 +240,17 @@ void Logger::log(const QString &vContent, LogType vLogType) { QString date = QDate::currentDate().toString(_dateFormat); - QString fileName = date + _dateSeparator + _prefix; + QString fileName = date + _dateSeparator + _logFileNamePrefix; switch (vLogType) { - case LogType::eLogBasic: case LogType::eLogEvent: case LogType::eLogDatum: - case LogType::eLogError: + case LogType::eLogDebug: fileName += _logFileNameExt[vLogType]; break; default: - fileName += _logFileNameExt[LogType::eLogError]; - LOG_ERROR(tr("Incorrect type of logging %1").arg(vLogType)); + fileName += _logFileNameExt[eLogDebug]; + LOG_DEBUG(QString("Incorrect type of logging %1").arg(vLogType)); } QString mContent = QTime::currentTime().toString(_timeFormat) + _separator; @@ -260,11 +264,10 @@ QString logPathName = _logPathNames[vLogType]; if (logPathName.isEmpty()) - logPathName = _logPathNames[LogType::eLogError]; + logPathName = _logPathNames[eLogDebug]; _logFileName = logPathName + fileName; - FileHandler::write(_logFileName, mContent + "\r\n", true); - if (vLogType == LogType::eLogError) { + if (vLogType == eLogDebug) { #ifdef QT_DEBUG //mContent.prepend("\033[1;31m --- @ --- \033[0m"); mContent.prepend(" @ "); @@ -284,8 +287,8 @@ { // coco begin validated: This needs user interaction to export to USB device // has been tested manually - QString mSource = Storage::Log_Base_Path_Name_Location; - QString mDestination = Storage::USB_Mount_Point; + QString mSource = SDCard_Base_Path_Name; + QString mDestination = USB_Mount_Point; QFuture future = QtConcurrent::run(&FileHandler::copyFolder, mSource, mDestination); _exportWatcher.setFuture(future); return true; @@ -301,6 +304,28 @@ // coco end /*! + * \brief Logger::removeOldLogs + * \details Remove old logs by iterating in the log/service folders and look for expired logs. + * \return count file(s) have been removed. + */ +int Logger::removeOldLogs() +{ + // coco begin validated: This needs user interaction to check the old files deleted + // has been tested manually + QStringList mLogFileFilter ; + QDate mOlderThan ; + for (int iType = 0; iType < eLogType_Count; iType++) { + LogType logType = static_cast(iType); + mLogFileFilter = Format::toStringList(_logFileNameExt .values(logType), true, "*"); + mOlderThan = QDate().currentDate().addDays( _logTypeExpiryDay.value(logType) * -1 ); + FileHandler::removeFiles({_logPathNames[logType]}, mLogFileFilter, mOlderThan); + } + + return true; +} +// coco end + +/*! * \brief Logger::concurrentRemoveOldLogs * \details * @@ -311,14 +336,7 @@ { // coco begin validated: This needs user interaction to check the old files deleted // has been tested manually - QString mLogsLocation = "./"; //Storage::Log_Base_Path_Name; - QStringList mLogFileFilter ; - QStringList mLogFolders ; - - mLogFolders = Format::toStringList(_logBasePathNames.values(), true, mLogsLocation); - mLogFileFilter = Format::toStringList(_logFileNameExt .values(), true, "*"); - QDate mOlderThan = QDate().currentDate().addDays(-1 * _removeOldLogsDaysOlderThan); - QFuture mFuture = QtConcurrent::run(&FileHandler::removeFiles, mLogFolders, mLogFileFilter, mOlderThan); + QFuture mFuture = QtConcurrent::run(this,&Logger::removeOldLogs); _removeOldLogsWatcher.setFuture(mFuture); return true; } @@ -330,4 +348,9 @@ // has been tested manually emit didRemoveOldLogs(); } + +void Logger::onSDCardSpaceChange(bool vReady, qint64 vTotal, qint64 vAvailable, quint8 vPercent) +{ + qDebug() << vReady << vTotal << vAvailable << vPercent; +} // coco end Index: sources/storage/logger.h =================================================================== diff -u -rd04653f0fbf1ed98178b6c7094beb4ec226a777f -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/storage/logger.h (.../logger.h) (revision d04653f0fbf1ed98178b6c7094beb4ec226a777f) +++ sources/storage/logger.h (.../logger.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -29,9 +29,9 @@ #define LOG_EXPORT _Logger.concurrentExport() -#define LOG_BASIC(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogBasic) +#define LOG_DEBUG(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogDebug) + #define LOG_EVENT(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogEvent) -#define LOG_ERROR(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogError) #define LOG_DATUM(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogDatum) // forward declarations @@ -42,14 +42,14 @@ /*! * \brief The Logger class * \details Main logger class that has all the required implementation for logging. - * The provided interface is the LOG_DATUM, LOG_EVENT, LOG_ERROR, LOG_EXPORT defines + * The provided interface is the LOG_DATUM, LOG_EVENT, LOG_DEBUG, LOG_EXPORT defines * and no other methods. * This should have its own thread. * \note * PLEASE BE CAREFUL THIS CLASS IS USING QtConcurrent::run FOR THE EXPORT LOG FILES. * AND ONLY PRIVATE VOID LOG (,) IS CALLING IN POOLED THREAD * PLEASE BE VERY CAREFUL. - * ALL THE OTHER CLASSES TO USE THIS CLASS SHOULD ONLY USE LOG_DATUM, LOG_EVENT, LOG_ERROR + * ALL THE OTHER CLASSES TO USE THIS CLASS SHOULD ONLY USE LOG_DATUM, LOG_EVENT, LOG_DEBUG * TO DO THE LOGGING */ class Logger : public QObject @@ -58,44 +58,46 @@ // friends friend class ::tst_logging; + public : enum LogType { - eLogBasic, - eLogEvent, - eLogError, - eLogDatum, + eLogDebug, ///< Application Error : CANBus messages doesn't have error it's Evnet/Data only + eLogEvent, ///< Massages on the CANBus : Error is an event type + eLogDatum, ///< Massages on the CANBus : Broadcast data type + eLogType_Count, }; private: - QDir _dir; - QString _prefix; + QDir _dir; + QString _logFileNamePrefix; QHash _logPathNames; const QHash _logBasePathNames { - { LogType::eLogBasic, "log/" }, { LogType::eLogEvent, "log/" }, { LogType::eLogDatum, "log/" }, - { LogType::eLogError, "service/" }, + { LogType::eLogDebug, "service/" }, }; const QHash _logPrefix { // Will be used for the logging in the file - { LogType::eLogBasic, "" }, // Object itself tells what it is { LogType::eLogEvent, "E" }, { LogType::eLogDatum, "D" }, - { LogType::eLogError, "" }, // it has its own file and all the content is Error + { LogType::eLogDebug, "" }, // it has its own file and all the content is Error }; const QHash _logTypeName { // Will be used for for information - { LogType::eLogBasic, "Basic" }, // Object itself tells what it is { LogType::eLogEvent, "Event" }, { LogType::eLogDatum, "Datum" }, - { LogType::eLogError, "Error" }, // it has its own file and all the content is Error + { LogType::eLogDebug, "Error" }, // it has its own file and all the content is Error }; const QHash _logFileNameExt { - { LogType::eLogBasic, ".log" }, { LogType::eLogEvent, ".log" }, { LogType::eLogDatum, ".log" }, - { LogType::eLogError, ".err" }, - }; + { LogType::eLogDebug, ".err" }, + }; + const QHash _logTypeExpiryDay { + { LogType::eLogEvent, 15 }, + { LogType::eLogDatum, 15 }, + { LogType::eLogDebug, 5 }, + }; const char *_dateFormat = "yyyy_MM_dd"; const char *_timeFormat = "HH:mm:ss"; @@ -108,8 +110,6 @@ QFutureWatcher _exportWatcher; QFutureWatcher _removeOldLogsWatcher; - const quint8 _removeOldLogsDaysOlderThan = 3; - QThread *_thread = nullptr; bool _init = false; @@ -149,17 +149,23 @@ void didExport(); // ----- Remove Old Logs structure +private: + int removeOldLogs(); private slots: bool concurrentRemoveOldLogs(); void onRemoveOldLogs(); signals: void didRemoveOldLogs(); +private slots: + void onSDCardSpaceChange(bool vReady, qint64 vTotal, qint64 vAvailable, quint8 vPercent); + // ----- logging structure private slots: void onLog (const QString &vContent, LogType vLogType); private: void log (const QString &vContent, LogType vLogType); + signals: /*! * \brief didLog Index: sources/storage/storageglobals.cpp =================================================================== diff -u -r30f83b2813e68ae3c2806399bf808b642c215b67 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/storage/storageglobals.cpp (.../storageglobals.cpp) (revision 30f83b2813e68ae3c2806399bf808b642c215b67) +++ sources/storage/storageglobals.cpp (.../storageglobals.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -21,6 +21,5 @@ const char *USB_File_System = "vfat"; // Log - const char *Log_Base_Path_Name = "/media/sd-card/"; - const char *Log_Base_Path_Name_Location = "/media/sd-card/log/"; + const char *SDCard_Base_Path_Name = "/media/sd-card/"; } Index: sources/storage/storageglobals.h =================================================================== diff -u -r30f83b2813e68ae3c2806399bf808b642c215b67 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/storage/storageglobals.h (.../storageglobals.h) (revision 30f83b2813e68ae3c2806399bf808b642c215b67) +++ sources/storage/storageglobals.h (.../storageglobals.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -23,6 +23,6 @@ extern const char *USB_File_System; // Log - extern const char *Log_Base_Path_Name ; - extern const char *Log_Base_Path_Name_Location; + extern const char *SDCard_Base_Path_Name; + } Fisheye: Tag 3aab84456cfbdc4c4f495975ba9b8968eb844309 refers to a dead (removed) revision in file `sources/storage/usbwatcher.cpp'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 3aab84456cfbdc4c4f495975ba9b8968eb844309 refers to a dead (removed) revision in file `sources/storage/usbwatcher.h'. Fisheye: No comparison available. Pass `N' to diff? Index: sources/threads.cpp =================================================================== diff -u -rb798668f16ad0967ab97e96f5f9a2cdd821e899f -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/threads.cpp (.../threads.cpp) (revision b798668f16ad0967ab97e96f5f9a2cdd821e899f) +++ sources/threads.cpp (.../threads.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -28,12 +28,12 @@ * this has currently been done in main.cpp in main() after the qpp.exe() is done. */ namespace Threads { - QThread _CanFrame_Thread ; - QThread _CanAcknow_Thread ; - QThread _CanMessage_Thread ; - QThread _USBWatcher_Thread ; - QThread _Logger_Thread ; - QThread _Application_Thread ; + QThread _CanFrame_Thread ; + QThread _CanAcknow_Thread ; + QThread _CanMessage_Thread ; + QThread _DriveWatcher_Thread ; + QThread _Logger_Thread ; + QThread _Application_Thread ; /*! * \brief registerTypes @@ -85,12 +85,12 @@ { // coco begin validated: Application termination is not correctly done in coco!!! // it has been tested and works perfectly fine in normal run. - quitThread(_CanFrame_Thread ); // validated - quitThread(_CanAcknow_Thread ); // validated - quitThread(_CanMessage_Thread ); // validated - quitThread(_USBWatcher_Thread ); // validated - quitThread(_Logger_Thread ); // validated - quitThread(_Application_Thread ); // validated + quitThread(_CanFrame_Thread ); // validated + quitThread(_CanAcknow_Thread ); // validated + quitThread(_CanMessage_Thread ); // validated + quitThread(_DriveWatcher_Thread ); // validated + quitThread(_Logger_Thread ); // validated + quitThread(_Application_Thread ); // validated } // coco end } Index: sources/threads.h =================================================================== diff -u -rb798668f16ad0967ab97e96f5f9a2cdd821e899f -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/threads.h (.../threads.h) (revision b798668f16ad0967ab97e96f5f9a2cdd821e899f) +++ sources/threads.h (.../threads.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -26,12 +26,12 @@ #endif namespace Threads { - extern QThread _CanFrame_Thread ; - extern QThread _CanAcknow_Thread ; - extern QThread _CanMessage_Thread ; - extern QThread _USBWatcher_Thread ; - extern QThread _Logger_Thread ; - extern QThread _Application_Thread; + extern QThread _CanFrame_Thread ; + extern QThread _CanAcknow_Thread ; + extern QThread _CanMessage_Thread ; + extern QThread _DriveWatcher_Thread ; + extern QThread _Logger_Thread ; + extern QThread _Application_Thread ; void registerTypes(); void quitThread (QThread &vThread); Index: sources/utility/types.h =================================================================== diff -u -r2437559b2d4cd4c2ac6a926b4f55652e55e1f616 -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- sources/utility/types.h (.../types.h) (revision 2437559b2d4cd4c2ac6a926b4f55652e55e1f616) +++ sources/utility/types.h (.../types.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -135,7 +135,7 @@ bool Types::getValue(const QByteArray &vData, int &vStartIndex, T &vValue, QString vValueName) { int end = vStartIndex + sizeof(T); if (vData.length() < end) { - LOG_ERROR(QString("Not enough data from position %1 to the length of %2 to get data of type '%3' in buffer %4%5") + LOG_DEBUG(QString("Not enough data from position %1 to the length of %2 to get data of type '%3' in buffer %4%5") .arg(vStartIndex) .arg(sizeof(T)) .arg(typeid(T).name()) Index: unittests/tst_initializations.cpp =================================================================== diff -u -rb798668f16ad0967ab97e96f5f9a2cdd821e899f -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- unittests/tst_initializations.cpp (.../tst_initializations.cpp) (revision b798668f16ad0967ab97e96f5f9a2cdd821e899f) +++ unittests/tst_initializations.cpp (.../tst_initializations.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -18,7 +18,7 @@ // Project #include "applicationcontroller.h" #include "guicontroller.h" -#include "usbwatcher.h" +#include "DriveWatcher.h" #include "caninterface.h" #include "frameinterface.h" #include "messagedispatcher.h" @@ -31,9 +31,9 @@ QCOMPARE( _ApplicationController.init(), ! _ApplicationController.init()); } -void tst_initializations::tst_USBWatcher_init() +void tst_initializations::tst_DriveWatcher_init() { - QCOMPARE( _USBWatcher.init(), ! _USBWatcher.init()); + QCOMPARE( _DriveWatcher.init(), ! _DriveWatcher.init()); } void tst_initializations::tst_FrameInterface_init() Index: unittests/tst_initializations.h =================================================================== diff -u -rb798668f16ad0967ab97e96f5f9a2cdd821e899f -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- unittests/tst_initializations.h (.../tst_initializations.h) (revision b798668f16ad0967ab97e96f5f9a2cdd821e899f) +++ unittests/tst_initializations.h (.../tst_initializations.h) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -29,7 +29,7 @@ private slots: void tst_ApplicationController_init(); - void tst_USBWatcher_init(); + void tst_DriveWatcher_init(); void tst_FrameInterface_init(); }; Index: unittests/tst_logging.cpp =================================================================== diff -u -r15de0cd12dad1ea5107c52e5ed89280bc9e29b1d -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- unittests/tst_logging.cpp (.../tst_logging.cpp) (revision 15de0cd12dad1ea5107c52e5ed89280bc9e29b1d) +++ unittests/tst_logging.cpp (.../tst_logging.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -72,7 +72,7 @@ void tst_logging::logError() { - LOG_ERROR("2 - Error log has been created"); + LOG_DEBUG("2 - Error log has been created"); QString mContent; FileHandler::read(_Logger._logFileName, mContent); QCOMPARE(mContent, "Error: , 2 - Error log has been created\n"); Index: unittests/tst_threads.cpp =================================================================== diff -u -rb798668f16ad0967ab97e96f5f9a2cdd821e899f -r3aab84456cfbdc4c4f495975ba9b8968eb844309 --- unittests/tst_threads.cpp (.../tst_threads.cpp) (revision b798668f16ad0967ab97e96f5f9a2cdd821e899f) +++ unittests/tst_threads.cpp (.../tst_threads.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) @@ -19,7 +19,7 @@ #include "threads.h" #include "applicationcontroller.h" #include "guicontroller.h" -#include "usbwatcher.h" +#include "DriveWatcher.h" #include "caninterface.h" #include "frameinterface.h" #include "messagedispatcher.h" @@ -35,7 +35,7 @@ void tst_threads::tst_Thread_init() { QCOMPARE( _Logger .init(Threads::_Logger_Thread ), ! _Logger .init(Threads::_Logger_Thread )); - QCOMPARE( _USBWatcher .init(Threads::_USBWatcher_Thread ), ! _USBWatcher .init(Threads::_USBWatcher_Thread )); + QCOMPARE( _DriveWatcher .init(Threads::_DriveWatcher_Thread ), ! _DriveWatcher .init(Threads::_DriveWatcher_Thread )); QCOMPARE( _CanInterface .init(Threads::_CanFrame_Thread ), ! _CanInterface .init(Threads::_CanFrame_Thread )); QCOMPARE( _FrameInterface .init(Threads::_CanFrame_Thread ), ! _FrameInterface .init(Threads::_CanFrame_Thread )); QCOMPARE( _MessageAcknowModel .init(Threads::_CanAcknow_Thread ), ! _MessageAcknowModel .init(Threads::_CanAcknow_Thread )); @@ -47,7 +47,7 @@ void tst_threads::tst_Thread_names() { QCOMPARE( _Logger .thread()->objectName(), "Storage::Logger_Thread" ); - QCOMPARE( _USBWatcher .thread()->objectName(), "Storage::USBWatcher_Thread" ); + QCOMPARE( _DriveWatcher .thread()->objectName(), "Storage::DriveWatcher_Thread" ); QCOMPARE( _CanInterface .thread()->objectName(), "Can::FrameInterface_Thread" ); QCOMPARE( _FrameInterface .thread()->objectName(), "Can::FrameInterface_Thread" ); QCOMPARE( _MessageAcknowModel .thread()->objectName(), "Can::MessageAcknowModel_Thread" );