Index: firmware/App/Modes/ModeTreatmentParams.c =================================================================== diff -u -r9302e1bd2413cbf99e80ac51aac38502d94801d9 -rc6f3b01d1b0a5e3fdf480a7ee205ca349e10d6d2 --- firmware/App/Modes/ModeTreatmentParams.c (.../ModeTreatmentParams.c) (revision 9302e1bd2413cbf99e80ac51aac38502d94801d9) +++ firmware/App/Modes/ModeTreatmentParams.c (.../ModeTreatmentParams.c) (revision c6f3b01d1b0a5e3fdf480a7ee205ca349e10d6d2) @@ -22,44 +22,82 @@ #include "DialOutFlow.h" #include "ModeTreatmentParams.h" #include "OperationModes.h" +#include "SystemCommMessages.h" #include "Utilities.h" #ifdef RM46_EVAL_BOARD_TARGET #include "Timers.h" static U32 start; #endif - /** - * @addtogroup HDTreatmentParamsMode - * @{ - */ +/** + * @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 treatParamsState; ///< Current state of treatment parameters mode state machine. +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 treatParamsRanges[ NUM_OF_TREATMENT_PARAMS ] = +{ + { CRITICAL_DATA_TYPE_U32, {.uInt=100}, {.uInt=1500}, {.uInt=10} }, // TREATMENT_PARAM_BLOOD_FLOW + { CRITICAL_DATA_TYPE_U32, {.uInt=100}, {.uInt=1600}, {.uInt=10} }, // TREATMENT_PARAM_DIALYSATE_FLOW + { CRITICAL_DATA_TYPE_U32, {.uInt=60}, {.uInt=1480}, {.uInt=10} }, // TREATMENT_PARAM_TREATMENT_DURATION + { CRITICAL_DATA_TYPE_U32, {.uInt=0}, {.uInt=1120}, {.uInt=10} }, // TREATMENT_PARAM_HEPARIN_PRE_STOP_TIME + { CRITICAL_DATA_TYPE_U32, {.uInt=100}, {.uInt=1300}, {.uInt=1100} }, // TREATMENT_PARAM_SALINE_BOLUS_VOLUME + { CRITICAL_DATA_TYPE_U32, {.uInt=0}, {.uInt=12}, {.uInt=10} }, // TREATMENT_PARAM_ACID_CONCENTRATE + { CRITICAL_DATA_TYPE_U32, {.uInt=0}, {.uInt=10}, {.uInt=10} }, // TREATMENT_PARAM_BICARB_CONCENTRATE + { CRITICAL_DATA_TYPE_U32, {.uInt=0}, {.uInt=13}, {.uInt=10} }, // TREATMENT_PARAM_DIALYZER_TYPE + { 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_U32, {.uInt=0}, {.uInt=160}, {.uInt=130} }, // TREATMENT_PARAM_BP_MEAS_INTERVAL + { CRITICAL_DATA_TYPE_U32, {.uInt=50}, {.uInt=1150}, {.uInt=175} }, // TREATMENT_PARAM_RINSEBACK_FLOW_RATE + { 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 U32 origBloodFlowRate_mL_min; ///< Originally set (before treatment) blood flow rate (in mL/min). -static U32 origDialysateFlowRate_mL_min; ///< Originally set (before treatment) dialysate flow rate (in mL/min). -static U32 origTreatmentDuration_min; ///< Originally set (before treatment) treatment duration (in min). -static U32 origArterialPressureLowLimit_mmHg; ///< Originally set (before treatment) arterial pressure lower alarm limit (in mmHg). -static U32 origArterialPressureHighLimit_mmHg; ///< Originally set (before treatment) arterial pressure upper alarm limit (in mmHg). -static U32 origVenousPressureLowLimit_mmHg; ///< Originally set (before treatment) venous pressure lower alarm limit (in mmHg). -static U32 origVenousPressureHighLimit_mmHg; ///< Originally set (before treatment) venous pressure upper alarm limit (in mmHg). -static F32 origUFVolume_L; ///< Originally set (before treatment) ultrafiltration volume (in liters). +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 ); -/************************************************************************* - * @brief initOpParamsMode +/*********************************************************************//** + * @brief * The initOpParamsMode function initializes the Operating Parameters Mode module. * @details * Inputs : none @@ -68,113 +106,449 @@ *************************************************************************/ void initTreatParamsMode( void ) { - treatParamsState = HD_TREATMENT_PARAMS_MODE_STATE_START; + currentTreatmentParamsState = HD_TREATMENT_PARAMS_MODE_STATE_START; } -/************************************************************************* - * @brief transitionToOpParamsMode +/*********************************************************************//** + * @brief * The transitionToOpParamsMode function prepares for transition to operating \n * parameters mode. * @details * Inputs : none - * Outputs : + * 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 -#ifndef UF_TEST_ENABLED - setBloodPumpTargetFlowRate( 300, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); - setDialInPumpTargetFlowRate( 300, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); - setDialOutPumpTargetRate( 325, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); -#endif #ifdef RM46_EVAL_BOARD_TARGET start = getMSTimerCount(); #endif } +/*********************************************************************//** + * @brief + * The resetAllTreatmentParameters function resets treatment parameters \n + * to default values. + * @details + * Inputs : none + * Outputs : All treatment parameters reset to default values. + * @return none + *************************************************************************/ static void resetAllTreatmentParameters( void ) { - U32 i; + U32 param; - for ( i = 0; i < NUM_OF_TREATMENT_PARAMS; i++ ) + for ( param = 0; param < NUM_OF_TREATMENT_PARAMS; param++ ) { - resetCriticalData( &treatmentParameters[ i ] ); + resetCriticalData( &treatmentParameters[ param ] ); + // set each treatment parameter to default value + setCriticalData( &treatmentParameters[ param ], treatParamsRanges[ param ].def ); + // set staged parameter values to zero + stagedParams[ param ].uInt = 0; } - origBloodFlowRate_mL_min = 0; - origDialysateFlowRate_mL_min = 0; - origTreatmentDuration_min = 0; - origArterialPressureLowLimit_mmHg = 0; - origArterialPressureHighLimit_mmHg = 0; - origVenousPressureLowLimit_mmHg = 0; - origVenousPressureHighLimit_mmHg = 0; - origUFVolume_L = 0.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 execOpParamsMode - * The execFaultMode function executes the Operating Parameters Mode state machine. +/*********************************************************************//** + * @brief + * The signalUserConfirmationOfTreatmentParameters function sets the user \n + * confirmation flag signaling user has confirmed treatment parameters. * @details * Inputs : none - * Outputs : - * @return current state (sub-mode) + * Outputs : treatParamsConfirmed + * @return TRUE if confirmation accepted, FALSE if not *************************************************************************/ -U32 execTreatParamsMode( void ) +BOOL signalUserConfirmationOfTreatmentParameters( void ) { - BOOL stop = isStopButtonPressed(); + BOOL result = FALSE; -#ifdef UF_TEST_ENABLED - requestNewOperationMode( MODE_PRET ); -#endif -#ifdef RM46_EVAL_BOARD_TARGET - if ( TRUE == didTimeout( start, 5000U ) ) + if ( ( MODE_TPAR == getCurrentOperationMode() ) && ( HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_CONFIRM == currentTreatmentParamsState ) ) { - requestNewOperationMode( MODE_PRET ); + treatParamsConfirmed = TRUE; + result = TRUE; } -#endif + return result; +} + +/*********************************************************************//** + * @brief + * The signalUserCancelTreatment function sets the cancelled treatment \n + * 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 ( treatParamsState ) + switch ( currentTreatmentParamsState ) { case HD_TREATMENT_PARAMS_MODE_STATE_START: - treatParamsState = HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_SEND; + 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)treatParamsState; + return (U32)currentTreatmentParamsState; } +/*********************************************************************//** + * @brief + * The handleWaitForUI2SendState function handles the wait for UI to send \n + * 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 \n + * 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_U32; 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 \n + * 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 + sendTreatmentParametersResponseMsg( paramsAreValid, (U08*)(&rejReasons[0]), + ( NUM_OF_TREATMENT_PARAMS - 1 ) * sizeof(U32) ); // UF vol. param not included in reject reasons + + return paramsAreValid; +} + +/*********************************************************************//** + * @brief + * The checkTreatmentParamsInRange function checks whether received \n + * 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_U32; 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 \n + * 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; + } + + // TODO - check BP measurement interval when cuff connection status is provided by UI (min goes up to 15 if cuff connected, interval must be zero if not) + + return result; +} + +/*********************************************************************//** + * @brief + * The isTreatmentParamInRange function determines whether a given treatment \n + * 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 ( treatParamsRanges[ param ].dataType ) + { + case CRITICAL_DATA_TYPE_U32: + if ( value.uInt >= treatParamsRanges[ param ].min.uInt && value.uInt <= treatParamsRanges[ param ].max.uInt ) + { + result = TRUE; + } + break; + + case CRITICAL_DATA_TYPE_S32: + if ( value.sInt >= treatParamsRanges[ param ].min.sInt && value.sInt <= treatParamsRanges[ param ].max.sInt ) + { + result = TRUE; + } + break; + + case CRITICAL_DATA_TYPE_F32: + if ( value.sFlt >= treatParamsRanges[ param ].min.sFlt && value.sFlt <= treatParamsRanges[ param ].max.sFlt ) + { + result = TRUE; + } + break; + + default: + // TODO - s/w fault + break; + } + + return result; +} + +/*********************************************************************//** + * @brief + * The extractTreatmentParamsFromPayload function extracts the individual \n + * treatment parameters received from the UI into a staging array where \n + * 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 + 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 setTreatmentParameterU32 function sets a given unsigned integer \n + * 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 @@ -191,14 +565,52 @@ } } +/*********************************************************************//** + * @brief + * The setTreatmentParameterS32 function sets a given signed integer treatment \n + * 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_LAST_U32 ) + { + 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 \n + * 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.flt = value; + data.sFlt = value; setCriticalData( &treatmentParameters[ param ], data ); } else @@ -207,6 +619,16 @@ } } +/*********************************************************************//** + * @brief + * The getTreatmentParameterU32 function gets the value of a given unsigned \n + * 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; @@ -226,16 +648,26 @@ return result; } -F32 getTreatmentParameterF32( TREATMENT_PARAM_T param ) +/*********************************************************************//** + * @brief + * The getTreatmentParameterS32 function gets the value of a given signed \n + * 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 ) { - F32 result = 0.0; + S32 result = 0; // validate parameter - if ( param >= TREATMENT_PARAM_FIRST_F32 && param < NUM_OF_TREATMENT_PARAMS ) + if ( param <= TREATMENT_PARAM_LAST_U32 ) { CRITICAL_DATAS_T data = getCriticalData( &treatmentParameters[ param ] ); - result = data.flt; + result = data.sInt; } else { @@ -245,44 +677,33 @@ return result; } -U32 getOrigBloodFlowRate_mL_min( void ) +/*********************************************************************//** + * @brief + * The getTreatmentParameterF32 function gets the value of a given floating point \n + * 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 ) { - return origBloodFlowRate_mL_min; -} + F32 result = 0.0; -U32 getOrigDialysateFlowRate_mL_min( void ) -{ - return origDialysateFlowRate_mL_min; -} + // validate parameter + if ( param >= TREATMENT_PARAM_FIRST_F32 && param < NUM_OF_TREATMENT_PARAMS ) + { + CRITICAL_DATAS_T data = getCriticalData( &treatmentParameters[ param ] ); -U32 getOrigTreatmentDuration_min( void ) -{ - return origTreatmentDuration_min; -} + result = data.sFlt; + } + else + { + // TODO - s/w fault + } -U32 getOrigArterialPressureLowLimit_mmHg( void ) -{ - return origArterialPressureLowLimit_mmHg; + return result; } -U32 getOrigArterialPressureHighLimit_mmHg( void ) -{ - return origArterialPressureHighLimit_mmHg; -} - -U32 getOrigVenousPressureLowLimit_mmHg( void ) -{ - return origVenousPressureLowLimit_mmHg; -} - -U32 getOrigVenousPressureHighLimit_mmHg( void ) -{ - return origVenousPressureHighLimit_mmHg; -} - -F32 getOrigUFVolume_L( void ) -{ - return origUFVolume_L; -} - /**@}*/