/*! * * Copyright (c) 2020-2024 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) 06-Jun-2021 * \author (original) Behrouz NematiPour * \date (original) 26-Aug-2020 * */ #pragma once // Qt #include // Project #include "GuiGlobalsAutoGen.h" #include "MessageGlobalsAutoGen.h" // forward declaration class tst_messaging; namespace Can { /*! * * \page DenaliMessageStructure Denali Message Structure * * CAN PAYLOAD STRUCTURE * * | #0 | #1 , #2 | #3 , #4 | #5 | #6 , #7 | #8 | .......... | * |:---:|:-------:|:-------:|:---:|:-------:|:---:|:----------:| * | A5 | #seq | MSG ID | Len | Data | CRC | ..padding..| * \verbatim 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 */ /*! * \brief The MessageBuilder class * \details This class is handling the can message by building and striping it. * This class constructs a message by reading array of bytes (QByteArray) in CANBus frame(s) * and converting them to messages by reading the Message ID, Data Length and data. * On the other hand, this class converts bytes of data requires to be transmitted to frame(s) and vice versa. */ 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: }; }