/*! * * 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) 05-Feb-2024 * \author (original) Behrouz NematiPour * \date (original) 26-Aug-2020 * */ #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 { // FixMe: This has to be move to each model. // it has been observed that these length can only check the payload length is correct. // but if the model still needs more the model will fail. // so it is better to keep them next to each other to make sure they are in sync. // ---- {Gui::GuiActionType::ID_PowerOff , 1 }, // 1 byte {Gui::GuiActionType::ID_ShuttingDown , 0 }, {Gui::GuiActionType::ID_KeepAlive , 255 }, // 0 => 255 to be able to run a multi-frame test. // Generic Confirm {Gui::GuiActionType::ID_DuetConfirmHDi , 3 * 4 }, // 3 parameters each 4bytes {Gui::GuiActionType::ID_DuetConfirmUIr , 2 * 4 }, // 2 parameters each 4bytes // POST {Gui::GuiActionType::ID_HDPostSingleResultData , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_HDPostFinalResultData , 1 * 4 }, // 1 parameters each 4bytes {Gui::GuiActionType::ID_DGPostSingleResultData , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_DGPostFinalResultData , 1 * 4 }, // 1 parameters each 4bytes {Gui::GuiActionType::ID_UIPostFinalResultData , 1 * 4 }, // 1 parameters each 4bytes {Gui::GuiActionType::ID_UIPostFinalResultHDReq , 0 * 4 }, // 0 parameters {Gui::GuiActionType::ID_HDRTCEpochData , 1 * 4 }, // 1 parameters each 4bytes // Service Mode {Gui::GuiActionType::ID_AdjustServiceModeReq , 0 * 4 }, // 0 parameters each 4bytes {Gui::GuiActionType::ID_AdjustServiceModeRsp , 2 * 4 }, // 2 parameters each 4bytes // ----- {Gui::GuiActionType::ID_TreatmentTime , 3 * 4 }, // 3 parameters each 4bytes {Gui::GuiActionType::ID_BloodFlow , 8 * 4 }, // 8 parameters each 4bytes {Gui::GuiActionType::ID_DialysateInletFlow , 7 * 4 }, // 7 parameters each 4bytes {Gui::GuiActionType::ID_DialysateOutletFlow , 13 * 4 }, //13 parameters each 4bytes {Gui::GuiActionType::ID_PressureOcclusion , 8 * 4 }, // 8 parameters each 4bytes {Gui::GuiActionType::ID_Saline , 3 * 4 }, // 3 parameters each 4bytes {Gui::GuiActionType::ID_Heparin , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_Rinseback , 6 * 4 }, // 6 parameters each 4bytes {Gui::GuiActionType::ID_Recirculate , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_BloodPrime , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_TreatmentStop , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_HDAirBubbleData , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_HDAirTrapData , 4 * 4 }, // 4 parameters each 4bytes {Gui::GuiActionType::ID_HDBloodLeakData , 2 * 4 }, // 2 parameters each 4bytes // ---- {Gui::GuiActionType::ID_HDOperationModeData , 2 * 4 }, // 2 parameter each 4bytes {Gui::GuiActionType::ID_PreTreatmentStates , 11 * 4 }, //11 parameters each 4bytes {Gui::GuiActionType::ID_TreatmentStates , 10 * 4 }, //10 parameters each 4bytes {Gui::GuiActionType::ID_PostTreatmentStates , 2 * 4 }, // 2 parameter each 4bytes // DG Data Messages {Gui::GuiActionType::ID_DGROPumpData , 6 * 4 }, // 6 parameters each 4bytes {Gui::GuiActionType::ID_DGPressuresData , 5 * 4 }, // 5 parameters each 4bytes {Gui::GuiActionType::ID_DGDrainPumpData , 8 * 4 }, // 8 parameters each 4bytes {Gui::GuiActionType::ID_DGOperationModeData , 2 * 4 }, // 2 parameter each 4bytes {Gui::GuiActionType::ID_DGReservoirData , 12 * 4 }, // 12 parameters each 4bytes {Gui::GuiActionType::ID_DGValvesStatesData , 1 * 2 + 13 }, // 1 parameter 16bits & 13 parameters each 1 byte {Gui::GuiActionType::ID_DGHeatersData , 11 * 4 }, // 11 parameters each 4bytes {Gui::GuiActionType::ID_DGLoadCellReadingsData , 4 * 4 }, // 4 parameters each 4bytes {Gui::GuiActionType::ID_DGTemperaturesData , 23 * 4 }, // 23 parameters each 4bytes {Gui::GuiActionType::ID_DGAccelerometerData , 9 * 4 }, // 9 parameters each 4bytes {Gui::GuiActionType::ID_DGConductivityData , 13 * 4 }, // 13 parameters each 4bytes // HD Data Messages {Gui::GuiActionType::ID_HDAccelerometerData , 9 * 4 }, // 9 parameters each 4bytes {Gui::GuiActionType::ID_HDSyringePumpData , 9 * 4 }, // 9 parameters each 4bytes {Gui::GuiActionType::ID_HDUsageInfoReq , 0 * 4 }, // 0 parameters each 4bytes {Gui::GuiActionType::ID_HDUsageInfoRsp , 4 * 4 + 2 }, // 4 parameters each 4bytes + 1 parameter 2 bytes // ---- TODO : AFTER GIVING IT SOME THOUGHT, IT SEEMS WE CAN GET THESE LEN FROM THE MODEL AND DO NOT NEED TO HAVE THIS BUT NEED TO INVESTIGATE MORE. {Gui::GuiActionType::ID_AlarmStatus , 4 * 4 + 2 }, // 4 parameters each 4bytes + 1 parameter 2bytes {Gui::GuiActionType::ID_AlarmTriggered , 8 * 4 }, // 5 parameters each 4bytes {Gui::GuiActionType::ID_AlarmCleared , 1 * 4 }, // 1 parameter each 4bytes {Gui::GuiActionType::ID_AlarmClearedConditionReq , 1 * 4 }, // 1 parameter each 4bytes // the same message 63:0x3F00 {Gui::GuiActionType::ID_AlarmClearedConditionRsp , 1 * 4 }, // 1 parameter each 4bytes // the same message 63:0x3F00 {Gui::GuiActionType::ID_AlarmSilenceReq , 1 * 4 }, // 1 parameter each 1bytes {Gui::GuiActionType::ID_AlarmUserActionReq , 1 * 4 }, // 1 parameter each 4bytes {Gui::GuiActionType::ID_AlarmActiveListReq , 0 * 4 }, // 0 parameter each 4bytes {Gui::GuiActionType::ID_AlarmActiveListRsp , 12 * 4 }, //12 parameter each 4bytes {Gui::GuiActionType::ID_AlarmVolumeSetReq , 1 * 4 }, // 1 parameter each 4bytes {Gui::GuiActionType::ID_AlarmVolumeSetRsp , 2 * 4 }, // 2 parameters each 4bytes // ---- {Gui::GuiActionType::ID_TreatmentRanges , 6 * 4 }, // 6 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_AdjustUltrafiltrationStateRsp , 3 * 4 }, // 3 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_AdjustUltrafiltrationConfirmReq , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_AdjustUltrafiltrationConfirmRsp , 5 * 4 }, // 5 parameters each 4bytes // ---- {Gui::GuiActionType::ID_AdjustPressuresLimitsReq , 3 * 4 }, // 3 parameter each 4bytes {Gui::GuiActionType::ID_AdjustPressuresLimitsRsp , 5 * 4 }, // 5 parameters each 4bytes // Pre-Treatment // Create Parameters // Pre-Treatment Initiate Treatment {Gui::GuiActionType::ID_AdjustInitTreatmentReq , 1 * 4 }, // 1 parameters each 4bytes {Gui::GuiActionType::ID_AdjustInitTreatmentRsp , 2 * 4 }, // 2 parameters each 4bytes // Pre-Treatment Treatment Parameters Validation/Confirm {Gui::GuiActionType::ID_AdjustParametersValidationReq , 17 * 4 }, //17 parameters each 4bytes {Gui::GuiActionType::ID_AdjustParametersValidationRsp , 18 * 4 }, //18 parameters each 4bytes {Gui::GuiActionType::ID_AdjustParametersConfirmReq , 1 * 4 }, // 1 parameters each 4bytes // Pre-Treatment Water Sample {Gui::GuiActionType::ID_DGFilterFlushData , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_AdjustWaterSampleReq , 1 * 4 }, // 1 parameters each 4bytes {Gui::GuiActionType::ID_AdjustWaterSampleRsp , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_AdjustWaterSampleResultReq , 1 * 4 }, // 1 parameters each 4bytes // Pre-Treatment Consumables Installation Confirm {Gui::GuiActionType::ID_AdjustConsumablesConfirmReq , 0 * 4 }, // 0 parameter // Pre-Treatment SelfTest NoCartridge Progress Data {Gui::GuiActionType::ID_SelfTestNoCartridgeData , 2 * 4 }, // 2 parameters each 4bytes // Pre-Treatment Disposables Installation Confirm {Gui::GuiActionType::ID_AdjustDisposablesConfirmReq , 0 * 4 }, // 0 parameter {Gui::GuiActionType::ID_AdjustDisposablesConfirmRsp , 2 * 4 }, // 2 parameter // Pre-Treatment SelfTest Dry Progress Data {Gui::GuiActionType::ID_SelfTestDryData , 2 * 4 }, // 2 parameters each 4bytes // Pre-Treatment Disposable Priming {Gui::GuiActionType::ID_AdjustDisposablesPrimeReq , 0 * 4 }, // 0 parameter {Gui::GuiActionType::ID_AdjustDisposablesPrimeRsp , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_DisposablesPrimeData , 2 * 4 }, // 2 parameters each 4bytes // Pre-Treatment Patient Connection Begin {Gui::GuiActionType::ID_AdjustPatientConnectionBeginReq , 0 * 4 }, // 0 parameter {Gui::GuiActionType::ID_AdjustPatientConnectionBeginRsp , 2 * 4 }, // 2 parameters each 4bytes // Pre-Treatment Ultrafiltration initial volume {Gui::GuiActionType::ID_AdjustUltrafiltrationInitReq , 1 * 4 }, // 1 parameter each 4bytes {Gui::GuiActionType::ID_AdjustUltrafiltrationInitRsp , 3 * 4 }, // 3 parameters each 4bytes // Pre-Treatment Patient Connection Confirm {Gui::GuiActionType::ID_AdjustPatientConnectionConfirmReq , 0 * 4 }, // 0 parameter {Gui::GuiActionType::ID_AdjustPatientConnectionConfirmRsp , 2 * 4 }, // 2 parameters each 4bytes // Pre-Treatment Start Treatment {Gui::GuiActionType::ID_AdjustStartTreatmentReq , 0 * 4 }, // 0 parameter {Gui::GuiActionType::ID_AdjustStartTreatmentRsp , 2 * 4 }, // 2 parameters each 4bytes // ---- {Gui::GuiActionType::ID_AdjustSalineReq , 1 * 4 }, // 1 parameter each 4bytes {Gui::GuiActionType::ID_AdjustSalineRsp , 3 * 4 }, // 3 parameters each 4bytes // ---- {Gui::GuiActionType::ID_AdjustHeparinReq , 1 * 4 }, // 1 parameter each 4bytes {Gui::GuiActionType::ID_AdjustHeparinRsp , 2 * 4 }, // 3 parameters each 4bytes // ---- Rinseback {Gui::GuiActionType::ID_AdjustRinsebackReq , 1 * 4 }, // 1 parameter each 4bytes {Gui::GuiActionType::ID_AdjustRinsebackRsp , 2 * 4 }, // 2 parameters each 4bytes // ---- Recirculate {Gui::GuiActionType::ID_AdjustRecirculateReq , 1 * 4 }, // 1 parameter each 4bytes {Gui::GuiActionType::ID_AdjustRecirculateRsp , 2 * 4 }, // 2 parameters each 4bytes // ---- Treatment End {Gui::GuiActionType::ID_AdjustTreatmentEndReq , 1 * 4 }, // 1 parameter each 4bytes {Gui::GuiActionType::ID_AdjustTreatmentEndRsp , 2 * 4 }, // 2 parameters each 4bytes // ---- Post-Treatment // ---- Patient Disconnect {Gui::GuiActionType::ID_AdjustPatientDisconnectNotifyReq , 0 * 4 }, // 0 parameter {Gui::GuiActionType::ID_AdjustPatientDisconnectConfirmReq , 0 * 4 }, // 0 parameter {Gui::GuiActionType::ID_AdjustPatientDisconnectConfirmRsp , 2 * 4 }, // 2 parameter each 4bytes // ---- Disposables Removal {Gui::GuiActionType::ID_AdjustDisposablesRemovalConfirmReq , 0 * 4 }, // 0 parameter {Gui::GuiActionType::ID_AdjustDisposablesRemovalConfirmRsp , 2 * 4 }, // 2 parameter each 4bytes // ---- Treatment Log {Gui::GuiActionType::ID_AdjustTreatmentLogReq , 0 * 4 }, // 0 parameter {Gui::GuiActionType::ID_AdjustTreatmentLogRsp , 36 * 4 }, //36 parameter each 4bytes {Gui::GuiActionType::ID_TreatmentLogAvrgeData , 5 * 4 }, // 5 parameter each 4bytes {Gui::GuiActionType::ID_TreatmentLogAlarmData , 3 * 4 }, // 3 parameter each 4bytes {Gui::GuiActionType::ID_TreatmentLogEventData , 3 * 4 }, // 3 parameter each 4bytes // ---- Versions {Gui::GuiActionType::ID_AdjustVersionsUIReq ,1+1+1+2+4 }, // variable length parameters {Gui::GuiActionType::ID_AdjustVersionsHDRsp ,1+1+1+2+1+1+1+1}, // variable length parameters {Gui::GuiActionType::ID_AdjustVersionsDGRsp ,1+1+1+2+1+1+1+1}, // variable length parameters {Gui::GuiActionType::ID_AdjustSerialHDRsp , 1 * 1 }, // minimum 1 parameter 1 byte {Gui::GuiActionType::ID_AdjustSerialDGRsp , 1 * 1 }, // minimum 1 parameter 1 byte // ---- {Gui::GuiActionType::ID_AdjustVersionsHDReq , 0 * 4 }, // 0 parameter {Gui::GuiActionType::ID_AdjustVersionsUIRsp ,1+1+1+2+4 }, // variable length parameters // ---- Service Information {Gui::GuiActionType::ID_AdjustServiceDatesReq , 0 * 4 }, // 0 parameter {Gui::GuiActionType::ID_AdjustServiceDatesHDRsp , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_AdjustServiceDatesDGRsp , 2 * 4 }, // 2 parameters each 4bytes // ---- RTC {Gui::GuiActionType::ID_AdjustHDDateTimeReq , 1 * 4 }, // 1 parameters each 4bytes {Gui::GuiActionType::ID_AdjustHDDateTimeRsp , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_AdjustDGDateTimeReq , 1 * 4 }, // 1 parameters each 4bytes {Gui::GuiActionType::ID_AdjustDGDateTimeRsp , 2 * 4 }, // 2 parameters each 4bytes // ---- Disinfect {Gui::GuiActionType::ID_AdjustDisinfectModeReq , 1 * 4 }, // 1 parameter 4bytes {Gui::GuiActionType::ID_AdjustDisinfectModeRsp , 2 * 4 }, // 2 parameters each 4bytes {Gui::GuiActionType::ID_AdjustDisinfectStartReq , 1 * 4 }, // 1 parameter 4bytes {Gui::GuiActionType::ID_AdjustDisinfectStartRsp , 2 * 4 }, // 2 parameters each 4bytes // ---- DG Cleaning Usage {Gui::GuiActionType::ID_AdjustDGCleaningUsageReq , 0 * 4 }, // 0 parameter {Gui::GuiActionType::ID_AdjustDGCleaningUsageRsp , 10 * 4 }, //10 parameters each 4bytes // ---- RO Water {Gui::GuiActionType::ID_DuetRoWaterStatDGq , 0 * 4 }, // 0 parameter each 4bytes {Gui::GuiActionType::ID_DuetRoWaterModeUIi , 1 * 4 }, // 1 parameter each 4bytes {Gui::GuiActionType::ID_DuetRoWaterModeDGr , 2 * 4 }, // 2 parameters each 4bytes // ---- {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 {Gui::GuiActionType::ID_HDGeneralEvent , 5 * 4 }, // 5 parameters each 4bytes {Gui::GuiActionType::ID_DGGeneralEvent , 5 * 4 }, // 5 parameters each 4bytes {Gui::GuiActionType::ID_AdjustInstitutionalRecordReq , 0 * 4 }, // 0 parameter {Gui::GuiActionType::ID_AdjustInstitutionalRecordRsp , 26 * 4 }, //26 parameters each 4 bytes }; /*! * \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, }; /*! * \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 Gui::GuiActionType actionId = Gui::GuiActionType::ID_Unknown; 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. return !isEmpty() && data.length() == length; // disabled coco end } }; typedef QList MessageList; typedef QList FrameList; }