/*! * * 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 MessageGlobals.h * \author (last) Dara Navaei * \date (last) 08-May-2024 * \author (original) Behrouz NematiPour * \date (original) 26-Aug-2020 * */ #pragma once // Qt #include // Project #include "types.h" namespace Can { /*! * \brief Sequence * \details the messages sequence type */ typedef qint16 Sequence; typedef Types::S16 Sequence_Bytes; #define SEQUENCE_MAX INT16_MAX /*! * \brief FrameCount * \details The maximum unsigned integer value to be used as the frame count */ typedef quint64 FrameCount; /*! * \brief The Payload_Data enum * \details Global information for message packet. */ enum Payload_Data : quint8 { ePayload_None = 0x00, ePayload_Sync = 0xA5, }; /*! * \brief The Frame_Data enum * \details Global information for each message frame. */ enum Frame_Data : quint8 { eLenCanFrame = 8, ///< The length of each can frame. Should be padded by 0x00 if is less. eLenHeaderInfo = 5, ///< The Header length witch is included in CRC after Sync byte (it's the sum of eLenSequence + eLenActionId + eLenLength) eLenMaxHeaderData = 3, ///< Maximum data byte can be in one frame as header data portion eLenMaxData = 255, ///< Maximum data length in a Can Message since data length value kept in one byte eLenSyncByte = 1, ///< The length of Sync byte at the beginning of each header frame eLenSequence = 2, ///< The length of Sequence number bytes (2) at the beginning of each header frame after sync eLenActionId = 2, ///< The length of MessageID bytes eLenLength = 1, ///< The length of data length value byte at the beginning of each header frame after MessageID eLenCRCDigits = 2, ///< The length of CRC value byte in each Denali message eLenChannelDigits = 3, ///< The length of channel value byte in each Denali message eLenMessageIDDigits = 4, ///< The length of message id value byte in each Denali message }; /*! * \brief The Can_Id enum * \details The Valid CANBus MessageID of each frame */ enum Can_Id : quint16 { eChlid_LOWEST = 0x7FF, eChlid_NONE = 0x7FF, // Broadcasts //// Alarm eChlid_HD_Alarm = 0x001, ///< HD alarm broadcast eChlid_DG_Alarm = 0x002, ///< DG alarm broadcast eChlid_UI_Alarm = 0x004, ///< UI alarm broadcast [Out] //// Sync eChlid_HD_Sync = 0x040, ///< HD sync broadcast eChlid_DG_Sync = 0x080, ///< DG sync broadcast eChlid_UI_Sync = 0x200, ///< UI sync broadcast [Out] // UI not listening eChlid_HD_DG = 0x008, ///< HD => DG eChlid_DG_HD = 0x010, ///< DG => HD // UI is listening eChlid_HD_UI = 0x020, ///< HD => UI eChlid_UI_HD = 0x100, ///< UI => HD [Out] // UI listens occasionally eChlid_DG_UI = 0x070, ///< DG => UI eChlid_UI_DG = 0x110, ///< UI => DG [Out] // Dialing channel has been requested by V&V team for CANBus testing // and clarify the source of the unexpected channel message // UI still does not do anything with the messages on these channels. eDialin_HD = 0x400, ///< dialin => HD eHD_Dialin = 0x401, ///< HD => dialin eDialin_DG = 0x402, ///< dialin => DG eDG_Dialin = 0x403, ///< DG => dialin eDialin_UI = 0x404, ///< dialin => UI eUI_Dialin = 0x405, ///< UI => dialin }; /*! * \brief The Can_Source enum * \details The allowable sources of the CANBus messages. */ enum Can_Source { eCan_Unknown = -1, eCan_HD = 0, eCan_DG = 1, eCan_DI = 2, eCan_UI = 3, }; enum Message_ID_Enum { ID_NONE = 0x0000, ID_HD_OP_MODE = 0x2500, ID_UI_TX_PARAMS_RQST = 0x3500, ID_HD_NEW_PARAMS_RESP = 0x3600, ID_UI_RQST_TX = 0x3800, ID_UI_CONFIRM_TX_PARAMS = 0x3B00, ID_PRE_TX_STATES_BC = 0x5C00, ID_SAMPLE_WATER_RESULT = 0x5f00, ID_FILTER_FLUSH_TIME_BC = 0x6000, ID_HD_SYS_SELF_TEST_TIME_BC = 0x6100, ID_UI_CONSUMABLES_INSTALL = 0x6800, ID_HD_UI_CONFIRM_RQST = 0xBA00, ID_UI_CONFIRM_RESP = 0xBB00, }; enum HD_OP_MODE { MODE_FAUL = 0, ///< Fault mode MODE_SERV, ///< Service mode MODE_INIT, ///< Initialization & POST mode MODE_STAN, ///< Standby mode MODE_TPAR, ///< Treatment Parameters mode MODE_PRET, ///< Pre-Treatment mode MODE_TREA, ///< Treatment mode MODE_POST, ///< Post-Treatment mode MODE_NLEG, ///< Not legal - an illegal mode transition occurred }; /*! * \brief The Message struct * \details The message structure after it's been converted form hex bytes to meaningful struct for UI. */ struct Message { // TODO : Should be converted to MessageModel class // no time left for now !!! Can_Id can_id = eChlid_NONE; Sequence sequence = 0; // seq 0 is invalid int actionId = 0; int length = 0; QByteArray head; QByteArray data; bool initialized = false; bool isEmpty () { // disabled coco begin validated:Has been validated manually. // Since the crc is part of the data and there is no message without crc // initialized flag and data.length() == 0 became the same. // It is preferred to keep it as is so that the initialization is independent of data. return !initialized || !data.length(); // disabled coco end } bool isComplete() { // disabled coco begin validated:Has been validated manually. // Since the crc is part of the data and there is no message without crc // then a message would never be empty. // It is preferred to keep it as is so that the initialization is independent of data. //qDebug() << data.length() << length; return !isEmpty() && data.length() == length; // disabled coco end } }; typedef QList MessageList; typedef QList FrameList; typedef Message_ID_Enum MessageID; }