Index: firmware/App/Modes/Dialysis.c =================================================================== diff -u -raeb1dea9ea10fcc70ae66023a87b565f29924c07 -r766708fceb0bdf1af8c7897df29d4f5036bfd3db --- firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision aeb1dea9ea10fcc70ae66023a87b565f29924c07) +++ firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 766708fceb0bdf1af8c7897df29d4f5036bfd3db) @@ -233,17 +233,17 @@ *************************************************************************/ void startDialysis( void ) { - // set last UF timestamp so UF ref is resumed from this time + // Set last UF timestamp so UF ref is resumed from this time lastUFTimeStamp = getMSTimerCount(); - // send dialysate outlet pump latest UF volumes + // Send dialysate outlet pump latest UF volumes setDialOutUFVolumes( refUFVolume, measUFVolume ); - // set valves for dialysis + // Set valves for dialysis setValvePosition( VDI, VALVE_POSITION_B_OPEN ); setValvePosition( VDO, VALVE_POSITION_B_OPEN ); setValvePosition( VBA, VALVE_POSITION_B_OPEN ); setValvePosition( VBV, VALVE_POSITION_B_OPEN ); - // restart pumps + // Restart pumps #ifndef RUN_PUMPS_OPEN_LOOP setBloodPumpTargetFlowRate( setBloodFlowRate, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); setDialInPumpTargetFlowRate( setDialysateFlowRate, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); @@ -253,7 +253,7 @@ #endif setDialOutPumpTargetRate( setDialysateFlowRate + (S32)setUFRate, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); // TODO - Heparin pump - // tell DG to start heating dialysate + // Tell DG to start heating dialysate cmdStartDGTrimmerHeater(); } @@ -268,12 +268,12 @@ *************************************************************************/ void stopDialysis( void ) { - // stop pumps + // Stop pumps setBloodPumpTargetFlowRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); setDialInPumpTargetFlowRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); setDialOutPumpTargetRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); // TODO - stop Heparin pump - // tell DG to stop heating dialysate + // Tell DG to stop heating dialysate cmdStopDGTrimmerHeater(); } @@ -294,7 +294,7 @@ TREATMENT_STATE_T currTreatSubMode = getTreatmentState(); SALINE_BOLUS_STATE_T currSalineBolusState = getSalineBolusState(); - // must be in treatment mode, dialysis sub-mode, saline bolus in idle state in order to start a saline bolus + // Must be in treatment mode, dialysis sub-mode, saline bolus in idle state in order to start a saline bolus if ( currOpMode != MODE_TREA ) { rejReason = REQUEST_REJECT_REASON_NOT_IN_TREATMENT_MODE; @@ -317,7 +317,7 @@ salineBolusStartRequested = TRUE; } - // send response + // Send response sendSalineBolusResponse( accept, rejReason, salineBolusVolume ); } @@ -338,7 +338,7 @@ TREATMENT_STATE_T currTreatSubMode = getTreatmentState(); SALINE_BOLUS_STATE_T currSalineBolusState = getSalineBolusState(); - // must be in treatment mode, dialysis sub-mode, saline bolus in delivery state in order to abort a saline bolus + // Must be in treatment mode, dialysis sub-mode, saline bolus in delivery state in order to abort a saline bolus if ( currOpMode != MODE_TREA ) { rejReason = REQUEST_REJECT_REASON_NOT_IN_TREATMENT_MODE; @@ -357,7 +357,7 @@ salineBolusAbortRequested = TRUE; } - // send response + // Send response sendSalineBolusResponse( accept, rejReason, salineBolusVolume ); } @@ -430,9 +430,9 @@ ( DIALYSIS_UF_STATE == currentDialysisState ) && ( UF_RUNNING_STATE == currentUFState ) ) { result = TRUE; - // set outlet pump to dialysate rate + // Set outlet pump to dialysate rate setDialOutPumpTargetRate( setDialysateFlowRate, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); - // go to UF paused state + // Go to UF paused state currentUFState = UF_PAUSED_STATE; } else @@ -455,9 +455,9 @@ } } - // send response w/ reason code if rejected + // Send response w/ reason code if rejected sendUFPauseResumeResponse( result, rejectReason, currentUFState ); - // send state data immediately for UI update + // Send state data immediately for UI update broadcastTreatmentTimeAndState(); return result; @@ -481,11 +481,11 @@ ( DIALYSIS_UF_STATE == currentDialysisState ) && ( UF_PAUSED_STATE == currentUFState ) ) { result = TRUE; - // set outlet pump to dialysate rate + set UF rate + // Set outlet pump to dialysate rate + set UF rate setDialOutPumpTargetRate( setDialysateFlowRate + FLOAT_TO_INT_WITH_ROUND( setUFRate ), MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); - // restart UF time accumulation for reference volume calculation + // Restart UF time accumulation for reference volume calculation lastUFTimeStamp = getMSTimerCount(); - // go to UF paused state + // Go to UF paused state currentUFState = UF_RUNNING_STATE; } else @@ -508,9 +508,9 @@ } } - // send response w/ reason code if rejected + // Send response w/ reason code if rejected sendUFPauseResumeResponse( result, rejectReason, currentUFState ); - // send state data immediately for UI update + // Send state data immediately for UI update broadcastTreatmentTimeAndState(); return result; @@ -525,10 +525,10 @@ *************************************************************************/ void execDialysis( void ) { - // check ultrafiltration max rate and accuracy during dialysis (even when ultrafiltration is paused). + // Check ultrafiltration max rate and accuracy during dialysis (even when ultrafiltration is paused). checkUFAccuracyAndVolume(); - // dialysis state machine + // Dialysis state machine switch ( currentDialysisState ) { case DIALYSIS_START_STATE: @@ -548,7 +548,7 @@ break; } - // publish saline bolus data at set interval (whether we're delivering one or not) + // Publish saline bolus data at set interval (whether we are delivering one or not) publishSalineBolusData(); } @@ -675,14 +675,14 @@ { UF_STATE_T result = UF_PAUSED_STATE; - // calculate UF volumes and provide to dialysate outlet pump controller + // Calculate UF volumes and provide to dialysate outlet pump controller updateUFVolumes(); - // handle saline bolus start request from user + // Handle saline bolus start request from user if ( TRUE == salineBolusStartRequested ) { salineBolusAutoResumeUF = FALSE; - // go to saline bolus state if we can + // Go to saline bolus state if we can if ( SALINE_BOLUS_STATE_IDLE == currentSalineBolusState ) { *dialysisState = DIALYSIS_SALINE_BOLUS_STATE; @@ -692,25 +692,18 @@ salineBolusStartRequested = FALSE; } } - // handle auto-resume after saline bolus + // Handle auto-resume after saline bolus else if ( TRUE == salineBolusAutoResumeUF ) { salineBolusAutoResumeUF = FALSE; - // set outlet pump to dialysate rate + set UF rate + // Set outlet pump to dialysate rate + set UF rate setDialOutPumpTargetRate( setDialysateFlowRate + FLOAT_TO_INT_WITH_ROUND( setUFRate ), MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); - // restart UF time accumulation for reference volume calculation + // Restart UF time accumulation for reference volume calculation lastUFTimeStamp = getMSTimerCount(); - // resume UF + // Resume UF result = UF_RUNNING_STATE; } - // TODO - test code - remove later - if ( TRUE == isStopButtonPressed() ) - { - resumeUF(); - result = UF_RUNNING_STATE; - } - return result; } @@ -730,31 +723,31 @@ U32 newTime = getMSTimerCount(); U32 msSinceLast = calcTimeBetween( lastUFTimeStamp, newTime ); - // update UF time + // Update UF time uFTimeMS += msSinceLast; lastUFTimeStamp = newTime; - // update UF ref volume in UF running state only + // Update UF ref volume in UF running state only refUFVolume += ( ( (F32)msSinceLast / MS_PER_SECOND ) / SEC_PER_MIN ) * setUFRate; - // calculate UF volumes and provide to dialysate outlet pump controller + // Calculate UF volumes and provide to dialysate outlet pump controller updateUFVolumes(); - // if we've reached target UF volume, UF is complete + // If we have reached target UF volume, UF is complete if ( measUFVolume >= maxUFVolumeML ) { result = UF_COMPLETED_STATE; } - // handle saline bolus start request from user + // Handle saline bolus start request from user else if ( TRUE == salineBolusStartRequested ) { if ( SALINE_BOLUS_STATE_IDLE == currentSalineBolusState ) { - // since we were doing UF prior to saline bolus, we want to auto-resume when done + // Since we were doing UF prior to saline bolus, we want to auto-resume when done salineBolusAutoResumeUF = TRUE; - // go to UF paused state + // Go to UF paused state result = UF_PAUSED_STATE; - // go to saline bolus state + // Go to saline bolus state *dialysisState = DIALYSIS_SALINE_BOLUS_STATE; } else @@ -763,13 +756,6 @@ } } - // TODO - test code - remove later - if ( TRUE == isStopButtonPressed() ) - { - pauseUF(); - result = UF_PAUSED_STATE; - } - return result; } @@ -786,14 +772,14 @@ { UF_STATE_T result = UF_OFF_STATE; - // calculate UF volumes and provide to dialysate outlet pump controller + // Calculate UF volumes and provide to dialysate outlet pump controller updateUFVolumes(); - // handle saline bolus start request from user + // Handle saline bolus start request from user if ( TRUE == salineBolusStartRequested ) { salineBolusAutoResumeUF = FALSE; - // go to saline bolus state + // Go to saline bolus state if ( SALINE_BOLUS_STATE_IDLE == currentSalineBolusState ) { *dialysisState = DIALYSIS_SALINE_BOLUS_STATE; @@ -820,14 +806,14 @@ { UF_STATE_T result = UF_COMPLETED_STATE; - // calculate UF volumes and provide to dialysate outlet pump controller + // Calculate UF volumes and provide to dialysate outlet pump controller updateUFVolumes(); - // handle saline bolus start request from user + // Handle saline bolus start request from user if ( TRUE == salineBolusStartRequested ) { salineBolusAutoResumeUF = FALSE; - // go to saline bolus state + // Go to saline bolus state if ( SALINE_BOLUS_STATE_IDLE == currentSalineBolusState ) { *dialysisState = DIALYSIS_SALINE_BOLUS_STATE; @@ -854,11 +840,11 @@ { SALINE_BOLUS_STATE_T result = SALINE_BOLUS_STATE_IDLE; - // handle saline bolus start request from user + // Handle saline bolus start request from user if ( TRUE == salineBolusStartRequested ) { salineBolusStartRequested = FALSE; - // cmd all pumps to stop + // Cmd all pumps to stop #ifndef RUN_PUMPS_OPEN_LOOP setBloodPumpTargetFlowRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); setDialInPumpTargetFlowRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); @@ -868,7 +854,7 @@ setDialInPumpTargetFlowRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); setDialOutPumpTargetRate( 0, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); #endif - // begin saline bolus + // Begin saline bolus result = SALINE_BOLUS_STATE_WAIT_FOR_PUMPS_STOP; } @@ -890,31 +876,31 @@ if ( ( FALSE == isBloodPumpRunning() ) && ( FALSE == isDialInPumpRunning() ) && ( FALSE == isDialOutPumpRunning() ) ) { - // reset bolus data before we start + // Reset bolus data before we start bolusSalineVolumeDelivered = 0.0; bolusSalineVolumeDelivered_Safety = 0.0; bolusSalineMotorCount = 0; bolusSalineLastMotorCount = getBloodPumpMotorCount(); bolusSalineLastVolumeTimeStamp = getMSTimerCount(); - // bypass dialyzer + // Bypass dialyzer setValvePosition( VDI, VALVE_POSITION_C_CLOSE ); setValvePosition( VDO, VALVE_POSITION_C_CLOSE ); - // switch to saline bag + // Switch to saline bag setValvePosition( VBA, VALVE_POSITION_C_CLOSE ); - // start blood pump at saline bolus rate + // Start blood pump at saline bolus rate #ifndef RUN_PUMPS_OPEN_LOOP setBloodPumpTargetFlowRate( SALINE_BOLUS_FLOW_RATE, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); #else setBloodPumpTargetFlowRate( SALINE_BOLUS_FLOW_RATE, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); #endif - // start dialysate inlet pump at re-circ rate + // Start dialysate inlet pump at re-circ rate #ifndef RUN_PUMPS_OPEN_LOOP setDialInPumpTargetFlowRate( DIALYSATE_FLOW_RATE_FOR_RECIRC, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_CLOSED_LOOP ); #else setDialInPumpTargetFlowRate( DIALYSATE_FLOW_RATE_FOR_RECIRC, MOTOR_DIR_FORWARD, PUMP_CONTROL_MODE_OPEN_LOOP ); #endif - // begin saline bolus + // Begin saline bolus result = SALINE_BOLUS_STATE_IN_PROGRESS; } @@ -941,7 +927,7 @@ U32 bldPumpMotorCount = getBloodPumpMotorCount(); U32 bldPumpMotorDelta = u32DiffWithWrap( bolusSalineLastMotorCount, bldPumpMotorCount ); - // update saline bolus volumes + // Update saline bolus volumes bolusSalineLastVolumeTimeStamp = getMSTimerCount(); bolusSalineVolumeDelivered += volSinceLastUpdateMl; totalSalineVolumeDelivered += volSinceLastUpdateMl; @@ -958,17 +944,17 @@ } #endif - // determine if we've reached maximum saline delivery volume + // Determine if we have reached maximum saline delivery volume if ( ( totalSalineVolumeDelivered >= (F32)MAX_SALINE_VOLUME_DELIVERED ) ) { result = SALINE_BOLUS_STATE_MAX_DELIVERED; } else { - // determine if bolus is complete + // Determine if bolus is complete if ( bolusSalineVolumeDelivered >= bolusTargetVolume ) { - // if safety thinks we've under-delivered the bolus, throw a fault + // If safety thinks we have under-delivered the bolus, throw a fault if ( bolusSalineVolumeDelivered_Safety < ( bolusTargetVolume * MIN_SALINE_BOLUS_VOLUME_PCT ) ) { #ifndef DISABLE_SALINE_BOLUS_CHECKS @@ -978,13 +964,13 @@ } result = SALINE_BOLUS_STATE_IDLE; } - // user is aborting saline bolus + // User is aborting saline bolus else if ( TRUE == salineBolusAbortRequested ) { salineBolusAbortRequested = FALSE; result = SALINE_BOLUS_STATE_IDLE; } - // determine if safety thinks we've over-delivered the bolus + // Determine if safety thinks we have over-delivered the bolus else if ( bolusSalineVolumeDelivered_Safety > ( bolusTargetVolume * MAX_SALINE_BOLUS_VOLUME_PCT ) ) { #ifndef DISABLE_SALINE_BOLUS_CHECKS @@ -995,27 +981,27 @@ } } - // are we stopping the bolus? + // Are we stopping the bolus? if ( result != SALINE_BOLUS_STATE_IN_PROGRESS ) { - // hard stop blood and dialysate pumps + // Hard stop blood and dialysate pumps signalBloodPumpHardStop(); signalDialInPumpHardStop(); - // send last saline bolus data + // Send last saline bolus data bolusSalineVolumeDelivered = 0.0; salineBolusBroadcastTimerCtr = SALINE_BOLUS_DATA_PUB_INTERVAL; publishSalineBolusData(); - // dialysis back to UF state + // Dialysis back to UF state *dialysisState = DIALYSIS_UF_STATE; - // end dialyzer bypass and resume dialysis if no alarms triggered + // End dialyzer bypass and resume dialysis if no alarms triggered if ( FALSE == errorFound ) { - // resume UF if appropriate + // Resume UF if appropriate if ( TRUE == salineBolusAutoResumeUF ) { currentUFState = UF_RUNNING_STATE; } - // resume dialysis + // Resume dialysis startDialysis(); } } @@ -1036,8 +1022,8 @@ { SALINE_BOLUS_STATE_T result = SALINE_BOLUS_STATE_MAX_DELIVERED; - // this is a terminal state for a given treatment - no more saline may be delivered to patient - // if we get here, pop back to UF + // This is a terminal state for a given treatment - no more saline may be delivered to patient + // If we get here, pop back to UF *dialysisState = DIALYSIS_UF_STATE; return result; @@ -1076,35 +1062,27 @@ *************************************************************************/ static void checkUFAccuracyAndVolume( void ) { - F32 uFMeasRate = measUFVolume - lastUFVolumeChecked; + F32 uFMeasRate = measUFVolume - lastUFVolumeChecked; // Volumes are at start/end of 1 hour period, so implied rate is per hour - // check max UF rate in last hour // TODO - is this check necessary considering next check below is a tighter check on this? -// if ( uFMeasRate > MAX_UF_RATE_ML_PER_HOUR ) -// { -//#ifndef DISABLE_UF_ALARMS -// SET_ALARM_WITH_1_F32_DATA( ALARM_ID_UF_RATE_TOO_HIGH_ERROR, uFMeasRate ); -//#endif -// } - - // check UF rate diff from target in last hour + // Check UF rate diff from target in last hour if ( uFMeasRate > maxUFRateAccuracyError_Ml_hr ) { #ifndef DISABLE_UF_ALARMS SET_ALARM_WITH_1_F32_DATA( ALARM_ID_UF_RATE_TOO_HIGH_ERROR, uFMeasRate ); #endif } - // if actively performing ultrafiltration right now, increment timer and see if time to start another 1 hour check period + // If actively performing ultrafiltration right now, increment timer and see if time to start another 1 hour check period if ( UF_RUNNING_STATE == currentUFState ) { if ( ++uFAccuracyCheckTimerCtr >= UF_ACCURACY_CHECK_INTERVAL ) { - // reset for next check interval + // Reset for next check interval lastUFVolumeChecked = measUFVolume; uFAccuracyCheckTimerCtr = 0; } } - // check total UF volume error + // Check total UF volume error if ( ( fabs( refUFVolume - measUFVolume ) ) >= (F32)MAX_UF_ACCURACY_ERROR_ML ) { #ifndef DISABLE_UF_ALARMS @@ -1128,7 +1106,7 @@ DG_RESERVOIR_ID_T activeRes = getDGActiveReservoir(); F32 latestResVolume = getReservoirWeightSmallFilter( activeRes ); - // calculate UF volumes and provide to dialysate outlet pump controller + // Calculate UF volumes and provide to dialysate outlet pump controller measUFVolume = measUFVolumeFromPriorReservoirs + ( latestResVolume - resStartVolume[ activeRes ] ); resFinalVolume[ activeRes ] = latestResVolume; setDialOutUFVolumes( refUFVolume, measUFVolume ); @@ -1148,7 +1126,7 @@ DG_RESERVOIR_ID_T inactiveRes = getDGInactiveReservoir(); F32 resVolume = getReservoirWeightLargeFilter( inactiveRes ); - // set starting baseline volume for next reservoir before we switch to it + // Set starting baseline volume for next reservoir before we switch to it resStartVolume[ inactiveRes ] = resVolume; } @@ -1166,7 +1144,7 @@ DG_RESERVOIR_ID_T activeRes = getDGActiveReservoir(); DG_RESERVOIR_ID_T inactiveRes = ( activeRes == DG_RESERVOIR_1 ? DG_RESERVOIR_2 : DG_RESERVOIR_1 ); - // update UF volume from prior reservoirs per tentative res volume for last reservoir + // Update UF volume from prior reservoirs per tentative res volume for last reservoir measUFVolumeFromPriorReservoirs += ( resFinalVolume[ inactiveRes ] - resStartVolume[ inactiveRes ] ); } @@ -1184,7 +1162,7 @@ DG_RESERVOIR_ID_T inactiveRes = getDGInactiveReservoir(); F32 resVolume = getReservoirWeightLargeFilter( inactiveRes ); - // update UF volume from prior reservoirs per final res volume for last reservoir a bit after we've switched and reservoir has settled + // Update UF volume from prior reservoirs per final res volume for last reservoir a bit after we have switched and reservoir has settled measUFVolumeFromPriorReservoirs -= ( resFinalVolume[ inactiveRes ] - resStartVolume[ inactiveRes ] ); resFinalVolume[ inactiveRes ] = resVolume; measUFVolumeFromPriorReservoirs += ( resFinalVolume[ inactiveRes ] - resStartVolume[ inactiveRes ] );