Index: main.cpp =================================================================== diff -u -r52221d8d944edb5fbd57542960561830def8ffa9 -r6c6f1f5d466badd9b4fd67be7c907234c342b2a2 --- main.cpp (.../main.cpp) (revision 52221d8d944edb5fbd57542960561830def8ffa9) +++ main.cpp (.../main.cpp) (revision 6c6f1f5d466badd9b4fd67be7c907234c342b2a2) @@ -7,7 +7,7 @@ * * \file main.cpp * \author (last) Behrouz NematiPour - * \date (last) 28-Mar-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,8 +101,12 @@ bool gEnableDryDemo = false ; QString gActiveCANBus = "can0"; +bool gEnableManufacturing = false ; +bool gUseRootHome = false ; + QString gParserErrorText = ""; + /*! * \page CommandLineSwitches Denali Command Line Switches * \verbatim @@ -199,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")); @@ -229,17 +234,17 @@ 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( @@ -254,6 +259,18 @@ 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(); @@ -271,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 @@ -352,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) @@ -394,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; @@ -447,7 +498,6 @@ //! - Initializing Application Controller _ApplicationController.init(Threads::_Application_Thread); - _ApplicationController.initSettings(); ////! - Initializing GUI Controller _GuiController.init(Threads::_Gui_Thread); @@ -482,6 +532,8 @@ Gui::_viewer->deleteLater(); + lockdown(); + return app_exec; } #endif