/************************************************************************** * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. * * 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 ModeTreatmentParams.c * * @author (last) Sean Nash * @date (last) 29-May-2020 * * @author (original) Sean Nash * @date (original) 29-May-2020 * ***************************************************************************/ #include "AlarmLamp.h" #include "BloodFlow.h" #include "Buttons.h" #include "DialInFlow.h" #include "DialOutFlow.h" #include "ModeTreatmentParams.h" #include "OperationModes.h" #include "SystemCommMessages.h" #ifdef RM46_EVAL_BOARD_TARGET #include "Timers.h" static U32 start; #endif /** * @addtogroup HDTreatmentParamsMode * @{ */ // ********** private definitions ********** #define MAX_DIALYSATE_VOLUME_ML ( 150 * ML_PER_LITER ) ///< Maximum dialysate volume (in mL) #define MIN_PRESSURE_ALARM_LIMIT_DELTA_MMHG ( 25 ) ///< Minimum pressure alarm limit delta (in mmHg) /// Record for range and default of treatment parameters. typedef struct { CRITICAL_DATA_TYPES_T dataType; ///< Data type for the treatment parameter CRITICAL_DATAS_T min; ///< minimum of range CRITICAL_DATAS_T max; ///< maximum of range CRITICAL_DATAS_T def; ///< default value } TREATMENT_PARAMS_PROPERTIES_T; // ********** private data ********** static HD_TREATMENT_PARAMS_MODE_STATE_T currentTreatmentParamsState; ///< Current state of treatment parameters mode state machine. /// Treatment parameter properties (types, ranges and defaults). const TREATMENT_PARAMS_PROPERTIES_T treatParamsProperties[ NUM_OF_TREATMENT_PARAMS ] = { { CRITICAL_DATA_TYPE_U32, {.uInt=100}, {.uInt=500}, {.uInt=100} }, // TREATMENT_PARAM_BLOOD_FLOW { CRITICAL_DATA_TYPE_U32, {.uInt=100}, {.uInt=600}, {.uInt=100} }, // TREATMENT_PARAM_DIALYSATE_FLOW { CRITICAL_DATA_TYPE_U32, {.uInt=60}, {.uInt=480}, {.uInt=240} }, // TREATMENT_PARAM_TREATMENT_DURATION { CRITICAL_DATA_TYPE_U32, {.uInt=0}, {.uInt=480}, {.uInt=0} }, // TREATMENT_PARAM_HEPARIN_PRE_STOP_TIME { CRITICAL_DATA_TYPE_U32, {.uInt=100}, {.uInt=300}, {.uInt=100} }, // TREATMENT_PARAM_SALINE_BOLUS_VOLUME { CRITICAL_DATA_TYPE_U32, {.uInt=0}, {.uInt=2}, {.uInt=0} }, // TREATMENT_PARAM_ACID_CONCENTRATE { CRITICAL_DATA_TYPE_U32, {.uInt=0}, {.uInt=0}, {.uInt=0} }, // TREATMENT_PARAM_BICARB_CONCENTRATE { CRITICAL_DATA_TYPE_U32, {.uInt=0}, {.uInt=3}, {.uInt=0} }, // TREATMENT_PARAM_DIALYZER_TYPE { CRITICAL_DATA_TYPE_U32, {.uInt=0}, {.uInt=60}, {.uInt=30} }, // TREATMENT_PARAM_BP_MEAS_INTERVAL { CRITICAL_DATA_TYPE_U32, {.uInt=50}, {.uInt=150}, {.uInt=75} }, // TREATMENT_PARAM_RINSEBACK_FLOW_RATE { CRITICAL_DATA_TYPE_S32, {.sInt=-300}, {.sInt=200}, {.sInt=-300} }, // TREATMENT_PARAM_ART_PRESSURE_LOW_LIMIT { CRITICAL_DATA_TYPE_S32, {.sInt=-300}, {.sInt=200}, {.sInt=100} }, // TREATMENT_PARAM_ART_PRESSURE_HIGH_LIMIT { CRITICAL_DATA_TYPE_S32, {.sInt=-100}, {.sInt=600}, {.sInt=-100} }, // TREATMENT_PARAM_VEN_PRESSURE_LOW_LIMIT { CRITICAL_DATA_TYPE_S32, {.sInt=100}, {.sInt=600}, {.sInt=400} }, // TREATMENT_PARAM_VEN_PRESSURE_HIGH_LIMIT { CRITICAL_DATA_TYPE_F32, {.sFlt=0.0}, {.sFlt=1.0}, {.sFlt=0.0} }, // TREATMENT_PARAM_HEPARIN_DISPENSE_RATE { CRITICAL_DATA_TYPE_F32, {.sFlt=0.0}, {.sFlt=2.0}, {.sFlt=0.0} }, // TREATMENT_PARAM_HEPARIN_BOLUS_VOLUME { CRITICAL_DATA_TYPE_F32, {.sFlt=35.0}, {.sFlt=38.0}, {.sFlt=37.0} }, // TREATMENT_PARAM_DIALYSATE_TEMPERATURE { CRITICAL_DATA_TYPE_F32, {.sFlt=0.0}, {.sFlt=8.0}, {.sFlt=0.0} }, // TREATMENT_PARAM_UF_VOLUME }; // current treatment parameter values static CRITICAL_DATA_T treatmentParameters[ NUM_OF_TREATMENT_PARAMS ]; ///< Treatment parameters. static CRITICAL_DATAS_T stagedParams[ NUM_OF_TREATMENT_PARAMS ]; ///< Temporary staged treatment parameters for validation and awaiting user confirmation. // original treatment parameter values (for those that can be changed during treatment) static ADJ_TREATMENT_PARAMS_T origTreatmentParams; ///< Originally set (before treatment) treatment parameters. static BOOL validTreatParamsReceived = FALSE; ///< Flag indicates user has provided treatment parameters. static BOOL treatParamsConfirmed = FALSE; ///< Flag indicates user has confirmed the treatment parameters. static BOOL treatmentCancelled = FALSE; ///< Flag indicates user has cancelled the treatment. // ********** private function prototypes ********** static void resetAllTreatmentParameters( void ); static HD_TREATMENT_PARAMS_MODE_STATE_T handleWaitForUI2SendState( void ); static HD_TREATMENT_PARAMS_MODE_STATE_T handleWaitForUI2ConfirmState( void ); static BOOL checkTreatmentParamsInRange( U32 *reasons ); static BOOL checkTreatmentParamsDependencies( U32 *reasons ); static BOOL isTreatmentParamInRange( TREATMENT_PARAM_T param, CRITICAL_DATAS_T value ); static void extractTreatmentParamsFromPayload( TREATMENT_PARAMS_DATA_PAYLOAD_T payload ); static void sendTreatmentParamsResponse( BOOL valid, U32 *reasons ); /*********************************************************************//** * @brief * The initOpParamsMode function initializes the Operating Parameters Mode module. * @details * Inputs : none * Outputs : Operating Parameters Mode module initialized. * @return none *************************************************************************/ void initTreatParamsMode( void ) { currentTreatmentParamsState = HD_TREATMENT_PARAMS_MODE_STATE_START; } /*********************************************************************//** * @brief * The transitionToOpParamsMode function prepares for transition to operating * parameters mode. * @details * Inputs : none * Outputs : Treatment Parameters mode reset prior to starting * @return none *************************************************************************/ void transitionToTreatParamsMode( void ) { // reset all treatment parameters when transitioning to this mode resetAllTreatmentParameters(); validTreatParamsReceived = FALSE; treatParamsConfirmed = FALSE; treatmentCancelled = FALSE; // temporary test code. TODO - remove later #ifdef RM46_EVAL_BOARD_TARGET start = getMSTimerCount(); #endif } /*********************************************************************//** * @brief * The resetAllTreatmentParameters function resets treatment parameters * to default values. * @details * Inputs : none * Outputs : All treatment parameters reset to default values. * @return none *************************************************************************/ static void resetAllTreatmentParameters( void ) { U32 param; for ( param = 0; param < NUM_OF_TREATMENT_PARAMS; param++ ) { resetCriticalData( &treatmentParameters[ param ] ); // set each treatment parameter to default value setCriticalData( &treatmentParameters[ param ], treatParamsProperties[ param ].def ); // set staged parameter values to zero stagedParams[ param ].uInt = 0; } // zero original parameter values origTreatmentParams.bloodFlowRate_mL_min = 0; origTreatmentParams.dialysateFlowRate_mL_min = 0; origTreatmentParams.treatmentDuration_min = 0; origTreatmentParams.arterialPressureLowLimit_mmHg = 0; origTreatmentParams.arterialPressureHighLimit_mmHg = 0; origTreatmentParams.venousPressureLowLimit_mmHg = 0; origTreatmentParams.venousPressureHighLimit_mmHg = 0; origTreatmentParams.uFVolume_L = 0.0; } /*********************************************************************//** * @brief * The signalUserConfirmationOfTreatmentParameters function sets the user * confirmation flag signaling user has confirmed treatment parameters. * @details * Inputs : none * Outputs : treatParamsConfirmed * @return TRUE if confirmation accepted, FALSE if not *************************************************************************/ BOOL signalUserConfirmationOfTreatmentParameters( void ) { BOOL result = FALSE; if ( ( MODE_TPAR == getCurrentOperationMode() ) && ( HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_CONFIRM == currentTreatmentParamsState ) ) { treatParamsConfirmed = TRUE; result = TRUE; } return result; } /*********************************************************************//** * @brief * The signalUserCancelTreatment function sets the cancelled treatment * flag signaling the user has cancelled the treatment. * @details * Inputs : none * Outputs : treatmentCancelled * @return TRUE if cancel accepted, FALSE if not *************************************************************************/ BOOL signalUserCancelTreatment( void ) { BOOL result = FALSE; if ( MODE_TPAR == getCurrentOperationMode() ) { treatmentCancelled = TRUE; result = TRUE; } return result; } /*********************************************************************//** * @brief * The execFaultMode function executes the Operating Parameters Mode state machine. * @details * Inputs : treatParamsState * Outputs : treatParamsState * @return current state (sub-mode) *************************************************************************/ U32 execTreatParamsMode( void ) { BOOL stop = isStopButtonPressed(); #ifndef UF_TEST_ENABLED // execute mode state machine switch ( currentTreatmentParamsState ) { case HD_TREATMENT_PARAMS_MODE_STATE_START: currentTreatmentParamsState = HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_SEND; break; case HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_SEND: currentTreatmentParamsState = handleWaitForUI2SendState(); break; case HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_CONFIRM: currentTreatmentParamsState = handleWaitForUI2ConfirmState(); break; default: // TODO - s/w fault break; } #else requestNewOperationMode( MODE_PRET ); #endif #ifdef RM46_EVAL_BOARD_TARGET if ( TRUE == didTimeout( start, 5000U ) ) { requestNewOperationMode( MODE_PRET ); } #endif return (U32)currentTreatmentParamsState; } /*********************************************************************//** * @brief * The handleWaitForUI2SendState function handles the wait for UI to send * treatment parameters state of treatment parameters mode. * @details * Inputs : * Outputs : * @return current state (sub-mode) *************************************************************************/ static HD_TREATMENT_PARAMS_MODE_STATE_T handleWaitForUI2SendState( void ) { HD_TREATMENT_PARAMS_MODE_STATE_T result = HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_SEND; if ( TRUE == treatmentCancelled ) { // go back to standby mode requestNewOperationMode( MODE_STAN ); treatmentCancelled = FALSE; } else if ( TRUE == validTreatParamsReceived ) { // go to wait for user confirmation state result = HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_CONFIRM; validTreatParamsReceived = FALSE; } return result; } /*********************************************************************//** * @brief * The handleWaitForUI2ConfirmState function handles the wait for UI to send * user confirmation state of treatment parameters mode. * @details * Inputs : * Outputs : * @return current state (sub-mode) *************************************************************************/ static HD_TREATMENT_PARAMS_MODE_STATE_T handleWaitForUI2ConfirmState( void ) { HD_TREATMENT_PARAMS_MODE_STATE_T result = HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_CONFIRM; // if user confirms treatment parameters, set them if ( TRUE == treatParamsConfirmed ) { TREATMENT_PARAM_T param; // set all treatment parameters (except UF volume which is not yet received) for ( param = TREATMENT_PARAM_FIRST_UINT; param < TREATMENT_PARAM_UF_VOLUME; param++ ) { setCriticalData( &treatmentParameters[ param ], stagedParams[ param ] ); } // retain original settings for treatment that may be adjusted later during treatment origTreatmentParams.bloodFlowRate_mL_min = treatmentParameters[ TREATMENT_PARAM_BLOOD_FLOW ].data.uInt; origTreatmentParams.dialysateFlowRate_mL_min = treatmentParameters[ TREATMENT_PARAM_DIALYSATE_FLOW ].data.uInt; origTreatmentParams.treatmentDuration_min = treatmentParameters[ TREATMENT_PARAM_TREATMENT_DURATION ].data.uInt; origTreatmentParams.arterialPressureLowLimit_mmHg = treatmentParameters[ TREATMENT_PARAM_ART_PRESSURE_LOW_LIMIT ].data.sInt; origTreatmentParams.arterialPressureHighLimit_mmHg = treatmentParameters[ TREATMENT_PARAM_ART_PRESSURE_HIGH_LIMIT ].data.sInt; origTreatmentParams.venousPressureLowLimit_mmHg = treatmentParameters[ TREATMENT_PARAM_VEN_PRESSURE_LOW_LIMIT ].data.sInt; origTreatmentParams.venousPressureHighLimit_mmHg = treatmentParameters[ TREATMENT_PARAM_VEN_PRESSURE_HIGH_LIMIT ].data.sInt; // go to pre-treatment mode requestNewOperationMode( MODE_PRET ); treatParamsConfirmed = FALSE; } else if ( TRUE == treatmentCancelled ) { // go back to standby mode requestNewOperationMode( MODE_STAN ); treatmentCancelled = FALSE; } return result; } /*********************************************************************//** * @brief * The validateAndSetTreatmentParameters function validates received * treatment parameters. * @details * Inputs : none * Outputs : stagedParams[], response sent * @param params payload record from treatment parameters message received from UI * @return TRUE if received treatment parameters are valid, FALSE if not *************************************************************************/ BOOL validateAndSetTreatmentParameters( TREATMENT_PARAMS_DATA_PAYLOAD_T params ) { BOOL paramsAreValid = FALSE; BOOL paramsAreInRange, paramsAreConsistent; U32 rejReasons[ NUM_OF_TREATMENT_PARAMS ]; // extract treatment parameters from given payload to staging array so we can more easily work with them extractTreatmentParamsFromPayload( params ); // range check each treatment parameter paramsAreInRange = checkTreatmentParamsInRange( &rejReasons[0] ); // validate dependencies paramsAreConsistent = checkTreatmentParamsDependencies( &rejReasons[0] ); // determine overall validity of received treatment parameters if ( ( TRUE == paramsAreInRange ) && ( TRUE == paramsAreConsistent ) ) { paramsAreValid = TRUE; validTreatParamsReceived = TRUE; } // respond to set treatment parameters request message sendTreatmentParamsResponse( paramsAreValid, &rejReasons[0] ); return paramsAreValid; } /*********************************************************************//** * @brief * The checkTreatmentParamsInRange function checks whether received * treatment parameters are in range. * @details * Inputs : stagedParams[] * Outputs : reasons[] * @param reasons Pointer to array of reject reason codes for each parameter * @return TRUE if treatment parameters are in range, FALSE if not *************************************************************************/ static BOOL checkTreatmentParamsInRange( U32 *reasons ) { BOOL result = TRUE; TREATMENT_PARAM_T param; // range check treatment parameters up to (but not including) UF volume for ( param = TREATMENT_PARAM_FIRST_UINT; param < TREATMENT_PARAM_UF_VOLUME; param++ ) { BOOL isParamInRange = isTreatmentParamInRange( param, stagedParams[ param ] ); reasons[ param ] = ( TRUE == isParamInRange ? REQUEST_REJECT_REASON_NONE : REQUEST_REJECT_REASON_PARAM_OUT_OF_RANGE ); if ( FALSE == isParamInRange ) { result = FALSE; } } return result; } /*********************************************************************//** * @brief * The checkTreatmentParamsDependencies function checks dependencies between * received treatment parameters. * @details * Inputs : stagedParams[] * Outputs : reasons[] * @param reasons Pointer to array of reject reason codes for each parameter * @return TRUE if treatment parameter dependencies are ok, FALSE if not *************************************************************************/ static BOOL checkTreatmentParamsDependencies( U32 *reasons ) { BOOL result = TRUE; U32 dialysateVolume_mL = stagedParams[ TREATMENT_PARAM_DIALYSATE_FLOW ].uInt * \ stagedParams[ TREATMENT_PARAM_TREATMENT_DURATION ].uInt; S32 arterialPresLimitDelta = stagedParams[ TREATMENT_PARAM_ART_PRESSURE_HIGH_LIMIT ].sInt - \ stagedParams[ TREATMENT_PARAM_ART_PRESSURE_LOW_LIMIT ].sInt; S32 venousPresLimitDelta = stagedParams[ TREATMENT_PARAM_VEN_PRESSURE_HIGH_LIMIT ].sInt - \ stagedParams[ TREATMENT_PARAM_VEN_PRESSURE_LOW_LIMIT ].sInt; // check max dialysate volume dependency if ( dialysateVolume_mL > MAX_DIALYSATE_VOLUME_ML ) { reasons[ TREATMENT_PARAM_DIALYSATE_FLOW ] = REQUEST_REJECT_REASON_DIAL_VOLUME_OUT_OF_RANGE; result = FALSE; } // check Heparin pre-stop vs. treatment duration if ( stagedParams[ TREATMENT_PARAM_HEPARIN_PRE_STOP_TIME ].uInt > stagedParams[ TREATMENT_PARAM_TREATMENT_DURATION ].uInt ) { reasons[ TREATMENT_PARAM_HEPARIN_PRE_STOP_TIME ] = REQUEST_REJECT_REASON_HEPARIN_PRESTOP_EXCEEDS_DURATION; result = FALSE; } // check arterial alarm limits dependency if ( arterialPresLimitDelta < MIN_PRESSURE_ALARM_LIMIT_DELTA_MMHG ) { reasons[ TREATMENT_PARAM_ART_PRESSURE_LOW_LIMIT ] = REQUEST_REJECT_REASON_ARTERIAL_PRESSURE_LOW_VS_HIGH; reasons[ TREATMENT_PARAM_ART_PRESSURE_HIGH_LIMIT ] = REQUEST_REJECT_REASON_ARTERIAL_PRESSURE_LOW_VS_HIGH; result = FALSE; } // check venous alarm limits dependency if ( venousPresLimitDelta < MIN_PRESSURE_ALARM_LIMIT_DELTA_MMHG ) { reasons[ TREATMENT_PARAM_VEN_PRESSURE_LOW_LIMIT ] = REQUEST_REJECT_REASON_VENOUS_PRESSURE_LOW_VS_HIGH; reasons[ TREATMENT_PARAM_VEN_PRESSURE_HIGH_LIMIT ] = REQUEST_REJECT_REASON_VENOUS_PRESSURE_LOW_VS_HIGH; result = FALSE; } return result; } /*********************************************************************//** * @brief * The isTreatmentParamInRange function determines whether a given treatment * parameter is in range. * @details * Inputs : treatParamsRanges[] * Outputs : none * @param param ID of parameter to check range for * @param value value of parameter to check range for * @return TRUE if given treatment parameter is in range, FALSE if not *************************************************************************/ static BOOL isTreatmentParamInRange( TREATMENT_PARAM_T param, CRITICAL_DATAS_T value ) { BOOL result = FALSE; switch ( treatParamsProperties[ param ].dataType ) { case CRITICAL_DATA_TYPE_U32: if ( value.uInt >= treatParamsProperties[ param ].min.uInt && value.uInt <= treatParamsProperties[ param ].max.uInt ) { result = TRUE; } break; case CRITICAL_DATA_TYPE_S32: if ( value.sInt >= treatParamsProperties[ param ].min.sInt && value.sInt <= treatParamsProperties[ param ].max.sInt ) { result = TRUE; } break; case CRITICAL_DATA_TYPE_F32: if ( value.sFlt >= treatParamsProperties[ param ].min.sFlt && value.sFlt <= treatParamsProperties[ param ].max.sFlt ) { result = TRUE; } break; default: // TODO - s/w fault break; } return result; } /*********************************************************************//** * @brief * The extractTreatmentParamsFromPayload function extracts the individual * treatment parameters received from the UI into a staging array where * they will be validated and stay until user confirms them. * @details * Inputs : none * Outputs : stagedParams[] * @param payload message payload record containing received treatment parameters * @return none *************************************************************************/ static void extractTreatmentParamsFromPayload( TREATMENT_PARAMS_DATA_PAYLOAD_T payload ) { // pull treatment parameters into data array so we can more easily work with them memcpy( &stagedParams[0], &payload, sizeof(TREATMENT_PARAMS_DATA_PAYLOAD_T) ); // stagedParams[ TREATMENT_PARAM_BLOOD_FLOW ].uInt = payload.bloodFlowRate_mL_min; // stagedParams[ TREATMENT_PARAM_DIALYSATE_FLOW ].uInt = payload.dialysateFlowRate_mL_min; // stagedParams[ TREATMENT_PARAM_TREATMENT_DURATION ].uInt = payload.treatmentDuration_min; // stagedParams[ TREATMENT_PARAM_HEPARIN_PRE_STOP_TIME ].uInt = payload.heparinPreStop_min; // stagedParams[ TREATMENT_PARAM_SALINE_BOLUS_VOLUME ].uInt = payload.salineBolusVolume_mL; // stagedParams[ TREATMENT_PARAM_ACID_CONCENTRATE ].uInt = payload.acidConcentrate; // stagedParams[ TREATMENT_PARAM_BICARB_CONCENTRATE ].uInt = payload.bicarbConcentrate; // stagedParams[ TREATMENT_PARAM_DIALYZER_TYPE ].uInt = payload.dialyzerType; // stagedParams[ TREATMENT_PARAM_ART_PRESSURE_LOW_LIMIT ].sInt = payload.arterialPressureLowLimit_mmHg; // stagedParams[ TREATMENT_PARAM_ART_PRESSURE_HIGH_LIMIT ].sInt = payload.arterialPressureHighLimit_mmHg; // stagedParams[ TREATMENT_PARAM_VEN_PRESSURE_LOW_LIMIT ].sInt = payload.venousPressureLowLimit_mmHg; // stagedParams[ TREATMENT_PARAM_VEN_PRESSURE_HIGH_LIMIT ].sInt = payload.venousPressureHighLimit_mmHg; // stagedParams[ TREATMENT_PARAM_BP_MEAS_INTERVAL ].uInt = payload.bloodPressureMeasurementInterval_min; // stagedParams[ TREATMENT_PARAM_RINSEBACK_FLOW_RATE ].uInt = payload.rinsebackFlowRate_mL_min; // stagedParams[ TREATMENT_PARAM_HEPARIN_DISPENSE_RATE ].sFlt = payload.heparinDispenseRate_mL_hr; // stagedParams[ TREATMENT_PARAM_HEPARIN_BOLUS_VOLUME ].sFlt = payload.heparinBolusVolume_mL; // stagedParams[ TREATMENT_PARAM_DIALYSATE_TEMPERATURE ].sFlt = payload.dialysateTemperature_degC; } /*********************************************************************//** * @brief * The sendTreatmentParamsResponse function responds to the treatment parameters * received from the UI. An over-all ok/rejected flag as well as individual reject * reason codes for each parameter are provided back to the UI. * @details * Inputs : none * Outputs : Response to treatment parameters message constructed and sent. * @param valid 1 if valid, 0 if not * @param reasons array of reject reason codes for each parameter (0=not rejected) * @return none *************************************************************************/ static void sendTreatmentParamsResponse( BOOL valid, U32 *reasons ) { U32 respPayload[NUM_OF_TREATMENT_PARAMS]; memcpy( &respPayload[0], &reasons[0], sizeof(TREATMENT_PARAMS_DATA_PAYLOAD_T) ); // respPayload[ 0 ] = reasons[ TREATMENT_PARAM_BLOOD_FLOW ]; // respPayload[ 1 ] = reasons[ TREATMENT_PARAM_DIALYSATE_FLOW ]; // respPayload[ 2 ] = reasons[ TREATMENT_PARAM_TREATMENT_DURATION ]; // respPayload[ 3 ] = reasons[ TREATMENT_PARAM_HEPARIN_DISPENSE_RATE ]; // respPayload[ 4 ] = reasons[ TREATMENT_PARAM_HEPARIN_BOLUS_VOLUME ]; // respPayload[ 5 ] = reasons[ TREATMENT_PARAM_HEPARIN_PRE_STOP_TIME ]; // respPayload[ 6 ] = reasons[ TREATMENT_PARAM_SALINE_BOLUS_VOLUME ]; // respPayload[ 7 ] = reasons[ TREATMENT_PARAM_ACID_CONCENTRATE ]; // respPayload[ 8 ] = reasons[ TREATMENT_PARAM_BICARB_CONCENTRATE ]; // respPayload[ 9 ] = reasons[ TREATMENT_PARAM_DIALYZER_TYPE ]; // respPayload[ 10 ] = reasons[ TREATMENT_PARAM_DIALYSATE_TEMPERATURE ]; // respPayload[ 11 ] = reasons[ TREATMENT_PARAM_ART_PRESSURE_LOW_LIMIT ]; // respPayload[ 12 ] = reasons[ TREATMENT_PARAM_ART_PRESSURE_HIGH_LIMIT ]; // respPayload[ 13 ] = reasons[ TREATMENT_PARAM_VEN_PRESSURE_LOW_LIMIT ]; // respPayload[ 14 ] = reasons[ TREATMENT_PARAM_VEN_PRESSURE_HIGH_LIMIT ]; // respPayload[ 15 ] = reasons[ TREATMENT_PARAM_BP_MEAS_INTERVAL ]; // respPayload[ 16 ] = reasons[ TREATMENT_PARAM_RINSEBACK_FLOW_RATE ]; sendTreatmentParametersResponseMsg( valid, (U08*)(&respPayload[0]), ( NUM_OF_TREATMENT_PARAMS - 1 ) * sizeof(U32) ); // UF vol. param not included in reject reasons } /*********************************************************************//** * @brief * The setTreatmentParameterU32 function sets a given unsigned integer * treatment parameter to a given value. * @details * Inputs : treatmentParameters[] * Outputs : treatmentParameters[] * @param param ID of treatment parameter to set unsigned integer value for * @param value unsigned integer value to assign to given treatment parameter * @return none *************************************************************************/ void setTreatmentParameterU32( TREATMENT_PARAM_T param, U32 value ) { // validate parameter if ( param <= TREATMENT_PARAM_LAST_UINT ) { CRITICAL_DATAS_T data = treatmentParameters[ param ].data; data.uInt = value; setCriticalData( &treatmentParameters[ param ], data ); } else { // TODO - s/w fault } } /*********************************************************************//** * @brief * The setTreatmentParameterS32 function sets a given signed integer treatment * parameter to a given value. * @details * Inputs : treatmentParameters[] * Outputs : treatmentParameters[] * @param param ID of treatment parameter to set signed integer value for * @param value signed integer value to assign to given treatment parameter * @return none *************************************************************************/ void setTreatmentParameterS32( TREATMENT_PARAM_T param, S32 value ) { // validate parameter if ( ( param >= TREATMENT_PARAM_FIRST_INT ) && ( param <= TREATMENT_PARAM_LAST_INT ) ) { CRITICAL_DATAS_T data = treatmentParameters[ param ].data; data.sInt = value; setCriticalData( &treatmentParameters[ param ], data ); } else { // TODO - s/w fault } } /*********************************************************************//** * @brief * The setTreatmentParameterF32 sets a given floating point treatment parameter * to a given value. * @details * Inputs : treatmentParameters[] * Outputs : treatmentParameters[] * @param param ID of treatment parameter to set floating point value for * @param value floating point value to assign to given treatment parameter * @return none *************************************************************************/ void setTreatmentParameterF32( TREATMENT_PARAM_T param, F32 value ) { // validate parameter if ( ( param >= TREATMENT_PARAM_FIRST_F32 ) && ( param < NUM_OF_TREATMENT_PARAMS ) ) { CRITICAL_DATAS_T data = treatmentParameters[ param ].data; data.sFlt = value; setCriticalData( &treatmentParameters[ param ], data ); } else { // TODO - s/w fault } } /*********************************************************************//** * @brief * The getTreatmentParameterU32 function gets the value of a given unsigned * integer treatment parameter. * @details * Inputs : treatmentParameters[] * Outputs : none * @param param ID of treatment parameter to get unsigned integer value for * @return value of given unsigned integer treatment parameter *************************************************************************/ U32 getTreatmentParameterU32( TREATMENT_PARAM_T param ) { U32 result = 0; // validate parameter if ( param <= TREATMENT_PARAM_LAST_UINT ) { CRITICAL_DATAS_T data = getCriticalData( &treatmentParameters[ param ] ); result = data.uInt; } else { // TODO - s/w fault } return result; } /*********************************************************************//** * @brief * The getTreatmentParameterS32 function gets the value of a given signed * integer treatment parameter. * @details * Inputs : treatmentParameters[] * Outputs : none * @param param ID of treatment parameter to get signed integer value for * @return value of given signed integer treatment parameter *************************************************************************/ S32 getTreatmentParameterS32( TREATMENT_PARAM_T param ) { S32 result = 0; // validate parameter if ( ( param >= TREATMENT_PARAM_FIRST_INT ) && ( param <= TREATMENT_PARAM_LAST_INT ) ) { CRITICAL_DATAS_T data = getCriticalData( &treatmentParameters[ param ] ); result = data.sInt; } else { // TODO - s/w fault } return result; } /*********************************************************************//** * @brief * The getTreatmentParameterF32 function gets the value of a given floating point * treatment parameter. * @details * Inputs : treatmentParameters[] * Outputs : none * @param param ID of treatment parameter to get floating point value for * @return value of given floating point treatment parameter *************************************************************************/ F32 getTreatmentParameterF32( TREATMENT_PARAM_T param ) { F32 result = 0.0; // validate parameter if ( ( param >= TREATMENT_PARAM_FIRST_F32 ) && ( param < NUM_OF_TREATMENT_PARAMS ) ) { CRITICAL_DATAS_T data = getCriticalData( &treatmentParameters[ param ] ); result = data.sFlt; } else { // TODO - s/w fault } return result; } /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /*********************************************************************//** * @brief * The testSetTreatmentParameterOverride function overrides the value of a * given treatment parameter. * @details * Inputs : none * Outputs : treatment parameter set to given value * @param param ID of treatment parameter to set value of * @param value value to set for given treatment parameter * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetTreatmentParameter( TREATMENT_PARAM_T param, CRITICAL_DATAS_T value ) { BOOL result = FALSE; if ( param < NUM_OF_TREATMENT_PARAMS ) { if ( TRUE == isTestingActivated() ) { // set parameter per its type switch ( treatParamsProperties[ param ].dataType ) { case CRITICAL_DATA_TYPE_U32: setTreatmentParameterU32( param, value.uInt ); result = TRUE; break; case CRITICAL_DATA_TYPE_S32: setTreatmentParameterS32( param, value.sInt ); result = TRUE; break; case CRITICAL_DATA_TYPE_F32: setTreatmentParameterF32( param, value.sFlt ); result = TRUE; break; default: // ok - do nothing break; } } } return result; } /**@}*/