Index: sources/canbus/caninterface.h =================================================================== diff -u -rf623529d6ec25b555f3ac2248d71fc2b5e7063d6 -r38e28c4551df41f9323678ce16f5ba35bb5bb855 --- sources/canbus/caninterface.h (.../caninterface.h) (revision f623529d6ec25b555f3ac2248d71fc2b5e7063d6) +++ sources/canbus/caninterface.h (.../caninterface.h) (revision 38e28c4551df41f9323678ce16f5ba35bb5bb855) @@ -1,6 +1,6 @@ /*! * - * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. + * Copyright (c) 2019-2019 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 @@ -21,62 +21,103 @@ #include "main.h" // Define -#define _CanInterface CanInterface::I() +#define _CanInterface Can::CanInterface::I() // forward declarations -class unittests; +class tst_canbus; // namespace namespace Can { /*! - * \brief CanBus interface - * \details This class contains the interface to CanBus\n - * And utilizes Qt QCanBus to interact with the CanBus\n - * On the OS side there is a driver installed to convert SPI to CAN\n - * Since the GUI Board by itself doesn't contain the CAN Bus. + * \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 ::unittests; + friend class ::tst_canbus; // constants const char *_canType = "socketcan"; QString _canInterface = "can0"; const int _canBitRate = 250000; // member variables - QCanBusDevice *_canDevice = nullptr; + QCanBusDevice *_canDevice = nullptr; qint64 _numberFramesWritten = 0; - QString _canStatus = ""; + QString _canStatus = ""; + bool _enableConsoleOut = false; - // Singleton - SINGLETON_DECL(CanInterface) -public: + QThread *_thread = nullptr; + bool _init = false; + +// Singleton +SINGLETON(CanInterface) + +public slots: bool init(); + bool init(QThread &vThread); + +private slots: void quit(); +public: QString status() const; + void enableConsoleOut(bool vEnabled) { _enableConsoleOut = vEnabled; } + void quitDevice(); private: - void connection(); + void initConnections(); - void status(const QString &vDescription, QString vError = ""); - void send(const QCanBusFrame &vFrame); + 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); + + static QString frameFlags(const QCanBusFrame &vFrame); + signals: - void didRead (const QCanBusFrame &vFrame ); - void didError(const QString &vStatus); + /*! + * \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); + public slots: private slots: + void onFrameTransmit (const QCanBusFrame &vFrame); + void onFrameReceive (); + void onFrameError (QCanBusDevice::CanBusError vError); + void onFrameWrittern (qint64 vFramesCount); - void onActionPerform(const QCanBusFrame &vFrame); - void onActionRequest(const QCanBusFrame &vFrame); - void onRead (); - void onError(QCanBusDevice::CanBusError vError); }; }