Index: sources/canbus/CanInterface.cpp =================================================================== diff -u -r64d87d540594252e8039ab2595016d98f1e3cc28 -r6c6f1f5d466badd9b4fd67be7c907234c342b2a2 --- sources/canbus/CanInterface.cpp (.../CanInterface.cpp) (revision 64d87d540594252e8039ab2595016d98f1e3cc28) +++ sources/canbus/CanInterface.cpp (.../CanInterface.cpp) (revision 6c6f1f5d466badd9b4fd67be7c907234c342b2a2) @@ -1,15 +1,15 @@ /*! * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * 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 CanInterface.cpp - * \author (last) Behrouz NematiPour - * \date (last) 07-Oct-2020 - * \author (original) Behrouz NematiPour - * \date (original) 26-Aug-2020 + * \file CanInterface.cpp + * \author (last) Behrouz NematiPour + * \date (last) 18-Apr-2022 + * \author (original) Behrouz NematiPour + * \date (original) 26-Aug-2020 * */ #include "CanInterface.h" @@ -39,17 +39,17 @@ /*! * \brief CanInterface Initialization - * \details Initializes the CANBUS and checks if can be connected + * \details Initializes the CANBus and checks if can be connected * \return true if connected, false otherwise */ bool CanInterface::init() { if ( _init ) return false; _init = true; - // coco begin validated: Manually tested since required to disable and enable the CANBus + // disabled coco begin validated: Manually tested since required to disable and enable the CANBus if ( ! initDevice() ) return false; - // coco end + // disabled coco end if ( ! testDevice() ) return false; initConnections(); @@ -58,7 +58,7 @@ QString logMessage = QString("UI,%1,%2") .arg(tr("%1 Initialized").arg(metaObject()->className())) .arg(status()); - LOG_EVENT(logMessage); + LOG_DEBUG(logMessage); return true; } @@ -73,9 +73,9 @@ */ bool CanInterface::init(QThread &vThread) { - // coco begin validated: Manually tested since required to disable and enable the CANBus + // disabled coco begin validated: Manually tested since required to disable and enable the CANBus if ( ! init() ) return false; - // coco end + // disabled coco end initThread(vThread); return true; } @@ -87,11 +87,11 @@ */ void CanInterface::quit() { - // coco begin validated: Application termination is not correctly done in coco!!! + // disabled coco begin validated: Application termination is not correctly done in coco!!! // it has been tested and works perfectly fine in normal run. quitThread(); // verified } -// coco end +// disabled coco end /*! * \brief CanInterface status @@ -109,7 +109,7 @@ * \param vEnabled - Enable console output if true */ void CanInterface::enableConsoleOut(bool vEnabled) { - // coco begin validated: This code meant to be used only for debugging and tested manually + // disabled coco begin validated: This code meant to be used only for debugging and tested manually if (_enableConsoleOut == vEnabled) return; _enableConsoleOut = vEnabled; if (_enableConsoleOut) { @@ -118,7 +118,7 @@ LOG_DEBUG("Console out CanInterface disabled"); } } -// coco end +// disabled coco end /*! * \brief CanInterface connections definition @@ -127,9 +127,9 @@ */ void CanInterface::initConnections() { - // coco begin validated: Manually tested since required to disable and enable the CANBus + // disabled coco begin validated: Manually tested since required to disable and enable the CANBus if (_canDevice) { - // coco end + // disabled coco end connect(_canDevice, SIGNAL( framesReceived()), this , SLOT (onFrameReceive ())); @@ -163,37 +163,39 @@ /*! * \brief CanInterface::quitThread - * \details Moves this object to main thread to be handled by QApplicaiton + * \details Moves this object to main thread to be handled by QApplication * And to be destroyed there. */ void CanInterface::quitThread() { - // coco begin validated: Application termination is not correctly done in coco!!! + // disabled coco begin validated: Application termination is not correctly done in coco!!! // it has been tested and works perfectly fine in normal run. if (! _thread) return; // runs in thread moveToThread(qApp->thread()); // verified } -// coco end +// disabled coco end /*! * \brief CanInterface::createDevice * \details Creates the CANBus device - * \return false if can't create the device + * \return false if cannot create the device */ bool CanInterface::initDevice() { QString mError; _canDevice = QCanBus::instance()->createDevice(_canType, _canInterface, &mError); - // coco begin validated: Manually tested since required to disable and enable the CANBus + // disabled coco begin validated: Manually tested since required to disable and enable the CANBus if (!_canDevice) { status(tr("Device Creation"), mError); LOG_DEBUG(status()); return false; } - // coco end + // disabled coco end + _canDevice->setConfigurationParameter(QCanBusDevice::CanFdKey , _canFDKey ); + _canDevice->setConfigurationParameter(QCanBusDevice::BitRateKey , _canBitRate ); return true; } @@ -220,9 +222,9 @@ */ void CanInterface::quitDevice() { - // coco begin validated: Manually tested since required to disable and enable the CANBus + // disabled coco begin validated: Manually tested since required to disable and enable the CANBus if (!_canDevice) return; - // coco end + // disabled coco end _canDevice->disconnectDevice(); delete _canDevice; _canDevice = nullptr; @@ -232,8 +234,8 @@ /*! * \brief CanInterface status * \details Sets the Can interface status description - * \param vDescription - Description about the CANBUS Interface errors - * \param vError - Qt CANBUS Interface Error + * \param vDescription - Description about the CANBus Interface errors + * \param vError - Qt CANBus Interface Error */ void CanInterface::status(const QString &vDescription, QString vError) { @@ -250,31 +252,30 @@ .arg(_canInterface) .arg(mError) ; - qDebug() << _canStatus; } /*! * \brief CanInterface send - * \details send a frame over the CANBUS - * \param vFrame - CANBUS message frame + * \details send a frame over the CANBus + * \param vFrame - CANBus message frame */ bool CanInterface::transmit(const QCanBusFrame &vFrame) { - // coco begin validated: Manually tested since required to disable and enable the CANBus + // disabled coco begin validated: Manually tested since required to disable and enable the CANBus if( !_canDevice ) return false; - //coco end + //disabled coco end return _canDevice->writeFrame(vFrame); } /*! * \brief CanInterface console Output messaging - * \details Sends out formatted CANBUS message to the console + * \details Sends out formatted CANBus message to the console * for debugging purposes. - * \param vFrame - The CANBUS frame to be sent out + * \param vFrame - The CANBus frame to be sent out */ void CanInterface::consoleOut(const QCanBusFrame &vFrame, const QString &vFrameCount) { - // coco begin validated: This code is only for debugging purposes and had been tested manually. + // disabled coco begin validated: This code is only for debugging purposes and had been tested manually. if ( ! _enableConsoleOut ) return; const QString time = QString::fromLatin1("%1.%2 ") @@ -288,9 +289,10 @@ else { view = vFrame.payload().toHex('.').replace(QByteArray("a5"),QByteArray("\033[1;33mA5\033[0m")); } + // the fprintf is used for the colored output fprintf(stderr, "%s %s %s %i %s\n", vFrameCount.toLatin1().constData(), time.toLatin1().constData(), flags.toLatin1().constData(), vFrame.frameId(), view.toLatin1().constData()); } -// coco end +// disabled coco end /*! * \brief CanInterface::rxCount @@ -321,22 +323,22 @@ */ FrameCount CanInterface::erCount() { - // coco begin validated: CANBus error handling has been tested manually. + // disabled coco begin validated: CANBus error handling has been tested manually. // since it requires massive can messages sent/received to catch the error Types::safeIncrement(_erFrameCount); return _erFrameCount; - // coco end + // disabled coco end } /*! * \brief frameFlags - * \details CANBUS message frame type as flags - * \param vFrame - CANBUS message frame + * \details CANBus message frame type as flags + * \param vFrame - CANBus message frame * \return Frame flag as QString */ QString CanInterface::frameFlags(const QCanBusFrame &vFrame) { - // coco begin validated: CANBus error handling has been tested manually. + // disabled coco begin validated: CANBus error handling has been tested manually. // since it requires massive can messages sent/received to catch the error QString result = QLatin1String(" --- "); @@ -348,17 +350,17 @@ result[3] = QLatin1Char('L'); return result; - // coco end + // disabled coco end } /*! * \brief CanInterface onError - * \details Can Bus error handler which sets the can status description - * \param vError - CANBUS error + * \details CANBus error handler which sets the can status description + * \param vError - CANBus error */ void CanInterface::onFrameError(QCanBusDevice::CanBusError vError) { - // coco begin validated: CANBus error handling has been tested manually. + // disabled coco begin validated: CANBus error handling has been tested manually. // since it requires massive can messages sent/received to catch the error erCount(); switch (vError) { @@ -380,13 +382,13 @@ } emit didFrameError(_canStatus); } -// coco end +// disabled coco end /*! * \brief CanInterface::onFrameWritten * \details This is the slot connected to the signal * which is emitted every time a payload of frames - * has been written to the CANBUS bus. + * has been written to the CANBus bus. * \param vFramesCount - The framesCount argument is set to the number of frames * that were written in this payload. */ @@ -399,37 +401,37 @@ /*! * \brief CanInterface onFrameReceived - * \details CANBUS message read handler + * \details CANBus message read handler */ void CanInterface::onFrameReceive () { - // coco begin validated: Manually tested since required to disable and enable the CANBus + // disabled coco begin validated: Manually tested since required to disable and enable the CANBus if (!_canDevice) return; - // coco end + // disabled coco end while (_canDevice->framesAvailable()) { const QCanBusFrame frame = _canDevice->readFrame(); rxCount(); - // coco begin validated: This code is only for debugging purposes and had been tested manually. + // disabled coco begin validated: This code is only for debugging purposes and had been tested manually. if ( _enableConsoleOut ) consoleOut(frame, QString("Rx:%1").arg(_rxFrameCount)); - // coco end + // disabled coco end emit didFrameReceive(frame); } } /*! * \brief CanInterface onActionPerform - * \details sends a CANBUS message frame of the CANBUS message of the performed action + * \details sends a CANBus message frame of the CANBus message of the performed action * This is a response from application UI to HD device - * \param vFrame - CANBUS message frame + * \param vFrame - CANBus message frame */ void CanInterface::onFrameTransmit(const QCanBusFrame &vFrame) { bool ok = transmit(vFrame); txCount(); - // coco begin validated: This code is only for debugging purposes and had been tested manually. + // disabled coco begin validated: This code is only for debugging purposes and had been tested manually. if ( _enableConsoleOut ) consoleOut(vFrame, QString("Tx:%1").arg(_txFrameCount)); - // coco end + // disabled coco end emit didFrameTransmit(ok); }