/*! * * 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 frameinterface.h * date 10/26/2019 * author Behrouz NematiPour * */ #pragma once // Qt #include #include // Project #include "main.h" #include "messageglobals.h" // Define #define _FrameInterface Can::FrameInterface::I() // forward declarations class tst_canbus; class tst_acknow; // namespace namespace Can { /*! * \brief The FrameInterface class * \details This class is an interface between QByteArray and QCanBusFrame * and gets the data as QByteArray and creates a frame * and sends it to the CanInterface to deal with the CANBUS. * And does it in reverse when receives a frame from CanInterface. */ class FrameInterface : public QObject { Q_OBJECT // friends friend class ::tst_canbus; friend class ::tst_acknow; /*! * \brief The ChannelGroup enum * \details The enum which represent the categories of the CANBUS channel */ enum class ChannelGroup { eChannel_Unknown, ///< An Unknown channels category eChannel_Ignores, ///< The Channels which will be ignored by UI eChannel_Listens, ///< The Channels that UI is listening to eChannel_Outputs, ///< The Channels that are related to UI frames out. }; QThread *_thread = nullptr; bool _init = false; struct Frame { Can_Id can_Id; QByteArray data ; Frame(Can_Id vCan_Id, const QByteArray &vData) { can_Id = vCan_Id; data = vData ; } }; QList _txFrameList; const quint16 _txFrameList_Max = 4000; // maximum number of frames in the transmit buffer bool _transmitted = false; const quint8 _interval = 7; // keep awake call of the UI board in ms QString _timestamp; // Singleton SINGLETON(FrameInterface) protected: void timerEvent(QTimerEvent *); public slots: bool init(); bool init(QThread &vThread); private slots: void quit(); private: void initConnections(); void initThread(QThread &vThread); void quitThread(); ChannelGroup checkChannel(quint32 vFrameId, bool *vOK = nullptr); void transmitFrame (Can_Id vCan_Id, const QByteArray &vData = 0); void appendHead (Can_Id vCan_Id, const QByteArray &vData ); void trnsmtHead (); void removeHead (); private slots: // Should be private for thread safety and is connected internally. void onFrameTransmit(Can_Id vCan_Id, const QByteArray &vData ); // GUI => CAN void onFrameReceive ( const QCanBusFrame &vFrame ); // GUI <= CAN void onFrameWritten (qint64 vCount ); // GUI <= CAN signals: /*! * \brief didFrameReceive * \details After CanInterface receives a frame notifies FrameInterface * by emitting CanInterface::didFrameReceive signal, * then Message Handler calls its slot FrameInterface::onFrameReceive to handle the message, * And when the message has been processed vCan_Id of type Can_Id which is the Channel ID of the frame * and vPayload of the frame of type QByteArray has been extracted, * This signal will be emitted to notify MessageDispatcher to start collecting data * for this message over this channel. * \param vCan_Id - Channel Id of the frame. * \param vPayload - Payload of the frame. */ void didFrameReceive (Can_Id vCan_Id, const QByteArray &vPayload); // GUI <= CAN /*! * \brief didFrameTransmit * \details After MessageDispatcher requests FrameInterface to transmit a message, * And FrameInterface calls its slot FrameInterface::onFrameTransmit to handle the message, * And when the message has been processed and a Frame has been created, * this signal will be emitted to notify CanInterface to send the frame. * \ref CanInterface::onFrameTransmit * \param vFrame - The frame which has been created to be transmitted. */ void didFrameTransmit( const QCanBusFrame &vFrame ); // GUI => CAN }; }