/*! * * 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 * \author (last) Behrouz NematiPour * \date (last) 07-May-2020 * \author (original) Behrouz NematiPour * \date (original) 09-Dec-2019 * */ #pragma once // Qt #include //#include // Project #include "GuiGlobals.h" #include "MessageGlobals.h" // forward declaration class tst_messaging; namespace Can { /*! * * \brief The Message Builder class * \details This class is handling the can message by building and striping it. * \verbatim * \table * // -- CAN PAYLOAD STRUCTURE -- * | #0| #1| #2| #3| #4| #5| #6| #7| #8| ........ | * |---|-------|-------|---|-------|---|-----------| * | A5| Seq# | 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) * \endverbatim */ class MessageBuilder : public QObject { Q_OBJECT friend class ::tst_messaging; bool _enableConsoleOut = false; void addSyncByte ( QByteArray &vPayload); void addSequence (QByteArray &vPayload, Sequence vSequence); bool addActionId ( QByteArray &vPayload, Gui::GuiActionType vAction) __attribute_warn_unused_result__; bool addData ( QByteArray &vPayload, Gui::GuiActionType vAction, const QByteArray &vData) __attribute_warn_unused_result__; void addCRC ( QByteArray &vPayload); void addPadding ( QByteArray &vPayload); quint8 calcCRC (const QByteArray &vData ); bool checkCRC (const QByteArray &vData , quint8 &vExpected, quint8 &vActual); bool checkCRC (const Message &vMessage); bool hasSyncByte ( QByteArray &vPayload); Sequence getSequence ( QByteArray &vPayload); QByteArray getHeader (const QByteArray &vPayload); quint16 getActionId ( QByteArray &vPayload); int getLength ( QByteArray &vPayload); QByteArray getData (const QByteArray &vPayload, int vLen); void printPayload(const QByteArray &vPayload, bool vIsHeader, Can_Id vCan_Id, bool vUseColor = true); void consoleOut (const QByteArray &vPayload, bool vIsHeader, Can_Id vCan_Id, bool vUseColor = true); public: explicit MessageBuilder(QObject *parent = nullptr); // build message to be sent frame by frame bool buildFrames (Gui::GuiActionType vAction , 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__; void enableConsoleOut(bool vEnabled); signals: public slots: }; }