Index: sources/canbus/caninterface.cpp =================================================================== diff -u -r057d3ef4e29c63235040c5cfe8c6421ef7787d6a -r44a85c96ab55e424866ec4cca0270aa218355f82 --- sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision 057d3ef4e29c63235040c5cfe8c6421ef7787d6a) +++ sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision 44a85c96ab55e424866ec4cca0270aa218355f82) @@ -1,30 +1,31 @@ -/*! - * - * 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 caninterface.cpp - * \date 2019/09/30 - * \author Behrouz NematiPour - * - */ +/*! + * + * Copyright (c) 2019-2020 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-May-2020 + * \author (original) Behrouz NematiPour + * \date (original) 28-Oct-2019 + * + */ #include "caninterface.h" // Qt #include #include +// stl +#include + // Project #include "logger.h" #include "messageglobals.h" #include "frameinterface.h" -// stl -#include - // namespace using namespace Can; @@ -46,7 +47,9 @@ if ( _init ) return false; _init = true; + // coco begin validated: Manually tested since required to disable and enable the canbus if ( ! initDevice() ) return false; + // coco end if ( ! testDevice() ) return false; initConnections(); @@ -68,7 +71,9 @@ */ bool CanInterface::init(QThread &vThread) { + // coco begin validated: Manually tested since required to disable and enable the canbus if ( ! init() ) return false; + // coco end initThread(vThread); return true; } @@ -82,7 +87,7 @@ { // coco begin validated: Application termination is not correctly done in coco!!! // it has been tested and works perfectly fine in normal run. - quitThread(); + quitThread(); // verified } // coco end @@ -103,7 +108,9 @@ */ void CanInterface::initConnections() { + // coco begin validated: Manually tested since required to disable and enable the canbus if (_canDevice) { + // coco end connect(_canDevice, SIGNAL( framesReceived()), this , SLOT (onFrameReceive ())); @@ -148,7 +155,7 @@ if (! _thread) return; // runs in thread - moveToThread(qApp->thread()); + moveToThread(qApp->thread()); // verified } // coco end @@ -161,11 +168,13 @@ { QString mError; _canDevice = QCanBus::instance()->createDevice(_canType, _canInterface, &mError); + // coco begin validated: Manually tested since required to disable and enable the canbus if (!_canDevice) { status(tr("Device Creation"), mError); LOG_ERROR(status()); return false; } + // coco end return true; } @@ -192,8 +201,9 @@ */ void CanInterface::quitDevice() { - if (!_canDevice) - return; + // coco begin validated: Manually tested since required to disable and enable the canbus + if (!_canDevice) return; + // coco end _canDevice->disconnectDevice(); delete _canDevice; _canDevice = nullptr; @@ -231,8 +241,9 @@ */ bool CanInterface::transmit(const QCanBusFrame &vFrame) { - if( !_canDevice ) - return false; + // coco begin validated: Manually tested since required to disable and enable the canbus + if( !_canDevice ) return false; + //coco end return _canDevice->writeFrame(vFrame); } @@ -244,6 +255,7 @@ */ void CanInterface::consoleOut(const QCanBusFrame &vFrame, const QString &vFrameCount) { + // coco begin validated: This code is only for debugging purposes and had been tested manually. if ( ! _enableConsoleOut ) return; LOG_EVENT_ONCE(QObject::tr("console out CanInterface Enabled")); @@ -261,6 +273,7 @@ } fprintf(stderr, "%s %s %s %i %s\n", vFrameCount.toLatin1().constData(), time.toLatin1().constData(), flags.toLatin1().constData(), vFrame.frameId(), view.toLatin1().constData()); } +// coco end /*! * \brief CanInterface::rxCount @@ -291,8 +304,11 @@ */ FrameCount CanInterface::erCount() { + // 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 } /*! @@ -303,6 +319,8 @@ */ QString CanInterface::frameFlags(const QCanBusFrame &vFrame) { + // 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(" --- "); if (vFrame.hasBitrateSwitch()) @@ -313,6 +331,7 @@ result[3] = QLatin1Char('L'); return result; + // coco end } /*! @@ -322,6 +341,8 @@ */ void CanInterface::onFrameError(QCanBusDevice::CanBusError vError) { + // 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) { case QCanBusDevice::ReadError: @@ -339,6 +360,7 @@ } emit didFrameError(_canStatus); } +// coco end /*! * \brief CanInterface::onFrameWritten @@ -361,13 +383,16 @@ */ void CanInterface::onFrameReceive () { - if (!_canDevice) - return; + // coco begin validated: Manually tested since required to disable and enable the canbus + if (!_canDevice) return; + // 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. if ( _enableConsoleOut ) consoleOut(frame, QString("Rx:%1").arg(_rxFrameCount)); + // coco end emit didFrameReceive(frame); } } @@ -382,7 +407,9 @@ { bool ok = transmit(vFrame); txCount(); + // 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 emit didFrameTransmit(ok); }