Index: firmware/App/Modes/ModeFill.c =================================================================== diff -u -rf847ac4a7a0a080c4b62886243f5b863c4e7730d -r7acc14a8f6eeaf6b26757fc2b5d2f6fc7edbdcec --- firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision f847ac4a7a0a080c4b62886243f5b863c4e7730d) +++ firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 7acc14a8f6eeaf6b26757fc2b5d2f6fc7edbdcec) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2019-2023 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2025 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 ModeFill.c * * @author (last) Dara Navaei -* @date (last) 20-Sep-2023 +* @date (last) 27-Feb-2025 * * @author (original) Leonardo Baloa * @date (original) 19-Nov-2019 @@ -54,27 +54,28 @@ #define RO_PUMP_800_ML_PER_MIN 800.0F ///< RO pump speed of 800.0 mL/minute. #define TARGET_RO_FLOW_RATE_IN_PAUSE_L 0.8F ///< Target flow rate for RO pump during pause in liters. #define MILLILITERS_PER_LITER 1000.0F ///< One liter is 1000 milliliters -#define ACID_PUMP_20_ML_PER_MIN 20.0F ///< Acid pump speed of 20.0 mL/minute. +#define ACID_PUMP_23_ML_PER_MIN 23.0F ///< Acid pump speed of 23.0 mL/minute. #define BICARB_PUMP_40_ML_PER_MIN 40.0F ///< Bicarb pump speed of 40.0 mL/minute. #define CONCENTRATE_PUMP_40_ML_PER_MIN 40.0F ///< Concentrate pump speed of 40.0 mL/minute. #define FILL_MODE_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the fill mode data is published on the CAN bus. #define DIALYSATE_FILL_TIME_OUT ( 5 * SEC_PER_MIN * MS_PER_SECOND ) ///< Time out period when reservoir is not filled with correct dialysate. -#define CONC_PUMPS_PRIME_AT_MAX_SPEED_TIME_OUT_MS ( 7 * MS_PER_SECOND ) ///< Concentrate pumps prime at maximum speed timeout in milliseconds. -#define CONC_PUMPS_PRIME_CHECK_COND_SNSRS_TIME_OUT_MS ( 10 * MS_PER_SECOND ) ///< Concentrate pumps prime check conductivity sensors timeout in milliseconds. -#define CONC_PUMPS_PRIME_MAX_ALLOWED_PRIME_TIME_OUT_MS ( 60 * MS_PER_SECOND ) ///< Concentrate pumps prime maximum allowed timeout in prime in milliseconds. +#define CONC_PUMPS_PRIME_AT_MAX_SPEED_TIME_OUT_MS ( 10 * MS_PER_SECOND ) ///< Concentrate pumps prime at maximum speed timeout in milliseconds. +#define CONC_PUMPS_PRIME_CHECK_COND_SNSRS_TIME_OUT_MS ( 13 * MS_PER_SECOND ) ///< Concentrate pumps prime check conductivity sensors timeout in milliseconds. +#define CONC_PUMPS_PRIME_MAX_ALLOWED_PRIME_TIME_OUT_MS ( 45 * MS_PER_SECOND ) ///< Concentrate pumps prime maximum allowed timeout in prime in milliseconds. #define HUNDRED_PERCENT_FACTOR 1.00F ///< Hundred percent of expected conductivity when first time reaches it. #define FLOW_INTEGRATED_VOLUME_CHECK_TOLERANCE 0.1F ///< Flow integrated volume has 10% tolerance compare to load cell reading. #define FIVE_PERCENT_FACTOR 0.05F ///< 5.0 / 100.0 used to calculate conductivity within range of -/+ 5%. +#define BICARB_CHECK_TOL_FACTOR 0.2F ///< Bicarb check tolerance factor. +#define ACID_CHECK_TOL_FACTOR 0.1F ///< Acid check tolerance factor. #define RO_PUMP_LOOKUP_TABLE_SIZE 4 ///< Size of array used as RO pump speed lookup table. #define CONCENTRATE_PUMP_PRIME_EXTRA_SPEED_ML_MIN 5.0F ///< Concentrate pump additional speed during priming in mL/min. #define CONCENTRATE_TEST_TIME_OUT_MS ( 30 * MS_PER_SECOND ) ///< Concentrate test time out period in ms. #define DELAY_FMP_CHECK_START_BY_MS ( 10 * MS_PER_SECOND ) ///< Delay start of FMP check during dialysate deliver state by this amount of time (in ms). #define CONCENTRATE_TEST_COND_COLLECTION_DELAY_MS ( 5 * MS_PER_SECOND ) ///< Concentrate test conductivity data collection delay in milliseconds. -#define MAX_RO_REJECTION_RATIO_ALLOW 0.10F ///< Maximum RO rejection ratio. #define MAX_CPO_CONDUCTIVITY_ALLOW 100.0F ///< Maximum CPo sensor conductivity value. #define MIN_FILL_TARGET_TO_CHECK_RO_AND_CPO_ML 550 ///< Minimum fill target to check the RO and CPo alarms in milliliters. @@ -95,6 +96,16 @@ // ********** private data ********** +/// Fill for calibration check enumeration from dialin +typedef enum dialin_fill_for_cal +{ + DIALIN_FILL_FOR_CAL_PRIME = 0, ///< Dialin fill for calibration prime. + DIALIN_FILL_FOR_CAL_BICARB_CHECK, ///< Dialin fill for calibration bicarb check. + DIALIN_FILL_FOR_CAL_ACID_CHECK, ///< Dialin fill for calibration acid check. + DIALIN_FILL_FOR_CAL_NONE, ///< Dialin fill for calibration none. + NUM_OF_DIALIN_FILL_FOR_CAL ///< Number of dialin fill for calibration. +} DIALIN_FILL_FOR_CAL_CHECK_T; + /// Fill conditions status typedef struct { @@ -156,8 +167,11 @@ // NOTE: This variable should be initialized here because the init function is called every time and then this variable is set to FALSE even if the settings from the // UI wants the RO only mode. static BOOL hasROOnlyModeBeenEnabled = FALSE; ///< Flag to indicate the RO only mode has been set or not. -static OVERRIDE_F32_T usedAcidVolumeML = { 0.0, 0.0, 0.0, 0.0 }; ///< The integrated acid concentration volume has been used in mL. -static OVERRIDE_F32_T usedBicarbVolumeML = { 0.0, 0.0, 0.0, 0.0 }; ///< The integrated bicarb concentration volume has been used in mL. +// NOTE: This variable should be initialized here because the init function is called every time and then it cannot be initialized there. This variable is +// set via Dialin for calibration check purposes only +static DIALIN_FILL_FOR_CAL_CHECK_T dialinFillForCalCheck = DIALIN_FILL_FOR_CAL_NONE; ///< Dialin fill for calibration check. +// NOTE: this variable should be initialized here because the init function is called every time and then this variable is set to 0.0. +static F32 maxRORejectionRatioFromHD = 0.0F; ///< Max RO rejection ratio from HD. static OVERRIDE_U32_T fillModeDataPublishInterval = { FILL_MODE_DATA_PUB_INTERVAL, FILL_MODE_DATA_PUB_INTERVAL, 0, 0 }; ///< Interval (in ms) at which to publish fill mode data to CAN bus. static OVERRIDE_F32_T integratedVolumeML = { 0.0, 0.0, 0.0, 0.0 }; ///< Total RO flow rate over period of time. @@ -242,7 +256,10 @@ // Set initial actuator states setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); -#if 0 + +#if !defined(DEBUG_ENABLED) && !defined (_RELEASE_) && !defined (_VECTORCAST_) + // Compile this part of code only if it is not debug, release, or VectorCAST. This is to make sure this part of code is not compiled + // and instrumented in VectorCAST // Reset the state machine // Note: the substate timers, and operation flags need to be reset on recovery, consider // reinitializing the state variables, the resetting the state, by calling setModeFillStateTransition() @@ -307,6 +324,7 @@ } } #endif + getFillChemicalCondRecord( &chemicalsCond ); turnOnUVReactor( INLET_UV_REACTOR ); turnOnUVReactor( OUTLET_UV_REACTOR ); @@ -476,60 +494,6 @@ /*********************************************************************//** * @brief - * The getChemicalUsedVolumeML function returns the consumed volume of the called - * chemical bottle in milliliters. - * @details Inputs: none - * @details Outputs: none - * @param bottle which the type of bottle (acid or bicarb) can be specified - * @return used chemical volume in millilters - *************************************************************************/ -F32 getChemicalUsedVolumeML( CHEMICAL_BOTTLES_T bottle ) -{ - F32 volume; - - if ( ACID == bottle ) - { - volume = getF32OverrideValue( &usedAcidVolumeML ); - } - else if ( BICARB == bottle ) - { - volume = getF32OverrideValue( &usedBicarbVolumeML ); - } - else - { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_CHEMICAL_BOTTLE_SELECTED, bottle ) - } - - return volume; -} - -/*********************************************************************//** - * @brief - * The resetChemicalUsedVolumeML function resets the used volume of a chemical - * bottle. - * @details Inputs: none - * @details Outputs: none - * @param bottle which the type of bottle (acid or bicarb) can be specified - * @return none - *************************************************************************/ -void resetChemicalUsedVolumeML( CHEMICAL_BOTTLES_T bottle ) -{ - if ( ACID == bottle ) - { - usedAcidVolumeML.data = 0.0F; - } - else if ( BICARB == bottle ) - { - usedBicarbVolumeML.data = 0.0F; - } - else - { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_CHEMICAL_BOTTLE_SELECTED, bottle ) - } -} - -/*********************************************************************//** - * @brief * The setThisFisrtFillFlag function sets the boolean flag that indicates * the acid and bicarb bottle need priming. * @details Inputs: none @@ -587,6 +551,21 @@ /*********************************************************************//** * @brief + * The setMaxRORejectionRatio function sets the RO rejection ratio that has + * been received from the HD institutional record. + * @details Inputs: none + * @details Outputs: roRejectionRatioFromHD + * @param RO rejection ratio + * @return none + *************************************************************************/ +void setMaxRORejectionRatio( F32 roRejectionRatio ) +{ + maxRORejectionRatioFromHD = roRejectionRatio; + SEND_EVENT_WITH_2_F32_DATA( DG_EVENT_RO_REJECTION_RATIO_FROM_HD_INSTIT_RECORD, maxRORejectionRatioFromHD, 0.0F ) +} + +/*********************************************************************//** + * @brief * The handleTestInletWaterState function tests for inlet water quality * and if this is the first fill of a treatment, prime the acid and bicarb * lines before jumping to dialysate production state. @@ -598,17 +577,48 @@ { DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_TEST_INLET_WATER; - // If this is the first fill of a treatment, prime acid and bicarb lines, otherwise transition - // to dialysate production directly - if ( TRUE == isThisTheFirstFill() ) + if ( ( isConcPumpParkInProgress( CONCENTRATEPUMPS_CP1_ACID ) != TRUE ) && ( isConcPumpParkInProgress( CONCENTRATEPUMPS_CP2_BICARB ) ) != TRUE ) { - result = DG_FILL_MODE_STATE_PRIME_CONCENTRATE_LINES; + // If this is the first fill of a treatment, prime acid and bicarb lines, otherwise transition + // to dialysate production directly + if ( TRUE == isThisTheFirstFill() ) + { + result = DG_FILL_MODE_STATE_PRIME_CONCENTRATE_LINES; + + if ( TRUE == getTestConfigStatus( TEST_CONFIG_EXPEDITE_PRE_TREATMENT ) ) + { + // If expedite pre-treatment flag is enabled, do not do the initial fill + result = DG_FILL_MODE_STATE_PRODUCE_DIALYSATE; + } + } + else + { + result = DG_FILL_MODE_STATE_PRODUCE_DIALYSATE; + } + + if ( TRUE == isTestingActivated() ) + { + switch ( dialinFillForCalCheck ) + { + case DIALIN_FILL_FOR_CAL_PRIME: + result = DG_FILL_MODE_STATE_PRIME_CONCENTRATE_LINES; + break; + + case DIALIN_FILL_FOR_CAL_BICARB_CHECK: + result = DG_FILL_MODE_STATE_TEST_BICARB_CONDUCTIVITY; + break; + + case DIALIN_FILL_FOR_CAL_ACID_CHECK: + result = DG_FILL_MODE_STATE_TEST_ACID_CONDUCTIVITY; + break; + + default: + // Do nothing. This means there is not a request for the fill calibration check so proceed with the normal operations. + break; + } + } + setModeFillStateTransition( result ); } - else - { - result = DG_FILL_MODE_STATE_PRODUCE_DIALYSATE; - } - setModeFillStateTransition( result ); return result; } @@ -693,7 +703,9 @@ averageBicarbConductivity = totalBicarbConductivity / bicarbConductivitySampleCount; - if ( TRUE == isValueWithinPercentRange( averageBicarbConductivity, bicarbCondUSPerCM, FIVE_PERCENT_FACTOR ) ) + SEND_EVENT_WITH_2_F32_DATA( DG_EVENT_BICARB_CHECK_RESULT, averageBicarbConductivity, bicarbCondUSPerCM ) + + if ( TRUE == isValueWithinPercentRange( averageBicarbConductivity, bicarbCondUSPerCM, BICARB_CHECK_TOL_FACTOR ) ) { isConductivityInRange = TRUE; } @@ -706,7 +718,7 @@ else { // Bicarb test failed, go to fault - SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DG_BICARB_CONDUCTIVITY_OUT_OF_RANGE, averageBicarbConductivity ); + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_BICARB_CONDUCTIVITY_OUT_OF_RANGE, averageBicarbConductivity, bicarbCondUSPerCM ) } } @@ -740,36 +752,30 @@ if ( TRUE == didTimeout( concentrateTestStartTime, CONCENTRATE_TEST_TIME_OUT_MS ) ) { - F32 acidCondUSPerCM = chemicalsCond.fillCondValues[ chemicalsTypes.acidType ][ FILL_COND_ACID_TEST ].acidConduSPerCM; + F32 acidCondUSPerCM = chemicalsCond.fillCondValues[ chemicalsTypes.acidType ][ FILL_COND_ACID_TEST ].bicarbConduSPerCM; BOOL hasAcidTestPassed = FALSE; - BOOL hasCD1CD2TestPassed = FALSE; averageBicarbConductivity = totalBicarbConductivity / bicarbConductivitySampleCount; averageAcidConductivity = totalAcidConductivity / acidConductivitySampleCount; pctDiffInConductivity = fabs( 2.0F * ( averageAcidConductivity - averageBicarbConductivity ) / ( averageAcidConductivity + averageBicarbConductivity ) ); + // NOTE: CD2 or bicarb conductivity sensor is used for acid check since it is a more accurate sensor. + // CD2 is the downstream of the acid concentrate pump so the acid sensed there. + SEND_EVENT_WITH_2_F32_DATA( DG_EVENT_ACID_CHECK_RESULT, averageBicarbConductivity, acidCondUSPerCM ) + SEND_EVENT_WITH_2_F32_DATA( DG_EVENT_COND1_VS_COND2_DIFF_RESULT, pctDiffInConductivity, 0.0F ) - if ( ( TRUE == isValueWithinPercentRange( averageAcidConductivity, acidCondUSPerCM, FIVE_PERCENT_FACTOR ) ) || + if ( ( TRUE == isValueWithinPercentRange( averageBicarbConductivity, acidCondUSPerCM, ACID_CHECK_TOL_FACTOR ) ) || ( TRUE == getTestConfigStatus( TEST_CONFIG_MIX_WITH_WATER ) ) ) { hasAcidTestPassed = TRUE; } else { - SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DG_ACID_CONDUCTIVITY_OUT_OF_RANGE, averageAcidConductivity ) + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_ACID_CONDUCTIVITY_OUT_OF_RANGE, averageBicarbConductivity, acidCondUSPerCM ) } - if ( ( pctDiffInConductivity < FIVE_PERCENT_FACTOR ) || ( TRUE == getTestConfigStatus( TEST_CONFIG_MIX_WITH_WATER ) ) ) + if ( TRUE == hasAcidTestPassed ) { - hasCD1CD2TestPassed = TRUE; - } - else - { - SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DG_CD1_CD2_CHECK_FAULT, pctDiffInConductivity ) - } - - if ( ( TRUE == hasAcidTestPassed ) && ( TRUE == hasCD1CD2TestPassed ) ) - { result = DG_FILL_MODE_STATE_PRODUCE_DIALYSATE; setModeFillStateTransition( result ); } @@ -798,18 +804,16 @@ if ( TRUE == didTimeout( concPumpPrimeStartTimeMS, CONC_PUMPS_PRIME_CHECK_COND_SNSRS_TIME_OUT_MS ) ) { /* Once the time for priming the concentrate lines has elapsed, check the mixing conductivity of the sensors - * If the acid and bicarb conductivity values are at about 100% of the target concentrate during fill, transition to the next state - * If the acid and bicarb conductivity values are not at 100% but the maximum prime time has elapsed, transition to the next state + * If the bicarb conductivity values are at about 100% of the target concentrate during fill, transition to the next state + * If the bicarb conductivity values are not at 100% but the maximum prime time has elapsed, transition to the next state */ - F32 acidConduSPerCM = getConductivityValue( CONDUCTIVITYSENSORS_CD1_SENSOR ); F32 bicarbConduSPerCM = getConductivityValue( CONDUCTIVITYSENSORS_CD2_SENSOR ); - F32 acidFillConduSPerCM = chemicalsCond.fillCondValues[ chemicalsTypes.acidType ][ FILL_COND_NORMAL_OP ].acidConduSPerCM; F32 bicarbFillConduSPerCM = chemicalsCond.fillCondValues[ chemicalsTypes.acidType ][ FILL_COND_NORMAL_OP ].bicarbConduSPerCM; /* we are insisting conductivity reach 100% of expected level since signal is very noisy and peak noise will reach 100% when average is about 93%. * if sensor noise is reduced, this level should also be reduced accordingly. */ - if ( ( acidConduSPerCM >= ( acidFillConduSPerCM * HUNDRED_PERCENT_FACTOR ) ) && ( bicarbConduSPerCM >= ( bicarbFillConduSPerCM * HUNDRED_PERCENT_FACTOR ) ) ) + if ( bicarbConduSPerCM >= ( bicarbFillConduSPerCM * HUNDRED_PERCENT_FACTOR ) ) { result = DG_FILL_MODE_STATE_DELIVER_DIALYSATE; setModeFillStateTransition( result ); @@ -882,8 +886,6 @@ integratedVolumeML.data += getMeasuredROFlowRateWithConcPumpsLPM() * ML_PER_LITER * FLOW_INTEGRATOR; } - usedAcidVolumeML.data += getMeasuredPumpSpeedMLPM( CONCENTRATEPUMPS_CP1_ACID ) * FLOW_INTEGRATOR; - usedBicarbVolumeML.data += getMeasuredPumpSpeedMLPM( CONCENTRATEPUMPS_CP2_BICARB ) * FLOW_INTEGRATOR; acidConductivityTotal += acidConduSPerCM; bicarbConductivityTotal += bicarbConduSPerCM; conductivitySampleCount++; @@ -924,10 +926,10 @@ // Fault alarm per PRS 483 SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_OUTLET_PRIMARY_CONDUCTIVITY_OUT_OF_RANGE, avgCPo, MAX_CPO_CONDUCTIVITY_ALLOW ); } - if ( ( avgRR > MAX_RO_REJECTION_RATIO_ALLOW ) && ( isROOnlyModeEnabled() != TRUE ) ) + if ( ( avgRR > maxRORejectionRatioFromHD ) && ( isROOnlyModeEnabled() != TRUE ) ) { // Fault alarm per PRS 483 - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_RO_REJECTION_RATIO_OUT_OF_RANGE, avgRR, MAX_RO_REJECTION_RATIO_ALLOW ); + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_RO_REJECTION_RATIO_OUT_OF_RANGE, avgRR, maxRORejectionRatioFromHD ); } } @@ -951,8 +953,6 @@ { setBadAvgConductivityDetectedFlag( TRUE ); // signal idle bad avg conductivity detected setThisFirstFillFlag( TRUE ); - resetChemicalUsedVolumeML( BICARB ); - resetChemicalUsedVolumeML( ACID ); SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_FILL_CONDUCTIVITY_OUT_OF_RANGE, avgBicarbConduSPerCM, bicarbNormalConduSPerCM ); // trigger replace bottles alarm #1 clearAlarm( ALARM_ID_DG_CREATING_DIALYSATE_PLEASE_WAIT ); // clear this alarm before triggering in case previous fill was bad and still active from before activateAlarmNoData ( ALARM_ID_DG_CREATING_DIALYSATE_PLEASE_WAIT ); @@ -1047,6 +1047,13 @@ pumpSpeedIndex = 0; setROPumpTargetFlowRateLPM( RO_PUMP_FLUSH_BUBBLES_FLOWS[ pumpSpeedIndex ] / MILLILITERS_PER_LITER, TARGET_RO_PRESSURE_PSI ); flushBubblesStartTime = getMSTimerCount(); + if ( ( DIALIN_FILL_FOR_CAL_PRIME == dialinFillForCalCheck ) && ( TRUE == isTestingActivated() ) ) + { + // After prime, the state transitions to flush bubbles. If the cal for check prime was set, transition to Gen Idle and + // set the fill for cal check to none. This is done upon the transition of the next state so then we can transition to Gen Idle. + dialinFillForCalCheck = DIALIN_FILL_FOR_CAL_NONE; + requestNewOperationMode( DG_MODE_GENE ); + } break; case DG_FILL_MODE_STATE_TEST_BICARB_CONDUCTIVITY: @@ -1068,7 +1075,7 @@ requestConcentratePumpOff( CONCENTRATEPUMPS_CP2_BICARB, NO_PARK_CONC_PUMPS ); // Set pumps flow rate to prepare for acid conductivity testing setROPumpTargetFlowRateLPM( RO_PUMP_800_ML_PER_MIN / MILLILITERS_PER_LITER, TARGET_RO_PRESSURE_PSI ); - setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP1_ACID, ACID_PUMP_20_ML_PER_MIN ); + setConcentratePumpTargetSpeed( CONCENTRATEPUMPS_CP1_ACID, ACID_PUMP_23_ML_PER_MIN ); requestConcentratePumpOn( CONCENTRATEPUMPS_CP1_ACID ); // Set back the conductivity of CD2 calibration table to the normal calibration table @@ -1078,6 +1085,15 @@ bicarbConductivitySampleCount = 0; acidConductivitySampleCount = 0; concentrateTestStartTime = getMSTimerCount(); + if ( ( DIALIN_FILL_FOR_CAL_BICARB_CHECK == dialinFillForCalCheck ) && ( TRUE == isTestingActivated() ) ) + { + // After bicarb test, the state transitions to acid test. If the cal for check prime was set, transition to Gen Idle and + // set the fill for cal check to none. This is done upon the transition of the next state so then we can transition to Gen Idle. + // NOTE: If the bicarb test fails, it transitions to fault mode so it automatically exits mode fill so this is only for the situation + // that bicarb test was successful + dialinFillForCalCheck = DIALIN_FILL_FOR_CAL_NONE; + requestNewOperationMode( DG_MODE_GENE ); + } break; case DG_FILL_MODE_STATE_PRODUCE_DIALYSATE: @@ -1087,11 +1103,20 @@ requestConcentratePumpOn( CONCENTRATEPUMPS_CP2_BICARB ); concPumpPrimeStartTimeMS = getMSTimerCount(); fillStatus.isThisFirstFill = FALSE; + if ( ( DIALIN_FILL_FOR_CAL_ACID_CHECK == dialinFillForCalCheck ) && ( TRUE == isTestingActivated() ) ) + { + // After acid test, the state transitions to acid test. If the cal for check prime was set, transition to Gen Idle and + // set the fill for cal check to none. This is done upon the transition of the next state so then we can transition to Gen Idle. + // NOTE: If the acid test fails, it transitions to fault mode so it automatically exits mode fill so this is only for the situation + // that bicarb test was successful + dialinFillForCalCheck = DIALIN_FILL_FOR_CAL_NONE; + requestNewOperationMode( DG_MODE_GENE ); + } break; case DG_FILL_MODE_STATE_DELIVER_DIALYSATE: setValveState( VPO, VALVE_STATE_FILL_C_TO_NC ); - if ( ( didFillRecoverFromPause != TRUE ) || ( 0 == dialysateFillStartTimeMS ) ) + if ( ( didFillRecoverFromPause != TRUE ) || ( 0 == dialysateFillStartTimeMS ) ) { dialysateFillStartTimeMS = getMSTimerCount(); } @@ -1241,8 +1266,8 @@ fillModeData.averageBicarbConductivity = averageBicarbConductivity; fillModeData.isThisTheFirstFill = isThisTheFirstFill(); fillModeData.pctDiffInConductivity = pctDiffInConductivity; - fillModeData.usedAcidVolumeML = getChemicalUsedVolumeML( ACID ); - fillModeData.usedBicarbVolumeML = getChemicalUsedVolumeML( BICARB ); + fillModeData.usedAcidVolumeML = 0.0F; + fillModeData.usedBicarbVolumeML = 0.0F; fillModeData.integratedVolumeML = getIntegratedVolumeML(); fillModeData.roOnlyModeStatus = (U32)isROOnlyModeEnabled(); fillModeData.badFillSignal = getCurrentBadFillSignal(); @@ -1259,105 +1284,8 @@ * TEST SUPPORT FUNCTIONS *************************************************************************/ - /*********************************************************************//** * @brief - * The testSetUsedAcidVolumeMLOverride function overrides the - * acid volume. - * @details Inputs: used acid volume - * @details Outputs: used acid volume - * @param value override used acid volume in mL - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testSetUsedAcidVolumeMLOverride( F32 value ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - usedAcidVolumeML.ovInitData = usedAcidVolumeML.data; - usedAcidVolumeML.ovData = value; - usedAcidVolumeML.override = OVERRIDE_KEY; - result = TRUE; - } - - return result; -} - -/*********************************************************************//** - * @brief - * The testResetUsedAcidVolumeMLOverride function resets the override - * of the used acid volume. - * @details Inputs: used acid volume - * @details Outputs: used acid volume - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testResetUsedAcidVolumeMLOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - usedAcidVolumeML.data = usedAcidVolumeML.ovInitData; - usedAcidVolumeML.override = OVERRIDE_RESET; - usedAcidVolumeML.ovInitData = 0.0F; - usedAcidVolumeML.ovData = 0.0F; - result = TRUE; - } - - return result; -} - -/*********************************************************************//** - * @brief - * The testSetUsedBicarbVolumeMLOverride function overrides the - * bicarb volume. - * @details Inputs: used bicarb volume - * @details Outputs: used bicarb volume - * @param value override used bicarb volume in mL - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testSetUsedBicarbVolumeMLOverride( F32 value ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - usedBicarbVolumeML.ovInitData = usedBicarbVolumeML.data; - usedBicarbVolumeML.ovData = value; - usedBicarbVolumeML.override = OVERRIDE_KEY; - result = TRUE; - } - - return result; -} - -/*********************************************************************//** - * @brief - * The testResetUsedBicarbVolumeMLOverride function resets the override - * of the used bicarb volume. - * @details Inputs: used bicarb volume - * @details Outputs: used bicarb volume - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testResetUsedBicarbVolumeMLOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - usedBicarbVolumeML.data = usedBicarbVolumeML.ovInitData; - usedBicarbVolumeML.override = OVERRIDE_RESET; - usedBicarbVolumeML.ovInitData = 0.0F; - usedBicarbVolumeML.ovData = 0.0F; - result = TRUE; - } - - return result; -} - -/*********************************************************************//** - * @brief * The testSetFillModeDataPublishIntervalOverride function overrides the * fill mode data publish interval. * @details Inputs: FillModeDataPublishInterval @@ -1447,4 +1375,28 @@ return result; } +/*********************************************************************//** + * @brief + * The testSetModeFillForCal function sets the variable to run mode fill only + * for calibration check + * @details Inputs: none + * @details Outputs: fillForCalCheck + * @param calForCheck the mode that is requested (0 = prime, 1 = bicarb check, + * 2 = acid check) + * @return TRUE if the request is in the range otherwise, FALSE + *************************************************************************/ +BOOL testSetModeFillForCal( U32 calForCheck ) +{ + BOOL result = FALSE; + + if ( ( calForCheck < NUM_OF_DIALIN_FILL_FOR_CAL ) && ( TRUE == isTestingActivated() ) ) + { + dialinFillForCalCheck = (DIALIN_FILL_FOR_CAL_CHECK_T)calForCheck; + result = TRUE; + requestNewOperationMode( DG_MODE_FILL ); + } + + return result; +} + /**@}*/