Index: sources/canbus/caninterface.h =================================================================== diff -u -r9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d -rc933552983a659ca4cc351ff4d43d07319adab1e --- sources/canbus/caninterface.h (.../caninterface.h) (revision 9a3ee027dbc33f39ee7df2a9dc5a7897c6b1854d) +++ sources/canbus/caninterface.h (.../caninterface.h) (revision c933552983a659ca4cc351ff4d43d07319adab1e) @@ -23,54 +23,83 @@ // Define #define _CanInterface CanInterface::I() +// forward declarations +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 ::tst_canbus; + // constants - const char *_canType = "socketcan"; - const char *_canInterface = "can0"; - const int _canBitRate = 250000; + 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) + SINGLETON_DECL(CanInterface) public: bool init(); void quit(); QString status() const; - + void enableConsoleOut(bool vEnabled) { _enableConsoleOut = vEnabled; } private: - void connection(); + void initConnections(); - void status(const QString &vDescription, QString vError = ""); - void send(const QCanBusFrame &vFrame); + 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); }; }