Index: main.cpp =================================================================== diff -u -r805119c460b4a266d6401c8705f4427e7fbe270f -rbb8f39a014644c70b832dd2a784f62fa9f6b6106 --- main.cpp (.../main.cpp) (revision 805119c460b4a266d6401c8705f4427e7fbe270f) +++ main.cpp (.../main.cpp) (revision bb8f39a014644c70b832dd2a784f62fa9f6b6106) @@ -26,6 +26,7 @@ #include #include #include +#include // Project #include "maintimer.h" @@ -39,7 +40,9 @@ #include "usbwatcher.h" #include "threads.h" +// kernel #include + /*! * \brief signalhandler * \details When application terminates it quits gracefully. @@ -59,6 +62,74 @@ } } +int gFakeInterval = 0 ; +QByteArray gFakeData = "" ; +const char *gFakeData_default = "00" ; +bool gSendEmptyKeepAwake = true ; + +bool gConsoleoutFrameInterface = false ; +bool gConsoleoutCanInterface = false ; + +/*! + * \brief commandlineParse + * \details parses the command line arguments + */ +void commandlineParse() { + QCommandLineParser parser; + parser.setApplicationDescription(QApplication::applicationName()); + parser.addHelpOption(); + parser.addVersionOption(); + + QCommandLineOption optionConsoleoutCanInterface( + QStringList() << "c" << "canOut", + QCoreApplication::translate("main", "Show the Can Frame Output")); + parser.addOption(optionConsoleoutCanInterface); + + QCommandLineOption optionConsoleoutFrameInterface( + QStringList() << "m" << "msgOut", + QCoreApplication::translate("main", "Show the Message Output")); + parser.addOption(optionConsoleoutFrameInterface); + + QCommandLineOption optionSendEmptyKeepAwake(QStringList() << "0" << "disable-keep-awake", + QCoreApplication::translate("main", "Disable send low priority, empty message on the CANBus just to keep UI board CAN driver awake")); + parser.addOption(optionSendEmptyKeepAwake); + + QCommandLineOption optionFakeInterval( + QStringList() << "i" << "fake-interval", + QCoreApplication::translate("main", "Test fake message interval(ms)"), + QCoreApplication::translate("main", "interval")); + parser.addOption(optionFakeInterval); + + 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); + + parser.process(*qApp); + + + gConsoleoutCanInterface = parser.isSet(optionConsoleoutCanInterface ); + gConsoleoutFrameInterface = parser.isSet(optionConsoleoutFrameInterface ); + if (parser.isSet(optionSendEmptyKeepAwake)) gSendEmptyKeepAwake = false; + 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; + } + gFakeData = QByteArray::fromHex(gFakeData); + } + } +} + #ifdef UNIT_TEST #include TEST_CLASS_INCLUDE QTEST_MAIN(TEST_CLASS_NAME) @@ -88,17 +159,6 @@ 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()) { @@ -109,6 +169,9 @@ .arg(VER_MINOR) .arg(ver_revis)); + //! - Parse the command line arguments + commandlineParse(); + //! - Translation initialization QTranslator translator; bool trLoaded = translator.load(QLocale(), app.applicationName(), QLatin1String("_"), QLatin1String(":/translations")); @@ -124,12 +187,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 +210,7 @@ //! - Initializing CanBus Message Dispatcher if (_MessageDispatcher.init(Threads::_CanMessage_Thread)) { - _MessageDispatcher.enableConsoleOut(_consoleoutFrameInterface); + _MessageDispatcher.enableConsoleOut(gConsoleoutFrameInterface); } //! - Initializing Application Controller