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.