Index: main.cpp =================================================================== diff -u -rd3412ddbb51dca3768ce29182d331e5274e9e745 -r6c6f1f5d466badd9b4fd67be7c907234c342b2a2 --- main.cpp (.../main.cpp) (revision d3412ddbb51dca3768ce29182d331e5274e9e745) +++ main.cpp (.../main.cpp) (revision 6c6f1f5d466badd9b4fd67be7c907234c342b2a2) @@ -7,7 +7,7 @@ * * \file main.cpp * \author (last) Behrouz NematiPour - * \date (last) 10-Feb-2023 + * \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" @@ -90,8 +91,8 @@ bool gDisableSDCFailLogStop = false ; bool gDisableCloudSyncFailStop = false ; -bool gEnableCheckInLog = false ; -bool gEnableAcknowLog = false ; +bool gDisableCheckInLog = false ; +bool gDisableAcknowLog = false ; bool gConsoleoutLogs = false ; bool gConsoleoutFrameInterface = false ; @@ -100,7 +101,12 @@ bool gEnableDryDemo = false ; QString gActiveCANBus = "can0"; +bool gEnableManufacturing = false ; +bool gUseRootHome = false ; +QString gParserErrorText = ""; + + /*! * \page CommandLineSwitches Denali Command Line Switches * \verbatim @@ -198,7 +204,7 @@ QCoreApplication::translate("main", "Disable unhandled messages report as an error in the log")); parser.addOption(optionDisableUnhandledReport); - // --- -d : enable-dialin-unhandled + // --- -d : disable-dialin-unhandled QCommandLineOption optionDisableDialinUnhandled( QStringList() << "d" << "disable-dialin-unhandled", QCoreApplication::translate("main", "Disable the Dialin messages logged as unhandled")); @@ -211,42 +217,65 @@ 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")); + 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")); + QCommandLineOption optionDisableCloudSyncFailStop( + QStringList() << "C" << "disable-cloudsync-fail-stop", + QCoreApplication::translate("main", "disable-cloudsync-fail-stop")); parser.addOption(optionDisableCloudSyncFailStop); - // --- -k : enable-Check-in-log (keep-alive) - QCommandLineOption optionEnableCheckInLog(QStringList() << "k" << "enable-check-in-log", - QCoreApplication::translate("main", "Enables Check-In Log")); - parser.addOption(optionEnableCheckInLog); + // --- -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 : enable-acknow-log (Acknowledge) - QCommandLineOption optionEnableAcknowLog(QStringList() << "K" << "enable-acknow-log", - QCoreApplication::translate("main", "Enables Acknowledgment Log")); - parser.addOption(optionEnableAcknowLog); + // --- -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")); + 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")); + 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 ); @@ -259,11 +288,14 @@ gDisableSDCFailLogStop = parser.isSet(optionDisableSDCardFailLogStop ); gDisableCloudSyncFailStop = parser.isSet(optionDisableCloudSyncFailStop ); - gEnableCheckInLog = parser.isSet(optionEnableCheckInLog ); - gEnableAcknowLog = parser.isSet(optionEnableAcknowLog ); + 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 @@ -340,6 +372,37 @@ 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) @@ -382,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; @@ -410,6 +473,10 @@ " \n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "); } + if ( ! gParserErrorText.isEmpty() ) { + LOG_DEBUG(QString("Command-line arguments process failed:") + gParserErrorText); + } + //! - Initializing the Device Controller _DeviceController.init(Threads::_DeviceController_Thread); @@ -431,7 +498,6 @@ //! - Initializing Application Controller _ApplicationController.init(Threads::_Application_Thread); - _ApplicationController.initSettings(); ////! - Initializing GUI Controller _GuiController.init(Threads::_Gui_Thread); @@ -466,6 +532,8 @@ Gui::_viewer->deleteLater(); + lockdown(); + return app_exec; } #endif