/*! * * Copyright (c) 2019-2019 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 * date 12/6/2019 * author Behrouz NematiPour * */ #pragma once // Qt #include // Project #include "guiglobals.h" using namespace Gui; namespace Can { /*! * \brief Payload Length * \details List of each action acceptable data length in the whole message packet. */ const QHash payloadLen { {GuiActionType::PowerOff , 1}, {GuiActionType::KeepAlive , 0}, {GuiActionType::BloodFlow , 24}, {GuiActionType::String , 255}, }; /*! * \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 = 3, ///< The Header length witch is included in CRC after Sync byte 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 eLenActionId = 2, ///< The length of Message ID bytes (2) at the beginning of each header frame after sync eLenLength = 1, ///< The length of data length value byte at the beginning of each header frame after Message ID }; /*! * \brief The Can_Id enum * \details The Valid Can Bus Message Id of each frame */ enum Can_Id : quint16 { eChlid_NONE = 0x000, // 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 = 0x020, ///< HD => UI eChlid_UI = 0x100, ///< UI => HD [Out] // UI lessens occasionally eChlid_DG_UI = eChlid_DG_Alarm, ///< No direct channel has been defined between DG&UI, May be required for logging eChlid_UI_DG = eChlid_UI_Sync , ///< No direct channel has been defined between DG&UI, May be required for logging }; /*! * \brief The Message struct * \details The message structure after it's been glued together. */ struct Message { // TODO : Should be converted to MessageModel class // no time left for now !!! Can_Id can_id; GuiActionType actionId = GuiActionType::Unknown; int length = 0; QByteArray head; QByteArray data; bool initialized = false; bool isEmpty () { return !initialized || !data.length(); } bool isComplete() { return !isEmpty() && data.length() == length; } }; typedef QList MessageList; typedef QList FrameList; }