Index: sources/ApplicationPost.cpp =================================================================== diff -u -re38423dd3840e625ed0728d9b0fb3f9eb9292500 -rab28e427d67bdb054a0173efb719e820f97b20b0 --- sources/ApplicationPost.cpp (.../ApplicationPost.cpp) (revision e38423dd3840e625ed0728d9b0fb3f9eb9292500) +++ sources/ApplicationPost.cpp (.../ApplicationPost.cpp) (revision ab28e427d67bdb054a0173efb719e820f97b20b0) @@ -1,320 +1,320 @@ -/*! - * - * Copyright (c) 2020-2024 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 ApplicationPost.cpp - * \author (last) Behrouz NematiPour - * \date (last) 29-Feb-2024 - * \author (original) Behrouz NematiPour - * \date (original) 26-Aug-2020 - * - */ -#include "ApplicationPost.h" -// Qt -#include -#include -#include - -// Project -#include "Logger.h" -#include "FileHandler.h" - -/*! - * \brief ApplicationPost::ApplicationPost - * \details Constructor - * \param parent - QObject parent owner object. - * Qt handles the children destruction by their parent objects life-cycle. - */ -ApplicationPost::ApplicationPost(QObject *parent) : QObject(parent) { } - -/*! - * \brief ApplicationPost::start - * \details Starting the post application initialization - * \return - */ -void ApplicationPost::start() -{ - QString postLogFileName = QDir::tempPath() + "/" + Storage::POST_LOG; - if (Storage::FileHandler::read(postLogFileName, _content)) { - - _isOSVersion = checkOSVersion (); - _isShaSum = checkShaSum (); - _isCANBus = checkCANBus (); - _isDisplay = checkDisplay (); - _isTouch = checkTouch (); - _isSDCard = checkSDCard (); - _isRtc = checkRtc (); - _isWiFi = checkWiFi (); // is not mandatory and the device can still be used without it. Alarm will be triggered to notify user in Active Alarm List. - _isBluetooth = checkBluetooth (); // is not mandatory and the device can still be used without it. Alarm will be triggered to notify user in Active Alarm List. - _isCloudSync = checkCloudSync (); // is not mandatory and the device can still be used without it. Alarm will be triggered to notify user in Active Alarm List. - _isEthernet = checkEthernet (); // this is not a Fault and not required the application to stop. No Alarm will be triggered. - _isSound = checkSound (); // this is not a Fault and not required the application to stop. No Alarm will be triggered. - _isYearCheck = checkYear (); - // WARNING: - // all of the checks have to be done, - // although some are not failing the final result, - // so they need to be assigned to a variable and then, AND(&&) them, - // otherwise on the first fail rest of the checks will not run by compiler optimization. - _isDone = - isOSVersion () && - isShaSum () && - isCANBus () && - isDisplay () && - isTouch () && - isSDCard () && - isRtc () && - isWiFi () && - isBluetooth () && - isCloudSync () && - // isEthernet () && // it is being executed to get the information but is not part of the POST failure. - // isSound () && - isYearCheck () - ; - } - else { - // TODO: Ignored for now but this could be a FileSystem check failure, and the post.log has to always exist. - // _done = false; - LOG_APPED(tr("The POST log file could not be read.")); - } - emit didDone(_isDone); -} - -/*! - * \brief ApplicationPost::checkOSVersion - * \details Checks the OS version - * \return false if the OS version is lower than 0.0.40 which is released for the Cybersecurity.. - */ -bool ApplicationPost::checkOSVersion() -{ - QString exrVer("%1\\s*\"\\d+\\.\\d+\\.\\d+\""); - QString exrBld("%1\\s*\"\\d+\""); - - QRegExp regVer(exrVer.arg(_postmsg_osversion)); - QRegExp regBld(exrBld.arg(_postmsg_osbuild )); - QString version; - QString build; - QStringList versions; - quint16 major; - quint16 minor; - quint16 micro; - - // check the statement exists in the long - int rowVer = _content.indexOf (regVer); - int rowBld = _content.indexOf (regBld); Q_UNUSED(rowBld); - bool ok = rowVer >= 0; // found - if ( ! ok ) goto lOut; - - // check the Os version is compatible - version = regVer.cap(0).replace(_postmsg_osversion,"").replace("\"",""); // 0 is the first captured and next if any are the subsets. - build = regBld.cap(0).replace(_postmsg_osbuild ,"").replace("\"",""); // 0 is the first captured and next if any are the subsets. - versions = version.split("."); - major = versions[0].toUInt(); // type, existance, count has been already tested by regex, and was rejected in first check section. - minor = versions[1].toUInt(); // type, existance, count has been already tested by regex, and was rejected in first check section. - micro = versions[2].toUInt(); // type, existance, count has been already tested by regex, and was rejected in first check section. - ok = major >= Storage::OS_VERSION_MAJOR && - minor >= Storage::OS_VERSION_MINOR && - micro >= Storage::OS_VERSION_MICRO ; - if ( ! ok ) goto lOut; - - _osVersion = version + "." + build; - -lOut: - if ( !ok ) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_OS_VERSION); - emit didOSVersion(ok); - return ok; -} - -/*! - * \brief ApplicationPost::checkOSInfo - * \details Checks if the - * \return it is false if the - */ -bool ApplicationPost::checkShaSum() -{ - bool ok = _content.contains(_postmsg_shasum + _postmsg_postfix_passed); - if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_SHASUM); - emit didShaSum(ok); - return ok; -} - -/*! - * \brief ApplicationPost::checkCANBus - * \details Checks the CANBus driver is loaded and the bus is functional - * \return false if there is an issue. - */ -bool ApplicationPost::checkCANBus() -{ - bool ok = _content.contains(_postmsg_canbus + _postmsg_postfix_passed); - if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_CANBUS); - emit didCANBus(ok); - return ok; -} - -/*! - * \brief ApplicationPost::checkDisplay - * \details Checks the display driver is loaded - * \return false if there is an issue [No Implementation yet (always true)]. - */ -bool ApplicationPost::checkDisplay() -{ - bool ok = true; - //TODO: do the test : not a good test has been found yet. - if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_DISPLAY); - emit didDisplay(ok); - return ok; -} - -/*! - * \brief ApplicationPost::checkTouchScreen - * \details Checks the touch driver is loaded - * \return false if there is an issue. - */ -bool ApplicationPost::checkTouch() -{ - bool ok = _content.contains(_postmsg_touch + _postmsg_postfix_passed); - if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_TOUCH); - emit didTouch(ok); - return ok; -} - -/*! - * \brief ApplicationPost::checkSDCard - * \details Checks the SD-Card drive is loaded and functional - * \return false if there is an issue. - */ -bool ApplicationPost::checkSDCard() -{ - bool ok = _content.contains(_postmsg_sdcard + _postmsg_postfix_passed); - if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_SDCARD); - emit didSDCard(ok); - return ok; -} - -/*! - * \brief ApplicationPost::CRC - * \details Checks the RTC driver is loaded and functional - * \return false if there is an issue - */ -bool ApplicationPost::checkRtc() -{ - bool ok = _content.contains(_postmsg_rtc + _postmsg_postfix_passed); - if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_RTC); - emit didRtc(ok); - return ok; -} - -/*! - * \brief ApplicationPost::checkEthernet - * \details Checks the Ethernet driver is loaded and functional. - * \return false if there is an issue [Removed from the PRS (always true)]. - */ -bool ApplicationPost::checkEthernet() -{ - bool ok = false; - int posDev = -1; - int posMac = -1; - QString section = ""; - posDev = _content.indexOf( _devEthernet ); if ( posDev < 0 ) goto lOut; - section = _content.mid(posDev, _macAppearLen); - posMac = section.indexOf(_macEthernetLabel); if ( posMac < 0 ) goto lOut; - _macEthernet = section.mid(posMac + _macEthernetLabel.length(), _macAddrssLen).toUpper(); if ( _macEthernet.isEmpty() ) goto lOut; - ok = true; - -lOut: - if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_ETHERNET); - emit didEthernet(ok); - return ok; -} - -/*! - * \brief ApplicationPost::checkWiFi - * \details Checks the WiFi driver is loaded and functional - * \return false if there is an issue. - */ -bool ApplicationPost::checkWiFi() -{ - bool ok = false; - int posDev = -1; - int posMac = -1; - QString section = ""; - posDev = _content.indexOf( _devWireless ); if ( posDev < 0 ) goto lOut; - section = _content.mid(posDev, _macAppearLen); - posMac = section.indexOf(_macWirelessLabel); if ( posMac < 0 ) goto lOut; - _macWireless = section.mid(posMac + _macWirelessLabel.length(), _macAddrssLen).toUpper(); if ( _macWireless.isEmpty() ) goto lOut; - ok = _content.contains(_postmsg_wifi + _postmsg_postfix_passed); - -lOut: - if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_WIFI); - emit didWiFi(ok); - return ok; -} - -/*! - * \brief ApplicationPost::checkBluetooth - * \details Checks the Bluetooth driver is loaded and functional - * \return false if there is an issue. - */ -bool ApplicationPost::checkBluetooth() -{ - bool ok = false; - int posDev = -1; - int posMac = -1; - QString section = ""; - posDev = _content.indexOf( _devBluetooth ); if ( posDev < 0 ) goto lOut; - section = _content.mid(posDev, _macAppearLen); - posMac = section.indexOf(_macBluetoothLabel); if ( posMac < 0 ) goto lOut; - _macBluetooth = section.mid(posMac + _macBluetoothLabel.length(), _macAddrssLen).toUpper(); if ( _macBluetooth.isEmpty() ) goto lOut; - ok = _content.contains(_postmsg_bluetooth + _postmsg_postfix_passed); - -lOut: - if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_BLUETOOTH); - emit didBluetooth(ok); - return ok; -} - -/*! - * \brief ApplicationPost::checkCloudSync - * \details Checks the CloudSync service is loaded and functional - * \return false if there is an issue. - */ -bool ApplicationPost::checkCloudSync() -{ - bool ok = true; - if (! gDisableCloudSyncFailStop ) { - ok = _content.contains(_postmsg_cloudsync + _postmsg_postfix_passed); - } - if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_CLOUDSYNC); - emit didCloudSync(ok); - return ok; -} - -/*! - * \brief ApplicationPost::checkSound - * \details Checks the sound driver is loaded. - * \return false if there is an issue [No Implementation yet (always true)]. - */ -bool ApplicationPost::checkSound() -{ - bool ok = true; - // do the test - if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_SOUND); - emit didSound(ok); - return ok; -} - -/*! - * \brief ApplicationPost::checkYear - * \details Checks if the year is greater than or equal to 2022. - * \return false if there is an issue. - */ -bool ApplicationPost::checkYear() -{ - QDate currentDate = QDate::currentDate(); - bool ok = currentDate.year() >= _yearMinimum; - if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_INVALID_YEAR); - emit didYearCheck(ok); - return ok; -} +/*! + * + * Copyright (c) 2020-2024 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 ApplicationPost.cpp + * \author (last) Behrouz NematiPour + * \date (last) 29-Feb-2024 + * \author (original) Behrouz NematiPour + * \date (original) 26-Aug-2020 + * + */ +#include "ApplicationPost.h" +// Qt +#include +#include +#include + +// Project +#include "Logger.h" +#include "FileHandler.h" + +/*! + * \brief ApplicationPost::ApplicationPost + * \details Constructor + * \param parent - QObject parent owner object. + * Qt handles the children destruction by their parent objects life-cycle. + */ +ApplicationPost::ApplicationPost(QObject *parent) : QObject(parent) { } + +/*! + * \brief ApplicationPost::start + * \details Starting the post application initialization + * \return + */ +void ApplicationPost::start() +{ + QString postLogFileName = QDir::tempPath() + "/" + Storage::POST_LOG; + if (Storage::FileHandler::read(postLogFileName, _content)) { + + _isOSVersion = checkOSVersion (); + _isShaSum = checkShaSum (); + _isCANBus = checkCANBus (); + _isDisplay = checkDisplay (); + _isTouch = checkTouch (); + _isSDCard = checkSDCard (); + _isRtc = checkRtc (); + _isWiFi = checkWiFi (); // is not mandatory and the device can still be used without it. Alarm will be triggered to notify user in Active Alarm List. + _isBluetooth = checkBluetooth (); // is not mandatory and the device can still be used without it. Alarm will be triggered to notify user in Active Alarm List. + _isCloudSync = checkCloudSync (); // is not mandatory and the device can still be used without it. Alarm will be triggered to notify user in Active Alarm List. + _isEthernet = checkEthernet (); // this is not a Fault and not required the application to stop. No Alarm will be triggered. + _isSound = checkSound (); // this is not a Fault and not required the application to stop. No Alarm will be triggered. + _isYearCheck = checkYear (); + // WARNING: + // all of the checks have to be done, + // although some are not failing the final result, + // so they need to be assigned to a variable and then, AND(&&) them, + // otherwise on the first fail rest of the checks will not run by compiler optimization. + _isDone = + isOSVersion () && + isShaSum () && + isCANBus () && + isDisplay () && + isTouch () && + isSDCard () && + isRtc () && + isWiFi () && + isBluetooth () && + isCloudSync () && + // isEthernet () && // it is being executed to get the information but is not part of the POST failure. + // isSound () && + isYearCheck () + ; + } + else { + // TODO: Ignored for now but this could be a FileSystem check failure, and the post.log has to always exist. + // _done = false; + LOG_APPED_UI(tr("The POST log file could not be read.")); + } + emit didDone(_isDone); +} + +/*! + * \brief ApplicationPost::checkOSVersion + * \details Checks the OS version + * \return false if the OS version is lower than 0.0.40 which is released for the Cybersecurity.. + */ +bool ApplicationPost::checkOSVersion() +{ + QString exrVer("%1\\s*\"\\d+\\.\\d+\\.\\d+\""); + QString exrBld("%1\\s*\"\\d+\""); + + QRegExp regVer(exrVer.arg(_postmsg_osversion)); + QRegExp regBld(exrBld.arg(_postmsg_osbuild )); + QString version; + QString build; + QStringList versions; + quint16 major; + quint16 minor; + quint16 micro; + + // check the statement exists in the long + int rowVer = _content.indexOf (regVer); + int rowBld = _content.indexOf (regBld); Q_UNUSED(rowBld); + bool ok = rowVer >= 0; // found + if ( ! ok ) goto lOut; + + // check the Os version is compatible + version = regVer.cap(0).replace(_postmsg_osversion,"").replace("\"",""); // 0 is the first captured and next if any are the subsets. + build = regBld.cap(0).replace(_postmsg_osbuild ,"").replace("\"",""); // 0 is the first captured and next if any are the subsets. + versions = version.split("."); + major = versions[0].toUInt(); // type, existance, count has been already tested by regex, and was rejected in first check section. + minor = versions[1].toUInt(); // type, existance, count has been already tested by regex, and was rejected in first check section. + micro = versions[2].toUInt(); // type, existance, count has been already tested by regex, and was rejected in first check section. + ok = major >= Storage::OS_VERSION_MAJOR && + minor >= Storage::OS_VERSION_MINOR && + micro >= Storage::OS_VERSION_MICRO ; + if ( ! ok ) goto lOut; + + _osVersion = version + "." + build; + +lOut: + if ( !ok ) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_OS_VERSION); + emit didOSVersion(ok); + return ok; +} + +/*! + * \brief ApplicationPost::checkOSInfo + * \details Checks if the + * \return it is false if the + */ +bool ApplicationPost::checkShaSum() +{ + bool ok = _content.contains(_postmsg_shasum + _postmsg_postfix_passed); + if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_SHASUM); + emit didShaSum(ok); + return ok; +} + +/*! + * \brief ApplicationPost::checkCANBus + * \details Checks the CANBus driver is loaded and the bus is functional + * \return false if there is an issue. + */ +bool ApplicationPost::checkCANBus() +{ + bool ok = _content.contains(_postmsg_canbus + _postmsg_postfix_passed); + if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_CANBUS); + emit didCANBus(ok); + return ok; +} + +/*! + * \brief ApplicationPost::checkDisplay + * \details Checks the display driver is loaded + * \return false if there is an issue [No Implementation yet (always true)]. + */ +bool ApplicationPost::checkDisplay() +{ + bool ok = true; + //TODO: do the test : not a good test has been found yet. + if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_DISPLAY); + emit didDisplay(ok); + return ok; +} + +/*! + * \brief ApplicationPost::checkTouchScreen + * \details Checks the touch driver is loaded + * \return false if there is an issue. + */ +bool ApplicationPost::checkTouch() +{ + bool ok = _content.contains(_postmsg_touch + _postmsg_postfix_passed); + if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_TOUCH); + emit didTouch(ok); + return ok; +} + +/*! + * \brief ApplicationPost::checkSDCard + * \details Checks the SD-Card drive is loaded and functional + * \return false if there is an issue. + */ +bool ApplicationPost::checkSDCard() +{ + bool ok = _content.contains(_postmsg_sdcard + _postmsg_postfix_passed); + if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_SDCARD); + emit didSDCard(ok); + return ok; +} + +/*! + * \brief ApplicationPost::CRC + * \details Checks the RTC driver is loaded and functional + * \return false if there is an issue + */ +bool ApplicationPost::checkRtc() +{ + bool ok = _content.contains(_postmsg_rtc + _postmsg_postfix_passed); + if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_RTC); + emit didRtc(ok); + return ok; +} + +/*! + * \brief ApplicationPost::checkEthernet + * \details Checks the Ethernet driver is loaded and functional. + * \return false if there is an issue [Removed from the PRS (always true)]. + */ +bool ApplicationPost::checkEthernet() +{ + bool ok = false; + int posDev = -1; + int posMac = -1; + QString section = ""; + posDev = _content.indexOf( _devEthernet ); if ( posDev < 0 ) goto lOut; + section = _content.mid(posDev, _macAppearLen); + posMac = section.indexOf(_macEthernetLabel); if ( posMac < 0 ) goto lOut; + _macEthernet = section.mid(posMac + _macEthernetLabel.length(), _macAddrssLen).toUpper(); if ( _macEthernet.isEmpty() ) goto lOut; + ok = true; + +lOut: + if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_ETHERNET); + emit didEthernet(ok); + return ok; +} + +/*! + * \brief ApplicationPost::checkWiFi + * \details Checks the WiFi driver is loaded and functional + * \return false if there is an issue. + */ +bool ApplicationPost::checkWiFi() +{ + bool ok = false; + int posDev = -1; + int posMac = -1; + QString section = ""; + posDev = _content.indexOf( _devWireless ); if ( posDev < 0 ) goto lOut; + section = _content.mid(posDev, _macAppearLen); + posMac = section.indexOf(_macWirelessLabel); if ( posMac < 0 ) goto lOut; + _macWireless = section.mid(posMac + _macWirelessLabel.length(), _macAddrssLen).toUpper(); if ( _macWireless.isEmpty() ) goto lOut; + ok = _content.contains(_postmsg_wifi + _postmsg_postfix_passed); + +lOut: + if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_WIFI); + emit didWiFi(ok); + return ok; +} + +/*! + * \brief ApplicationPost::checkBluetooth + * \details Checks the Bluetooth driver is loaded and functional + * \return false if there is an issue. + */ +bool ApplicationPost::checkBluetooth() +{ + bool ok = false; + int posDev = -1; + int posMac = -1; + QString section = ""; + posDev = _content.indexOf( _devBluetooth ); if ( posDev < 0 ) goto lOut; + section = _content.mid(posDev, _macAppearLen); + posMac = section.indexOf(_macBluetoothLabel); if ( posMac < 0 ) goto lOut; + _macBluetooth = section.mid(posMac + _macBluetoothLabel.length(), _macAddrssLen).toUpper(); if ( _macBluetooth.isEmpty() ) goto lOut; + ok = _content.contains(_postmsg_bluetooth + _postmsg_postfix_passed); + +lOut: + if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_BLUETOOTH); + emit didBluetooth(ok); + return ok; +} + +/*! + * \brief ApplicationPost::checkCloudSync + * \details Checks the CloudSync service is loaded and functional + * \return false if there is an issue. + */ +bool ApplicationPost::checkCloudSync() +{ + bool ok = true; + if (! gDisableCloudSyncFailStop ) { + ok = _content.contains(_postmsg_cloudsync + _postmsg_postfix_passed); + } + if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_CLOUDSYNC); + emit didCloudSync(ok); + return ok; +} + +/*! + * \brief ApplicationPost::checkSound + * \details Checks the sound driver is loaded. + * \return false if there is an issue [No Implementation yet (always true)]. + */ +bool ApplicationPost::checkSound() +{ + bool ok = true; + // do the test + if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_SOUND); + emit didSound(ok); + return ok; +} + +/*! + * \brief ApplicationPost::checkYear + * \details Checks if the year is greater than or equal to 2022. + * \return false if there is an issue. + */ +bool ApplicationPost::checkYear() +{ + QDate currentDate = QDate::currentDate(); + bool ok = currentDate.year() >= _yearMinimum; + if (! ok) emit didFail(Gui::GuiAlarmID::ALARM_ID_HD_UI_POST_FAILURE_INVALID_YEAR); + emit didYearCheck(ok); + return ok; +}