/*! * * 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 MessageInterpreter.h * \author (last) Peter Lucia * \date (last) 15-Oct-2020 * \author (original) Behrouz NematiPour * \date (original) 26-Aug-2020 * */ #pragma once // Qt #include // Project #include "MessageGlobals.h" #include "MModel.h" // forward declaration class tst_messaging; class tst_logging; class tst_canbus; namespace Can { /*! * \brief The MessageInterpreter class * \details This the class that interprets the messages to/from frames. * UI only understands GuiActionType and QVariantList data types * And CANBUS only understands QCanBusFrame with Hex values in QByteArrays * This is the class which interpret this data to/from. * This class is converting the data of messages to frames regarding the Message ID from values to array of bytes * or converting the payload of frames from data of messages regarding the Message ID from array of bytes to values. \n * To make it simple : \n * - UI => Data of Messages (Values) => Frames (Bytes) => CANBus. \n * - CANBus => Frames (Bytes) => Data of Messages (Values) => UI. \n * */ class MessageInterpreter : public QObject { Q_OBJECT // friend friend class ::tst_messaging; friend class ::tst_logging; friend class ::tst_models; // list of the unhandled messages with their definition to be able to log them like the ones which are not unhandled and have models. // it is the quickest to add them to support the V&V team. QMap _messageList { // /*QString("0x6A00").toUInt(0,16)*/ { 0x6A00 , { "FluidLeak","U32" }}, { 0x6C00 , { "BloodLeak","U32","U32" }}, { 0x4900 , { "TxStopPrg","U32","U32" }}, }; bool isType (const Message &vMessage, Gui::GuiActionType vType) const; bool isPayloadLenValid (const Message &vMessage, Gui::GuiActionType vType) const; bool isValidMessage (const Message &vMessage, Gui::GuiActionType vType) const; void logInvalidLength (const Gui::GuiActionType &vActionId); void printUnhandled (const Message &vMessage ) const; void logReceivedMessage (const Model::MAbstract &vModel); bool interpretMessage_HD (const Message &vMessage, QVariantList &vData) __attribute_warn_unused_result__; bool interpretMessage_DG (const Message &vMessage, QVariantList &vData) __attribute_warn_unused_result__; // ----- Debug bool canbusFaultCountData (const Message &vMessage, QVariantList &vData) __attribute_warn_unused_result__; // ----- Adjustments bool adjustUltrafiltrationEdit (const Message &vMessage, QVariantList &vData) __attribute_warn_unused_result__; bool adjustUltrafiltrationConfirm (const Message &vMessage, QVariantList &vData) __attribute_warn_unused_result__; template bool notify (const Message &vMessage, QVariantList &vData, Gui::GuiActionType vIdCheck) __attribute_warn_unused_result__; bool logUnhandledMessage (const Message &vMessage) const; public: explicit MessageInterpreter(QObject *parent = nullptr); // interpret the data into GUI understandable Actions/Data bool interpretMessage(const Message &vMessage, QVariantList &vData) __attribute_warn_unused_result__; bool interpretMessage(const Gui::GuiActionType &vActionId, const QVariantList &vData, QByteArray &vPayload, Can_Id &vCanId) __attribute_warn_unused_result__; static Can_Source identifySource(Can_Id vCanId); signals: ACTION_RECEIVE_SIGNALS }; }