Index: sources/canbus/messageinterpreter.cpp =================================================================== diff -u -rb798668f16ad0967ab97e96f5f9a2cdd821e899f -r24dfaab03aaabc7b7714c5a4264dfbfca65aa41a --- sources/canbus/messageinterpreter.cpp (.../messageinterpreter.cpp) (revision b798668f16ad0967ab97e96f5f9a2cdd821e899f) +++ sources/canbus/messageinterpreter.cpp (.../messageinterpreter.cpp) (revision 24dfaab03aaabc7b7714c5a4264dfbfca65aa41a) @@ -2,26 +2,31 @@ * * 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. + * 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 messageinterpreter.cpp - * \date 12/11/2019 - * \author Behrouz NematiPour + * \file messageinterpreter.cpp + * \author (last) Behrouz NematiPour + * \date (last) 20-Aug-2020 + * \author (original) Behrouz NematiPour + * \date (original) 13-Dec-2019 * */ #include "messageinterpreter.h" // Qt #include +// #include // Project #include "logger.h" #include "format.h" using namespace Can; +using namespace Model; +#define DEBUG_RECEIVE_SIGNAL(vID, vMODEL) //qDebug() << vID << vMODEL; + /*! * \brief MessageInterpreter::MessageInterpreter * \details Constructor @@ -30,6 +35,43 @@ */ MessageInterpreter::MessageInterpreter(QObject *parent) : QObject(parent) { } +/*! + * \brief MessageInterpreter::notify + * \details Checks and prepares the model with the Message Data + * Regarding the type of message logs the message received. + * Notifies observers by emitting the didActionReceive( < Data > ) signal + * \param vMessage - The Denali message + * \param vID - The Message ID to be checked against + * \param vModel - The appropriate model for the Message Data + * \param vData - A QVariant list of the Message Data which will be used for debugging if needed. + * \return true on successful check and prepare. + */ +template +bool MessageInterpreter::notify(const Message &vMessage, QVariantList &vData, Gui::GuiActionType vIdCheck) +{ + bool ok = false; + TModel tModel; + if ( ! isValidMessage(vMessage, vIdCheck) ) return ok; + ok = tModel.fromByteArray(vMessage.data); + tModel.toVariantList(vData); + // coco begin validated : Tested manually. This code will never go false + // because the isValidMessage is catching errors. + // only is checking here for developer safety if logic has changed. + if ( ! ok ) return false; + // coco end + emit didActionReceive(tModel.data()); + logReceivedMessage(tModel); + DEBUG_RECEIVE_SIGNAL(vIdCheck, typeid(TModel).name()) + return ok; +} + +/*! + * \brief MessageInterpreter::isType + * \details Checks if this is the message intended to be + * \param vMessage - The message + * \param vType - The type of the message to be checked against + * \return true on correct type + */ bool MessageInterpreter::isType(const Message &vMessage, Gui::GuiActionType vType) const { if ( vMessage.actionId != vType ) { @@ -38,17 +80,94 @@ return true; } +/*! + * \brief MessageInterpreter::isPayloadLenValid + * \details Checks if the Data length has been defined for this type of message + * if not logs Undefined Data Length error + * if defined checks if the correct length of data is provided for this type of message. + * if not logs Incorrect Data Length error + * otherwise returns true + * \param vMessage - The message + * \param vType - The type of the message to be checked against + * \return true on correct data length for the type vType + */ bool MessageInterpreter::isPayloadLenValid(const Message &vMessage, Gui::GuiActionType vType) const { + QString mActionIdHexString = Format::toHexString(vMessage.actionId); + if ( ! payloadLen.contains(vType) ) { + LOG_DEBUG(QString("Undefined data length for received Message with ID '%1'").arg(mActionIdHexString)); + return false; + } if ( vMessage.data.length() < payloadLen[vType] ) { - QString mActionIdHexString = Format::toHexString(vMessage.actionId); - LOG_ERROR(tr("Incorrect data for Message ID (HD) '%1'").arg(mActionIdHexString)); + LOG_DEBUG(QString("Incorrect data length for received Message with ID '%1'").arg(mActionIdHexString)); return false; } return true; } /*! + * \brief MessageInterpreter::logInvalidLength + * \details Logs invalid data length for the message type vActionId + * \param vActionId - Message Type + */ +void MessageInterpreter::logInvalidLength(const Gui::GuiActionType &vActionId) +{ + QString mActionIdHexString = Format::toHexString(vActionId); + LOG_DEBUG(QString("Incorrect data length for transmit message with ID '%1'") + .arg(mActionIdHexString)); +} + +/*! + * \brief MessageInterpreter::validateMessage + * \details Validate the message by checking its type and data + * \param vMessage - The message + * \param vType - The type of the message to be checked against + * \return true on valid massage + */ +bool MessageInterpreter::isValidMessage(const Message &vMessage, Gui::GuiActionType vType) const +{ + if ( ! isType (vMessage, vType) ) return false; + if ( ! isPayloadLenValid(vMessage, vType) ) return false; + return true; +} + +/*! + * \brief MessageInterpreter::printUnhandled + * \details Prints out the formatted string of the vMessage of type Message + * In case the Message ID of received CANBUS message + * is known to the interpreter but has not been handled/implemented. + * \param vMessage - The message contains Unhandled Message ID + */ +void MessageInterpreter::printUnhandled(const Message &vMessage) const +{ + if ( gDisableUnhandledReport ) return; + QString mActionIdHexString = Format::toHexString(vMessage.actionId, false, eLenMessageIDDigits); + QString logMessage = tr("Unhandled Message ID (HD)") + '\n' + + QString("%1 # %2 %3") + .arg(int(vMessage.can_id), 3, 16, QChar('0')) + .arg(mActionIdHexString) + .arg(QString(vMessage.data.toHex('.'))); + LOG_DEBUG(logMessage); +} + +/*! + * \brief MessageInterpreter::logReceived + * \details Regarding the type of message logs the message received. + * \param vModel - the MAbstract model type + */ +void MessageInterpreter::logReceivedMessage(const Model::MAbstract &vModel) +{ + switch (vModel.typeText()) { + case Model::MAbstract::Type_Enum::eDatum: + LOG_DATUM(vModel.toString()); + break; + case Model::MAbstract::Type_Enum::eEvent: + LOG_EVENT(vModel.toString()); + break; + } +} + +/*! * \brief MessageInterpreter::interpretMessage * \details This method will be called * to interpret messages from UI regarding vActionId. @@ -63,60 +182,121 @@ bool MessageInterpreter::interpretMessage(const Gui::GuiActionType &vActionId, const QVariantList &vData, QByteArray &vPayload) { bool ok = true; + QString mSenderID = "UI,"; + vPayload.clear(); - int count = vData.count(); + int count = vData.length(); + + LOG_EVENT(QString("%0").arg(vActionId)); + switch (vActionId) { // notice we are in transmit mode - case Gui::GuiActionType::PowerOff: - if (count) { - vPayload += vData[0].toUInt(); - } else { - QString mActionIdHexString = Format::toHexString(vActionId); - LOG_ERROR(tr("Incorrect data for Message ID (UI) '%1'").arg(mActionIdHexString)); - ok = false; - } - break; + case Gui::GuiActionType::ID_Acknow: // len: 0, can have zero len + break; // No data, Just registered - case Gui::GuiActionType::KeepAlive: - // Nothing needs to be done. - // KeepAlive has No data. - // Mentioned in the switch/case to be registered as a valid message. - // - // Note : added this line to be able to do the Fake Test - if (count) { - vPayload = Format::fromVariant(vData[0]); - } - break; + case Gui::GuiActionType::ID_KeepAlive: // len: 255, can have any len + { + if ( count ) { // this message has a variable length + vPayload = Format::fromVariant(vData[0]); + } + LOG_EVENT(mSenderID + QString("CheckIn")); + } break; - case Gui::GuiActionType::Acknow: - // Nothing needs to be done. - // Acknow has No data. - // Mentioned in the switch/case to be registered as a valid message. - break; + case Gui::GuiActionType::ID_RawData: // len: 255, can have any len + { + if ( count ) { // this message has a variable length + vPayload = Format::fromVariant(vData[0]); + } + LOG_EVENT(mSenderID + QString("RawData")); - case Gui::GuiActionType::String: - if (count) { - vPayload = Format::fromVariant(vData[0]); - } - break; + } break; - case Gui::GuiActionType::AdjustBloodDialysateReq: - if (count) { + case Gui::GuiActionType::ID_PowerOff: + { + if ( ! count ) { logInvalidLength(vActionId); return false; } + vPayload += Format::fromVariant(vData); + LOG_EVENT(AdjustPowerOffRequestData::toString(vData)); + + } break; + + case Gui::GuiActionType::ID_AdjustBloodDialysateReq: + { + if ( ! count ) { logInvalidLength(vActionId); return false; } vPayload = Format::fromVariant(vData); - } - break; + LOG_EVENT(AdjustBloodDialysateRequestData::toString(vData)); + } break; - case Gui::GuiActionType::AdjustDurationReq: - if (count) { + case Gui::GuiActionType::ID_AdjustDurationReq: + { + if ( ! count ) { logInvalidLength(vActionId); return false; } vPayload = Format::fromVariant(vData); - } - break; + LOG_EVENT(AdjustDurationRequestData::toString(vData)); + } break; - default: - QString mActionIdHexString = Format::toHexString(vActionId); - LOG_ERROR(tr("Unknown Message ID (UI) '%1'").arg(mActionIdHexString)); - ok = false; - break; + case Gui::GuiActionType::ID_AdjustUltrafiltrationStateReq: { + if ( ! count ) { logInvalidLength(vActionId); return false; } + vPayload = Format::fromVariant(vData); + LOG_EVENT(AdjustUltrafiltrationStateRequestData::toString(vData)); + } break; + case Gui::GuiActionType::ID_AdjustUltrafiltrationEditReq: { + if ( ! count ) { logInvalidLength(vActionId); return false; } + vPayload = Format::fromVariant(vData); + LOG_EVENT(AdjustUltrafiltrationEditRequestData::toString(vData)); + } break; + + case Gui::GuiActionType::ID_AdjustUltrafiltrationConfirmReq: { + if ( ! count ) { logInvalidLength(vActionId); return false; } + vPayload = Format::fromVariant(vData); + LOG_EVENT(AdjustUltrafiltrationConfirmRequestData::toString(vData)); + } break; + + case Gui::GuiActionType::ID_AdjustSalineReq: { + if ( ! count ) { logInvalidLength(vActionId); return false; } + vPayload = Format::fromVariant(vData); + LOG_EVENT(AdjustSalineRequestData::toString(vData)); + } break; + + case Gui::GuiActionType::ID_AlarmSilenceReq: { + if ( ! count ) { logInvalidLength(vActionId); return false; } + vPayload = Format::fromVariant(vData); + LOG_EVENT(AlarmSilenceRequestData::toString(vData)); + } break; + + case Gui::GuiActionType::ID_AlarmUserAckReq: { + if ( ! count ) { logInvalidLength(vActionId); return false; } + vPayload = Format::fromVariant(vData); + LOG_EVENT(AlarmAcknowledgeRequestData::toString(vData)); + } break; + + case Gui::GuiActionType::ID_StartTreatmentReq: { + if ( ! count ) { logInvalidLength(vActionId); return false; } + vPayload = Format::fromVariant(vData); + LOG_EVENT(StartTreatmentRequestData::toString(vData)); + } break; + + case Gui::GuiActionType::ID_ConfirmTreatmentReq: { + if ( count != 0 ) { logInvalidLength(vActionId); return false; } + vPayload = Format::fromVariant(vData); + LOG_EVENT(ConfirmTreatmentRequestData::toString(vData)); + } break; + + case Gui::GuiActionType::ID_EndTreatmentReq: { + if ( count != 0 ) { logInvalidLength(vActionId); return false; } + vPayload = Format::fromVariant(vData); + LOG_EVENT(EndTreatmentRequestData::toString(vData)); + } break; + + case Gui::GuiActionType::ID_CreateTreatmentReq: { + if ( ! count ) { logInvalidLength(vActionId); return false; } + vPayload = Format::fromVariant(vData); + LOG_EVENT(AdjustTreatmentParametersRequestData::toString(vData)); + } break; + + default: { + QString mActionIdHexString = Format::toHexString(vActionId); + LOG_DEBUG(mSenderID + tr("Unknown transmit Message with ID '%1'").arg(mActionIdHexString)); + ok = false; + } break; } return ok; } @@ -138,45 +318,23 @@ { bool ok = false; switch (vMessage.can_id) { - case eChlid_HD_UI: + case eChlid_HD_UI : case eChlid_HD_Alarm: - case eChlid_HD_Sync: - ok = interpretMessage_HD(vMessage, vData); - break; - // coco begin validated: Is a placeholder and There is no definition/implementation of DG communication with UI. - case eChlid_DG_UI: - //case eChlid_DG_Alarm: - //case eChlid_DG_Sync: - ok = interpretMessage_DG(vMessage, vData); - break; + case eChlid_HD_Sync : ok = interpretMessage_HD(vMessage, vData); break; + case eChlid_DG_HD : + + case eChlid_DG_UI : + // case eChlid_DG_Alarm: // commented out for now. Currently there is no message in this category. + case eChlid_DG_Sync : ok = interpretMessage_DG(vMessage, vData); break; + default: break; - // coco end } return ok; } /*! - * \brief MessageInterpreter::printUnhandled - * \details Prints out the formatted string of the vMessage of type Message - * In case the Message ID of received CANBUS message - * is known to the interpreter but has not been handled/implemented. - * \param vMessage - The message contains Unhandled Message ID - */ -void MessageInterpreter::printUnhandled(const Message &vMessage) -{ - if ( gDisableHunhandledReport ) return; - QString mActionIdHexString = Format::toHexString(vMessage.actionId, false, eLenMessageIDDigits); - QString logMessage = tr("Unhandled Message ID (HD)") + '\n' + - QString("%1 # %2 %3") - .arg(vMessage.can_id, 3, 16, QChar('0')) - .arg(mActionIdHexString) - .arg(QString(vMessage.data.toHex('.'))); - LOG_ERROR(logMessage); -} - -/*! * \brief MessageInterpreter::interpretMessage_HD * \details This method will be called * for received messages from HD to interpret the vMessage of type Message @@ -191,79 +349,55 @@ */ bool MessageInterpreter::interpretMessage_HD(const Message &vMessage, QVariantList &vData) { - bool ok = false; + bool ok = false; vData.clear(); - switch (vMessage.actionId) { // notice we are in receive mode - case Gui::GuiActionType::PowerOff: { - ok = powerOffData (vMessage, vData); - break; - } - case Gui::GuiActionType::Acknow: - ok = true; - break; + // ----- Debug + case Gui::GuiActionType::ID_CANBusFaultCount : ok = canbusFaultCountData (vMessage, vData); break; // TODO : implement notify<>() - case Gui::GuiActionType::PowerOffBroadcast: - ok = true; - break; + // ----- Datum + case Gui::GuiActionType::ID_TreatmentTime : ok = notify(vMessage, vData, Gui::GuiActionType::ID_TreatmentTime ); break; + case Gui::GuiActionType::ID_BloodFlow : ok = notify(vMessage, vData, Gui::GuiActionType::ID_BloodFlow ); break; + case Gui::GuiActionType::ID_DialysateInletFlow : ok = notify(vMessage, vData, Gui::GuiActionType::ID_DialysateInletFlow ); break; + case Gui::GuiActionType::ID_DialysateOutletFlow : ok = notify(vMessage, vData, Gui::GuiActionType::ID_DialysateOutletFlow ); break; + case Gui::GuiActionType::ID_TreatmentRanges : ok = notify(vMessage, vData, Gui::GuiActionType::ID_TreatmentRanges ); break; + case Gui::GuiActionType::ID_PressureOcclusion : ok = notify(vMessage, vData, Gui::GuiActionType::ID_PressureOcclusion ); break; + case Gui::GuiActionType::ID_TreatmentStates : ok = notify(vMessage, vData, Gui::GuiActionType::ID_TreatmentStates ); break; + case Gui::GuiActionType::ID_PrimingData : ok = notify(vMessage, vData, Gui::GuiActionType::ID_PrimingData ); break; + case Gui::GuiActionType::ID_Saline : ok = notify(vMessage, vData, Gui::GuiActionType::ID_Saline ); break; - case Gui::GuiActionType::BloodFlow: - ok = bloodFlowData (vMessage, vData); - break; + // ----- Events + case Gui::GuiActionType::ID_HDOperationModeData : ok = notify(vMessage, vData, Gui::GuiActionType::ID_HDOperationModeData ); break; + case Gui::GuiActionType::ID_HDDebugText : ok = notify(vMessage, vData, Gui::GuiActionType::ID_HDDebugText ); break; - case Gui::GuiActionType::DialysateInletFlow: - ok = dialysateInletFlowData (vMessage, vData); - break; + case Gui::GuiActionType::ID_Acknow : ok = true; break; // TODO : implement notify<>() + case Gui::GuiActionType::ID_PowerOff : ok = notify(vMessage, vData, Gui::GuiActionType::ID_PowerOff ); break; + case Gui::GuiActionType::ID_ShuttingDown : ok = true; LOG_EVENT("HD,ShuttingDown"); break; // TODO : implement notify<>() + case Gui::GuiActionType::ID_AlarmStatus : ok = alarmStatus (vMessage, vData); break; // TODO : implement notify<>() + case Gui::GuiActionType::ID_AlarmTriggered : ok = alarmTriggered (vMessage, vData); break; // TODO : implement notify<>() + case Gui::GuiActionType::ID_AlarmCleared : ok = alarmCleared (vMessage, vData); break; // TODO : implement notify<>() + case Gui::GuiActionType::ID_CreateTreatmentRsp : ok = notify(vMessage, vData, Gui::GuiActionType::ID_CreateTreatmentRsp ); break; - case Gui::GuiActionType::DialysateOutletFlow: - ok = dialysateOutletFlowData (vMessage, vData); - break; + // Adjustment Response Messages + case Gui::GuiActionType::ID_AdjustDurationRsp : ok = notify(vMessage, vData, Gui::GuiActionType::ID_AdjustDurationRsp ); break; + case Gui::GuiActionType::ID_AdjustBloodDialysateRsp : ok = notify(vMessage, vData, Gui::GuiActionType::ID_AdjustBloodDialysateRsp); break; + case Gui::GuiActionType::ID_AdjustSalineRsp : ok = notify(vMessage, vData, Gui::GuiActionType::ID_AdjustSalineRsp ); break; - case Gui::GuiActionType::TreatmentTime: - ok = treatmentTime (vMessage, vData); - break; + // ok = notify(vMessage, vData, Gui::GuiActionType::ID_AdjustUltrafiltrationStateReq); break; + // this message has been inherited from MAbstract and should use notify but since the response message is not standard can't use notify yet. + // when received gets payload len error and can't be interpreted. + case Gui::GuiActionType::ID_AdjustUltrafiltrationStateReq : ok = adjustUltrafiltrationState (vMessage, vData); break; // TODO : implement notify<>() + case Gui::GuiActionType::ID_AdjustUltrafiltrationEditRsp : ok = adjustUltrafiltrationEdit (vMessage, vData); break; // TODO : implement notify<>() + case Gui::GuiActionType::ID_AdjustUltrafiltrationConfirmRsp : ok = adjustUltrafiltrationConfirm (vMessage, vData); break; // TODO : implement notify<>() - case Gui::GuiActionType::AlarmStatus: - ok = alarmStatus (vMessage, vData); - break; + case Gui::GuiActionType::ID_StartTreatmentRsp : ok = notify (vMessage, vData, Gui::GuiActionType::ID_StartTreatmentRsp ); break; + case Gui::GuiActionType::ID_EndTreatmentRsp : ok = notify (vMessage, vData, Gui::GuiActionType::ID_EndTreatmentRsp ); break; - case Gui::GuiActionType::PressureOcclusion: - ok = pressureOcclusionData (vMessage, vData); - break; - - case Gui::GuiActionType::TreatmentRanges: - ok = treatmentRangesData (vMessage, vData); - break; - - case Gui::GuiActionType::AdjustBloodDialysateRsp: - ok = adjustBloodDialysateData (vMessage, vData); - break; - - case Gui::GuiActionType::AdjustDurationRsp: - ok = adjustDurationData (vMessage, vData); - break; - // unhandles messages: these will only be logged as received message // there has nothing been defined for these messages. - case Gui::GuiActionType::AlarmTriggered: - printUnhandled (vMessage); - ok = true; - break; - - case Gui::GuiActionType::AlarmCleared: - printUnhandled (vMessage); - ok = true; - break; - - case Gui::GuiActionType::TreatmentState: - printUnhandled (vMessage); - ok = true; - break; - - default: - printUnhandled (vMessage); - break; + default : printUnhandled (vMessage ); break; } + return ok; } @@ -282,377 +416,164 @@ */ bool MessageInterpreter::interpretMessage_DG(const Message &vMessage, QVariantList &vData) { - // coco begin validated: No data have been interpreted from DG yet - Q_UNUSED(vMessage ); - Q_UNUSED(vData ); - return false; -} -// coco end + bool ok = false; + vData.clear(); + switch (vMessage.actionId) { // notice we are in receive mode + case Gui::GuiActionType::ID_DGCheckIn: // TODO : implement notify<>() + ok = true; + LOG_EVENT(QString("DG,CheckIn," + QVariant(vData).toStringList().join(','))); + break; -/*! - * \brief MessageInterpreter::getPowerOffData - * \details This is the method which interprets the PowerOff message data - * in vMessage of type Message. - * to its elements of data. - * \param vMessage - The vMessage of type Message which contains all the data, require to be interpreted. - * \param vData - The BloodFlow data - * \return true if the data can be extracted as defined for PowerOff Message ID - */ -bool MessageInterpreter::getPowerOffData(const Message &vMessage, Model::MPowerOff &vData) -{ - if ( vMessage.actionId != Gui::GuiActionType::PowerOff) { - return false; - } + case Gui::GuiActionType::ID_DGROPumpData : ok = notify(vMessage, vData, Gui::GuiActionType::ID_DGROPumpData ); break; + case Gui::GuiActionType::ID_DGPressuresData : ok = notify(vMessage, vData, Gui::GuiActionType::ID_DGPressuresData ); break; + case Gui::GuiActionType::ID_DGDrainPumpData : ok = notify(vMessage, vData, Gui::GuiActionType::ID_DGDrainPumpData ); break; + case Gui::GuiActionType::ID_DGOperationModeData : ok = notify(vMessage, vData, Gui::GuiActionType::ID_DGOperationModeData ); break; + case Gui::GuiActionType::ID_DGReservoirData : ok = notify(vMessage, vData, Gui::GuiActionType::ID_DGReservoirData ); break; + case Gui::GuiActionType::ID_DGValvesStatesData : ok = notify(vMessage, vData, Gui::GuiActionType::ID_DGValvesStatesData ); break; + case Gui::GuiActionType::ID_DGHeatersData : ok = notify(vMessage, vData, Gui::GuiActionType::ID_DGHeatersData ); break; + case Gui::GuiActionType::ID_DGLoadCellReadingsData : ok = notify(vMessage, vData, Gui::GuiActionType::ID_DGLoadCellReadingsData); break; + case Gui::GuiActionType::ID_DGTemperaturesData : ok = notify(vMessage, vData, Gui::GuiActionType::ID_DGTemperaturesData ); break; + case Gui::GuiActionType::ID_DGDebugText : ok = notify(vMessage, vData, Gui::GuiActionType::ID_DGDebugText ); break; - if ( vMessage.data.length() < payloadLen[Gui::GuiActionType::PowerOff] ) { - QString mActionIdHexString = Format::toHexString(vMessage.actionId); - LOG_ERROR(tr("Incorrect data for Message ID (HD) '%1'").arg(mActionIdHexString)); - return false; - } + // unhandled messages: these will only be logged as received message + // there has nothing been defined for these messages. + default: + printUnhandled (vMessage); + break; - vData.fromByteArray(vMessage.data); - - return true; -} - -/*! - * \brief MessageInterpreter::bloodFlowData - * \details Used the getBloodFlowData method and converts each parameter - * in vData of type QVaranitList, to be used in the GUI - * Also logs the data - * \param vMessage - The message - * \param vData - the output data - * \return return value of the method getBloodFlowData - */ -bool MessageInterpreter::powerOffData(const Message &vMessage, QVariantList &vData) -{ - bool ok; - Model::MPowerOff mData; - ok = getPowerOffData(vMessage, mData); - LOG_DATUM(mData.toString()); - - if (ok) { - mData.toVariantList(vData); - emit didActionReceive(mData.data()); } - return ok; -} -/*! - * \brief MessageInterpreter::getBloodFlowData - * \details This is the method which interprets the Blood Flow message data in vMessage of type Message - * to its elements of data. - * \param vMessage - The vMessage of type Message which contains all the data, require to be interpreted. - * \param vData - The BloodFlow data - * \return true if the message can be successfully converted to the Blood Flow data elements. - */ -bool MessageInterpreter::getBloodFlowData(const Message &vMessage, Model::MBloodFlow &vData) -{ - if ( vMessage.actionId != Gui::GuiActionType::BloodFlow ) { - return false; - } - - if ( vMessage.data.length() < payloadLen[Gui::GuiActionType::BloodFlow] ) { - QString mActionIdHexString = Format::toHexString(vMessage.actionId); - LOG_ERROR(tr("Incorrect data for Message ID (HD) '%1'").arg(mActionIdHexString)); - return false; - } - - vData.fromByteArray(vMessage.data); - - return true; -} - -/*! - * \brief MessageInterpreter::bloodFlowData - * \details Used the getBloodFlowData method and converts each parameter - * in vData of type QVaranitList, to be used in the GUI - * Also logs the data - * \param vMessage - The message - * \param vData - the output data - * \return return value of the method getBloodFlowData - */ -bool MessageInterpreter::bloodFlowData(const Message &vMessage, QVariantList &vData) -{ - bool ok; - Model::MBloodFlow mData; - ok = getBloodFlowData(vMessage, mData); - LOG_DATUM(mData.toString()); - - if (ok) { - mData.toVariantList(vData); - emit didActionReceive(mData.data()); - } return ok; } -/*! - * \brief MessageInterpreter::getDialysateInletFlowData - * \details This is the method which interprets the Dialysate Inlet Flow message data in vMessage of type Message - * to its elements of data. - * \param vMessage - The vMessage of type Message which contains all the data, require to be interpreted. - * \param vData - The dialydate inlet flow data - * \return true if the message can be successfully converted to the Blood Flow data elements. - */ -bool MessageInterpreter::getDialysateInletFlowData(const Message &vMessage, Model::MDialysateFlow &vData) -{ - if ( vMessage.actionId != Gui::GuiActionType::DialysateInletFlow ) { - return false; - } +// ---------- ---------- Message handlers ---------- ---------- // - if ( vMessage.data.length() < payloadLen[Gui::GuiActionType::DialysateInletFlow] ) { - QString mActionIdHexString = Format::toHexString(vMessage.actionId); - LOG_ERROR(tr("Incorrect data for Message ID (HD) '%1'").arg(mActionIdHexString)); - return false; - } - - vData.fromByteArray(vMessage.data); - - return true; -} - +// ---------- ---------- ---------- ---------- ---------- Debug ---------- ---------- ---------- ---------- ---------- // /*! - * \brief MessageInterpreter::dialysateInletFlowData - * \details Used the getDialysateInletFlowData method and converts each parameter - * in vData of type QVaranitList, to be used in the GUI - * Also logs the data - * \param vMessage - The message - * \param vData - the output data - * \return return value of the method getDialysateInletFlowData + * \brief MessageInterpreter::canbusFaultCountData + * \details This method interprets Fault Count message data + * in vMessage of type Message. This message is only used for debugging purposes. + * \param vMessage - The vMessage of type Message which contains all the data, + * require to be interpreted. + * \param vData - Fault Count data + * \return true if the data can be extracted as defined for Fault Count Message ID */ -bool MessageInterpreter::dialysateInletFlowData(const Message &vMessage, QVariantList &vData) +bool MessageInterpreter::canbusFaultCountData(const Message &vMessage, QVariantList &vData) { - bool ok; - Model::MDialysateFlow mData; - ok = getDialysateInletFlowData(vMessage, mData); - LOG_DATUM(mData.toString()); + // TODO : review other methods + bool ok = false; + if ( ! isValidMessage(vMessage, Gui::GuiActionType::ID_CANBusFaultCount) ) return ok; + QVariantList mData; + int index = 0; + Types::U32 mCanBUSFaultCount; + ok = GetValue(vMessage.data, index, mCanBUSFaultCount); + // coco begin validated : developer safety if for any reason length of CanBUSFaultCount set to 0 if (ok) { - mData.toVariantList(vData); - emit didActionReceive(mData.data()); + // coco end + vData += mCanBUSFaultCount.value; } return ok; } +// ---------- ---------- ---------- ---------- ---------- Events ---------- ---------- ---------- ---------- ---------- // +// ---------- ---------- ---------- ---------- ---------- - HD ---------- ---------- ---------- ---------- ---------- // /*! - * \brief MessageInterpreter::getDialysateOutletFlowData - * \details This is the method which interprets the Dialysate Outlet Flow message data in vMessage of type Message - * to its elements of data. - * \param vMessage - The vMessage of type Message which contains all the data, require to be interpreted. - * \param vData - The dialydate outlet flow data (ultrafiltration) - * \return true if the message can be successfully converted to the Blood Flow data elements. + * \brief MessageInterpreter::alarmStatus + * \details This method interprets Alarm Status message data + * in vMessage of type Message. + * \param vMessage - The vMessage of type Message which contains all the data, + * require to be interpreted. + * \param vData - Alarm Status data + * \return true if the data can be extracted as defined for Alarm Status Message ID */ -bool MessageInterpreter::getDialysateOutletFlowData(const Message &vMessage, Model::MOutletFlow &vData) -{ - if ( vMessage.actionId != Gui::GuiActionType::DialysateOutletFlow ) { - return false; - } +bool MessageInterpreter::alarmStatus(const Message &vMessage, QVariantList &vData) { + // TODO : review other methods + bool ok = false; + if ( ! isValidMessage(vMessage, Gui::GuiActionType::ID_AlarmStatus) ) return ok; - if ( vMessage.data.length() < payloadLen[Gui::GuiActionType::DialysateOutletFlow] ) { - QString mActionIdHexString = Format::toHexString(vMessage.actionId); - LOG_ERROR(tr("Incorrect data for Message ID (HD) '%1'").arg(mActionIdHexString)); - return false; - } + Model::MAlarmStatus mData; + ok = mData.fromByteArray(vMessage.data); + LOG_EVENT("HD," + mData.toString()); - vData.fromByteArray(vMessage.data); + mData.toVariantList(vData); + emit didActionReceive(mData.data()); - return true; -} - -/*! - * \brief MessageInterpreter::dialysateOutletFlowData - * \details Used the getDialysateOutletFlowData method and converts each parameter - * in vData of type QVaranitList, to be used in the GUI - * Also logs the data - * \param vMessage - The message - * \param vData - the output data - * \return return value of the method getDialysateOutletFlowData - */ -bool MessageInterpreter::dialysateOutletFlowData(const Message &vMessage, QVariantList &vData) -{ - bool ok; - Model::MOutletFlow mData; - ok = getDialysateOutletFlowData(vMessage, mData); - LOG_DATUM(mData.toString()); - - if (ok) { - mData.toVariantList(vData); - emit didActionReceive(mData.data()); - } return ok; } /*! - * \brief MessageInterpreter::getDialysateOutletFlowData - * \param vMessage - The vMessage of type Message which contains all the data, require to be interpreted. - * \param vData - Treatment Time data - * \return true if the message can be successfully converted to the Blood Flow data elements. - */ -bool MessageInterpreter::getTreatmentTime( const Message &vMessage , Model::MTreatmentTime &vData) -{ - if ( vMessage.actionId != Gui::GuiActionType::TreatmentTime ) { - return false; - } - - if ( vMessage.data.length() < payloadLen[Gui::GuiActionType::TreatmentTime] ) { - QString mActionIdHexString = Format::toHexString(vMessage.actionId); - LOG_ERROR(tr("Incorrect data for Message ID (HD) '%1'").arg(mActionIdHexString)); - return false; - } - - vData.fromByteArray(vMessage.data); - - return true; -} - -/*! - * \brief MessageInterpreter::treatmentTime - * \details Used the getTreatmentTime method and converts each parameter - * in vData of type QVaranitList, to be used in the GUI - * Also logs the data - * \param vMessage - The message - * \param vData - the output data - * \return return value of the method getDialysateOutletFlowData - */ -bool MessageInterpreter::treatmentTime(const Message &vMessage, QVariantList &vData) -{ - bool ok; - Model::MTreatmentTime mData; - ok = getTreatmentTime(vMessage, mData); - LOG_DATUM(mData.toString()); - - if (ok) { - mData.toVariantList(vData); - emit didActionReceive(mData.data()); - } - return ok; -} - -/*! - * \brief MessageInterpreter::getAlarmStatus - * \details This method interprets AlarmStatus message data + * \brief MessageInterpreter::alarmTriggered + * \details This method interprets Alarm Triggered message data * in vMessage of type Message. * \param vMessage - The vMessage of type Message which contains all the data, * require to be interpreted. - * \param vData - Alarm Status dta - * \return true if the data can be extracted as defined for AlarmStatus Message ID + * \param vData - Alarm Triggered data + * \return true if the data can be extracted as defined for Alarm Triggered Message ID */ -bool MessageInterpreter::getAlarmStatus(const Message &vMessage, Model::MAlarmStatus &vData) +bool MessageInterpreter::alarmTriggered(const Message &vMessage, QVariantList &vData) { - if ( vMessage.actionId != Gui::GuiActionType::AlarmStatus ) { - return false; - } + // TODO : review other methods + bool ok = false; + if ( ! isValidMessage(vMessage, Gui::GuiActionType::ID_AlarmTriggered) ) return ok; - if ( vMessage.data.length() < payloadLen[Gui::GuiActionType::AlarmStatus] ) { - QString mActionIdHexString = Format::toHexString(vMessage.actionId); - LOG_ERROR(tr("Incorrect data for Message ID (HD) '%1'").arg(mActionIdHexString)); - return false; - } + Model::MAlarmTriggered mData; + ok = mData.fromByteArray(vMessage.data); + LOG_EVENT("HD," + mData.toString()); - vData.fromByteArray(vMessage.data); + mData.toVariantList(vData); + emit didActionReceive(mData.data()); - return true; -} - -/*! - * \brief MessageInterpreter::alarmStatus - * \details Used the getAlarmStatus method and converts each parameter - * in vData of type QVaranitList, to be used in the GUI - * Also logs the data - * \param vMessage - The message - * \param vData - the output data - * \return return value of the method getAlarmStatus - */ -bool MessageInterpreter::alarmStatus(const Message &vMessage, QVariantList &vData) { - bool ok; - Model::MAlarmStatus mData; - ok = getAlarmStatus(vMessage, mData); - LOG_DATUM(mData.toString()); - - if (ok) { - mData.toVariantList(vData); - emit didActionReceive(mData.data()); - } return ok; - - // --- an example of unit test --- // - // Types::Flags flag; - // int i = 0; - // QByteArray ba; - // ba += 0x83; ba += 0xf8; ba += 0x28; ba += 0xa1; - // Types::getBits(ba, i, flag, 32); - // qDebug() << '@' << flag << flag.toString() << ba; } /*! - * \brief MessageInterpreter::getPressureOcclusionData - * \details This method interprets Pressure Occlusion message data + * \brief MessageInterpreter::alarmCleared + * \details This method interprets Alarm Cleared message data * in vMessage of type Message. * \param vMessage - The vMessage of type Message which contains all the data, * require to be interpreted. - * \param vData - Pressure Occlusion data - * \return true if the data can be extracted as defined for PressureOcclusion Message ID + * \param vData - Alarm Cleared data + * \return true if the data can be extracted as defined for Alarm Cleared Message ID */ -bool MessageInterpreter::getPressureOcclusionData(const Message &vMessage, Model::MPressureOcclusion &vData) +bool MessageInterpreter::alarmCleared(const Message &vMessage, QVariantList &vData) { - if ( vMessage.actionId != Gui::GuiActionType::PressureOcclusion ) { - return false; - } + // TODO : review other methods + bool ok = false; + if ( ! isValidMessage(vMessage, Gui::GuiActionType::ID_AlarmCleared) ) return ok; - if ( vMessage.data.length() < payloadLen[Gui::GuiActionType::PressureOcclusion] ) { - QString mActionIdHexString = Format::toHexString(vMessage.actionId); - LOG_ERROR(tr("Incorrect data for Message ID (HD) '%1'").arg(mActionIdHexString)); - return false; - } + Model::MAlarmCleared mData; + ok = mData.fromByteArray(vMessage.data); + LOG_EVENT("HD," + mData.toString()); - vData.fromByteArray(vMessage.data); + mData.toVariantList(vData); + emit didActionReceive(mData.data()); - return true; -} - -/*! - * \brief MessageInterpreter::pressureOcclusionData - * \details Used the getPressureOcclusionData method and converts each parameter - * in vData of type QVaranitList, to be used in the GUI - * Also logs the data - * \param vMessage - The message - * \param vData - the output data - * \return return value of the method getPressureOcclusionData - */ -bool MessageInterpreter::pressureOcclusionData(const Message &vMessage, QVariantList &vData) -{ - bool ok; - Model::MPressureOcclusion mData; - ok = getPressureOcclusionData(vMessage, mData); - LOG_DATUM(mData.toString()); - - if (ok) { - mData.toVariantList(vData); - emit didActionReceive(mData.data()); - } return ok; } +// ---------- ---------- ---------- ---------- ---------- Adjustments ---------- ---------- ---------- ---------- ---------- // + /*! - * \brief MessageInterpreter::getTreatmentRangesData - * \details This method interprets Treatment Ranges message data + * \brief MessageInterpreter::ultrafiltrationState + * \details This method interprets Treatment Ultrafiltration State Adjustment Response message data * in vMessage of type Message. * \param vMessage - The vMessage of type Message which contains all the data, * require to be interpreted. - * \param vData - Treatment Ranges data - * \return true if the data can be extracted as defined for Treatment Ranges Message ID + * \param vData - Treatment Ultrafiltration State Adjustment Response data + * \return true if the data can be extracted as defined for Treatment Ultrafiltration State Adjustment Response Message ID */ -bool MessageInterpreter::treatmentRangesData(const Message &vMessage, QVariantList &vData) +bool MessageInterpreter::adjustUltrafiltrationState(const Message &vMessage, QVariantList &vData) { - // TODO : review other methods bool ok = false; - if ( ! isType (vMessage, Gui::GuiActionType::TreatmentRanges) ) return ok; - if ( ! isPayloadLenValid(vMessage, Gui::GuiActionType::TreatmentRanges) ) return ok; + // TODO : In HD the Ultrafiltration State change shall have the rejection reason like other responses. + if ( ! isType (vMessage, Gui::GuiActionType::ID_AdjustUltrafiltrationStateReq) ) return ok; + if ( ! isPayloadLenValid(vMessage, Gui::GuiActionType::ID_AcknowGeneric ) ) return ok; // This is an exception It has to be changed. - Model::MTreatmentRanges mData; + Model::MAdjustUltrafiltrationStateResponse mData; ok = mData.fromByteArray(vMessage.data); - LOG_DATUM(mData.toString()); + LOG_EVENT(mData.toString()); mData.toVariantList(vData); emit didActionReceive(mData.data()); @@ -661,24 +582,22 @@ } /*! - * \brief MessageInterpreter::adjustBloodDialysateData - * \details This method interprets AdjustBlood Dialysate Response message data + * \brief MessageInterpreter::adjustUltrafiltrationEditData + * \details This method interprets Treatment Ultrafiltration Volume Adjustment Response message data * in vMessage of type Message. * \param vMessage - The vMessage of type Message which contains all the data, * require to be interpreted. - * \param vData - AdjustBlood Dialysate Response data - * \return true if the data can be extracted as defined for AdjustBlood Dialysate Response Message ID + * \param vData - Treatment Ultrafiltration Volume Adjustment Response data + * \return true if the data can be extracted as defined for Treatment Ultrafiltration Volume Adjustment Response Message ID */ -bool MessageInterpreter::adjustBloodDialysateData(const Message &vMessage, QVariantList &vData) +bool MessageInterpreter::adjustUltrafiltrationEdit(const Message &vMessage, QVariantList &vData) { - // TODO : review other methods bool ok = false; - if ( ! isType (vMessage, Gui::GuiActionType::AdjustBloodDialysateRsp) ) return ok; - if ( ! isPayloadLenValid(vMessage, Gui::GuiActionType::AdjustBloodDialysateRsp) ) return ok; + if ( ! isValidMessage(vMessage, Gui::GuiActionType::ID_AdjustUltrafiltrationEditRsp) ) return ok; - Model::MAdjustBloodDialysateResponse mData; + Model::MAdjustUltrafiltrationEditResponse mData; ok = mData.fromByteArray(vMessage.data); - LOG_DATUM(mData.toString()); + LOG_EVENT("HD," + mData.toString()); mData.toVariantList(vData); emit didActionReceive(mData.data()); @@ -687,27 +606,25 @@ } /*! - * \brief MessageInterpreter::adjustDurationData - * \details This method interprets Treatment Duration Adjustment Response message data + * \brief MessageInterpreter::adjustUltrafiltrationConfirmData + * \details This method interprets Treatment Ultrafiltration Volume Adjustment Confirm Response message data * in vMessage of type Message. * \param vMessage - The vMessage of type Message which contains all the data, * require to be interpreted. - * \param vData - Treatment Duration Adjustment Response data - * \return true if the data can be extracted as defined for Treatment Duration Adjustment Response Message ID + * \param vData - Treatment Ultrafiltration Volume Adjustment Confirm Response data + * \return true if the data can be extracted as defined for Treatment Ultrafiltration Volume Adjustment Confirm Response Message ID */ -bool MessageInterpreter::adjustDurationData(const Message &vMessage, QVariantList &vData) +bool MessageInterpreter::adjustUltrafiltrationConfirm(const Message &vMessage, QVariantList &vData) { bool ok = false; - if ( ! isType (vMessage, Gui::GuiActionType::AdjustDurationRsp) ) return ok; - if ( ! isPayloadLenValid(vMessage, Gui::GuiActionType::AdjustDurationRsp) ) return ok; + if ( ! isValidMessage(vMessage, Gui::GuiActionType::ID_AdjustUltrafiltrationConfirmRsp) ) return ok; - Model::MAdjustDurationResponse mData; + Model::MAdjustUltrafiltrationConfirmResponse mData; ok = mData.fromByteArray(vMessage.data); - LOG_DATUM(mData.toString()); + LOG_EVENT("HD," + mData.toString()); mData.toVariantList(vData); emit didActionReceive(mData.data()); return ok; } -