Index: main.cpp =================================================================== diff -u -rdb92783a0a9dab0ddf2b68c51d15b1ae1cb3ddcc -r6c6f1f5d466badd9b4fd67be7c907234c342b2a2 --- main.cpp (.../main.cpp) (revision db92783a0a9dab0ddf2b68c51d15b1ae1cb3ddcc) +++ main.cpp (.../main.cpp) (revision 6c6f1f5d466badd9b4fd67be7c907234c342b2a2) @@ -1,15 +1,15 @@ /*! * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * Copyright (c) 2019-2023 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 main.cpp - * \author (last) Behrouz NematiPour - * \date (last) 16-Oct-2020 - * \author (original) Behrouz NematiPour - * \date (original) 24-Sep-2019 + * \file main.cpp + * \author (last) Behrouz NematiPour + * \date (last) 14-Apr-2023 + * \author (original) Behrouz NematiPour + * \date (original) 24-Sep-2019 * */ @@ -41,6 +41,7 @@ #include "Compatible.h" // Project +#include "FileHandler.h" #include "MainTimer.h" #include "CanInterface.h" #include "FrameInterface.h" @@ -55,7 +56,6 @@ #include "CloudSyncController.h" #include "Threads.h" -// #include "FileHandler.h" // kernel #include @@ -85,40 +85,61 @@ bool gSendEmptyKeepAwake = false ; bool gFakeSeqAtBegin = false ; bool gDisableUnhandledReport = false ; +bool gDisableDialinUnhandled = false ; bool gDisableTimeout = false ; bool gDisableAlarmNoMinimize = false ; +bool gDisableSDCFailLogStop = false ; +bool gDisableCloudSyncFailStop = false ; +bool gDisableCheckInLog = false ; +bool gDisableAcknowLog = false ; + bool gConsoleoutLogs = false ; bool gConsoleoutFrameInterface = false ; bool gConsoleoutCanInterface = false ; +bool gEnableDryDemo = false ; +QString gActiveCANBus = "can0"; + +bool gEnableManufacturing = false ; +bool gUseRootHome = false ; + +QString gParserErrorText = ""; + + /*! * \page CommandLineSwitches Denali Command Line Switches * \verbatim * Usage: ./denali [options] * Denali * * Options: - * -h, --help Displays this help. - * -v, --version Displays version information. - * -c, --canOut Show the Can Frame Output - * -m, --msgOut Show the Message Output - * -l, --logOut Show the Logs Output - * -0, --enable-keep-awake Enable send low priority, empty message on - * the CANBus just to keep UI board CAN driver - * awake - * -i, --fake-interval Test fake message interval(ms) - * -f, --fake-message Test fake message data - * will use default sequenced long fake message - * if set to 00(default) - * will used only if correct integer value - * assigned for interval option - * -b, --fake-message-seq-at-begin Test fake message sequence at the beginning - * of the frame - * -u, --disable-unhandled-report Disable unhandled messages report as an - * error in the log - * -q, --disable-timeout Disables HD communication timeout - * + * -h, --help Displays this help. + * -v, --version Displays version information. + * -c, --canOut Show the Can Frame Output + * -m, --msgOut Show the Message Output + * -l, --logOut Show the Logs Output + * -0, --enable-keep-awake Enable send low priority, empty message + * on the CANBus just to keep UI board CAN + * driver awake + * -i, --fake-interval Test fake message interval(ms) + * -f, --fake-message Test fake message data + * will use default sequenced long fake + * message if set to 00(default) + * will used only if correct integer value + * assigned for interval option + * -b, --fake-message-seq-at-begin Test fake message sequence at the + * beginning of the frame + * -u, --disable-unhandled-report Disable unhandled messages report as an + * error in the log + * -d, --disable-dialin-unhandled Disable the Dialin messages logged as + * unhandled + * -q, --disable-timeout Disables HD communication timeout + * -a, --disable-alarm-no-minimize Disables alarm no minimize + * -S, --disable-sd-card-fail-log-stop disable-sd-card-fail-log-stop + * -C, --disable-cloudsync-fail-stop disable-cloudsync-fail-stop + * -k, --enable-check-in-log Enables Check-In Log + * -K, --enable-acknow-log Enables Acknowledgment Log * \endverbatim */ /*! @@ -178,30 +199,111 @@ parser.addOption(optionFakeSeqAtBegin); // --- -u : disable-unhandled-report - QCommandLineOption optionDisableUnhandledReport(QStringList() << "u" << "disable-unhandled-report", - QCoreApplication::translate("main", "Disable unhandled messages report as an error in the log")); + QCommandLineOption optionDisableUnhandledReport( + QStringList() << "u" << "disable-unhandled-report", + QCoreApplication::translate("main", "Disable unhandled messages report as an error in the log")); parser.addOption(optionDisableUnhandledReport); + // --- -d : disable-dialin-unhandled + QCommandLineOption optionDisableDialinUnhandled( + QStringList() << "d" << "disable-dialin-unhandled", + QCoreApplication::translate("main", "Disable the Dialin messages logged as unhandled")); + parser.addOption(optionDisableDialinUnhandled); + // --- -q : disable-timeout - QCommandLineOption optionDisableTimeout(QStringList() << "q" << "disable-timeout", - QCoreApplication::translate("main", "Disables HD communication timeout")); + QCommandLineOption optionDisableTimeout( + QStringList() << "q" << "disable-timeout", + QCoreApplication::translate("main", "Disables HD communication timeout")); parser.addOption(optionDisableTimeout); // --- -a : disable-alarm-no-minimize - QCommandLineOption optionDisableAlarmMoMinimize(QStringList() << "a" << "disable-alarm-no-minimize", - QCoreApplication::translate("main", "Disables alarm no minimize")); + QCommandLineOption optionDisableAlarmMoMinimize( + QStringList() << "a" << "disable-alarm-no-minimize", + QCoreApplication::translate("main", "Disables alarm no minimize")); parser.addOption(optionDisableAlarmMoMinimize); + // --- -S : disable-sd-card-fail-log-stop + QCommandLineOption optionDisableSDCardFailLogStop( + QStringList() << "S" << "disable-sd-card-fail-log-stop", + QCoreApplication::translate("main", "disable-sd-card-fail-log-stop")); + parser.addOption(optionDisableSDCardFailLogStop); + + // --- -C : disable-cloudsync-fail-stop + QCommandLineOption optionDisableCloudSyncFailStop( + QStringList() << "C" << "disable-cloudsync-fail-stop", + QCoreApplication::translate("main", "disable-cloudsync-fail-stop")); + parser.addOption(optionDisableCloudSyncFailStop); + + // --- -k : disable-Check-in-log (keep-alive) + QCommandLineOption optionDisableCheckInLog( + QStringList() << "k" << "disable-check-in-log", + QCoreApplication::translate("main", "Disables Check-In Log")); + parser.addOption(optionDisableCheckInLog); + + // --- -K : disable-acknow-log (Acknowledge) + QCommandLineOption optionDisableAcknowLog( + QStringList() << "K" << "disable-acknow-log", + QCoreApplication::translate("main", "Disables Acknowledgment Log")); + parser.addOption(optionDisableAcknowLog); + + // --- -D : enable-dry-demo + QCommandLineOption optionEnableDryDemo( + QStringList() << "D" << "enable-dry-demo", + QCoreApplication::translate("main", "Enables Dry-Demo Mode")); + parser.addOption(optionEnableDryDemo); + + // --- -A : active-can-bus + QCommandLineOption optionActiveCANBus( + QStringList() << "A" << "active-can-bus", + QCoreApplication::translate("main", "Sets the Active CANBus [Shall start with 'can' or 'vcan]"), + QCoreApplication::translate("main", "CANBus")); + parser.addOption(optionActiveCANBus); + + // --- -E : enable-manufacturing + QCommandLineOption optionEnableManufacturing( + QStringList() << "E" << "enable-manufacturing", + QCoreApplication::translate("main", "Enables the manufacturing mode to configure the system for the first time.")); + parser.addOption(optionEnableManufacturing); + + // --- -R : use-root-home + QCommandLineOption optionUseRootHome( + QStringList() << "R" << "use-root-home", + QCoreApplication::translate("main", "In case the application is not in Manufacturing Setup but needs to use root home folder for configurations.")); + parser.addOption(optionUseRootHome); + // --- parse command lines + if ( ! parser.parse(qApp->arguments()) ) { + gParserErrorText = parser.errorText(); + return; + } parser.process(*qApp); gConsoleoutCanInterface = parser.isSet(optionConsoleoutCanInterface ); gConsoleoutFrameInterface = parser.isSet(optionConsoleoutFrameInterface ); gConsoleoutLogs = parser.isSet(optionConsoleoutLogs ); gDisableUnhandledReport = parser.isSet(optionDisableUnhandledReport ); + gDisableDialinUnhandled = parser.isSet(optionDisableDialinUnhandled ); gDisableTimeout = parser.isSet(optionDisableTimeout ); gDisableAlarmNoMinimize = parser.isSet(optionDisableAlarmMoMinimize ); + gDisableSDCFailLogStop = parser.isSet(optionDisableSDCardFailLogStop ); + gDisableCloudSyncFailStop = parser.isSet(optionDisableCloudSyncFailStop ); + gDisableCheckInLog = parser.isSet(optionDisableCheckInLog ); + gDisableAcknowLog = parser.isSet(optionDisableAcknowLog ); + + gEnableDryDemo = parser.isSet(optionEnableDryDemo ); + + gEnableManufacturing = parser.isSet(optionEnableManufacturing ); + gUseRootHome = parser.isSet(optionUseRootHome ); + + if ( parser.isSet(optionActiveCANBus ) ) { + QString value = parser.value(optionActiveCANBus); + if ( ! value.startsWith("-") && // if a value is not given for the switch then the next switch becomes the value of the previous one + ( value.startsWith("can") || value.startsWith("vcan") ) ) { // to be more precise + gActiveCANBus = value; + } + } + if (parser.isSet(optionSendEmptyKeepAwake)) gSendEmptyKeepAwake = true; bool ok = false; @@ -258,17 +360,49 @@ } if ( ! ver_branch.isEmpty()) ver_branch += '.'; - QCoreApplication::setApplicationVersion( - QString("%1%2%3%4%5.%6") - .arg(ver_branch) - .arg(ver_major) - .arg(ver_minor) - .arg(ver_micro) - .arg(ver_revis) - .arg(ver_comp ) - ); + ver_comp = "." + ver_comp; + QString version = ""; + version += ver_branch ; + version += ver_major ; + version += ver_minor ; + version += ver_micro ; + version += ver_revis ; // build number + version += ver_comp ; + + QCoreApplication::setApplicationVersion(version); } +/*! + * \brief lockdown + * \details runs the lockdown shellscript as a detached process + * and ment to be executed just before the application quits + * and only when application running in manufacturing mode. + * Must not stop application shutdown in any way. + * If any error happens it only logs. + */ +void lockdown() { + // there are two setup scenarios: + // only during setup mode which is -E (manufacturing setup) application is running under the root user permissions + // and all the files are copied to the /home/root/ te later be copied to secured locations + // and that will be done by lockdown.sh script running within application after the user is done with the setup and QUIT s the application. + if ( gEnableManufacturing ) { + QString scriptName = Storage::Device_Lockdown; + quint16 errorCode; + QString errorText; + errorCode = Device::DeviceError::checkScript (scriptName, Storage::Device_Lockdown ); + errorText = Device::DeviceError::deviceErrorText( static_cast(errorCode), 1); + qDebug() << errorText; // since we are in the manufacturing mode it is possible to probably take a look at the serial, if not that is being logged. +#ifdef BUILD_FOR_TARGET + Storage::FileHandler::write("/home/root/lockdown.log" , errorText, false); +#else + Storage::FileHandler::write("/home/denali/lockdown.log" , errorText, false); +#endif + if ( ! errorCode ) { + QProcess::startDetached( scriptName, { qApp->applicationName() + ":" + QString::number(qApp->applicationPid()) }); + } + } +} + #ifdef UNIT_TEST #include TEST_CLASS_INCLUDE QTEST_MAIN(TEST_CLASS_NAME) @@ -288,7 +422,9 @@ #endif // setting the environment for the keyboard. - qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); + qputenv("QT_IM_MODULE" , QByteArray("qtvirtualkeyboard" )); + qputenv("QT_VIRTUALKEYBOARD_STYLE" , QByteArray("denali" )); + qputenv("QT_VIRTUALKEYBOARD_LAYOUT_PATH", QByteArray(":/plugins/QtQuick/VirtualKeyboard/Layouts" )); //! - Qt Application initialization and parameters settings // Qt Core Application parameters settings @@ -309,7 +445,7 @@ commandlineParse(); // SYSTEM TEST FOR INSTRUCTIONS WHEN THERE IS NO PORT AVAILABLE - // Storage::FileHandler::copyFolder(QString(Storage::USB_Mount_Point) + "Instructions", QString(Storage::Settings_Path_Name)); + // Storage::FileHandler::copyFolder(QString(Storage::USB_Mount_Point) + "Instructions", QString(Storage::Settings_Path())); //! - Translation initialization QTranslator translator; @@ -321,6 +457,8 @@ //! - Initializing required thread types Threads::registerTypes(); + bool guiStarted = startGui(); + //! - Initializing Logger if(_Logger.init(Threads::_Logger_Thread)) { _Logger.enableConsoleOut(gConsoleoutLogs); @@ -330,11 +468,15 @@ if (gFakeInterval) { QString msg = " ~~ !!!!! APPLICATION RUNNING IN THE TEST MODE !!!!! ~~ "; qDebug() << msg; - LOG_EVENT(" \n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ " + LOG_APPED(" \n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ " " \n " + msg + " \n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "); } + if ( ! gParserErrorText.isEmpty() ) { + LOG_DEBUG(QString("Command-line arguments process failed:") + gParserErrorText); + } + //! - Initializing the Device Controller _DeviceController.init(Threads::_DeviceController_Thread); @@ -356,10 +498,9 @@ //! - Initializing Application Controller _ApplicationController.init(Threads::_Application_Thread); - _ApplicationController.initSettings(); ////! - Initializing GUI Controller - _GuiController.init(Threads::_Application_Thread); + _GuiController.init(Threads::_Gui_Thread); //! - Initializing Main Timer _MainTimer.init(); @@ -376,7 +517,7 @@ //! - Initialize the QML Viewer and starts GUI int app_exec = -1; LOG_DEBUG("UI Initializing"); - if ( startGui() ) { + if ( guiStarted /*startGui()*/ ) { LOG_DEBUG("UI Initialized"); _ApplicationController .startPOST(); app_exec = app.exec(); @@ -391,6 +532,8 @@ Gui::_viewer->deleteLater(); + lockdown(); + return app_exec; } #endif