Index: denali.pro.user =================================================================== diff -u -rc2d5f189c024f35e6b53032b58fba51100822c41 -r4836b003eb45d7f8cb98ea4c7999d068f0beb0d2 --- denali.pro.user (.../denali.pro.user) (revision c2d5f189c024f35e6b53032b58fba51100822c41) +++ denali.pro.user (.../denali.pro.user) (revision 4836b003eb45d7f8cb98ea4c7999d068f0beb0d2) @@ -1,14 +1,14 @@ - + EnvironmentId {67370740-e20f-4fc6-be45-6652e866a8bf} ProjectExplorer.Project.ActiveTarget - 1 + 0 ProjectExplorer.Project.EditorSettings @@ -68,7 +68,7 @@ Qt 5.12.5 (iMX8) Qt 5.12.5 (iMX8) {5d6458ef-f917-4aef-a092-c77bbe106149} - 1 + 0 0 0 @@ -359,6 +359,7 @@ false false true + false false @@ -999,7 +1000,7 @@ true false - /home/denali/Project/tmp/build/denali-Desktop_Qt_5_12_5_GCC_64bit-Debug + 1 Index: sources/canbus/caninterface.cpp =================================================================== diff -u -rfd4648bc7ac8d86b125053e33419779493741afe -r4836b003eb45d7f8cb98ea4c7999d068f0beb0d2 --- sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision fd4648bc7ac8d86b125053e33419779493741afe) +++ sources/canbus/caninterface.cpp (.../caninterface.cpp) (revision 4836b003eb45d7f8cb98ea4c7999d068f0beb0d2) @@ -22,11 +22,6 @@ #include "messageglobals.h" #include "frameinterface.h" -// stl -#include - -#define FrameCount_MAX UINT64_MAX - // namespace using namespace Can; @@ -270,7 +265,7 @@ * \details count received frames up the size of the FrameCount type size * \return frame count */ -CanInterface::FrameCount CanInterface::rxCount() +FrameCount CanInterface::rxCount() { if ( _rxFrameCount <= FrameCount_MAX ) { ++_rxFrameCount; @@ -285,7 +280,7 @@ * \details count transmitted frames up the size of the FrameCount type size * \return frame count */ -CanInterface::FrameCount CanInterface::txCount() +FrameCount CanInterface::txCount() { if ( _txFrameCount <= FrameCount_MAX ) { ++_txFrameCount; @@ -354,6 +349,8 @@ } else { mFrameCount = vFramesCount - (FrameCount_MAX - vFramesCount); } + qDebug() << "0 - Frame written #" << mFrameCount; + emit didFrameWritten(vFramesCount); } /*! Index: sources/canbus/caninterface.h =================================================================== diff -u -r94f7349bd073a732dba5295250fc0e26f740743c -r4836b003eb45d7f8cb98ea4c7999d068f0beb0d2 --- sources/canbus/caninterface.h (.../caninterface.h) (revision 94f7349bd073a732dba5295250fc0e26f740743c) +++ sources/canbus/caninterface.h (.../caninterface.h) (revision 4836b003eb45d7f8cb98ea4c7999d068f0beb0d2) @@ -19,6 +19,7 @@ // Project #include "main.h" +#include "messageglobals.h" // Define #define _CanInterface Can::CanInterface::I() @@ -60,7 +61,6 @@ QThread *_thread = nullptr; bool _init = false; - typedef quint64 FrameCount; FrameCount _rxFrameCount = 0; FrameCount _txFrameCount = 0; @@ -120,12 +120,14 @@ */ void didFrameTransmit(bool ok); + void didFrameWritten(qint64 vCount); + public slots: private slots: void onFrameTransmit (const QCanBusFrame &vFrame); void onFrameReceive (); void onFrameError (QCanBusDevice::CanBusError vError); - void onFrameWritten (qint64 vFramesCount); + void onFrameWritten (qint64 vFramesCount); }; } Index: sources/canbus/frameinterface.cpp =================================================================== diff -u -r805119c460b4a266d6401c8705f4427e7fbe270f -r4836b003eb45d7f8cb98ea4c7999d068f0beb0d2 --- sources/canbus/frameinterface.cpp (.../frameinterface.cpp) (revision 805119c460b4a266d6401c8705f4427e7fbe270f) +++ sources/canbus/frameinterface.cpp (.../frameinterface.cpp) (revision 4836b003eb45d7f8cb98ea4c7999d068f0beb0d2) @@ -16,6 +16,7 @@ // Qt #include #include +#include // Project #include "logger.h" @@ -44,6 +45,9 @@ initConnections(); + startTimer(10); + + LOG_EVENT(QObject::tr("%1 Initialized").arg(metaObject()->className())); return true; @@ -91,6 +95,10 @@ // From CAN connect(&_CanInterface , SIGNAL( didFrameReceive( const QCanBusFrame &)), this , SLOT( onFrameReceive( const QCanBusFrame &))); + + connect(&_CanInterface , SIGNAL( didFrameWritten(qint64 )), + this , SLOT( onFrameWritten(qint64 ))); + } /*! @@ -140,6 +148,9 @@ */ void FrameInterface::transmitFrame(Can_Id vFrameId, const QByteArray &vData) { + qDebug() << " + " << _fc; + ++_fc; + qDebug() << " + " << _fc; QCanBusFrame mFrame; mFrame.setFrameId(vFrameId); if (vData.length() > Can::eLenCanFrame) { @@ -181,7 +192,7 @@ case eChlid_UI_Alarm : case eChlid_UI_Sync : - //case eChlid_UI_DG : + //case eChlid_UI_DG : channelGroup = ChannelGroup::eChannel_Outputs; break; @@ -204,9 +215,52 @@ */ void FrameInterface::onFrameTransmit(Can_Id vCan_Id, const QByteArray &vData) { - transmitFrame(vCan_Id, vData); + //QMutexLocker locker(&_mutexTransmit1); + QString mtime = QTime::currentTime().toString("HH:mm:ss.zzz"); + _frameList.append(Frame(vCan_Id, vData)); + qDebug() << mtime << "1 - Send Queued #" << _frameList.count(); + + //transmitFrame(vCan_Id, vData); + + //qDebug() << " ~ " << _fc; + //if ( _waitSend ) { + // _frameList.append(Frame(vCan_Id, vData)); + // qDebug() << mtime << "2 - Send postponed #" << _frameList.count(); + //} else { + // if (_frameList.isEmpty()) { + // transmitFrame(vCan_Id, vData); + // qDebug() << mtime << "1 - Send immediate #" << _frameList.count(); + // } else { + // Frame frame = _frameList.first(); + // transmitFrame(frame.can_Id, frame.data); + // qDebug() << mtime << "3 - Send From Q #" << _frameList.count(); + // } + //} + //qDebug() << " ~ " << _fc; } +void FrameInterface::onFrameWritten(qint64 vCount) +{ + //QMutexLocker locker(&_mutexTransmit2); + QString mtime = QTime::currentTime().toString("HH:mm:ss.zzz"); + qDebug() << mtime << "4 - Send frame #" << _frameList.count() << vCount; + if (!_frameList.isEmpty()) _frameList.removeFirst(); + // qDebug() << " - " << _fc; + // _fc -= vCount; + // qDebug() << " - " << _fc; +} + +void FrameInterface::timerEvent(QTimerEvent *) +{ + //QMutexLocker locker(&_mutexTransmit3); + //transmitFrame(eChlid_LOWEST, QByteArray()); + if (_frameList.isEmpty()) return; + QString mtime = QTime::currentTime().toString("HH:mm:ss.zzz"); + Frame frame = _frameList.first(); + transmitFrame(frame.can_Id, frame.data); + qDebug() << mtime << "2 - Send From Q #" << _frameList.count(); +} + /*! * \brief FrameInterface::onFrameReceive * \details This the slot connected to the CanInterface didFrameReceive signal. Index: sources/canbus/frameinterface.h =================================================================== diff -u -r805119c460b4a266d6401c8705f4427e7fbe270f -r4836b003eb45d7f8cb98ea4c7999d068f0beb0d2 --- sources/canbus/frameinterface.h (.../frameinterface.h) (revision 805119c460b4a266d6401c8705f4427e7fbe270f) +++ sources/canbus/frameinterface.h (.../frameinterface.h) (revision 4836b003eb45d7f8cb98ea4c7999d068f0beb0d2) @@ -16,6 +16,7 @@ // Qt #include #include +#include // Project #include "main.h" @@ -60,6 +61,23 @@ 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 _frameList; + bool _waitSend = false; + QMutex _mutexTransmit1; + QMutex _mutexTransmit2; + QMutex _mutexTransmit3; + qint64 _fc = 0; + + // Singleton SINGLETON(FrameInterface) @@ -82,6 +100,7 @@ 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: /*! @@ -108,5 +127,7 @@ * \param vFrame - The frame which has been created to be transmitted. */ void didFrameTransmit( const QCanBusFrame &vFrame ); // GUI => CAN +protected: + void timerEvent(QTimerEvent *); }; } Index: sources/canbus/messageglobals.h =================================================================== diff -u -rc2d5f189c024f35e6b53032b58fba51100822c41 -r4836b003eb45d7f8cb98ea4c7999d068f0beb0d2 --- sources/canbus/messageglobals.h (.../messageglobals.h) (revision c2d5f189c024f35e6b53032b58fba51100822c41) +++ sources/canbus/messageglobals.h (.../messageglobals.h) (revision 4836b003eb45d7f8cb98ea4c7999d068f0beb0d2) @@ -30,6 +30,11 @@ typedef Types::S16 Sequence_Bytes; #define SEQUENCE_MAX INT16_MAX +// stl +#include +#define FrameCount_MAX UINT64_MAX +typedef quint64 FrameCount; + /*! * \brief Payload Length * \details List of each ActionID required data (in byte) length in the message. @@ -81,6 +86,8 @@ * \details The Valid Can Bus MessageID of each frame */ enum Can_Id : quint16 { + eChlid_LOWEST = 0x7FF, + eChlid_NONE = 0x000, // Broadcasts //// Alarm