/*! * * 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.h * \date 2019/09/30 * \author Behrouz NematiPour * */ #pragma once // Qt #include #include // Project #include "main.h" // Define #define _CanInterface CanInterface::I() // forward declarations class unittests; // 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. */ class CanInterface : public QObject { Q_OBJECT // friends friend class ::unittests; // constants const char *_canType = "socketcan"; QString _canInterface = "can0"; const int _canBitRate = 250000; // member variables QCanBusDevice *_canDevice = nullptr; qint64 _numberFramesWritten = 0; QString _canStatus = ""; // Singleton SINGLETON_DECL(CanInterface) public: bool init(); void quit(); QString status() const; private: void connection(); void status(const QString &vDescription, QString vError = ""); void send(const QCanBusFrame &vFrame); signals: void didRead (const QCanBusFrame &vFrame ); void didError(const QString &vStatus); public slots: private slots: void onActionPerform(const QCanBusFrame &vFrame); void onActionRequest(const QCanBusFrame &vFrame); void onRead (); void onError(QCanBusDevice::CanBusError vError); }; }