/*! * * 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 MessageGlobals.h * \date 12/6/2019 * \author Behrouz NematiPour * */ #pragma once // Qt #include // Project #include "guiglobals.h" #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 Payload Length * \details List of each ActionID required data (in byte) length in the message. * So the data collector has to collect this amount of bytes as payload of a message. */ const QHash payloadLen { // ---- {Gui::GuiActionType::PowerOff , 1 }, {Gui::GuiActionType::PowerOffBroadcast , 0 }, {Gui::GuiActionType::KeepAlive , 255 }, // 0 => 255 to be able to run a multi-frame test. {Gui::GuiActionType::BloodFlow , 7 * 4 }, // 7 parameters each 4bytes {Gui::GuiActionType::DialysateInletFlow , 7 * 4 }, // 7 parameters each 4bytes {Gui::GuiActionType::DialysateOutletFlow , 7 * 4 }, // 7 parameters each 4bytes {Gui::GuiActionType::TreatmentTime , 3 * 4 }, // 3 parameters each 4bytes {Gui::GuiActionType::PressureOcclusion , 5 * 4 }, // 5 parameters each 4bytes {Gui::GuiActionType::LoadCellReadings , 4 * 4 }, // 4 parameters each 4bytes {Gui::GuiActionType::TemperatureSensors , 12 * 4 }, // 12 parameters each 4bytes // ---- {Gui::GuiActionType::AlarmStatus , 4 * 4 + 2 }, // 4 parameters each 4bytes + 1 parameter 2bytes // ---- {Gui::GuiActionType::TreatmentRanges , 6 * 4 }, // 6 parameters each 4bytes // ---- {Gui::GuiActionType::AdjustBloodDialysateReq , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::AdjustBloodDialysateRsp , 4 * 4 }, // 4 parameters each 4bytes // ---- {Gui::GuiActionType::AdjustDurationReq , 1 * 4 }, // 1 parameters each 4bytes {Gui::GuiActionType::AdjustDurationRsp , 4 * 4 }, // 4 parameters each 4bytes // ---- {Gui::GuiActionType::AdjustUltrafiltrationStateReq , 1 * 4 }, // 1 parameters each 4bytes // ---- {Gui::GuiActionType::AdjustUltrafiltrationEditReq , 1 * 4 }, // 1 parameters each 4bytes {Gui::GuiActionType::AdjustUltrafiltrationEditRsp , 7 * 4 }, // 7 parameters each 4bytes // ---- {Gui::GuiActionType::AdjustUltrafiltrationConfirmReq , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::AdjustUltrafiltrationConfirmRsp , 5 * 4 }, // ---- {Gui::GuiActionType::CanBUSFaultCount , 1 }, {Gui::GuiActionType::String , 255 }, {Gui::GuiActionType::Acknow , 0 }, {Gui::GuiActionType::AcknowGeneric , 1 }, }; /*! * \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, eLenChannelDigits = 3, eLenMessageIDDigits = 4, }; /*! * \brief The Can_Id enum * \details The Valid Can Bus 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 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 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; Sequence sequence = 0; // seq 0 is invalid Gui::GuiActionType actionId = Gui::GuiActionType::Unknown; int length = 0; QByteArray head; QByteArray data; bool initialized = false; bool isEmpty () { // 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. // I preffer too keep it as it is so the initialization would be independent of the data. return !initialized || !data.length(); // coco end } bool isComplete() { // 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. // I preffer too keep it as it is so the initialization would be independent of the data. return !isEmpty() && data.length() == length; // coco end } }; typedef QList MessageList; typedef QList FrameList; }