#pragma once // Qt #include // Project #include "GuiGlobalsAutoGen.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_AlarmStatusData , 1 * 2 + 3 * 4 }, // 1 parameter(s) of 2 byte(s) and 3 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_AlarmTriggered , 8 * 4 }, // 8 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_AlarmCleared , 1 * 4 }, // 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_AlarmConditionCleared , 1 * 4 }, // 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDAlarmInformationData , 6 * 1 + 6 * 4 }, // 6 parameter(s) of 1 byte(s) and 6 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDAlarmInfoData , 1 * 4 }, // 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_UIActiveAlarmsListRequest , 0 * 4 }, // 0 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDActiveAlarmsListRequestResponse , 12 * 4 }, // 12 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_FWVersionsRequest , 3 * 1 + 1 * 2 + 1 * 4 }, // 3 parameter(s) of 1 byte(s) and 1 parameter(s) of 2 byte(s) and 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDVersionResponse , 7 * 1 + 1 * 2 + 1 * 4 }, // 7 parameter(s) of 1 byte(s) and 1 parameter(s) of 2 byte(s) and 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDVersionResponse , 7 * 1 + 1 * 2 + 1 * 4 }, // 7 parameter(s) of 1 byte(s) and 1 parameter(s) of 2 byte(s) and 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_UICheckIN , 0 * 4 }, // 0 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDBloodPumpData , 9 * 4 }, // 9 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDOPModeData , 2 * 4 }, // 2 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDOPModeData , 2 * 4 }, // 2 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDEvent , 5 * 4 }, // 5 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDEvent , 5 * 4 }, // 5 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDValvesStatesData , 30 * 1 + 1 * 2 }, // 30 parameter(s) of 1 byte(s) and 1 parameter(s) of 2 byte(s) {Gui::GuiActionType::ID_DDPressuresData , 14 * 4 }, // 14 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDVoltagesData , 11 * 4 }, // 11 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDBubblesData , 2 * 4 }, // 2 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDConductivityData , 4 * 4 }, // 4 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDAirPumpData , 2 * 4 }, // 2 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDSwitchesData , 1 * 4 }, // 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_PowerOffWarning , 1 * 4 }, // 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_OffButtonPressRequest , 1 * 1 }, // 1 parameter(s) of 1 byte(s) {Gui::GuiActionType::ID_TDPressureData , 12 * 4 }, // 12 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDConcentratePumpData , 25 * 4 }, // 25 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDTemperatureData , 11 * 4 }, // 11 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DialysatePumpsData , 20 * 4 }, // 20 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDHeatersData , 17 * 4 }, // 17 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDLevelData , 3 * 4 }, // 3 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDAirTrapData , 7 * 4 }, // 7 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDValvesData , 2 * 2 + 3 * 4 }, // 2 parameter(s) of 2 byte(s) and 3 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_ROEvent , 5 * 4 }, // 5 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_ROAlarmInfoData , 1 * 4 }, // 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDBalChamberData , 8 * 4 }, // 8 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDGenDialysateModeData , 9 * 4 }, // 9 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDGenDialysateRequestData , 7 * 4 }, // 7 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_ROValvesStatesData , 9 * 1 + 1 * 2 }, // 9 parameter(s) of 1 byte(s) and 1 parameter(s) of 2 byte(s) {Gui::GuiActionType::ID_ROPumpData , 8 * 4 }, // 8 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_ROOPModeData , 2 * 4 }, // 2 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_ROPressuresData , 18 * 4 }, // 18 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_ROLevelData , 1 * 4 }, // 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_ROFlowData , 4 * 4 }, // 4 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_ROConductivityData , 2 * 4 }, // 2 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDROStartStopCmdRequest , 3 * 4 }, // 3 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_ROTemperatureData , 5 * 4 }, // 5 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_ROHeaterData , 4 * 4 }, // 4 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDTreatmentTimeData , 3 * 4 }, // 3 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDTreatmentStateData , 10 * 4 }, // 10 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDSalineBolusData , 4 * 4 }, // 4 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDUltrafiltrationData , 4 * 4 }, // 4 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_UITreatmentParamsTOValidate , 19 * 4 }, // 19 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDRespTreatmentParamsTOValidate , 21 * 4 }, // 21 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_UIUltrafiltrationVolumeTOValidate , 1 * 4 }, // 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDRespUltrafiltrationVolumeTOValidate , 3 * 4 }, // 3 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDTreatmentParamRanges , 6 * 4 }, // 6 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_UITreatmentParamsConfirmed , 1 * 4 }, // 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_UIInitiateTreatmentWorkflow , 1 * 4 }, // 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDRespInitiateTreatmentWorkflow , 2 * 4 }, // 2 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_UIUFPauseResumeRequest , 1 * 4 }, // 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDUFPauseResumeResponse , 2 * 4 }, // 2 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_ROGenWaterModeData , 2 * 4 }, // 2 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDPreGenDialysateStateData , 1 * 4 }, // 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDPostGenDialysateStateData , 1 * 4 }, // 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDPreGenDialysateRequestData , 5 * 4 }, // 5 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_ROPreGenWaterModeData , 1 * 4 }, // 1 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDEjectorData , 2 * 4 }, // 2 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_TDTreatmentSetPoints , 3 * 4 }, // 3 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_DDPistonPumpControlData , 9 * 4 }, // 9 parameter(s) of 4 byte(s) {Gui::GuiActionType::ID_AckMessageThatRequiresAck , 0 * 4 }, // 0 parameter(s) of 4 byte(s) }; /*! * \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_TD_Alarm = 0x001, ///< TD alarm broadcast eChlid_DD_Alarm = 0x002, ///< DD alarm broadcast eChlid_FP_Alarm = 0x003, ///< FP alarm broadcast eChlid_UI_Alarm = 0x004, ///< UI alarm broadcast [Out] //// Sync eChlid_TD_Sync = 0x100, ///< HD sync broadcast eChlid_DD_Sync = 0x101, ///< DD sync broadcast eChlid_FP_Sync = 0x102, ///< DD sync broadcast eChlid_UI_Sync = 0x103, ///< UI sync broadcast [Out] // UI not listening eChlid_TD_DD = 0x010, ///< TD => DD eChlid_DD_TD = 0x011, ///< DD => TD eChlid_DD_FP = 0x021, ///< DD => FP eChlid_FP_DD = 0x020, ///< FP => DD // UI is listening eChlid_TD_UI = 0x040, ///< TD => UI eChlid_UI_TD = 0x041, ///< UI => TD [Out] // UI listens occasionally eChlid_DD_UI = eChlid_DD_Sync , ///< DD => UI eChlid_UI_DD = eChlid_UI_Sync , ///< UI => DD [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_TD = 0x400, ///< dialin => TD eTD_Dialin = 0x401, ///< TD => dialin eDialin_DD = 0x402, ///< dialin => DD eDD_Dialin = 0x403, ///< DD => dialin eDialin_FP = 0x404, ///< dialin => FP eFP_Dialin = 0x405, ///< FP => dialin eDialin_UI = 0x406, ///< dialin => UI eUI_Dialin = 0x407, ///< UI => dialin }; /*! * \brief The Can_Source enum * \details The allowable sources of the CANBus messages. */ enum Can_Source { eCan_Unknown = -1, eCan_TD = 0, eCan_DD = 1, eCan_FP = 2, eCan_DI = 3, }; /*! * \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 () { // 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(); } bool isComplete() { // 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; } }; typedef QList MessageList; typedef QList FrameList; }