/*! * * 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 * \author (last) Peter Lucia * \date (last) 25-Jun-2020 * \author (original) Behrouz NematiPour * \date (original) 06-Dec-2019 * */ #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::ID_PowerOff , 1 }, {Gui::GuiActionType::ID_ShuttingDown , 0 }, {Gui::GuiActionType::ID_KeepAlive , 255 }, // 0 => 255 to be able to run a multi-frame test. // ----- {Gui::GuiActionType::ID_TreatmentTime , 3 * 4 }, // 3 parameters each 4bytes {Gui::GuiActionType::ID_BloodFlow , 7 * 4 }, // 7 parameters each 4bytes {Gui::GuiActionType::ID_DialysateInletFlow , 7 * 4 }, // 7 parameters each 4bytes {Gui::GuiActionType::ID_DialysateOutletFlow , 7 * 4 }, // 7 parameters each 4bytes {Gui::GuiActionType::ID_PressureOcclusion , 5 * 4 }, // 5 parameters each 4bytes // ---- {Gui::GuiActionType::ID_HDOperationModeData , 1 * 4 }, // 1 parameter each 4bytes // ---- {Gui::GuiActionType::ID_DGROPumpData , 3 * 4 }, // 3 parameters each 4bytes {Gui::GuiActionType::ID_DGPressuresData , 4 * 4 }, // 4 parameters each 4bytes {Gui::GuiActionType::ID_DGDrainPumpData , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_DGOperationModeData , 1 * 4 }, // 1 parameter each 4bytes {Gui::GuiActionType::ID_DGReservoirData , 3 * 4 }, // 3 parameters each 4bytes {Gui::GuiActionType::ID_DGValvesStatesData , 1 * 2 }, // 1 parameters each 2bytes {Gui::GuiActionType::ID_DGHeatersData , 3 * 4 }, // 3 parameters each 4bytes {Gui::GuiActionType::ID_DGLoadCellReadingsData , 4 * 4 }, // 4 parameters each 4bytes {Gui::GuiActionType::ID_DGTemperaturesData , 12 * 4 }, // 12 parameters each 4bytes // ---- {Gui::GuiActionType::ID_AlarmStatus , 4 * 4 + 2 }, // 4 parameters each 4bytes + 1 parameter 2bytes {Gui::GuiActionType::ID_AlarmTriggered , 1 * 4 }, // 1 parameter each 4bytes {Gui::GuiActionType::ID_AlarmCleared , 1 * 4 }, // 1 parameter each 4bytes {Gui::GuiActionType::ID_AlarmSilenceReq , 5 * 4 }, // 5 parameters each 4bytes {Gui::GuiActionType::ID_AlarmSilenceRsp , 5 * 4 }, // 5 parameters each 4bytes // ---- {Gui::GuiActionType::ID_TreatmentRanges , 6 * 4 }, // 6 parameters each 4bytes {Gui::GuiActionType::ID_TreatmentStates , 3 * 4 }, // 3 parameters each 4bytes // ---- {Gui::GuiActionType::ID_AdjustBloodDialysateReq , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_AdjustBloodDialysateRsp , 4 * 4 }, // 4 parameters each 4bytes // ---- {Gui::GuiActionType::ID_AdjustDurationReq , 1 * 4 }, // 1 parameter each 4bytes {Gui::GuiActionType::ID_AdjustDurationRsp , 4 * 4 }, // 4 parameters each 4bytes // ---- {Gui::GuiActionType::ID_AdjustUltrafiltrationStateReq , 1 * 4 }, // 1 parameter each 4bytes // ---- {Gui::GuiActionType::ID_AdjustUltrafiltrationEditReq , 1 * 4 }, // 1 parameter each 4bytes {Gui::GuiActionType::ID_AdjustUltrafiltrationEditRsp , 8 * 4 }, // 8 parameters each 4bytes // --- {Gui::GuiActionType::ID_CreateTreatmentReq , 17 * 4 }, // 17 parameters, each 4 bytes {Gui::GuiActionType::ID_CreateTreatmentRsp , 18 * 4 }, // 18 parameters, each 4 bytes // ---- {Gui::GuiActionType::ID_AdjustUltrafiltrationConfirmReq , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_AdjustUltrafiltrationConfirmRsp , 5 * 4 }, // ---- {Gui::GuiActionType::ID_CANBusFaultCount , 1 }, {Gui::GuiActionType::ID_RawData , 255 }, {Gui::GuiActionType::ID_Acknow , 0 }, {Gui::GuiActionType::ID_AcknowGeneric , 1 }, {Gui::GuiActionType::ID_HDDebugText , 40 + 1 }, // ASCII text - 40 bytes + null term {Gui::GuiActionType::ID_DGDebugText , 40 + 1 }, // ASCII text - 40 bytes + null term }; /*! * \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 = 0x070, ///< 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::ID_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; }