Index: firmware/App/Modes/ModeTreatmentParams.c =================================================================== diff -u -r933a18d740285e70be9d00696ed0f5a5381bc8e4 -r30f049651877229042e3f8700c8596e5b9a1e0f4 --- firmware/App/Modes/ModeTreatmentParams.c (.../ModeTreatmentParams.c) (revision 933a18d740285e70be9d00696ed0f5a5381bc8e4) +++ firmware/App/Modes/ModeTreatmentParams.c (.../ModeTreatmentParams.c) (revision 30f049651877229042e3f8700c8596e5b9a1e0f4) @@ -15,7 +15,7 @@ * ***************************************************************************/ -#include // for memcpy() +#include // For memcpy() #include "AlarmLamp.h" #include "BloodFlow.h" @@ -25,10 +25,6 @@ #include "ModeTreatmentParams.h" #include "OperationModes.h" #include "SystemCommMessages.h" -#ifdef RM46_EVAL_BOARD_TARGET - #include "Timers.h" - static U32 start; -#endif /** * @addtogroup HDTreatmentParamsMode @@ -43,9 +39,9 @@ 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 + 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 ********** @@ -75,11 +71,11 @@ { CRITICAL_DATA_TYPE_F32, {.sFlt=0.0}, {.sFlt=8.0}, {.sFlt=0.0} }, // TREATMENT_PARAM_UF_VOLUME }; -// current treatment parameter values +// 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) +// 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. @@ -119,21 +115,21 @@ *************************************************************************/ void transitionToTreatParamsMode( void ) { - // reset this mode + // Reset this mode initTreatParamsMode(); - // reset all treatment parameters when transitioning to this mode + // Reset all treatment parameters when transitioning to this mode resetAllTreatmentParameters(); validTreatParamsReceived = FALSE; treatParamsConfirmed = FALSE; treatParamsRejected = FALSE; treatmentCancelled = FALSE; - // temporary test code. TODO - remove later -#ifdef RM46_EVAL_BOARD_TARGET - start = getMSTimerCount(); -#endif + // Set user alarm recovery actions allowed in this mode + setAlarmUserActionEnabled( ALARM_USER_ACTION_RESUME, FALSE ); + setAlarmUserActionEnabled( ALARM_USER_ACTION_RINSEBACK, FALSE ); + setAlarmUserActionEnabled( ALARM_USER_ACTION_END_TREATMENT, FALSE ); } /*********************************************************************//** @@ -150,20 +146,17 @@ for ( param = 0; param < NUM_OF_TREATMENT_PARAMS; param++ ) { - // set type, range, and default value for each treatment parameter + // Set type, range, and default value for each treatment parameter treatmentParameters[ param ].typ = treatParamsProperties[ param ].dataType; treatmentParameters[ param ].minimum = treatParamsProperties[ param ].min; treatmentParameters[ param ].maximum = treatParamsProperties[ param ].max; treatmentParameters[ param ].defValue = treatParamsProperties[ param ].def; resetCriticalData( &treatmentParameters[ param ] ); - // set staged parameter values to zero + // Set staged parameter values to zero stagedParams[ param ].uInt = 0; } -#ifndef DISABLE_UI_TREATMENT_WORKFLOW - setTreatmentParameterF32( TREATMENT_PARAM_UF_VOLUME, 0.6 ); -#endif - // zero original parameter values + // Zero original parameter values origTreatmentParams.bloodFlowRate_mL_min = 0; origTreatmentParams.dialysateFlowRate_mL_min = 0; origTreatmentParams.treatmentDuration_min = 0; @@ -241,14 +234,28 @@ /*********************************************************************//** * @brief - * The execFaultMode function executes the Operating Parameters Mode state machine. + * The signalAlarmActionToTreatParamsMode function executes the given alarm action + * as appropriate while in Treatment Parameters Mode. + * @details Inputs: none + * @details Outputs: given alarm action executed + * @param action ID of alarm action to execute + * @return none + *************************************************************************/ +void signalAlarmActionToTreatParamsMode( ALARM_ACTION_T action ) +{ + +} + +/*********************************************************************//** + * @brief + * The execTreatParamsMode function executes the Operating Parameters Mode state machine. * @details Inputs: treatParamsState * @details Outputs: treatParamsState * @return current state (sub-mode) *************************************************************************/ U32 execTreatParamsMode( void ) { - // execute mode state machine + // Execute mode state machine switch ( currentTreatmentParamsState ) { case HD_TREATMENT_PARAMS_MODE_STATE_START: @@ -268,15 +275,6 @@ break; } -#ifdef DISABLE_UI_TREATMENT_WORKFLOW - requestNewOperationMode( MODE_PRET ); -#endif -#ifdef RM46_EVAL_BOARD_TARGET - if ( TRUE == didTimeout( start, 5000U ) ) - { - requestNewOperationMode( MODE_PRET ); - } -#endif return (U32)currentTreatmentParamsState; } @@ -295,14 +293,14 @@ if ( TRUE == treatmentCancelled ) { - // go back to standby mode + // Go back to standby mode requestNewOperationMode( MODE_STAN ); treatmentCancelled = FALSE; } else if ( TRUE == validTreatParamsReceived ) { - // go to wait for user confirmation state + // Go to wait for user confirmation state result = HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_CONFIRM; validTreatParamsReceived = FALSE; @@ -323,20 +321,20 @@ { 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 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) + // Set all treatment parameters (except UF volume which is not yet received) for ( param = TREATMENT_PARAM_FIRST_UINT; param < TREATMENT_PARAM_UF_VOLUME; param++ ) { if ( FALSE == setCriticalData( &treatmentParameters[ param ], stagedParams[ param ] ) ) { // TODO - should never get here - s/w fault? } } - // retain original settings for treatment that may be adjusted later during treatment + // Retain original settings for treatment that may be adjusted later during treatment origTreatmentParams.bloodFlowRate_mL_min = getCriticalData( &treatmentParameters[ TREATMENT_PARAM_BLOOD_FLOW ] ).uInt; origTreatmentParams.dialysateFlowRate_mL_min = getCriticalData( &treatmentParameters[ TREATMENT_PARAM_DIALYSATE_FLOW ] ).uInt; origTreatmentParams.treatmentDuration_min = getCriticalData( &treatmentParameters[ TREATMENT_PARAM_TREATMENT_DURATION ] ).uInt; @@ -345,22 +343,22 @@ origTreatmentParams.venousPressureLowLimit_mmHg = getCriticalData( &treatmentParameters[ TREATMENT_PARAM_VEN_PRESSURE_LOW_LIMIT ] ).sInt; origTreatmentParams.venousPressureHighLimit_mmHg = getCriticalData( &treatmentParameters[ TREATMENT_PARAM_VEN_PRESSURE_HIGH_LIMIT ] ).sInt; - // go to pre-treatment mode + // Go to pre-treatment mode requestNewOperationMode( MODE_PRET ); treatParamsConfirmed = FALSE; } else if ( TRUE == treatParamsRejected ) { treatParamsRejected = FALSE; - // user rejected last parameter set, so reset them and wait for new set + // User rejected last parameter set, so reset them and wait for new set resetAllTreatmentParameters(); result = HD_TREATMENT_PARAMS_MODE_STATE_WAIT_4_UI_2_SEND; } else if ( TRUE == treatmentCancelled ) { treatmentCancelled = FALSE; - // go back to standby mode + // Go back to standby mode requestNewOperationMode( MODE_STAN ); } @@ -369,6 +367,36 @@ /*********************************************************************//** * @brief + * The validateAndSetUFVolume function validates received ultrafiltration + * volume treatment parameter. + * @details Inputs: none + * @details Outputs: + * @param uFVolumeMl UF volume (in mL) from UI to validate + * @return TRUE if received UF volume parameter is valid, FALSE if not + *************************************************************************/ +BOOL validateAndSetUFVolume( F32 uFVolumeMl ) +{ + BOOL accepted = FALSE; + REQUEST_REJECT_REASON_CODE_T rejReason = REQUEST_REJECT_REASON_NONE; + F32 uFVolumeL = uFVolumeMl / (F32)ML_PER_LITER; + + // Validate given UF volume TODO - check dependencies too + accepted = setTreatmentParameterF32( TREATMENT_PARAM_UF_VOLUME, uFVolumeL ); + if ( FALSE == accepted ) + { + rejReason = REQUEST_REJECT_REASON_UF_VOLUME_OUT_OF_RANGE; + } + + // Respond to set treatment parameters request message + uFVolumeL = getTreatmentParameterF32( TREATMENT_PARAM_UF_VOLUME ); + uFVolumeMl = uFVolumeL * (F32)ML_PER_LITER; + sendUFVolumeSetResponseMsg( accepted, rejReason, uFVolumeMl ); + + return accepted; +} + +/*********************************************************************//** + * @brief * The validateAndSetTreatmentParameters function validates received * treatment parameters. * @details Inputs: none @@ -382,23 +410,23 @@ 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 + // Extract treatment parameters from given payload to staging array so we can more easily work with them extractTreatmentParamsFromPayload( params ); - // range check each treatment parameter + // Range check each treatment parameter paramsAreInRange = checkTreatmentParamsInRange( &rejReasons[0] ); - // validate dependencies + // Validate dependencies paramsAreConsistent = checkTreatmentParamsDependencies( &rejReasons[0] ); - // determine overall validity of received treatment parameters + // Determine overall validity of received treatment parameters if ( ( TRUE == paramsAreInRange ) && ( TRUE == paramsAreConsistent ) ) { paramsAreInvalid = FALSE; validTreatParamsReceived = TRUE; } - // respond to set treatment parameters request message + // Respond to set treatment parameters request message sendTreatmentParamsResponse( paramsAreInvalid, &rejReasons[0] ); return !paramsAreInvalid; @@ -418,7 +446,7 @@ BOOL result = TRUE; TREATMENT_PARAM_T param; - // range check treatment parameters up to (but not including) UF volume + // 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 ] ); @@ -452,30 +480,30 @@ S32 venousPresLimitDelta = stagedParams[ TREATMENT_PARAM_VEN_PRESSURE_HIGH_LIMIT ].sInt - \ stagedParams[ TREATMENT_PARAM_VEN_PRESSURE_LOW_LIMIT ].sInt; - // check max dialysate volume dependency + // 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; reasons[ TREATMENT_PARAM_TREATMENT_DURATION ] = REQUEST_REJECT_REASON_DIAL_VOLUME_OUT_OF_RANGE; result = FALSE; } - // check Heparin pre-stop vs. treatment duration + // 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 + // 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 + // 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; @@ -544,7 +572,7 @@ *************************************************************************/ static void extractTreatmentParamsFromPayload( TREATMENT_PARAMS_DATA_PAYLOAD_T payload ) { - // pull treatment parameters into data array so we can more easily work with them + // Pull treatment parameters into data array so we can more easily work with them memcpy( &stagedParams[0], &payload, sizeof(TREATMENT_PARAMS_DATA_PAYLOAD_T) ); } @@ -583,7 +611,7 @@ { BOOL result = FALSE; - // validate parameter + // Validate parameter if ( param <= TREATMENT_PARAM_LAST_UINT ) { CRITICAL_DATAS_T data = treatmentParameters[ param ].data; @@ -613,7 +641,7 @@ { BOOL result = FALSE; - // validate parameter + // Validate parameter if ( ( param >= TREATMENT_PARAM_FIRST_INT ) && ( param <= TREATMENT_PARAM_LAST_INT ) ) { CRITICAL_DATAS_T data = treatmentParameters[ param ].data; @@ -643,7 +671,7 @@ { BOOL result = FALSE; - // validate parameter + // Validate parameter if ( ( param >= TREATMENT_PARAM_FIRST_F32 ) && ( param < NUM_OF_TREATMENT_PARAMS ) ) { CRITICAL_DATAS_T data = treatmentParameters[ param ].data; @@ -672,7 +700,7 @@ { U32 result = 1; - // validate parameter + // Validate parameter if ( param <= TREATMENT_PARAM_LAST_UINT ) { CRITICAL_DATAS_T data = getCriticalData( &treatmentParameters[ param ] ); @@ -700,7 +728,7 @@ { S32 result = 1; - // validate parameter + // Validate parameter if ( ( param >= TREATMENT_PARAM_FIRST_INT ) && ( param <= TREATMENT_PARAM_LAST_INT ) ) { CRITICAL_DATAS_T data = getCriticalData( &treatmentParameters[ param ] ); @@ -728,7 +756,7 @@ { F32 result = 1.0; - // validate parameter + // Validate parameter if ( ( param >= TREATMENT_PARAM_FIRST_F32 ) && ( param < NUM_OF_TREATMENT_PARAMS ) ) { CRITICAL_DATAS_T data = getCriticalData( &treatmentParameters[ param ] ); @@ -767,7 +795,7 @@ { if ( TRUE == isTestingActivated() ) { - // set parameter per its type + // Set parameter per its type if ( CRITICAL_DATA_TYPE_U32 == treatParamsProperties[ param ].dataType ) { result = setTreatmentParameterU32( param, value.uInt );