Index: sources/canbus/caninterface.h =================================================================== diff -u -rd2035a8728794afeefaa244bf8d1597926d945f5 -r618891879f5cdc68e37ee68eea005afb76dd4e5b --- sources/canbus/caninterface.h (.../caninterface.h) (revision d2035a8728794afeefaa244bf8d1597926d945f5) +++ sources/canbus/caninterface.h (.../caninterface.h) (revision 618891879f5cdc68e37ee68eea005afb76dd4e5b) @@ -1,144 +1,144 @@ /*! - * + * * 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.h * \author (last) Behrouz NematiPour * \date (last) 02-Mar-2020 * \author (original) Behrouz NematiPour * \date (original) 28-Oct-2019 - * + * */ -#pragma once - -// Qt -#include -#include - -// Project -#include "main.h" -#include "messageglobals.h" - - -// Define -#define _CanInterface Can::CanInterface::I() - -// forward declarations -class tst_canbus; -class tst_acknow; - -// namespace -namespace Can { - -/*! - * \brief CANBUS interface - * \details This class contains the interface to CANBUS - * And utilizes Qt QCanBus to interact with the CANBUS - * This class works only with the QCanBusFrame frames. - * On the OS side there is a driver installed to convert SPI to CAN - * Since the GUI Board by itself doesn't contain the CAN Bus. - * Application would know nothing about the SPI-TO-CAN - */ -class CanInterface : public QObject -{ - Q_OBJECT - - // friends - friend class ::tst_canbus; - friend class ::tst_acknow; - - // constants - const char *_canType = "socketcan"; - QString _canInterface = "can0"; - const int _canBitRate = 250000; - - // member variables - QCanBusDevice *_canDevice = nullptr; - QString _canStatus = ""; - bool _enableConsoleOut = false; - - QThread *_thread = nullptr; - bool _init = false; - - FrameCount _rxFrameCount = 0; - FrameCount _txFrameCount = 0; - FrameCount _erFrameCount = 0; - -// Singleton -SINGLETON(CanInterface) - -public slots: - bool init(); - bool init(QThread &vThread); - -private slots: - void quit(); - -public: - QString status() const; - void enableConsoleOut(bool vEnabled); - - void quitDevice(); -private: - void initConnections(); - - void initThread(QThread &vThread); - void quitThread(); - - bool initDevice(); - bool testDevice(); - - void status (const QString &vDescription, QString vError = ""); - bool transmit (const QCanBusFrame &vFrame); - void consoleOut (const QCanBusFrame &vFrame, const QString &vFrameCount); - - FrameCount rxCount(); - FrameCount txCount(); - FrameCount erCount(); - - static QString frameFlags(const QCanBusFrame &vFrame); - -signals: - /*! - * \brief didFrameReceive - * \details This signal will be emitted when a frame has been received - * \param vFrame - The Frame which has been received - */ - void didFrameReceive (const QCanBusFrame &vFrame ); - - /*! - * \brief didFrameError - * \details If and error occurs on CanDevice after the error is processed - * this signal can be used as a notifier. - * \param vStatus - CanDevice status with some extra information. - */ - void didFrameError (const QString &vStatus); - - /*! - * \brief didFrameTransmit - * \details After the frame has been transmitted this signal can be used as a notifier. - * \param ok - is true if the frame has been transmitted successfully - */ - void didFrameTransmit(bool ok); - - /*! - * \brief didFrameWritten - * \details After the frame transmission is done - * and acknowledged by a node on the CANBus, - * this signal is emmited. - * \param vCount is the number of frame which has been written - */ - void didFrameWritten(qint64 vCount); - -public slots: -private slots: - void onFrameTransmit (const QCanBusFrame &vFrame); - void onFrameReceive (); - void onFrameError (QCanBusDevice::CanBusError vError); - void onFrameWritten (qint64 vFramesCount); - -}; -} +#pragma once + +// Qt +#include +#include + +// Project +#include "main.h" +#include "messageglobals.h" + + +// Define +#define _CanInterface Can::CanInterface::I() + +// forward declarations +class tst_canbus; +class tst_acknow; + +// namespace +namespace Can { + +/*! + * \brief CANBUS interface + * \details This class contains the interface to CANBUS + * And utilizes Qt QCanBus to interact with the CANBUS + * This class works only with the QCanBusFrame frames. + * On the OS side there is a driver installed to convert SPI to CAN + * Since the GUI Board by itself doesn't contain the CAN Bus. + * Application would know nothing about the SPI-TO-CAN + */ +class CanInterface : public QObject +{ + Q_OBJECT + + // friends + friend class ::tst_canbus; + friend class ::tst_acknow; + + // constants + const char *_canType = "socketcan"; + QString _canInterface = "can0"; + const int _canBitRate = 250000; + + // member variables + QCanBusDevice *_canDevice = nullptr; + QString _canStatus = ""; + bool _enableConsoleOut = false; + + QThread *_thread = nullptr; + bool _init = false; + + FrameCount _rxFrameCount = 0; + FrameCount _txFrameCount = 0; + FrameCount _erFrameCount = 0; + +// Singleton +SINGLETON(CanInterface) + +public slots: + bool init(); + bool init(QThread &vThread); + +private slots: + void quit(); + +public: + QString status() const; + void enableConsoleOut(bool vEnabled); + + void quitDevice(); +private: + void initConnections(); + + void initThread(QThread &vThread); + void quitThread(); + + bool initDevice(); + bool testDevice(); + + void status (const QString &vDescription, QString vError = ""); + bool transmit (const QCanBusFrame &vFrame); + void consoleOut (const QCanBusFrame &vFrame, const QString &vFrameCount); + + FrameCount rxCount(); + FrameCount txCount(); + FrameCount erCount(); + + static QString frameFlags(const QCanBusFrame &vFrame); + +signals: + /*! + * \brief didFrameReceive + * \details This signal will be emitted when a frame has been received + * \param vFrame - The Frame which has been received + */ + void didFrameReceive (const QCanBusFrame &vFrame ); + + /*! + * \brief didFrameError + * \details If and error occurs on CanDevice after the error is processed + * this signal can be used as a notifier. + * \param vStatus - CanDevice status with some extra information. + */ + void didFrameError (const QString &vStatus); + + /*! + * \brief didFrameTransmit + * \details After the frame has been transmitted this signal can be used as a notifier. + * \param ok - is true if the frame has been transmitted successfully + */ + void didFrameTransmit(bool ok); + + /*! + * \brief didFrameWritten + * \details After the frame transmission is done + * and acknowledged by a node on the CANBus, + * this signal is emitted. + * \param vCount is the number of frame which has been written + */ + void didFrameWritten(qint64 vCount); + +public slots: +private slots: + void onFrameTransmit (const QCanBusFrame &vFrame); + void onFrameReceive (); + void onFrameError (QCanBusDevice::CanBusError vError); + void onFrameWritten (qint64 vFramesCount); + +}; +}