/*! * * 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 * */ /*! * \mainpage UI Software Design Description * \section Detailed Description * This document has been generated by Doxygen.\n * This document describes the detail description of the UI Application Software design.\n * UI Application starts by Application Initialization which happens in \ref main.cpp "Initialization section".\n */ // Qt #include #include #include #include #include // Project #include "maintimer.h" #include "caninterface.h" #include "frameinterface.h" #include "messageacknowmodel.h" #include "messagedispatcher.h" #include "applicationcontroller.h" #include "guicontroller.h" #include "logger.h" #include "usbwatcher.h" #include "threads.h" #include "filehandler.h" #include /*! * \brief signalhandler * \details When application terminates it quits gracefully. * \param sig - The Linux signal causes the termination. */ void signalhandler(int sig) { if (sig == SIGINT) { qDebug() << QObject::tr("Application terminated by SIGINT"); qApp->quit(); } else if (sig == SIGTERM) { qDebug() << QObject::tr("Application terminated by SIGTERM"); qApp->quit(); } } int gFakeInterval; QByteArray gFakeData; bool gConsoleoutFrameInterface = false; bool gConsoleoutCanInterface = false; /*! * \brief enableFakeTestData * \details reads the test.dat from the application folder and sets the global variables * also regarding the command line arguments passed to the application sets the console out. */ void enableFakeTestData() { QString mContent; QString mTestDat = QApplication::applicationDirPath() + "/test.dat"; qDebug() << mTestDat; if (Storage::FileHandler::read(mTestDat, mContent)) { QStringList mLines = mContent.split('\n'); if (mLines.count() > 1) { bool ok = false; QString mInterval = mLines[0]; int interval = mInterval.toInt(&ok); if (ok) { gFakeInterval = interval; } gFakeData = mLines[1].toLatin1(); gFakeData = QByteArray::fromHex(gFakeData); qDebug() << " ~~ !!!!! APPLICATION RUNNING IN THE TEST MODE !!!!! ~~ " ; LOG_EVENT(" \n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ " " \n ~~ !!!!! APPLICATION RUNNING IN THE TEST MODE !!!!! ~~ " " \n ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ "); } } QStringList args = qApp->arguments(); if (args.length() >= 2) { gConsoleoutFrameInterface = args[1] == "1"; } if (args.length() >= 3) { gConsoleoutCanInterface = args[2] == "1"; } } #ifdef UNIT_TEST #include TEST_CLASS_INCLUDE QTEST_MAIN(TEST_CLASS_NAME) #else /*! \brief Application Initialization\n * Some part of the application need to be initialized out of any thread. * So is initialized here to be initialized in the main thread. * this section also includes: */ int main(int argc, char *argv[]) { #ifndef SQUISH_COCO_BULD signal(SIGINT , signalhandler); signal(SIGTERM, signalhandler); #endif //! - Qt Application initialization and parameters settings // Qt Core Application parameters settings QApplication::setApplicationName(QLatin1String("Denali")); QApplication::setOrganizationName(QLatin1String("Diality Inc.")); //! - Check the required font(s) present and can be loaded QApplication::setFont(QFont("Barlow")); // Qt Core Application Initialization QApplication app(argc, argv); app.thread()->setObjectName("Main Thread"); //! - 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)); //! - Translation initialization QTranslator translator; bool trLoaded = translator.load(QLocale(), app.applicationName(), QLatin1String("_"), QLatin1String(":/translations")); if (trLoaded) { app.installTranslator(&translator); } //! - Initializing required thread types Threads::registerTypes(); //! - Initializing Logger _Logger.init(Threads::_Logger_Thread); LOG_EVENT(QObject::tr("Application Started")); // Test code for debugging can messages enableFakeTestData(); //! - Initializing USB Watcher _USBWatcher.init(Threads::_USBWatcher_Thread); //! - Initializing CanBus Interface if (_CanInterface.init(Threads::_CanFrame_Thread)) { _CanInterface.enableConsoleOut(gConsoleoutCanInterface); } //! - Initializing CanBus Message Handler _FrameInterface.init(Threads::_CanFrame_Thread); //! - Initializing the CanBus Message Acknowledgment Model _MessageAcknowModel.init(Threads::_CanAcknow_Thread); //! - Initializing CanBus Message Dispatcher if (_MessageDispatcher.init(Threads::_CanMessage_Thread)) { _MessageDispatcher.enableConsoleOut(gConsoleoutFrameInterface); } //! - Initializing Application Controller _ApplicationController.init(Threads::_Application_Thread); ////! - Initializing GUI Controller _GuiController.init(Threads::_Application_Thread); //! - Initializing Main Timer _MainTimer.init(); //! - Initialize the Qml Viewer and starts GUI startGui(); 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. _CanInterface.quitDevice(); Threads::quitThreads(); return app_exec; } #endif