Index: sources/canbus/messagebuilder.cpp =================================================================== diff -u -re58b907a69d4ca7daa77d69791593b886d1b80e8 -r8c69137f18382bdc55a5678e6ed44a7683fe4dea --- sources/canbus/messagebuilder.cpp (.../messagebuilder.cpp) (revision e58b907a69d4ca7daa77d69791593b886d1b80e8) +++ sources/canbus/messagebuilder.cpp (.../messagebuilder.cpp) (revision 8c69137f18382bdc55a5678e6ed44a7683fe4dea) @@ -19,11 +19,16 @@ #include "logger.h" #include "crc.h" #include "format.h" -#include "types.h" // namespace using namespace Can; +/*! + * \brief MessageBuilder::MessageBuilder + * \details Constructor + * \param parent - QObject parent owner object. + * Qt handles the children destruction by their parent objects life-cycle. + */ MessageBuilder::MessageBuilder(QObject *parent) : QObject(parent) { } /*! @@ -32,17 +37,16 @@ * and vData of type QByteArray which has been requested to be sent by UI. * The message will be chopped into 8 bytes frames to be able to be send * by fixed length CANBUS protocol. - * \param vAction - The ActionID of the requested message. - * \param vData - The payload of the message. - * \param ok - Will be set if any error happens. - * This parameter has been defined as mandatory check - * so it has been passed and checked. - * \return list of frames of type FrameList + * \param vAction - The ActionID of the requested message. + * \param vData - The payload of the message. + * \param vFrameList - The list of frames which has been created by vAction and vData to be sent. + * \return false on error */ bool MessageBuilder::buildFrames(Gui::GuiActionType vAction, const QByteArray &vData, FrameList &vFrameList) { QByteArray mPayload ; addSyncByte (mPayload); // Sync Byte + addSequence (mPayload); // adding sequence if ( ! addActionId (mPayload, vAction) ) { // MessageID return false; } @@ -76,6 +80,13 @@ vPayload.append(ePayload_Sync); // Sync byte } +void MessageBuilder::addSequence(QByteArray &/*vPayload*/) +{ +// Types::S16 seq; +// seq.value = +// vPayload.append(); +} + /*! * \brief MessageBuilder::addActionId * \details Adds the sync/start byte at the end of the Payload vPayload of type QByteArray @@ -171,18 +182,20 @@ * \brief MessageBuilder::checkCRC * \details This method checks the crc8 of the vData of type QByteArray * by using the last byte as the crc8 of the rest of the data - * \param vData - The data of type QByteArray to be used for crc8 calculation. + * \param vData - The data of type QByteArray to be used for crc8 calculation. + * \param vExpected - The expected CRC value + * \param vActual - The actual value which has been read * \return returns false if the crc8 is not correct or the data is empty. */ -bool MessageBuilder::checkCRC(const QByteArray &vData, quint8 &vExpected, quint8 &vBeenRead) +bool MessageBuilder::checkCRC(const QByteArray &vData, quint8 &vExpected, quint8 &vActual) // TODO : This section better to be in the MessageModel { #ifndef DISABLE_CRC int len = vData.length(); if ( ! len ) return false; - vBeenRead = vData.back(); + vActual = vData.back(); vExpected = calcCRC(vData.mid(0, len - 1)); - bool ok = vExpected == vBeenRead; + bool ok = vExpected == vActual; // it's very good but I'm not sure if it's correct. //bool ok = calcCRC(vData) == 0; return ok; @@ -194,8 +207,8 @@ /*! * \brief MessageBuilder::checkCRC * \details Overloaded CheckCRC which checks the CRC and Log the error if there is. - * \param vMessage - * \return + * \param vMessage - The message to check for the CRC + * \return false if has error */ bool MessageBuilder::checkCRC(const Message &vMessage) { @@ -230,9 +243,7 @@ consoleOut(vPayload, true, vCan_Id); vMessage.can_id = vCan_Id; vMessage.head = getHeader (mPayload); // keep header before taking it out of the payload. doesn't affect payload -#ifndef DISABLE_SEQUENCE vMessage.sequence = getSequence (mPayload); -#endif vMessage.actionId = getActionId (mPayload); vMessage.length = getLength (mPayload); vMessage.data = getData (mPayload, vMessage.length); @@ -286,9 +297,10 @@ * \note Removes the 2 bytes of ActionID from vPayload * It starts from the first byte so those 2 bytes should be the first 2 bytes. */ -qint16 MessageBuilder::getSequence(QByteArray &vPayload) +Sequence MessageBuilder::getSequence(QByteArray &vPayload) { - Types::S16 mSequence; + // be careful about using the Types::S16 type and always check with the Sequence type. + Sequence_Bytes mSequence; int index = 0; Types::getValue<>(vPayload, index, mSequence); vPayload = vPayload.mid(eLenSequence); @@ -438,6 +450,8 @@ void MessageBuilder::consoleOut(const QByteArray &vPayload, bool vIsHeader, Can_Id vCan_Id, bool vUseColor) { if ( ! _enableConsoleOut) return; - LOG_EVENT(QObject::tr("console out MessageDispatcher Enabled")); + + LOG_EVENT_ONCE(QObject::tr("console out MessageDispatcher Enabled")); + printPayload(vPayload, vIsHeader, vCan_Id, vUseColor); }