/*! * * 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 MessageInterpreter.h * \author (last) Behrouz NematiPour * \date (last) 13-Oct-2022 * \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 {}; 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; bool interpretMessage_TD (const Message &vMessage, QVariantList &vData) __attribute_warn_unused_result__; bool interpretMessage_DD (const Message &vMessage, QVariantList &vData) __attribute_warn_unused_result__; bool interpretMessage_FP (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__; void updateUnhandledMessages(); static Can_Source identifySource (Can_Id vCanId, QString *vText = nullptr); static Can_Id identifyDestination(Can_Id vCanId, QString *vText = nullptr); signals: ACTION_RECEIVE_SIGNALS }; }