/*! * * 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 "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. * \n * // -- CAN PAYLOAD STRUCTURE -- \n * #0 #1 #2 #3 #4 #5 #6 #7 #8 #9 \n * +---+---+---+---+---+---+---+---+---+---+--.......--+ \n * | A5| Seq# | MsgId |Len| Data |CRC|..padding..| \n * +---+---+---+---+---+---+---+---+---+---+--.......--+ \n * \n * Header Frame: \n * 1 - CRC is last after payload \n * Ex1 - If Len=0 then CRC is #4 \n * Ex2 - If Len=1 then CRC is #5 and payload is #4 \n * 2 - If CRC is not the last by in the frame \n * then there is padding 0x00 to make the frame 8 byte fix \n * \n * Tail Frame: \n * 3 - Partial frames only have Payload and CRC ( and padded) \n * \n */ 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: }; }