Index: firmware/App/Modes/Dialysis.c =================================================================== diff -u -r2acda0ccdd00334bec87bfbe61c4e78e867925de -r515a40fb83e3fc13384dae12dba25b45aeeea904 --- firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 2acda0ccdd00334bec87bfbe61c4e78e867925de) +++ firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 515a40fb83e3fc13384dae12dba25b45aeeea904) @@ -145,13 +145,30 @@ uFAccuracyCheckTimerCtr = 0; lastUFVolumeChecked = 0.0; - // initialize saline bolus variables + resetSalineBolus(); +} + +/*********************************************************************//** + * @brief + * The resetSalineBolus function initializes the saline bolus variables + * at start of treatment or after stopping a bolus (e.g. alarm). Total + * saline bolus volume delivered will not be affected by this function. + * @details Inputs: none + * @details Outputs: Dialysis sub-mode module initialized. + * @return none + *************************************************************************/ +void resetSalineBolus( void ) +{ salineBolusStartRequested = FALSE; salineBolusAbortRequested = FALSE; salineBolusAutoResumeUF = FALSE; bolusSalineVolumeDelivered = 0.0; bolusSalineVolumeDelivered_Safety = 0.0; bolusSalineRotorCount = 0; + if ( currentSalineBolusState != SALINE_BOLUS_STATE_MAX_DELIVERED ) + { + currentSalineBolusState = SALINE_BOLUS_STATE_IDLE; + } } /*********************************************************************//** @@ -168,7 +185,6 @@ *************************************************************************/ void transitionToDialysis( void ) { - // TODO - anything needed here? } /*********************************************************************//** @@ -442,7 +458,8 @@ } } - // TODO - send response w/ reason code if rejected + // send response w/ reason code if rejected + sendUFPauseResumeResponse( result, rejectReason ); return result; } @@ -493,7 +510,8 @@ } } - // TODO - send response w/ reason code if rejected + // send response w/ reason code if rejected + sendUFPauseResumeResponse( result, rejectReason ); return result; } @@ -669,11 +687,15 @@ if ( TRUE == salineBolusStartRequested ) { salineBolusAutoResumeUF = FALSE; - // go to saline bolus state + // go to saline bolus state if we can if ( SALINE_BOLUS_STATE_IDLE == currentSalineBolusState ) { *dialysisState = DIALYSIS_SALINE_BOLUS_STATE; } + else + { + salineBolusStartRequested = FALSE; + } } // handle auto-resume after saline bolus else if ( TRUE == salineBolusAutoResumeUF ) @@ -743,6 +765,10 @@ // go to saline bolus state *dialysisState = DIALYSIS_SALINE_BOLUS_STATE; } + else + { + salineBolusStartRequested = FALSE; + } } // TODO - test code - remove later @@ -781,6 +807,10 @@ { *dialysisState = DIALYSIS_SALINE_BOLUS_STATE; } + else + { + salineBolusStartRequested = FALSE; + } } return result; @@ -812,6 +842,10 @@ { *dialysisState = DIALYSIS_SALINE_BOLUS_STATE; } + else + { + salineBolusStartRequested = FALSE; + } } return result; @@ -872,7 +906,6 @@ bolusSalineRotorCount = 0; bolusSalineLastRotorCount = getBloodPumpRotorCount(); bolusSalineLastVolumeTimeStamp = getMSTimerCount(); - // TODO - turn off accumulation of dialysate usage // bypass dialyzer setValvePosition( VDI, VALVE_POSITION_C_CLOSE ); @@ -910,6 +943,7 @@ static SALINE_BOLUS_STATE_T handleSalineBolusInProgressState( DIALYSIS_STATE_T *dialysisState ) { SALINE_BOLUS_STATE_T result = SALINE_BOLUS_STATE_IN_PROGRESS; + BOOL errorFound = FALSE; F32 timeSinceLastVolumeUpdateMin = (F32)calcTimeSince( bolusSalineLastVolumeTimeStamp ) / (F32)( MS_PER_SECOND * SEC_PER_MIN ); F32 bolusTargetVolume = getTreatmentParameterU32( TREATMENT_PARAM_SALINE_BOLUS_VOLUME ); F32 bldFlowRate = getMeasuredBloodFlowRate(); // TODO - should I use raw flow instead of filtered here??? @@ -926,6 +960,11 @@ bolusSalineVolumeDelivered_Safety = ( (F32)bolusSalineRotorCount * VOLUME_PER_BP_MOTOR_REV_ML ); // TODO - include upstream pressure compensation to this calc // TODO - check for empty saline bag + if ( 0 ) + { + // TODO - empty saline bag alarm + errorFound = TRUE; + } // determine if we've reached maximum saline delivery volume if ( ( totalSalineVolumeDelivered >= (F32)MAX_SALINE_VOLUME_DELIVERED ) ) @@ -941,18 +980,20 @@ if ( bolusSalineVolumeDelivered_Safety < ( bolusTargetVolume * MIN_SALINE_BOLUS_VOLUME_PCT ) ) { // TODO - fault + errorFound = TRUE; } result = SALINE_BOLUS_STATE_IDLE; } // determine if safety thinks we've over-delivered the bolus else if ( bolusSalineVolumeDelivered_Safety > ( bolusTargetVolume * MAX_SALINE_BOLUS_VOLUME_PCT ) ) { // TODO - fault + errorFound = TRUE; result = SALINE_BOLUS_STATE_IDLE; } } - // are we stopping the bolus and resuming treatment? + // are we stopping the bolus? if ( result != SALINE_BOLUS_STATE_IN_PROGRESS ) { // hard stop blood and dialysate pumps @@ -961,19 +1002,22 @@ // send last saline bolus data salineBolusBroadcastTimerCtr = SALINE_BOLUS_DATA_PUB_INTERVAL; publishSalineBolusData(); - // switch back to dialyzer - // switch back to patient artery - - if ( TRUE == salineBolusAutoResumeUF ) + setValvePosition( VBA, VALVE_POSITION_B_OPEN ); + // end dialyzer bypass and resume dialysis if no alarms triggered + if ( FALSE == errorFound ) { - // TODO - resume dialysis - // TODO - resume UF + // end dialyzer bypass + setValvePosition( VDI, VALVE_POSITION_B_OPEN ); + setValvePosition( VDO, VALVE_POSITION_B_OPEN ); + // resume UF if appropriate + if ( TRUE == salineBolusAutoResumeUF ) + { + currentUFState = UF_RUNNING_STATE; + } + // resume dialysis + startDialysis(); } - // TODO - resume dialysate usage - - // resume dialysis - startDialysis(); } return result;