Index: sources/canbus/messagedispatcher.cpp =================================================================== diff -u -r0e87420e50dd94c37eb25f289ef3262e0e45d7f4 -r939d1bae9a394697d46ca913a2dc3442bf8ef82f --- sources/canbus/messagedispatcher.cpp (.../messagedispatcher.cpp) (revision 0e87420e50dd94c37eb25f289ef3262e0e45d7f4) +++ sources/canbus/messagedispatcher.cpp (.../messagedispatcher.cpp) (revision 939d1bae9a394697d46ca913a2dc3442bf8ef82f) @@ -21,6 +21,7 @@ #include "logger.h" #include "applicationcontroller.h" #include "frameinterface.h" +#include "messageacknowmodel.h" #define DEBUG_ACKBACK_HD_TO_UI @@ -83,15 +84,20 @@ void MessageDispatcher::initConnections() { // From GUI - connect(&_ApplicationController, SIGNAL(didActionTransmit(GuiActionType, const QVariantList &)), - this , SLOT( onActionTransmit(GuiActionType, const QVariantList &))); + connect(&_ApplicationController, SIGNAL(didActionTransmit(GuiActionType , const QVariantList &)), + this , SLOT( onActionTransmit(GuiActionType , const QVariantList &))); // From HD - connect(&_FrameInterface , SIGNAL(didFrameReceive ( Can_Id, const QByteArray &)), - this , SLOT( onFrameReceive ( Can_Id, const QByteArray &))); + connect(&_FrameInterface , SIGNAL(didFrameReceive (Can_Id , const QByteArray &)), + this , SLOT( onFrameReceive (Can_Id , const QByteArray &))); - connect(this ,SIGNAL(didFramesTransmit( Can_Id, const FrameList &)), - this , SLOT( onFramesTransmit( Can_Id, const FrameList &))); + + // + connect(&_MessageAcknowModel , SIGNAL(didFramesTransmit(Can_Id, Sequence, const FrameList &)), + this , SLOT( onFramesTransmit(Can_Id, Sequence, const FrameList &))); + + connect(&_MessageAcknowModel , SIGNAL(didFailedTransmit( Sequence )), + this , SLOT( onFailedTransmit( Sequence ))); } /*! @@ -164,14 +170,22 @@ * \brief MessageDispatcher::onFramesTransmit * \details this slots calls the framesTransmit to emit the didFrameTransmit signal * to queue the frame(s) to be sent - * \param vCan_Id - CanBus channel + * \param vSequence - sequence of the message which is going to be resent. (not used) * \param vFrameList - frame(s) to be sent */ -void MessageDispatcher::onFramesTransmit(Can_Id vCan_Id, const FrameList &vFrameList) +void MessageDispatcher::onFramesTransmit(Can_Id vCan_Id, Sequence vSequence, const FrameList &vFrameList) { + Q_UNUSED(vSequence) framesTransmit(vCan_Id, vFrameList); } +void MessageDispatcher::onFailedTransmit(Sequence vSequence) +{ + Q_UNUSED(vSequence) + // may requires showing an alarm screen + // but we don't know yet. +} + /*! * \brief MessageDispatcher::onActionTransmit * \details This slot will be called by ApplicationController::didActionTransmit @@ -181,7 +195,7 @@ */ void MessageDispatcher::onActionTransmit(GuiActionType vActionId, const QVariantList &vData) { - actionTransmit(vActionId, vData, txCount()); + actionTransmit(vActionId, vData); } /*! @@ -194,6 +208,14 @@ */ void MessageDispatcher::actionTransmit(GuiActionType vActionId, const QVariantList &vData, Sequence vSequence) { + txCount(); + if (vSequence == 0) { // initialize + // it's obvious that this assignment does not effect outside of the function. + // but is make it easier to just assume the correct value has been passed + // and still using the function parameter as a local variable. + vSequence = _txSequence; + } + QByteArray mData; if (! _interpreter.interpretMessage(vActionId, vData, mData)) { LOG_ERROR(tr("Incorrect Message, can't be interpreted")); @@ -204,7 +226,13 @@ FrameList frameList; Sequence mSequence = vSequence; bool mNeedsAcknow = needsAcknow(vActionId); - if (mNeedsAcknow) mSequence = -mSequence; + if (mNeedsAcknow) { + mSequence = -mSequence; + LOG_EVENT(tr("UI Ack Req %1").arg(mSequence)); +#ifdef DEBUG_ACKBACK_HD_TO_UI + qDebug() << tr(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ UI AckReq : %1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ").arg(mSequence); +#endif + } if ( ! _builder.buildFrames(vActionId, mData, frameList, mSequence) ) { LOG_ERROR(tr("Incorrect Message can't be built")); @@ -216,7 +244,7 @@ // since it does not need Re-Acknow // and this is the sequence number which will be used // to remove the message from the Acknow list. - emit didAcknowTransmit(vSequence, eChlid_UI_HD, frameList); + emit didAcknowTransmit(eChlid_UI_HD, vSequence, frameList); } framesTransmit(eChlid_UI_HD, frameList); } @@ -266,17 +294,26 @@ { bool ok = false; QVariantList mData; + Sequence mSequence = vMessage.sequence; if (_interpreter.interpretMessage(vMessage, mData)) { ok = true; GuiActionType mActionId = vMessage.actionId; switch (mActionId) { case GuiActionType::Acknow: - emit didAcknowReceive(vMessage.sequence); + LOG_EVENT(tr("HD Ack Bak %1").arg(mSequence)); + #ifdef DEBUG_ACKBACK_HD_TO_UI + qDebug() << tr(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HD AckBak : %1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ").arg(mSequence); + #endif + emit didAcknowReceive(mSequence); break; default: - if (vMessage.sequence < 0) { - actionTransmit(GuiActionType::Acknow, {}, vMessage.sequence); - qDebug() << tr(" ~~~~~~~~~~ Ack Back : %1~~~~~~~~~~ ").arg(vMessage.sequence); + if (mSequence < 0) { + LOG_EVENT(tr("HD Ack Req %1").arg(mSequence)); + #ifdef DEBUG_ACKBACK_HD_TO_UI + qDebug() << tr(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HD AckReq : %1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ").arg(mSequence); + #endif + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ UI AckBak is immediately handled at the same place. + actionTransmit(GuiActionType::Acknow, {}, -mSequence); } emit didActionReceive(mActionId, mData); break; @@ -327,18 +364,12 @@ { switch(vActionId) { case GuiActionType::Acknow: - // this is the Acknow itself - // since the actionTransmit will make any needsAcknow sequence to negative - // and the Ack Back should be in positive after receiving it in negative - // actually this make it positive and send it back. - return true; + return false; default: - // TEST : this code is for test. #ifdef DEBUG_ACKBACK_HD_TO_UI - return ( ! (_txSequence % 21) ); + return true; #else return false; #endif } - return false; }