/*! * * Copyright (c) 2020-2023 Diality Inc. - All Rights Reserved. * \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 MainTimer.cpp * \author (last) Behrouz NematiPour * \date (last) 28-Sep-2022 * \author (original) Behrouz NematiPour * \date (original) 26-Aug-2020 * */ #include "MainTimer.h" //Qt #include //Project #include "Logger.h" //#include "FileHandler.h" /*! * \brief MainTimer::MainTimer * \details Constructor * \param parent - QObject parent owner object. * Qt handles the children destruction by their parent objects life-cycle. */ MainTimer::MainTimer(QObject *parent) : QObject(parent) { } /*! * \brief MainTimer::init * \details starts the timer ans sets the timer interval * \return */ bool MainTimer::init() { // disabled coco begin validated: This is a fake data generator for CANBus missing/swapped frames Testing // will never be executed on the product // has been tested manually if (gFakeInterval) { startTimer(gFakeInterval); } // disabled coco end else { startTimer(_interval); } LOG_DEBUG(tr("%1 Initialized").arg(metaObject()->className())); return true; } /*! * \brief MainTimer::quit * \details Does nothing for now */ void MainTimer::quit() { } /*! * \brief MainTimer::isDateChanged * \details Checks the date has been changed * \return true if date changed. */ bool MainTimer::isDateChanged(bool vIncludeTime) { // old date // current date static int oy,om,od; int cy,cm,cd; // old time // current time static int oH,oM,oS; int cH,cM,cS; QDateTime::currentDateTime().date().getDate(&cy, &cm, &cd); // disabled coco begin validated: Decided to not to check each second // has been tested manually if (vIncludeTime) { QTime currentTime = QDateTime::currentDateTime().time(); cH = currentTime.hour(); cM = currentTime.minute(); cS = currentTime.second(); } if (oy == cy && om == cm && od == cd) { if (vIncludeTime) { if (oH == cH && oM == cM && oS == cS) { return false; } else { // date oy = cy; om = cm; od = cd; // time oH = cH; oM = cM; oS = cS; } // disabled coco end } else return false; } else { oy = cy; om = cm; od = cd; } return true; } /*! * \brief MainTimer::timerEvent * \details This event handler has been re-implemented in here * to receive timer events for the object * for the timer which has been set to _checkInterval * Emits the didTimeout signal on each interval. */ void MainTimer::timerEvent(QTimerEvent *) { #ifndef DISABLE_KEEP_ALIVE emit didTimeout(); #endif // I'm not sure how often we need to check for this. // if it needs to be checked each second pass true // if it needs to be checked each day pass false if (isDateChanged(false)) { emit didDateChange(); } }