Index: sources/canbus/MessageDispatcher.cpp =================================================================== diff -u -rc0b30f1fa82d0121706351057ab52b3bb1141459 -r7936e751fe1cd3517d0d548b53fef41f41b4db4a --- sources/canbus/MessageDispatcher.cpp (.../MessageDispatcher.cpp) (revision c0b30f1fa82d0121706351057ab52b3bb1141459) +++ sources/canbus/MessageDispatcher.cpp (.../MessageDispatcher.cpp) (revision 7936e751fe1cd3517d0d548b53fef41f41b4db4a) @@ -88,6 +88,10 @@ */ void MessageDispatcher::initConnections() { + // Message transmit + connect(&_ApplicationController, SIGNAL(didActionTransmit(const QVariantList &)), + this , SLOT( onActionTransmit(const QVariantList &))); + // From HD connect(&_FrameInterface , SIGNAL(didFrameReceive (Can_Id , const QByteArray &)), this , SLOT( onFrameReceive (Can_Id , const QByteArray &))); @@ -102,6 +106,9 @@ // Application Settings are ready connect(&_ApplicationController, SIGNAL(didSettingsDone ()), this , SLOT( onSettingsDone ())); + + connect(&_interpreter , SIGNAL(didUnhandledMsgReady(const QVariantList &)), + this , SLOT(doUnhandledMsgReady(const QVariantList &))); } /*! @@ -158,13 +165,12 @@ // disabled coco end _messageList[vCan_Id].append(Message()); } - qDebug() << "5" <<__FUNCTION__; // build the message and check. if (! buildMessage(vCan_Id, vPayload)) { return; } Message mMessage = _messageList[vCan_Id].last(); - qDebug() << "6" <<__FUNCTION__; + //qDebug() << "6" <<__FUNCTION__; // TODO : must be moved to a MessageModel class if (mMessage.isComplete()) { @@ -224,6 +230,50 @@ _interpreter.updateUnhandledMessages(); } +void MessageDispatcher::actionTransmit(const QVariantList &vData, Sequence vSequence) +{ + // For dry demo + 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 same variable (function parameter) as a local variable. + vSequence = _txSequence; + } + + QByteArray mData; + Can_Id canid = static_cast(vData[1].toUInt()); + + for (int i = 2; i < vData.size(); ++i) { + mData += Format::fromVariant(vData[i]); + } + + FrameList frameList; + Sequence mSequence = vSequence; + bool mNeedsAcknow = false; //needsAcknow(vCanId); + if (mNeedsAcknow) { + mSequence = -mSequence; + } + + // disabled coco begin validated: Has been tested manually but in this function this cannot be false because the message interpreter is doing the same validation. + // still checking here in case the logic has changed therefore buildFrame should still validate the message for developer safety. + if ( ! _builder.buildFrames(vData[0].toUInt(), mData, frameList, mSequence) ) { + LOG_DEBUG(QString("Incorrect Message cannot be built")); // TODO : LogInfo Improvement + qDebug() << "Cannot build message"; + return; + } + // disabled coco end + if (mNeedsAcknow) { + // NOTE : here vSequence should be used which is not negative + // because when we get the Acknow it is not the negative + // 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(canid, vSequence, frameList); + } + framesTransmit(canid, frameList); +} + /*! * \brief MessageDispatcher::actionTransmit * \details This method is called by slot MessageDispatcher::onActionTransmit @@ -232,8 +282,10 @@ * \param vActionId - The ActionID of the message * \param vData - The data of the Message */ +/* void MessageDispatcher::actionTransmit(const QVariantList &vData, Sequence vSequence, Can_Id vCanId) { + Q_UNUSED(vCanId) txCount(); if (vSequence == 0) { // initialize // it's obvious that this assignment does not effect outside of the function. @@ -244,7 +296,7 @@ quint8 vActionId = 0; QByteArray mData; - Can_Id canid = vCanId; + Can_Id canid = Can::Can_Id::eChlid_UI_HD; // TODO figure out //vCanId; if (! _interpreter.interpretMessage(vData, mData, canid)) { LOG_DEBUG(QString("Incorrect Message, cannot be interpreted, %1").arg(Format::toHexString(vActionId))); // TODO : LogInfo Improvement return; @@ -253,20 +305,20 @@ // TODO : Create a buildFrames method FrameList frameList; Sequence mSequence = vSequence; - bool mNeedsAcknow = needsAcknow(vCanId); + bool mNeedsAcknow = true; //needsAcknow(vCanId); if (mNeedsAcknow) { mSequence = -mSequence; if ( ! gDisableAcknowLog ) { - LOG_APPED_UI(tr("Ack Req, Sq:%1, ID:%2").arg(mSequence).arg(Format::toHexString(vActionId))); + LOG_APPED_UI(tr("Ack Req, Sq:%1, ID:%2").arg(mSequence).arg(Format::toHexString(vActionId))); } #ifdef DEBUG_ACKBACK_HD_TO_UI - qDebug() << tr(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ UI AckReq : %1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ").arg(mSequence); + qDebug() << tr(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ UI AckReq : %1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ").arg(mSequence); #endif } // disabled coco begin validated: Has been tested manually but in this function this cannot be false because the message interpreter is doing the same validation. // still checking here in case the logic has changed therefore buildFrame should still validate the message for developer safety. - if ( ! _builder.buildFrames(mData, frameList, mSequence) ) { + if ( ! _builder.buildFrames(0, mData, frameList, mSequence) ) { LOG_DEBUG(QString("Incorrect Message cannot be built")); // TODO : LogInfo Improvement return; } @@ -282,6 +334,7 @@ framesTransmit(canid, frameList); } +*/ /*! * \brief MessageDispatcher::framesTransmit * \details iterates through all the frames and emits to send the frames @@ -325,25 +378,24 @@ */ bool MessageDispatcher::checkAcknowReceived(const Message &vMessage, const QString &vSrcText) { - Q_UNUSED(vMessage); - Q_UNUSED(vSrcText); - return true; - /* - GuiActionType mActionId = vMessage.actionId; + enum GuiActionsType_Enum /* : quint16 QML does not support enum types */ { + ID_Acknow = 0xFFFF, + }; + + int mActionId = vMessage.actionId; Sequence mSequence = vMessage.sequence; bool ok = false; - if ( mActionId == GuiActionType::ID_Acknow ) { + if ( mActionId == ID_Acknow ) { ok = true; if ( ! gDisableAcknowLog ) { LOG_APPED(tr(" ,%1,Ack Bak, Sq:%2").arg(vSrcText).arg(mSequence)); } - #ifdef DEBUG_ACKBACK_HD_TO_UI - qDebug() << tr(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HD AckBak : %1 %2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ").arg(mSequence).arg(vMessage.actionId); - #endif +#ifdef DEBUG_ACKBACK_HD_TO_UI + qDebug() << tr(" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HD AckBak : %1 %2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~ ").arg(mSequence).arg(vMessage.actionId); +#endif emit didAcknowReceive(mSequence); } return ok; -*/ } /*! @@ -355,13 +407,15 @@ */ bool MessageDispatcher::checkAcknowTransmit(const Message &vMessage, const QString &vSrcText) { + enum GuiActionsType_Enum /* : quint16 QML does not support enum types */ { + ID_Acknow = 0xFFFF, + }; + bool ok = false; - int mActionId = 0; + int mActionId = vMessage.actionId; Sequence mSequence = vMessage.sequence; - // UI shall acknowledge the messages is intended for UI. if ( ! needsAcknow(vMessage.can_id)) return ok; // false - if (mSequence < 0) { ok = true; if ( ! gDisableAcknowLog ) { @@ -373,7 +427,13 @@ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ UI AckBak is immediately handled at the same place. QString dstText; Can_Id dstID = MessageInterpreter::identifyDestination(vMessage.can_id, &dstText); - actionTransmit({}, -mSequence, dstID); + Q_UNUSED(dstID) + + QVariantList msg; + msg.append(static_cast(ID_Acknow)); + msg.append(Can_Id::eChlid_HD_UI); + + actionTransmit(msg, -mSequence); if ( ! gDisableAcknowLog ) { LOG_APPED_UI(tr("Ack Bak, Sq:%1, Dst:%2").arg(-mSequence).arg(dstText)); } @@ -398,10 +458,10 @@ QVariantList mData; QString srcText; MessageInterpreter::identifySource(vMessage.can_id, &srcText); + if ( ! checkAcknowReceived(vMessage, srcText) ) { // check if the message was an acknowledge. checkAcknowTransmit(vMessage, srcText); // then if needs acknow send it immediately. } - // disabled coco begin validated: Has been validated manually. If MessageInterpreter::interpretMessage fails, this also returns false if ( _interpreter.interpretMessage( vMessage, mData ) ) { ok = true; @@ -481,3 +541,8 @@ return ok; } + +void MessageDispatcher::doUnhandledMsgReady(const QVariantList &msg) +{ + emit didUnhandledMsgDispatcher(msg); +}