Index: sources/ApplicationPost.cpp =================================================================== diff -u -r2ef03b2ce51b4dc507f66e9671953a8e0824bde9 -rabd0e958420f25e5b8dd8ce6e21131f8561b99e0 --- sources/ApplicationPost.cpp (.../ApplicationPost.cpp) (revision 2ef03b2ce51b4dc507f66e9671953a8e0824bde9) +++ sources/ApplicationPost.cpp (.../ApplicationPost.cpp) (revision abd0e958420f25e5b8dd8ce6e21131f8561b99e0) @@ -16,6 +16,7 @@ // Qt #include #include +#include // Project #include "Logger.h" Index: sources/cloudsync/CloudSyncController.cpp =================================================================== diff -u -r2ef03b2ce51b4dc507f66e9671953a8e0824bde9 -rabd0e958420f25e5b8dd8ce6e21131f8561b99e0 --- sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision 2ef03b2ce51b4dc507f66e9671953a8e0824bde9) +++ sources/cloudsync/CloudSyncController.cpp (.../CloudSyncController.cpp) (revision abd0e958420f25e5b8dd8ce6e21131f8561b99e0) @@ -18,7 +18,7 @@ #include // Project -#include "MessageDispatcher.h" +// #include "MessageDispatcher.h" #include "ApplicationController.h" #include "DeviceController.h" #include "FileHandler.h" @@ -102,6 +102,8 @@ connect(&_ApplicationController , SIGNAL(didPOSTCloudSync(bool)), this , SLOT( onPOSTCloudSync(bool))); + connect(&_ApplicationController , SIGNAL(didActionReceive (GuiActionType , const QVariantList &)), + this , SLOT( onActionReceive (GuiActionType , const QVariantList &))); connect(&_DeviceController , SIGNAL(didCryptSetupMount(bool)), this , SLOT( onCryptSetupMount(bool))); @@ -110,8 +112,6 @@ this , SLOT( onWatchFileChange (const QString &))); connect(&_DeviceController , SIGNAL(didFactoryReset (bool)), this , SLOT( onFactoryReset (bool))); - connect(&_MessageDispatcher , SIGNAL(didActionReceive (GuiActionType , const QVariantList &)), - this , SLOT( onActionReceive (GuiActionType , const QVariantList &))); connect(&_TreatmentLog , SIGNAL(didTxPending (const QString &)), this , SLOT( onTxPending (const QString &))); connect(this , SIGNAL(didInitComplete ()), Index: sources/storage/FileHandler.cpp =================================================================== diff -u -rf6c480d06e4b8c770012115d20df2a44e0da8031 -rabd0e958420f25e5b8dd8ce6e21131f8561b99e0 --- sources/storage/FileHandler.cpp (.../FileHandler.cpp) (revision f6c480d06e4b8c770012115d20df2a44e0da8031) +++ sources/storage/FileHandler.cpp (.../FileHandler.cpp) (revision abd0e958420f25e5b8dd8ce6e21131f8561b99e0) @@ -19,6 +19,7 @@ #include #include #include +#include // Project @@ -438,3 +439,22 @@ QFileInfo fileInfo(vFilePath); return fileInfo.canonicalFilePath() != fileInfo.filePath(); } + +/*! + * \brief FileHandler::sha256sum + * \param vFileName - the file name including path to generate the sha256sum for + * \param vOk - if used will contain the success/true, fail/false of the checksum generation + * \return The checksum result in hex sting. + */ +QString FileHandler::sha256sum(QString vFileName, bool *vOk) { + bool ok = true; + QByteArray shasum; + QCryptographicHash hash(QCryptographicHash::Sha256); + QFile file(vFileName); + if ( ! file.open(QIODevice::ReadOnly)) { ok = false; goto lOut; } + hash.addData(&file); + shasum = hash.result().toHex(); +lOut: + if (vOk) *vOk = ok; + return shasum; +} Index: sources/storage/FileHandler.h =================================================================== diff -u -rf6c480d06e4b8c770012115d20df2a44e0da8031 -rabd0e958420f25e5b8dd8ce6e21131f8561b99e0 --- sources/storage/FileHandler.h (.../FileHandler.h) (revision f6c480d06e4b8c770012115d20df2a44e0da8031) +++ sources/storage/FileHandler.h (.../FileHandler.h) (revision abd0e958420f25e5b8dd8ce6e21131f8561b99e0) @@ -15,15 +15,8 @@ #pragma once // Qt -#include -#include -#include -#include -#include - #include #include -#include // forward declarations class tst_fileHandler; @@ -67,7 +60,6 @@ static bool write (const QString &vFileName, const QString &vContent, bool vAppend = true ); static bool read (const QString &vFileName, QString &vContent, bool vAppend = false); - static bool read (const QString &vFileName, QJsonObject &vContent, QJsonParseError *error = nullptr); static int copyFolder (const QString &vSource , const QString &vDestination); static int moveFolder (const QString &vSource , const QString &vDestination); @@ -86,6 +78,9 @@ static bool isPathSymLink(const QString &vFilePath); + static QString sha256sum( QString vFileName, bool *vOk = nullptr ); + + /*! * \brief FileHandler::copyFile * \details Copies a file chunk by chunk Index: sources/storage/Logger.cpp =================================================================== diff -u -rf724589acaa51725f5e5f8a746404d01804efbcf -rabd0e958420f25e5b8dd8ce6e21131f8561b99e0 --- sources/storage/Logger.cpp (.../Logger.cpp) (revision f724589acaa51725f5e5f8a746404d01804efbcf) +++ sources/storage/Logger.cpp (.../Logger.cpp) (revision abd0e958420f25e5b8dd8ce6e21131f8561b99e0) @@ -24,6 +24,7 @@ #include // Project +#include "ApplicationController.h" #include "DeviceController.h" #include "Threads.h" #include "StorageGlobals.h" @@ -39,9 +40,7 @@ * \param parent - QObject parent owner object. * Qt handles the children destruction by their parent objects life-cycle. */ -Logger::Logger(QObject *parent) : QObject(parent) { - _logFileNamePrefix = QFileInfo(qApp->applicationFilePath()).baseName(); -} +Logger::Logger(QObject *parent) : QObject(parent) {} /*! * \brief Logger::init @@ -130,6 +129,9 @@ */ void Logger::initConnections() { + connect(&_ApplicationController , SIGNAL(didActionReceive (GuiActionType , const QVariantList &)), + this , SLOT( onActionReceive (GuiActionType , const QVariantList &))); + connect(&_exportLogsWatcher, SIGNAL(finished ()), this , SLOT(onExportLogs())); @@ -313,13 +315,12 @@ { if ( ! checkThread() ) return; - static QString date; QString mContent; // - Add header - QString currentDate = QDate::currentDate().toString(_dateFormat); - if ( date != currentDate ) { - if ( ! date.isEmpty() ) { + QString currentDate = QDate::currentDate().toString(_fileDateFormat); + if ( _logFileNameDate != currentDate ) { + if ( ! _logFileNameDate.isEmpty() ) { switch ( vLogType ) { case eLogAppED : mContent = _headerA; break; case eLogDebug : mContent = _headerD; break; @@ -328,11 +329,20 @@ } mContent += "\r\n"; } - date = currentDate; + _logFileNameDate = currentDate; } // - Make log file name - QString fileName = date + _dateSeparator + _logFileNamePrefix; + if (_logFileNameMode.isEmpty()) { + _logFileNameMode = _logFileNameMode_init; + _logFileNameTime = QDateTime::currentDateTime().time().toString(_fileTimeFormat); + } + + QString fileName = _logFileNameDate + // + _fileSeparator + _logFileNameTime + + _fileSeparator + _logFileNameHDSN + // + _fileSeparator + _logFileNameMode + ; switch (vLogType) { case LogType::eLogAppED: case LogType::eLogDebug: @@ -375,7 +385,7 @@ * into USB drive folder (Storage::USB_Mount_Point) * \return true if at least one file has been exported */ -bool Logger::exportLogs(const Gui::GuiStringIndexMap &vExportList) +bool Logger::exportLogs(const GuiStringIndexMap &vExportList) { return exportList(vExportList, eLogAppED); } @@ -386,7 +396,7 @@ * into USB drive folder (Storage::USB_Mount_Point) * \return true if at least one file has been exported */ -bool Logger::exportErrs(const Gui::GuiStringIndexMap &vExportList) +bool Logger::exportErrs(const GuiStringIndexMap &vExportList) { return exportList(vExportList, eLogDebug); } @@ -397,7 +407,7 @@ * into USB drive folder (Storage::USB_Mount_Point) * \return true if at least one file has been exported */ -bool Logger::exportTrts(const Gui::GuiStringIndexMap &vExportList) +bool Logger::exportTrts(const GuiStringIndexMap &vExportList) { return exportList(vExportList, eLogTrtmt); } @@ -422,7 +432,7 @@ * \return always returns true for now. * \note This method uses QtConcurrent run to execute the FileHandler copyFolder method. */ -bool Logger::concurrentExportLogs(const Gui::GuiStringIndexMap &vExportList) +bool Logger::concurrentExportLogs(const GuiStringIndexMap &vExportList) { if ( ! concurrentExportIsOk() ) return false; @@ -439,7 +449,7 @@ * \return always returns true for now. * \note This method uses QtConcurrent run to execute the FileHandler copyFolder method. */ -bool Logger::concurrentExportErrs(const Gui::GuiStringIndexMap &vExportList) +bool Logger::concurrentExportErrs(const GuiStringIndexMap &vExportList) { if ( ! concurrentExportIsOk() ) return false; @@ -456,7 +466,7 @@ * \return always returns true for now. * \note This method uses QtConcurrent run to execute the FileHandler copyFolder method. */ -bool Logger::concurrentExportTrts(const Gui::GuiStringIndexMap &vExportList) +bool Logger::concurrentExportTrts(const GuiStringIndexMap &vExportList) { if ( ! concurrentExportIsOk() ) return false; @@ -487,6 +497,75 @@ // disabled coco end /*! + * \brief CloudSyncController::onActionReceive + * \details The slot which will be called when a CANBus message is received, and will be sent to CloudSync if related. + * \param vAction - The message action + * \param vData - The message data + */ +void Logger::onActionReceive(GuiActionType vAction, const QVariantList &vData) +{ + switch (vAction) { + case GuiActionType::ID_HDOperationModeData : { + if ( vData.length() >= 2 ) { + bool ok = true; + quint32 opMode = vData[0].toUInt(&ok); if ( ! ok ) return; + quint32 subMode = vData[1].toUInt(&ok); if ( ! ok ) return; + QString mode; + if ( subMode >= GuiHDStandbyStates::STANDBY_WAIT_FOR_DISINFECT_STATE ) { + mode = "Disinfect"; + if( _logFileNameMode != mode ) { + _logFileNameMode = mode; + _logFileNameTime = QDateTime::currentDateTime().time().toString(_fileTimeFormat); + } + } + else { + switch ( opMode ) { + case GuiHDOpModes::MODE_NLEG: + case GuiHDOpModes::MODE_FAUL: + case GuiHDOpModes::MODE_SERV: + case GuiHDOpModes::MODE_INIT: + case GuiHDOpModes::MODE_STAN: + mode = _logFileNameMode_init; + if( _logFileNameMode != mode ) { + _logFileNameMode = mode; + _logFileNameTime = QDateTime::currentDateTime().time().toString(_fileTimeFormat); + } + break; + case GuiHDOpModes::MODE_TPAR: + case GuiHDOpModes::MODE_PRET: + case GuiHDOpModes::MODE_TREA: + case GuiHDOpModes::MODE_POST: + mode = "Treatment"; + if( _logFileNameMode != mode ) { + _logFileNameMode = mode; + _logFileNameTime = QDateTime::currentDateTime().time().toString(_fileTimeFormat); + } + break; + + default: + break; + } + break; + } + } + } + break; + + case GuiActionType::ID_AdjustSerialHDRsp : { + if ( vData.length() >= 1 ) { + QString hdSerial= vData[0].toString(); + if ( hdSerial.trimmed().isEmpty() ) hdSerial = "Unknown"; + _logFileNameHDSN = hdSerial; + } + } + break; + + default: + break; + } +} + +/*! * \brief Logger::removeLogs * \details Remove old logs by iterating in the log/service folders and look for expired logs. * \return count file(s) have been removed. @@ -679,7 +758,7 @@ * \param vLogType - type of the log files to get the correct location for export. * \return true if the export is successful. */ -bool Logger::exportList(const Gui::GuiStringIndexMap &vExportList, Logger::LogType vLogType) +bool Logger::exportList(const GuiStringIndexMap &vExportList, Logger::LogType vLogType) { // DEBUG: qDebug() << __FUNCTION__ << vExportList; // qDebug() << " ~~~~~~~~~~ " << QThread::currentThread()->objectName(); @@ -697,7 +776,7 @@ result = FileHandler::copyFolder( mSource, mDestination); } else { - Gui::GuiStringIndexMapIterator it(vExportList); + GuiStringIndexMapIterator it(vExportList); while ( it.hasNext() ) { it.next(); // qDebug() << it.key() << it.value() << mSource << mDestination; Index: sources/storage/Logger.h =================================================================== diff -u -r2ef03b2ce51b4dc507f66e9671953a8e0824bde9 -rabd0e958420f25e5b8dd8ce6e21131f8561b99e0 --- sources/storage/Logger.h (.../Logger.h) (revision 2ef03b2ce51b4dc507f66e9671953a8e0824bde9) +++ sources/storage/Logger.h (.../Logger.h) (revision abd0e958420f25e5b8dd8ce6e21131f8561b99e0) @@ -43,6 +43,8 @@ // forward declarations class tst_logging; +using namespace Gui; + namespace Storage { /*! @@ -101,7 +103,29 @@ const char *_headerA = "TimeStamp,ID,SubSys,Name,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40"; const char *_headerD = "TimeStamp,Description"; QDir _dir; - QString _logFileNamePrefix; + + // The HSSerial is going to be the HD Serial always, + // but while booting the logger is initialized first before the HD sends its serial number. + // therefore during the bootup and POST that we don't have the serial, will use BootPOST. + QString _logFileNameHDSN = "BootPOST" ; + + // The Mode is the device main states comming from HD_OpMode + // this is not exactly the HD_OpModes and will be interpreted in desired cycles. + // At the moment we decided to have Standby, Treatment, Disinfection, and I am adding Initial as well. + // Initially + // Treatment + // Disinfect + // DisinfectHeat // later: the UI message needs to get updated and not using SubMode + // DisinfectChem // later: the UI message needs to get updated and not using SubMode + // DisinfectChemFlsh // later: the UI message needs to get updated and not using SubMode + // DisinfectFlsh // later: the UI message needs to get updated and not using SubMode + // "Disinfect" + // "Treatment" + const char *_logFileNameMode_init = "NotRunnig"; + QString _logFileNameMode = "" ; + QString _logFileNameDate = "" ; + QString _logFileNameTime = "" ; + QHash _logPathNames; const QHash _logBasePathNames { { LogType::eLogAppED, Storage::Log_Folder_Application}, @@ -134,12 +158,14 @@ { LogType::eLogTrtmt, Storage::Txr_Max_Allowable_Trtmt_Space_Percent }, }; - const char *_dateFormat = "yyyy_MM_dd" ; // date used in the file name - const char *_timeFormat = "HH:mm:ss.zzz"; // timestamp in the file + const char *_fileDateFormat = "yyyyMMdd" ; // date used in the file name + const char *_fileTimeFormat = "HHmmss" ; // timestamp in the file - const char *_dateSeparator = "_"; // used in filename - const char *_separator = ","; + const char *_timeFormat = "HH:mm:ss.zzz"; // timestamp in the file + const char *_fileSeparator = "_"; // used in filename + const char *_separator = ","; + bool _enableConsoleOut = false; QString _logFileName = ""; @@ -184,16 +210,18 @@ // ----- Export structure private : - bool exportList(const Gui::GuiStringIndexMap &vExportList, LogType vLogType); - bool exportLogs(const Gui::GuiStringIndexMap &vExportList); - bool exportErrs(const Gui::GuiStringIndexMap &vExportList); - bool exportTrts(const Gui::GuiStringIndexMap &vExportList); + bool exportList (const GuiStringIndexMap &vExportList, LogType vLogType); + bool exportLogs (const GuiStringIndexMap &vExportList); + bool exportErrs (const GuiStringIndexMap &vExportList); + bool exportTrts (const GuiStringIndexMap &vExportList); + public slots: // this slot is thread safe and can be called from outside by LOG_EXPORT. bool concurrentExportIsOk (); - bool concurrentExportLogs (const Gui::GuiStringIndexMap &vExportList); - bool concurrentExportErrs (const Gui::GuiStringIndexMap &vExportList); - bool concurrentExportTrts (const Gui::GuiStringIndexMap &vExportList); + bool concurrentExportLogs (const GuiStringIndexMap &vExportList); + bool concurrentExportErrs (const GuiStringIndexMap &vExportList); + bool concurrentExportTrts (const GuiStringIndexMap &vExportList); void onExportLogs (); + signals: void didExportLogs(); void didExportStat(quint32 vIndex, const QString &vFileName, quint8 vPercent); @@ -205,6 +233,7 @@ bool concurrentRemoveLogs(LogType vLogType = eLogFiles); void onRemoveLogs(); void onCryptSetupMount (bool vPass); + void onActionReceive (GuiActionType vAction, const QVariantList &vData); signals: /*!