Index: main.cpp =================================================================== diff -u -r805119c460b4a266d6401c8705f4427e7fbe270f -r44a85c96ab55e424866ec4cca0270aa218355f82 --- main.cpp (.../main.cpp) (revision 805119c460b4a266d6401c8705f4427e7fbe270f) +++ main.cpp (.../main.cpp) (revision 44a85c96ab55e424866ec4cca0270aa218355f82) @@ -1,15 +1,16 @@ /*! - * + * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. - * \copyright \n - * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, \n - * IN PART OR IN WHOLE, \n - * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. \n - * - * \file main.cpp - * \date 2019/09/30 - * \author Behrouz NematiPour - * + * \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) Peter Lucia + * \date (last) 26-Jun-2020 + * \author (original) Behrouz NematiPour + * \date (original) 24-Sep-2019 + * */ /*! @@ -26,6 +27,8 @@ #include #include #include +#include +#include // Project #include "maintimer.h" @@ -39,7 +42,9 @@ #include "usbwatcher.h" #include "threads.h" +// kernel #include + /*! * \brief signalhandler * \details When application terminates it quits gracefully. @@ -59,6 +64,152 @@ } } +int gFakeInterval = 0 ; +QByteArray gFakeData = "" ; +const char *gFakeData_default = "00" ; +bool gSendEmptyKeepAwake = false ; +bool gFakeSeqAtBegin = false ; +bool gDisableHunhandledReport = false ; +bool gDisableTimeout = false ; + +bool gConsoleoutFrameInterface = false ; +bool gConsoleoutCanInterface = false ; + +/*! + * \brief commandlineParse + * \details parses the command line arguments \n + * Usage: ./denali [options] \n + * Denali \n + * \n + * Options: \n + * -h, --help Displays this help. \n + * -v, --version Displays version information. \n + * -c, --canOut Show the Can Frame Output \n + * -m, --msgOut Show the Message Output \n + * -0, --enable-keep-awake Enable send low priority, empty message on \n + * the CANBus just to keep UI board CAN driver \n + * awake \n + * -i, --fake-interval Test fake message interval(ms) \n + * -f, --fake-message Test fake message data \n + * will use default sequenced long fake message \n + * if set to 00(default) \n + * will used only if correct intger value \n + * assigned for interval option \n + */ +void commandlineParse() { + QCommandLineParser parser; + parser.setApplicationDescription(QApplication::applicationName()); + parser.addHelpOption(); + parser.addVersionOption(); + + // --- -c : canOut + QCommandLineOption optionConsoleoutCanInterface( + QStringList() << "c" << "canOut", + QCoreApplication::translate("main", "Show the Can Frame Output")); + parser.addOption(optionConsoleoutCanInterface); + + // --- -m : msgOut + QCommandLineOption optionConsoleoutFrameInterface( + QStringList() << "m" << "msgOut", + QCoreApplication::translate("main", "Show the Message Output")); + parser.addOption(optionConsoleoutFrameInterface); + + + // --- -0 : enable-keep-awake (the fast mode) + QCommandLineOption optionSendEmptyKeepAwake(QStringList() << "0" << "enable-keep-awake", + QCoreApplication::translate("main", "Enable send low priority, empty message on the CANBus just to keep UI board CAN driver awake")); + parser.addOption(optionSendEmptyKeepAwake); + + // --- -i : fake-interval + QCommandLineOption optionFakeInterval( + QStringList() << "i" << "fake-interval", + QCoreApplication::translate("main", "Test fake message interval(ms)"), + QCoreApplication::translate("main", "interval")); + parser.addOption(optionFakeInterval); + + // --- -f : fake-message + QCommandLineOption optionFakeData( + QStringList() << "f" << "fake-message", + QCoreApplication::translate("main", "Test fake message data\n" + "will use default sequenced long fake message if set to 00(default)\n" + "will used only if correct intger value assigned for interval option"), + QCoreApplication::translate("main", "data")); + parser.addOption(optionFakeData); + + // --- -b : fake-message-seq-atbegin + QCommandLineOption optionFakeSeqAtBegin( + QStringList() << "b" << "fake-message-seq-atbegin", + QCoreApplication::translate("main", "Test fake message sequence at the beginning of the frame")); + parser.addOption(optionFakeSeqAtBegin); + + // --- -u : disable-unhandled-report + QCommandLineOption optionDisableHunhandledReport(QStringList() << "u" << "disable-unhandled-report", + QCoreApplication::translate("main", "Disable unhandled messages report as an error in the log")); + parser.addOption(optionDisableHunhandledReport); + + // --- -u : disable-unhandled-report + QCommandLineOption optionDisableTimeout(QStringList() << "q" << "disable-timeout", + QCoreApplication::translate("main", "Disables HD communication timeout")); + parser.addOption(optionDisableTimeout); + + + // --- parse command lines + parser.process(*qApp); + + gConsoleoutCanInterface = parser.isSet(optionConsoleoutCanInterface ); + gConsoleoutFrameInterface = parser.isSet(optionConsoleoutFrameInterface ); + gDisableHunhandledReport = parser.isSet(optionDisableHunhandledReport ); + gDisableTimeout = parser.isSet(optionDisableTimeout ); + + if (parser.isSet(optionSendEmptyKeepAwake)) gSendEmptyKeepAwake = true; + bool ok = false; + + if (parser.isSet(optionFakeInterval)) { + int interval = parser.value(optionFakeInterval).toInt(&ok); + if (ok) { + gFakeInterval = interval; + if (parser.isSet(optionFakeData)) { + gFakeData = parser.value(optionFakeData).toLatin1(); + } else { + gFakeData = gFakeData_default; + } + if (parser.isSet(optionFakeSeqAtBegin)) { + gFakeSeqAtBegin = true; + } + gFakeData = QByteArray::fromHex(gFakeData); + } + } +} +/*! + * \brief setApplicationVersion + * \details sets up the application version regarding the environment valiables + * which are set by bamboo and if those are not set value of 0 will be used + * and revision(build) version will be set to current date/time. + */ +void setApplicationVersion() { + QString ver_major = QString("%1").arg(VER_MAJOR); + if (ver_major.isEmpty()) { + ver_major = VER_MAJOR_DEV; + } + QString ver_minor = QString("%1").arg(VER_MINOR); + if (ver_minor.isEmpty()) { + ver_minor = VER_MINOR_DEV; + } + QString ver_micro = QString("%1").arg(VER_MICRO); + if (ver_micro.isEmpty()) { + ver_micro = VER_MICRO_DEV; + } + QString ver_revis = QString("%1").arg(VER_REVIS); + if (ver_revis.isEmpty()) { + ver_revis = VER_REVIS_DEV; + } + QCoreApplication::setApplicationVersion(QString("%1.%2.%3.%4") + .arg(ver_major) + .arg(ver_minor) + .arg(ver_micro) + .arg(ver_revis)); +} + #ifdef UNIT_TEST #include TEST_CLASS_INCLUDE QTEST_MAIN(TEST_CLASS_NAME) @@ -88,27 +239,12 @@ QApplication app(argc, argv); app.thread()->setObjectName("Main Thread"); - // Test code for debugging can messages - bool _consoleoutFrameInterface = false; - bool _consoleoutCanInterface = false; - QStringList args = app.arguments(); - if (args.length() >= 2) { - _consoleoutFrameInterface = args[1] == "1"; - } - if (args.length() >= 3) { - _consoleoutCanInterface = args[2] == "1"; - } - //! - Setting the application version regarding the Bamboo build number. - QString ver_revis = QString("%1").arg(VER_REVIS); - if (ver_revis.isEmpty()) { - ver_revis = QString("%1").arg(VER_DEVEL); - } - QCoreApplication::setApplicationVersion(QString("%1.%2.%3") - .arg(VER_MAJOR) - .arg(VER_MINOR) - .arg(ver_revis)); + setApplicationVersion(); + //! - Parse the command line arguments + commandlineParse(); + //! - Translation initialization QTranslator translator; bool trLoaded = translator.load(QLocale(), app.applicationName(), QLatin1String("_"), QLatin1String(":/translations")); @@ -124,12 +260,19 @@ LOG_EVENT(QObject::tr("Application Started")); + if (gFakeInterval) { + qDebug() << " ~~ !!!!! APPLICATION RUNNING IN THE TEST MODE !!!!! ~~ " ; + LOG_EVENT(" \n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ " + " \n ~~ !!!!! APPLICATION RUNNING IN THE TEST MODE !!!!! ~~ " + " \n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "); + } + //! - Initializing USB Watcher _USBWatcher.init(Threads::_USBWatcher_Thread); //! - Initializing CanBus Interface if (_CanInterface.init(Threads::_CanFrame_Thread)) { - _CanInterface.enableConsoleOut(_consoleoutCanInterface); + _CanInterface.enableConsoleOut(gConsoleoutCanInterface); } //! - Initializing CanBus Message Handler @@ -140,7 +283,7 @@ //! - Initializing CanBus Message Dispatcher if (_MessageDispatcher.init(Threads::_CanMessage_Thread)) { - _MessageDispatcher.enableConsoleOut(_consoleoutFrameInterface); + _MessageDispatcher.enableConsoleOut(gConsoleoutFrameInterface); } //! - Initializing Application Controller @@ -153,10 +296,11 @@ _MainTimer.init(); //! - Initialize the Qml Viewer and starts GUI - startGui(); + int app_exec = -1; + if ( startGui() ) { + app_exec = app.exec(); + } - int app_exec = app.exec(); - // Due to Qt Error the CAN Device cannot be disable/enable from withing another thread // (other than main thread which is the owner of the CanDevice). // So it needs to be done here in main thread.