Index: sources/ApplicationController.cpp =================================================================== diff -u -rc8da96049610870d3a8c9c00edc04f80ae62085f -r6abfb957108b171a8a5ab6770ad9b463235c210b --- sources/ApplicationController.cpp (.../ApplicationController.cpp) (revision c8da96049610870d3a8c9c00edc04f80ae62085f) +++ sources/ApplicationController.cpp (.../ApplicationController.cpp) (revision 6abfb957108b171a8a5ab6770ad9b463235c210b) @@ -112,8 +112,8 @@ connect(&_settingsWatcher, SIGNAL(finished ()), this , SLOT(onSettingsUpdate())); - connect(this , SIGNAL(isUnhandledMsgReady(QString)), - &_dryDemoStates, SLOT(onMsgReceived(QString))); + connect(this , SIGNAL(isUnhandledMsgReady(QString)), + &_dryDemoStates, SLOT(onMsgReceived(QString))); } /*! Index: sources/DryDemoStates.cpp =================================================================== diff -u -rc8da96049610870d3a8c9c00edc04f80ae62085f -r6abfb957108b171a8a5ab6770ad9b463235c210b --- sources/DryDemoStates.cpp (.../DryDemoStates.cpp) (revision c8da96049610870d3a8c9c00edc04f80ae62085f) +++ sources/DryDemoStates.cpp (.../DryDemoStates.cpp) (revision 6abfb957108b171a8a5ab6770ad9b463235c210b) @@ -1,9 +1,10 @@ #include "DryDemoStates.h" +#include "ApplicationController.h" DryDemoStates::DryDemoStates(drydemoXMLstates *parent) : drydemoXMLstates(parent) { - //start(); + //start(); // Why cannot I start the state machine here? } @@ -12,8 +13,24 @@ // TODO call the state machine qDebug() << "Msg Received" << msg; - start(); + if (!isRunning()) { + start(); // TODO why cannot start the state machine somewhere else? + // TODO How to leave this function? + } + //connectToState("Idle", onEntry([&]() { + // qDebug() << "In onEntry" << activeStateNames(); + // submitEvent("Tx_Start_Rqst");})); + connectToState("Idle", onEntry([&]() { - qDebug() << "In onEntry"; - submitEvent("Tx_Start_Rqst");})); + qDebug() << "In onEntry" << activeStateNames(); + })); + + qDebug() << "New state" << activeStateNames(); + + QVariantList list; + list.append(static_cast(0x2A00)); + list.append(Can_Id::eChlid_HD_UI); + list.append(68); + list.append(34.56); + emit _ApplicationController.didActionTransmit(list); } Index: sources/DryDemoStates.h =================================================================== diff -u -rc8da96049610870d3a8c9c00edc04f80ae62085f -r6abfb957108b171a8a5ab6770ad9b463235c210b --- sources/DryDemoStates.h (.../DryDemoStates.h) (revision c8da96049610870d3a8c9c00edc04f80ae62085f) +++ sources/DryDemoStates.h (.../DryDemoStates.h) (revision 6abfb957108b171a8a5ab6770ad9b463235c210b) @@ -6,12 +6,15 @@ #include "MessageGlobals.h" #include "drydemoxmlstates.h" - // TODO maybe the DryDemoStates in the scxml not needed? +//#define _dryDemoStates DryDemoStates::I() + class DryDemoStates : public drydemoXMLstates { Q_OBJECT + //SINGLETON(DryDemoStates) + public: DryDemoStates(drydemoXMLstates *parent = nullptr); Index: sources/canbus/MessageBuilder.cpp =================================================================== diff -u -rc0b30f1fa82d0121706351057ab52b3bb1141459 -r6abfb957108b171a8a5ab6770ad9b463235c210b --- sources/canbus/MessageBuilder.cpp (.../MessageBuilder.cpp) (revision c0b30f1fa82d0121706351057ab52b3bb1141459) +++ sources/canbus/MessageBuilder.cpp (.../MessageBuilder.cpp) (revision 6abfb957108b171a8a5ab6770ad9b463235c210b) @@ -43,14 +43,15 @@ * \param vFrameList - The list of frames which has been created by vAction and vData to be sent. * \return true on successful to build a frame */ -bool MessageBuilder::buildFrames(const QByteArray &vData, FrameList &vFrameList, Sequence vSequence) +bool MessageBuilder::buildFrames(quint16 msgID, const QByteArray &vData, FrameList &vFrameList, Sequence vSequence) { QByteArray mPayload ; addSyncByte (mPayload); // Sync Byte addSequence (mPayload, vSequence); // adding sequence - if ( ! addActionId (mPayload ) ) { // MessageID + if ( ! addActionId (mPayload, msgID ) ) { // MessageID return false; } + if ( ! addData (mPayload, vData) ) { // Regarding Payload Length, Adding required Data return false; } @@ -103,9 +104,18 @@ * \param vAction - The ActionID of the message which needs to be appended * to the Payload vPayload */ -bool MessageBuilder::addActionId(QByteArray &vPayload) +bool MessageBuilder::addActionId(QByteArray &vPayload, quint16 msgID) { - Q_UNUSED(vPayload); + //if (vAction != 0x0000) { + if (true) { + quint16 mAction = msgID; + vPayload += (mAction >> 8) & 0xFF; // high byte + vPayload += mAction & 0xFF; // low byte + } else { + QString mHexString = Format::toHexString(0x000, false, eLenMessageIDDigits); + LOG_DEBUG(QString("Incorrect Action ID '%1'").arg(mHexString)); + return false; + } return true; } @@ -120,7 +130,7 @@ bool MessageBuilder::addData(QByteArray &vPayload, const QByteArray &vData) { quint8 vAction = 0; - quint8 len = 0; //payloadLen[vAction]; + quint8 len = vData.size(); // if len has been set to max(255) // it means it has no limit and can be as long as 255 bytes if (len == eLenMaxData) { @@ -141,6 +151,7 @@ } vPayload += len; vPayload += vData.mid(0, len); // Adding required Data + qDebug() << "Payload added" << vPayload; return true; } Index: sources/canbus/MessageBuilder.h =================================================================== diff -u -rc0b30f1fa82d0121706351057ab52b3bb1141459 -r6abfb957108b171a8a5ab6770ad9b463235c210b --- sources/canbus/MessageBuilder.h (.../MessageBuilder.h) (revision c0b30f1fa82d0121706351057ab52b3bb1141459) +++ sources/canbus/MessageBuilder.h (.../MessageBuilder.h) (revision 6abfb957108b171a8a5ab6770ad9b463235c210b) @@ -65,7 +65,7 @@ void addSyncByte ( QByteArray &vPayload); void addSequence (QByteArray &vPayload, Sequence vSequence); - bool addActionId ( QByteArray &vPayload) __attribute_warn_unused_result__; + bool addActionId ( QByteArray &vPayload, quint16 msgID) __attribute_warn_unused_result__; bool addData ( QByteArray &vPayload, const QByteArray &vData) __attribute_warn_unused_result__; void addCRC ( QByteArray &vPayload); void addPadding ( QByteArray &vPayload); @@ -88,7 +88,7 @@ explicit MessageBuilder(QObject *parent = nullptr); // build message to be sent frame by frame - bool buildFrames (const QByteArray &vData, FrameList &vFrameList, Sequence vSequence) __attribute_warn_unused_result__; + bool buildFrames (quint16 msgID, const QByteArray &vData, FrameList &vFrameList, Sequence vSequence) __attribute_warn_unused_result__; // build message from received frames bool buildMessage(const QByteArray &vPayload, Message &vMessage, Can_Id vCan_Id) __attribute_warn_unused_result__; Index: sources/canbus/MessageDispatcher.cpp =================================================================== diff -u -rc8da96049610870d3a8c9c00edc04f80ae62085f -r6abfb957108b171a8a5ab6770ad9b463235c210b --- sources/canbus/MessageDispatcher.cpp (.../MessageDispatcher.cpp) (revision c8da96049610870d3a8c9c00edc04f80ae62085f) +++ sources/canbus/MessageDispatcher.cpp (.../MessageDispatcher.cpp) (revision 6abfb957108b171a8a5ab6770ad9b463235c210b) @@ -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 &))); @@ -227,6 +231,51 @@ _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]); + qDebug() << "Data" << mData << 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 @@ -247,16 +296,17 @@ 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 + qDebug() << "Cannot Interpret"; return; } - + qDebug() << "Got to action" << mData << vCanId << vData[0]; // TODO : Create a buildFrames method FrameList frameList; Sequence mSequence = vSequence; - bool mNeedsAcknow = needsAcknow(vCanId); + bool mNeedsAcknow = false; //needsAcknow(vCanId); if (mNeedsAcknow) { mSequence = -mSequence; if ( ! gDisableAcknowLog ) { @@ -269,8 +319,9 @@ // 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 + qDebug() << "Cannot build message"; return; } // disabled coco end Index: sources/canbus/MessageDispatcher.h =================================================================== diff -u -rc8da96049610870d3a8c9c00edc04f80ae62085f -r6abfb957108b171a8a5ab6770ad9b463235c210b --- sources/canbus/MessageDispatcher.h (.../MessageDispatcher.h) (revision c8da96049610870d3a8c9c00edc04f80ae62085f) +++ sources/canbus/MessageDispatcher.h (.../MessageDispatcher.h) (revision 6abfb957108b171a8a5ab6770ad9b463235c210b) @@ -120,7 +120,10 @@ void initThread(QThread &vThread); void quitThread(); - void actionTransmit (const QVariantList &vData, Sequence vSequence = 0, Can_Id vCanId = Can::Can_Id::eChlid_UI_HD); + // NOTE: vSequence = 0 has been removed to differentiate the overloading + void actionTransmit (const QVariantList &vData, Sequence vSequence, Can_Id vCanId = Can::Can_Id::eChlid_UI_HD); + void actionTransmit (const QVariantList &vData, Sequence vSequence = 0); // For dry-demo + void framesTransmit (Can_Id vCan_Id, const FrameList &vFrameList); bool needsAcknow (); Index: sources/canbus/MessageInterpreter.cpp =================================================================== diff -u -rc8da96049610870d3a8c9c00edc04f80ae62085f -r6abfb957108b171a8a5ab6770ad9b463235c210b --- sources/canbus/MessageInterpreter.cpp (.../MessageInterpreter.cpp) (revision c8da96049610870d3a8c9c00edc04f80ae62085f) +++ sources/canbus/MessageInterpreter.cpp (.../MessageInterpreter.cpp) (revision 6abfb957108b171a8a5ab6770ad9b463235c210b) @@ -32,12 +32,12 @@ // a macro to simplify the transmit message // would be better later to be replaced by a template method // like the notify method of received messages -#define INTERPRET_TRANSMIT_MESSAGE(vMODEL) \ - if ( ! length ) { logInvalidLength(vActionId); return false; } \ - vCanId = vMODEL::canid(); \ +#define INTERPRET_TRANSMIT_MESSAGE() \ + /*if ( ! length ) { logInvalidLength(vActionId); return false; }*/ \ + vCanId = eChlid_HD_Sync; /*vMODEL::canid();*/ \ vPayload = Format::fromVariant(vData); \ - LOG_APPED_MSG(vActionId, vMODEL::toString(vData)); \ - DEBUG_SIGNAL(0, typeid(vMODEL).name()) + /*LOG_APPED_MSG(vActionId, vMODEL::toString(vData));*/ \ + /*DEBUG_SIGNAL(0, typeid(vMODEL).name())*/ // another version of the INTERPRET_TRANSMIT_MESSAGE for empty messages // same later improvements apply to this MACRO as well. @@ -208,7 +208,8 @@ vPayload.clear(); int length = vData.length(); Q_UNUSED(length); - + INTERPRET_TRANSMIT_MESSAGE(); + qDebug() << "Len" << length << vData[0] << vPayload; return ok; } Index: sources/utility/format.cpp =================================================================== diff -u -rfe9459548d7b0f6c1d8cb77c0e23d7a385b48fa2 -r6abfb957108b171a8a5ab6770ad9b463235c210b --- sources/utility/format.cpp (.../format.cpp) (revision fe9459548d7b0f6c1d8cb77c0e23d7a385b48fa2) +++ sources/utility/format.cpp (.../format.cpp) (revision 6abfb957108b171a8a5ab6770ad9b463235c210b) @@ -127,6 +127,7 @@ Types::S32 s32; s32.value = vData.toInt(); Types::setValue(s32, mData); + qDebug() << "Variant in Int" << vData << mData; return mData; }