/*! * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, * IN PART OR IN WHOLE, * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * file messagebuilder.h * date 12/6/2019 * author Behrouz NematiPour * */ #pragma once // Qt #include #include // Project #include "guiactions.h" #include "messageglobals.h" using namespace Gui; namespace Can { /*! * * \brief The Message Builder class * \details This class is handling the can message by building and striping it. * * // -- CAN PAYLOAD STRUCTURE -- * #0 #1 #2 #3 #4 #5 #6 #7 * +---+---+---+---+---+---+---+---+--.......--+ * | A5| MsgId |Len| Data |CRC|..padding..| * +---+---+---+---+---+---+---+---+--.......--+ * * Header Frame: * 1 - CRC is last after payload * Ex1 - If Len=0 then CRC is #4 * Ex2 - If Len=1 then CRC is #5 and payload is #4 * 2 - If CRC is not the last by in the frame * then there is padding 0x00 to make the frame 8 byte fix * * Tail Frame: * 3 - Partial frames only have Payload and CRC ( and padded) * */ class MessageBuilder : public QObject { Q_OBJECT public: explicit MessageBuilder(QObject *parent = nullptr); // build message to be sent QList buildMessage(GuiActionType vAction , const QByteArray &vData); void addSyncByte (QByteArray &vPayload); void addActionId (QByteArray &vPayload, GuiActionType vAction); void addData (QByteArray &vPayload, GuiActionType vAction, const QByteArray &vData); void addCRC (QByteArray &vPayload); void addPadding (QByteArray &vPayload); // CRC tools quint8 calcCRC (const QByteArray &vData); bool checkCRC (const QByteArray &vData, quint8 vCRC); // strip message to its parts bool stripMessage (const QByteArray &vPayload, Message &vMessage); bool hasSyncByte ( QByteArray &vPayload); GuiActionType getActionId ( QByteArray &vPayload); quint8 getLength ( QByteArray &vPayload); QByteArray getData ( QByteArray &vPayload, quint8 vLen, bool *ok = nullptr); signals: public slots: }; }