Index: main.cpp =================================================================== diff -u -r805119c460b4a266d6401c8705f4427e7fbe270f -rd3edfbd78f021082f37c7ee79a5a31a57b2808d4 --- main.cpp (.../main.cpp) (revision 805119c460b4a266d6401c8705f4427e7fbe270f) +++ main.cpp (.../main.cpp) (revision d3edfbd78f021082f37c7ee79a5a31a57b2808d4) @@ -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,115 @@ } } +int gFakeInterval = 0 ; +QByteArray gFakeData = "" ; +const char *gFakeData_default = "00" ; +bool gSendEmptyKeepAwake = true ; +bool gFakeSeqAtBegin = false ; +bool gDisableHunhandledReport = 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, --disable-keep-awake Disable 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(); + + // --- + 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); + + // --- + QCommandLineOption optionFakeSeqAtBegin( + QStringList() << "b" << "fake-message-seq-atbegin", + QCoreApplication::translate("main", "Test fake message sequence at the beginning of the frame")); + parser.addOption(optionFakeSeqAtBegin); + + // --- + QCommandLineOption optionDisableHunhandledReport(QStringList() << "u" << "disable-unhandled-report", + QCoreApplication::translate("main", "Disable unhandled messages report as an error in the log")); + parser.addOption(optionDisableHunhandledReport); + + + // --- + parser.process(*qApp); + + gConsoleoutCanInterface = parser.isSet(optionConsoleoutCanInterface ); + gConsoleoutFrameInterface = parser.isSet(optionConsoleoutFrameInterface ); + gDisableHunhandledReport = parser.isSet(optionDisableHunhandledReport ); + + 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; + } + if (parser.isSet(optionFakeSeqAtBegin)) { + gFakeSeqAtBegin = true; + } + gFakeData = QByteArray::fromHex(gFakeData); + } + } +} + #ifdef UNIT_TEST #include TEST_CLASS_INCLUDE QTEST_MAIN(TEST_CLASS_NAME) @@ -88,17 +200,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 +210,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 +228,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 +251,7 @@ //! - Initializing CanBus Message Dispatcher if (_MessageDispatcher.init(Threads::_CanMessage_Thread)) { - _MessageDispatcher.enableConsoleOut(_consoleoutFrameInterface); + _MessageDispatcher.enableConsoleOut(gConsoleoutFrameInterface); } //! - Initializing Application Controller