Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r48ca7fd644c67920acc29a80b7af379d0a134d1a -r6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b) @@ -407,6 +407,44 @@ return valveState; } + +/*********************************************************************//** + * @brief + * The setHydValveStatetoClosedState function sets the all Hydraulics / DD + * valves to close state except balancing chamber, UF and Inlet water control. + * @details \b Inputs: none + * @details \b Outputs: valve states + * @return none. + *************************************************************************/ +void setHydValveStatetoClosedState( void ) +{ + VALVES_T valve; + + // Set all Hydraulics valves to closed state + for ( valve = FIRST_HYD_VALVE; valve < LAST_HYD_VALVE; valve++ ) + { + setValveState( valve, VALVE_STATE_CLOSED ); + } +} + +/*********************************************************************//** + * @brief + * The setUFValveStatetoClosedState function sets the all UF valves + * to close state. + * @details \b Inputs: none + * @details \b Outputs: valve states + * @return none. + *************************************************************************/ +void setUFValveStatetoClosedState( void ) +{ + VALVES_T valve; + + // Set all UF valves to closed state + for ( valve = FIRST_UF_VALVE; valve <= LAST_UF_VALVE; valve++ ) + { + setValveState( valve, VALVE_STATE_CLOSED ); + } +} /*********************************************************************//** * @brief Index: firmware/App/Controllers/Valves.h =================================================================== diff -u -r48ca7fd644c67920acc29a80b7af379d0a134d1a -r6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b --- firmware/App/Controllers/Valves.h (.../Valves.h) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) +++ firmware/App/Controllers/Valves.h (.../Valves.h) (revision 6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b) @@ -96,6 +96,8 @@ BOOL setValveState( VALVES_T valve, VALVE_STATE_NAMES_T valveState ); BOOL setValveStateDelayed( VALVES_T valve, VALVE_STATE_NAMES_T valveState, U32 delayMs ); VALVE_STATE_NAMES_T getValveStateName( VALVES_T valveID ); +void setHydValveStatetoClosedState( void ); +void setUFValveStatetoClosedState( void ); BOOL testValvesStatesPublishIntervalOverride( MESSAGE_T *message ); BOOL testValveStateOverride( MESSAGE_T *message ); Index: firmware/App/Modes/BalancingChamber.c =================================================================== diff -u -rbbd8ef64eb4b178ca76a9721908fee7347a71c6a -r6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b --- firmware/App/Modes/BalancingChamber.c (.../BalancingChamber.c) (revision bbd8ef64eb4b178ca76a9721908fee7347a71c6a) +++ firmware/App/Modes/BalancingChamber.c (.../BalancingChamber.c) (revision 6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b) @@ -48,8 +48,6 @@ static U32 currentBalChamberSwitchingCounter; ///< Counter (in task interval) to monitor the timing spent during balancing chamber fill/drain operation. static BOOL isBalChamberFillInProgress; ///< Flag indicating balancing chamber fill/drain is in progress. static BOOL isPressureStalbilizedDuringFill; ///< Flag indicating that the pressure is stablized due to fill complete. -static BOOL isDialysateGoodtoDeliver; ///< Flag indicating whether ready to deliver dialysate or not. -static OVERRIDE_U32_T isDialDeliveryInProgress; ///< To indicate dialysate started delivering to dialyzer for treatment (overrideable) static BAL_CHAMBER_SW_STATE_T balChamberSWState; ///< Current balancing chamber switching state ( state 1 or state 2). static U32 balChamberDataPublicationTimerCounter; ///< Used to schedule balancing chamber data publication to CAN bus. static OVERRIDE_U32_T balChamberDataPublishInterval; ///< Balancing chamber data publish interval. @@ -61,8 +59,6 @@ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillEnd(void); static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillStart( void ); static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillEnd(void); -static BAL_CHAMBER_EXEC_STATE_T handleBalChamberDialDeliveryPause( void ); -static void balChamberDialDeliveryBypassCheck( void ); static void publishBalChamberData( void ); static U32 getBalChamberDataPublishInterval( void ); @@ -81,10 +77,6 @@ balChamberSwitchingFreq.ovData = 0.0F; balChamberSwitchingFreq.ovInitData = 0.0F; balChamberSwitchingFreq.override = OVERRIDE_RESET; - isDialDeliveryInProgress.data = FALSE; - isDialDeliveryInProgress.ovData = FALSE; - isDialDeliveryInProgress.ovInitData = FALSE; - isDialDeliveryInProgress.override = OVERRIDE_RESET; balChamberDataPublishInterval.data = BAL_CHAMBER_DATA_PUBLISH_INTERVAL; balChamberDataPublishInterval.ovData = BAL_CHAMBER_DATA_PUBLISH_INTERVAL; balChamberDataPublishInterval.ovInitData = 0; @@ -93,7 +85,6 @@ isBalChamberFillInProgress = FALSE; currentBalChamberSwitchingCounter = 0; isPressureStalbilizedDuringFill = FALSE; - isDialysateGoodtoDeliver = FALSE; balChamberDataPublicationTimerCounter = 0; } @@ -133,34 +124,6 @@ /*********************************************************************//** * @brief - * The execBalancingChamberMonitor function monitors the balancing chamber fill - * operations and alarm if temperature and conductivity is not in range. - * @details \b Inputs: balChamberExecState - * @details \b Outputs: balChamberExecState - * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong balancing chamber state invoked. - * @return current state. - *************************************************************************/ -void execBalancingChamberMonitor( void ) -{ - // Read temperature and conducitivity - //F32 hydChamberTemperature = getTemperatureValue( TEMPSENSORS_HYDRAULICS_PRIMARY_HEATER ); - //F32 biCarbConductivity = getConductivityValue( CONDUCTIVITYSENSORS_CD1_SENSOR ); - //F32 acidBicarbMixConductivity = getConductivityValue( CONDUCTIVITYSENSORS_CD3_SENSOR ); - - // Monitor critical parameter while balancing chamber fill is in progress - if ( TRUE == isBalChamberFillInProgress ) - { - // Temperature range check - - // Coductivity range check - - // Also, TD confirms to deliver dialysate - isDialysateGoodtoDeliver = TRUE; - } -} - -/*********************************************************************//** - * @brief * The execBalancingChamberControl function executes the balancing chamber state machine. * @details \b Inputs: balChamberExecState * @details \b Outputs: balChamberExecState @@ -172,8 +135,7 @@ // Increment counter during fill time only, Also check dialysate needs to be bypassed. if ( TRUE == isBalChamberFillInProgress ) { - balChamberDialDeliveryBypassCheck(); - currentBalChamberSwitchingCounter += 1; + currentBalChamberSwitchingCounter += 1; } // execute current balancing chamber exec state @@ -207,10 +169,6 @@ balChamberExecState = handleBalChamberState2FillEnd(); break; - case BAL_CHAMBER_DIAL_DELIVERY_PAUSE: - balChamberExecState = handleBalChamberDialDeliveryPause(); - break; - default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DD_SOFTWARE_FAULT, SW_FAULT_ID_BAL_CHAMBER_INVALID_EXEC_STATE, balChamberExecState ) balChamberExecState = BAL_CHAMBER_STATE_START; @@ -328,6 +286,29 @@ /*********************************************************************//** * @brief + * The valveControlForBCOpenState function open the all balancing + * chamber valves. + * @details \b Inputs: none + * @details \b Outputs: valve states + * @return none. + *************************************************************************/ +void valveControlForBCOpenState( void ) +{ + // Open balancing chamber valve combinations V1,V6 and V4,V7 + setValveState( BCV1, VALVE_STATE_OPEN ); + setValveState( BCV6, VALVE_STATE_OPEN ); + setValveState( BCV4, VALVE_STATE_OPEN ); + setValveState( BCV7, VALVE_STATE_OPEN ); + + //Open balancing chamber valve combinations V2,V5 and V3,V8 + setValveState( BCV2, VALVE_STATE_OPEN ); + setValveState( BCV5, VALVE_STATE_OPEN ); + setValveState( BCV3, VALVE_STATE_OPEN ); + setValveState( BCV8, VALVE_STATE_OPEN ); +} + +/*********************************************************************//** + * @brief * The handleBalChamberState1FillStart function handles the balancing chamber * state 1 fill and time to fill chamber counter being updated. * @details \b Inputs: Pressure @@ -527,64 +508,28 @@ /*********************************************************************//** * @brief - * The handleBalChamberDialDeliveryBypassCheck function decides closing the - * bypass valve and open up the dialyzer valves for treatment. - * @details \b Inputs: isDialysateGoodtoDeliver - * @details \b Outputs: isDialysateGoodtoDeliver,isDialDeliveryInProgress - * @return none. - *************************************************************************/ -static void balChamberDialDeliveryBypassCheck( void ) -{ - if ( TRUE == isDialysateGoodtoDeliver ) - { - // Close bypass valve and Open VDI, VDo valves - setValveState( VDB2, VALVE_STATE_CLOSED ); - setValveState( VDI, VALVE_STATE_OPEN ); - setValveState( VDO, VALVE_STATE_OPEN ); - - // update dialysate delivery status. - isDialDeliveryInProgress.data = TRUE; - } - else - { - // Open bypass valve and raise alarm - setValveState( VDI, VALVE_STATE_CLOSED ); - setValveState( VDO, VALVE_STATE_CLOSED ); - setValveState( VDB2, VALVE_STATE_OPEN ); - - // update dialysate delivery status. - isDialDeliveryInProgress.data = FALSE; - } -} - -/*********************************************************************//** - * @brief - * The handleBalChamberDialDeliveryPause function pauses the dialysate - * delivery due to alarm conditions. - * @details \b Inputs: none + * The getCurrentBalancingChamberExecState function returns the current state + * of the balancing chamber. + * @details \b Inputs: balChamberExecState * @details \b Outputs: none - * @return next balancing chamber state. + * @return the current state of balancing chamber states. *************************************************************************/ -static BAL_CHAMBER_EXEC_STATE_T handleBalChamberDialDeliveryPause( void ) +BAL_CHAMBER_EXEC_STATE_T getCurrentBalancingChamberExecState( void ) { - BAL_CHAMBER_EXEC_STATE_T state = BAL_CHAMBER_DIAL_DELIVERY_PAUSE; - - //TODO : handle any pause state actions - - return state; + return balChamberExecState; } /*********************************************************************//** * @brief - * The getCurrentBalancingChamberExecState function returns the current state - * of the balancing chamber. - * @details \b Inputs: balChamberExecState + * The getBalancingChamberFillinProgressStatus function returns the current + * balancing chamber fill in progress status. + * @details \b Inputs: isBalChamberFillInProgress * @details \b Outputs: none - * @return the current state of balancing chamber states. + * @return the current balancing chamber fill in progress. *************************************************************************/ -BAL_CHAMBER_EXEC_STATE_T getCurrentBalancingChamberExecState( void ) +BOOL getBalancingChamberFillinProgressStatus( void ) { - return balChamberExecState; + return isBalChamberFillInProgress; } /*********************************************************************//** @@ -609,26 +554,6 @@ /*********************************************************************//** * @brief - * The getDialDeliveryProgressStatus function gets the dialysate delivery - * progress status. - * @details \b Inputs: isDialDeliveryInProgress - * @details \b Outputs: none - * @return the current status of dialysate delivery - *************************************************************************/ -U32 getDialDeliveryProgressStatus( void ) -{ - U32 result = isDialDeliveryInProgress.data; - - if ( OVERRIDE_KEY == isDialDeliveryInProgress.override ) - { - result = isDialDeliveryInProgress.ovData; - } - - return result; -} - -/*********************************************************************//** - * @brief * The getBalChamberDataPublishInterval function gets the balancing chamber * data publish interval. * @details \b Inputs: balChamberDataPublishInterval @@ -666,12 +591,10 @@ data.balChamberExecState = (U32)balChamberExecState; data.balChamberSWState = (U32)balChamberSWState; data.balChamberSWFreq = getBalChamberSwitchingFreq(); - data.isDialDelInProgress = (BOOL)getDialDeliveryProgressStatus(); data.balChamberSwPeriod = balChamberSwitchingPeriod; data.isBalChamberFillInProgress = isBalChamberFillInProgress; data.currentBalChamberSwitchingCounter = currentBalChamberSwitchingCounter; data.isPressureStalbilizedDuringFill = isPressureStalbilizedDuringFill; - data.isDialysateGoodtoDeliver = isDialysateGoodtoDeliver; broadcastData( MSG_ID_DD_BAL_CHAMBER_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( BAL_CHAMBER_DATA_T ) ); @@ -704,23 +627,6 @@ /*********************************************************************//** * @brief - * The testDialDeliveryInProgressOverride function sets the override value - * of the dialysate delivery In progress flag. - * @details Inputs: isDialDeliveryInProgress - * @details Outputs: isDialDeliveryInProgress - * @param message Override message from Dialin which includes the override - * value to override the dialysate delivery in progress flag. - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testDialDeliveryInProgressOverride( MESSAGE_T *message ) -{ - BOOL result = u32Override( message, &isDialDeliveryInProgress, 0, TRUE ); - - return result; -} - -/*********************************************************************//** - * @brief * The testBalChamberSwFreqOverride function sets the override value * of the balancing chamber switching frequency. * @details Inputs: balChamberSwitchingFreq Index: firmware/App/Modes/BalancingChamber.h =================================================================== diff -u -rb6d20d9e5c704a9f7ebceea9bb12731dac61fc2a -r6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b --- firmware/App/Modes/BalancingChamber.h (.../BalancingChamber.h) (revision b6d20d9e5c704a9f7ebceea9bb12731dac61fc2a) +++ firmware/App/Modes/BalancingChamber.h (.../BalancingChamber.h) (revision 6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b) @@ -37,12 +37,10 @@ U32 balChamberExecState; ///< Balancing chamber execution state U32 balChamberSWState; ///< Balancing chamber switching state (state 1 or state 2) F32 balChamberSWFreq; ///< Balancing chamber switching frequency - BOOL isDialDelInProgress; ///< Whether Dialysate Delivery in progress or not U32 balChamberSwPeriod; ///< Balancing chamber switching period BOOL isBalChamberFillInProgress; ///< Whether balancing chamber fill in progress or not U32 currentBalChamberSwitchingCounter; ///< Current balancing chamber switching counter BOOL isPressureStalbilizedDuringFill; ///< Whether pressure stabilized during fill or not - BOOL isDialysateGoodtoDeliver; ///< Ready to deliver dialysate or not } BAL_CHAMBER_DATA_T; // ********** public function prototypes ********** @@ -55,10 +53,11 @@ BAL_CHAMBER_EXEC_STATE_T getCurrentBalancingChamberExecState( void ); // Get the current state of the balancing chamber execution F32 getBalChamberSwitchingFreq( void ); // Get the balancing chamber switching frequency U32 getDialDeliveryProgressStatus( void ); // Get the dialysate delivery in progress status +BOOL getBalancingChamberFillinProgressStatus( void ); // Get the balancing chamber fill in progress status void valveControlForBCClosedState( void ); // Closes all balancing chamber valves +void valveControlForBCOpenState( void ); // Open all balancing chamber valves BOOL testDDBalChamberDataPublishIntervalOverride( MESSAGE_T *message ); // To override the balancing chamber data publish interval -BOOL testDialDeliveryInProgressOverride( MESSAGE_T *message ); // To override the dialysate delivery in progress flag BOOL testBalChamberSwFreqOverride( MESSAGE_T *message ); // To override the balancing chamber switching frequency /**@}*/ Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -rb6d20d9e5c704a9f7ebceea9bb12731dac61fc2a -r6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision b6d20d9e5c704a9f7ebceea9bb12731dac61fc2a) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b) @@ -26,6 +26,7 @@ #include "OperationModes.h" #include "Pressure.h" #include "TaskGeneral.h" +#include "TDInterface.h" #include "Temperature.h" #include "Timers.h" #include "Valves.h" @@ -57,6 +58,8 @@ //static BOOL isHydChamberTempinRange = FALSE; ///< Flag indicating hydraulics chamber water temperature is in range. static U32 hydChamberPressureCheckStartTimeMS; ///< Current time when hydraulics chamber pressure check satrted in milliseconds. static U32 spentDialPressureCheckStartTimeMS; ///< Current time when spent dialysate pressure check started in milliseconds. +static OVERRIDE_U32_T isDialDeliveryInProgress; ///< To indicate dialysate started delivering to dialyzer for treatment (overrideable) +static BOOL isDialysateGoodtoDeliver; ///< Flag indicating whether ready to deliver dialysate or not. static U32 genDialysateDataPublicationTimerCounter; ///< Used to schedule generate dialysate data publication to CAN bus. static OVERRIDE_U32_T genDialysateDataPublishInterval; ///< Generate dialysate mode data publish interval. @@ -68,6 +71,7 @@ static DD_GEND_MODE_STATE_T handleGendHydChamberPressureCheckState( void ); static DD_GEND_MODE_STATE_T handleGendFreshDialysatePressureCheckState( void ); static DD_GEND_MODE_STATE_T handleGendSpentDialysatePressureCheckState( void ); +static DD_GEND_MODE_STATE_T handleGendProduceDialysateyState( void ); static DD_GEND_MODE_STATE_T handleGendDialysateDeliveryState( void ); static DD_GEND_MODE_STATE_T handleGendDialysateDeliveryPauseState( void ); static void publishGenDialysateModeData( void ); @@ -87,6 +91,11 @@ // targetHydChamberFluidTemp.override = OVERRIDE_RESET; // isHydChamberTempinRange = FALSE; genDialysateState = DD_GEND_STATE_START; + isDialysateGoodtoDeliver = FALSE; + isDialDeliveryInProgress.data = FALSE; + isDialDeliveryInProgress.ovData = FALSE; + isDialDeliveryInProgress.ovInitData = FALSE; + isDialDeliveryInProgress.override = OVERRIDE_RESET; hydChamberPressureCheckStartTimeMS = 0; spentDialPressureCheckStartTimeMS = 0; genDialysateDataPublishInterval.data = GEN_DIALYSATE_DATA_PUBLISH_INTERVAL; @@ -115,8 +124,35 @@ return genDialysateState; } + /*********************************************************************//** * @brief + * The execGenDialysateMonitor function monitors the balancing chamber fill + * operations and alarm if temperature and conductivity is not in range. + * @details \b Inputs: + * @details \b Outputs: + * @details \b Alarm: none. + * @return none. + *************************************************************************/ +void execGenDialysateMonitor( void ) +{ + // Read temperature and conducitivity + //F32 hydChamberTemperature = getTemperatureValue( TEMPSENSORS_HYDRAULICS_PRIMARY_HEATER ); + //F32 biCarbConductivity = getConductivityValue( CONDUCTIVITYSENSORS_CD1_SENSOR ); + //F32 acidBicarbMixConductivity = getConductivityValue( CONDUCTIVITYSENSORS_CD3_SENSOR ); + + // Monitor critical parameter while balancing chamber fill is in progress + if ( TRUE == getBalancingChamberFillinProgressStatus() ) + { + // Temperature range check + + // Coductivity range check + isDialysateGoodtoDeliver = TRUE; + } +} + +/*********************************************************************//** + * @brief * The setModeGenDStateTransition function sets the actuators and variables * for the state transition in generate dialysis mode. * @details Inputs: Valve states, Pump speed @@ -136,12 +172,8 @@ case DD_GEND_HYD_CHAMBER_WATER_INLET_CHECK_STATE: // Close all balancing chamber and hydraulics valves valveControlForBCClosedState(); - setValveState( VHI, VALVE_STATE_CLOSED ); //D03 - setValveState( VHB, VALVE_STATE_CLOSED ); //D08 - setValveState( VHO, VALVE_STATE_CLOSED ); //D14 - setValveState( VTD, VALVE_STATE_CLOSED ); //D52 - setValveState( VDR, VALVE_STATE_CLOSED ); //D53 - setValveState( VP2, VALVE_STATE_CLOSED ); //D47 + setHydValveStatetoClosedState(); + setUFValveStatetoClosedState(); // Get the target temperature from TD //targetHydChamberFluidTemp.data = HYD_CHAMBER_FLUID_TEMP_C_MIN; @@ -164,13 +196,32 @@ case DD_GEND_SPENT_DIALYSATE_PRESSURE_CHECK_STATE: // Start the timer for spent dialysate pressure check spentDialPressureCheckStartTimeMS = getMSTimerCount(); + + // Open all balancing chamber valves for free flow + valveControlForBCOpenState(); + + // Make sure valves are in correct position + setValveState( VDR, VALVE_STATE_OPEN ); //D53 + setValveState( VDI, VALVE_STATE_CLOSED ); + setValveState( VDO, VALVE_STATE_CLOSED ); + setValveState( VDB2, VALVE_STATE_OPEN ); + // Start D48/SDP pump setDialysatePumpTargetRPM( SPENT_DIALYSATE_PUMP, SPENT_DIAL_PUMP_INITIAL_RPM ); break; + case DD_GEND_PRODUCE_DIALYSATE_STATE: + // Enable bypass valve + setValveState( VDI, VALVE_STATE_CLOSED ); + setValveState( VDO, VALVE_STATE_CLOSED ); + setValveState( VDB2, VALVE_STATE_OPEN ); + break; + case DD_GEND_DIALYSATE_DELIVERY_STATE: - // Make sure valves are in correct position - setValveState( VDR, VALVE_STATE_OPEN ); //D53 + // Disable bypass valve + setValveState( VDB2, VALVE_STATE_CLOSED ); + setValveState( VDI, VALVE_STATE_OPEN ); + setValveState( VDO, VALVE_STATE_OPEN ); break; case DD_GEND_DIALYSATE_DELIVERY_PAUSE: @@ -236,6 +287,10 @@ genDialysateState = handleGendSpentDialysatePressureCheckState(); break; + case DD_GEND_PRODUCE_DIALYSATE_STATE: + genDialysateState = handleGendProduceDialysateyState(); + break; + case DD_GEND_DIALYSATE_DELIVERY_STATE: genDialysateState = handleGendDialysateDeliveryState(); break; @@ -269,11 +324,11 @@ // Read floater switch BOOL result = FALSE; LEVEL_STATE_T floaterLevel1 = getLevelStatus( FLOATER_1 ); - LEVEL_STATE_T floaterLevel2 = getLevelStatus( FLOATER_2 ); + //LEVEL_STATE_T floaterLevel2 = getLevelStatus( FLOATER_2 ); //F32 hydChamberTemperature = getTemperatureValue( TEMPSENSORS_HYDRAULICS_PRIMARY_HEATER ); // High level is met - if ( STATE_HIGH == floaterLevel2 ) + if ( STATE_HIGH == floaterLevel1 ) { //turn off inlet water valve setValveState( VHO, VALVE_STATE_CLOSED ); @@ -307,10 +362,10 @@ } // Invalid levels - if ( ( STATE_LOW == floaterLevel1 ) && ( STATE_HIGH == floaterLevel2 ) ) - { - //TODO : check for invalid levels and trigger alarm - } +// if ( ( STATE_LOW == floaterLevel1 ) && ( STATE_HIGH == floaterLevel2 ) ) +// { +// //TODO : check for invalid levels and trigger alarm +// } return result; } @@ -416,8 +471,8 @@ { // Proceed to next state transitionToBalChamberFill(); - setModeGenDStateTransition( DD_GEND_DIALYSATE_DELIVERY_STATE ); - state = DD_GEND_DIALYSATE_DELIVERY_STATE; + setModeGenDStateTransition( DD_GEND_PRODUCE_DIALYSATE_STATE ); + state = DD_GEND_PRODUCE_DIALYSATE_STATE; } else if ( TRUE == didTimeout( spentDialPressureCheckStartTimeMS, SPENT_DIAL_PRES_CHECK_TIME_OUT ) ) { @@ -430,23 +485,52 @@ /*********************************************************************//** * @brief + * The handleGendProduceDialysateyState function produces dialysate + * by executing balancing chamber and decides to pass the dialysate + * for treatment. + * @details \b Inputs: none + * @details \b Outputs: balancing chamber state. + * @return the current state of gen dialysate mode + *************************************************************************/ +static DD_GEND_MODE_STATE_T handleGendProduceDialysateyState( void ) +{ + DD_GEND_MODE_STATE_T state = DD_GEND_PRODUCE_DIALYSATE_STATE; + + //Execute balancing chamber + execBalancingChamberControl(); + + //if the produced dialysate is good and TD asks for dialysate delivery + // move to next state + if ( ( TRUE == isDialysateGoodtoDeliver ) && ( FALSE == getTDDialyzerBypass() ) ) + { + setModeGenDStateTransition( DD_GEND_DIALYSATE_DELIVERY_STATE ); + state = DD_GEND_DIALYSATE_DELIVERY_STATE; + } + + return state; +} + +/*********************************************************************//** + * @brief * The handleGendDialysateDeliveryState function performing dialysate - * delivery by executing balacning chamber. + * delivery by executing balancing chamber. * @details \b Inputs: none * @details \b Outputs: balancing chamber state. * @return the current state of gen dialysate mode *************************************************************************/ static DD_GEND_MODE_STATE_T handleGendDialysateDeliveryState( void ) { DD_GEND_MODE_STATE_T state = DD_GEND_DIALYSATE_DELIVERY_STATE; - U32 balChamberstate; //Execute balancing chamber - balChamberstate = execBalancingChamberControl(); + execBalancingChamberControl(); - if ( BAL_CHAMBER_DIAL_DELIVERY_PAUSE == balChamberstate ) + // if TD asks for bypass or dialysate is not good to deliver + //transition to produce dialystate state + if ( ( FALSE == isDialysateGoodtoDeliver ) || ( TRUE == getTDDialyzerBypass() ) ) { - //handle if balancing chamber is paused for some reasons. + setModeGenDStateTransition( DD_GEND_PRODUCE_DIALYSATE_STATE ); + state = DD_GEND_PRODUCE_DIALYSATE_STATE; } return state; @@ -485,6 +569,42 @@ /*********************************************************************//** * @brief + * The requestDDStop function handles an TD request to stop (return to standby mode). + * @details \b Inputs: none + * @details \b Outputs: DD standby mode requested + * @return TRUE if request accepted. + *************************************************************************/ +BOOL requestDDStop( void ) +{ + BOOL result = TRUE; + + requestNewOperationMode( DD_MODE_STAN ); + + return result; +} + +/*********************************************************************//** + * @brief + * The getDialDeliveryProgressStatus function gets the dialysate delivery + * progress status. + * @details \b Inputs: isDialDeliveryInProgress + * @details \b Outputs: none + * @return the current status of dialysate delivery + *************************************************************************/ +U32 getDialDeliveryProgressStatus( void ) +{ + U32 result = isDialDeliveryInProgress.data; + + if ( OVERRIDE_KEY == isDialDeliveryInProgress.override ) + { + result = isDialDeliveryInProgress.ovData; + } + + return result; +} + +/*********************************************************************//** + * @brief * The getGenDilaysateDataPublishInterval function gets the generate dialysate * mode data publish interval. * @details \b Inputs: genDialysateDataPublishInterval @@ -520,13 +640,15 @@ GEN_DIALYSATE_MODE_DATA_T data; data.genDialysateExecState = (U32)getCurrentGenDialysateState(); + data.isDialDelInProgress = (BOOL)getDialDeliveryProgressStatus(); data.floaterLevel1 = (U32)getLevelStatus( FLOATER_1 ); data.floaterLevel2 = (U32)getLevelStatus( FLOATER_2 ); data.BiCarbLevel = (U32)getLevelStatus( BICARB_LEVEL ); data.SpentChamberLevel = (U32)getLevelStatus( SPENT_DIALYSATE_LEVEL ); data.hydNegativePressure = getFilteredPressure( PRESSURE_SENSOR_HYDRAULICS_OUTLET ); data.hydPositivePressure = getFilteredPressure( PRESSURE_SENSOR_FRESH_DIALYSATE ); data.spentDialysatePressure = getFilteredPressure( PRESSURE_SENSOR_SPENT_DIALYSATE ); + data.isDialysateGoodtoDeliver = isDialysateGoodtoDeliver; broadcastData( MSG_ID_DD_GEN_DIALYSATE_MODE_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( GEN_DIALYSATE_MODE_DATA_T ) ); @@ -559,6 +681,23 @@ /*********************************************************************//** * @brief + * The testDialDeliveryInProgressOverride function sets the override value + * of the dialysate delivery In progress flag. + * @details Inputs: isDialDeliveryInProgress + * @details Outputs: isDialDeliveryInProgress + * @param message Override message from Dialin which includes the override + * value to override the dialysate delivery in progress flag. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testDialDeliveryInProgressOverride( MESSAGE_T *message ) +{ + BOOL result = u32Override( message, &isDialDeliveryInProgress, 0, TRUE ); + + return result; +} + +/*********************************************************************//** + * @brief * The testGenDHydChamberFluidTempOverride function sets the override value * of the hydraulics chamber fluid temperature. * @details Inputs: targetHydChamberFluidTemp Index: firmware/App/Modes/ModeGenDialysate.h =================================================================== diff -u -r48ca7fd644c67920acc29a80b7af379d0a134d1a -r6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b --- firmware/App/Modes/ModeGenDialysate.h (.../ModeGenDialysate.h) (revision 48ca7fd644c67920acc29a80b7af379d0a134d1a) +++ firmware/App/Modes/ModeGenDialysate.h (.../ModeGenDialysate.h) (revision 6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b) @@ -35,24 +35,28 @@ typedef struct { U32 genDialysateExecState; ///< Generate dialysate execution state + BOOL isDialDelInProgress; ///< Whether Dialysate Delivery in progress or not U32 floaterLevel1; ///< Floater level 1 (low or medium) U32 floaterLevel2; ///< Floater level 2 (medium or high) U32 BiCarbLevel; ///< BiCarb Chamber level U32 SpentChamberLevel; ///< Spent dialysate chamber level F32 hydNegativePressure; ///< Hydraulics chamber negative pressure F32 hydPositivePressure; ///< Hydraulics chamber positive pressure F32 spentDialysatePressure; ///< Spent Dialysate positive pressure + BOOL isDialysateGoodtoDeliver; ///< Ready to deliver dialysate or not } GEN_DIALYSATE_MODE_DATA_T; // ********** public function prototypes ********** void initGenDialysateMode( void ); // initialize this gen dialysate mode unit U32 transitionToGenDialysateMode( void ); // prepares for transition to gen dialysate mode U32 execGenDialysateMode( void ); // execute the gen dialysate mode state machine (call from OperationModes) +BOOL requestDDStop( void ); // TD request to stop the dialysate generation. DD_GEND_MODE_STATE_T getCurrentGenDialysateState( void ); // get the current state of the gen dialysate mode. BOOL testDDGenDialysateDataPublishIntervalOverride( MESSAGE_T *message ); +BOOL testDialDeliveryInProgressOverride( MESSAGE_T *message ); // To override the dialysate delivery in progress flag BOOL testGenDHydChamberFluidTempOverride( MESSAGE_T *message ); // Override the hydraulics chamber fluid temperature /**@}*/ Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -rbbd8ef64eb4b178ca76a9721908fee7347a71c6a -r6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision bbd8ef64eb4b178ca76a9721908fee7347a71c6a) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b) @@ -260,22 +260,6 @@ /*********************************************************************//** * @brief - * The requestDDStop function handles an TD request to stop (return to standby mode). - * @details \b Inputs: none - * @details \b Outputs: DD standby mode requested - * @return TRUE if request accepted. - *************************************************************************/ -BOOL requestDDStop( void ) -{ - BOOL result = TRUE; - - requestNewOperationMode( DD_MODE_STAN ); - - return result; -} - -/*********************************************************************//** - * @brief * The startDDFlush function starts DD flush mode. * @details \b Inputs: standbyState * @details \b Outputs: none Index: firmware/App/Modes/ModeStandby.h =================================================================== diff -u -rbbd8ef64eb4b178ca76a9721908fee7347a71c6a -r6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b --- firmware/App/Modes/ModeStandby.h (.../ModeStandby.h) (revision bbd8ef64eb4b178ca76a9721908fee7347a71c6a) +++ firmware/App/Modes/ModeStandby.h (.../ModeStandby.h) (revision 6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b) @@ -46,7 +46,6 @@ BOOL areInletWaterConditionsAlarmsActive( void ); // checks water inlet pressure, temperature and conductivity alarms. BOOL requestDDStart( void ); // TD requests DD start (go to generation dialysate mode) -BOOL requestDDStop( void ); // TD request to stop the dialysate generation. BOOL startDDFlush( void ); // TD start flush mode BOOL startDDHeatDisinfect( void ); // TD start heat disinfect mode Index: firmware/App/Monitors/Level.c =================================================================== diff -u -rc85d9f0a8023fabdf1cd557965958d225e2b9085 -r6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b --- firmware/App/Monitors/Level.c (.../Level.c) (revision c85d9f0a8023fabdf1cd557965958d225e2b9085) +++ firmware/App/Monitors/Level.c (.../Level.c) (revision 6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b) @@ -98,11 +98,13 @@ { // Process the status of the Level case FLOATER_1: - currentLevelStatus = ( getFPGAFloater1Status() != 0 ? STATE_LOW : STATE_MEDIUM ); + //currentLevelStatus = ( getFPGAFloater1Status() != 0 ? STATE_LOW : STATE_MEDIUM ); + currentLevelStatus = ( getFPGAFloater1Status() != 0 ? STATE_LOW : STATE_HIGH ); break; case FLOATER_2: - currentLevelStatus = ( getFPGAFloater2Status() != 0 ? STATE_MEDIUM : STATE_HIGH ); + // TODO: Commenting for alpha protoype + //currentLevelStatus = ( getFPGAFloater2Status() != 0 ? STATE_MEDIUM : STATE_HIGH ); break; case BICARB_LEVEL: Index: firmware/App/Services/Messaging.c =================================================================== diff -u -rbbd8ef64eb4b178ca76a9721908fee7347a71c6a -r6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b --- firmware/App/Services/Messaging.c (.../Messaging.c) (revision bbd8ef64eb4b178ca76a9721908fee7347a71c6a) +++ firmware/App/Services/Messaging.c (.../Messaging.c) (revision 6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b) @@ -199,7 +199,6 @@ // ********** private function prototypes ********** static BOOL sendTestAckResponseMsg( MSG_ID_T msgID, BOOL ack ); -static BOOL sendAckResponseMsg( MSG_ID_T msgID, COMM_BUFFER_T buffer, BOOL ack ); /*********************************************************************//** * @brief @@ -325,7 +324,7 @@ * @param ack TRUE if test message was handled successfully, FALSE if not * @return TRUE if response message successfully queued for transmit, FALSE if not *************************************************************************/ -static BOOL sendAckResponseMsg( MSG_ID_T msgID, COMM_BUFFER_T buffer, BOOL ack ) +BOOL sendAckResponseMsg( MSG_ID_T msgID, COMM_BUFFER_T buffer, BOOL ack ) { BOOL result; MESSAGE_T msg; @@ -589,57 +588,7 @@ return status; } -/*********************************************************************//** - * @brief - * The handleDialysateDeliveryRequestMsg function handles a dailysate - * delivery request from TD and updates dialysate flowrate, UF rate, - * dialysate temperature, dialyzer bypass and concentrate types ( acid - * and bicarb types). - * @details Inputs: none - * @details Outputs: message handled - * @param message a pointer to the message to handle - * @return TRUE if message is sucessfully parsed, FALSE if not. - *************************************************************************/ -BOOL handleDialysateDeliveryRequestMsg( MESSAGE_T *message ) -{ - BOOL result = FALSE; - if ( message->hdr.payloadLen == sizeof( DIALYSATE_DELIVERY_REQ_PAYLOAD_T ) ) - { - DIALYSATE_DELIVERY_REQ_PAYLOAD_T startTxRequest; - DD_OP_MODE_T ddMode = getCurrentOperationMode(); - - memcpy( &startTxRequest, message->payload, sizeof( DIALYSATE_DELIVERY_REQ_PAYLOAD_T ) ); - - if ( ( DD_MODE_STAN == ddMode ) && ( TRUE == startTxRequest.start ) ) - { - result = requestDDStart(); - } - else if ( ( DD_MODE_GEND == ddMode ) && ( FALSE == startTxRequest.start ) ) - { - result = requestDDStop(); - } - - if ( ddMode >= DD_MODE_STAN ) - { - // Set dialysate flow rate, UF rate and dialysate temperature - setTDDialysateFlowrate( startTxRequest.dialRate ); - setTDUFRate( startTxRequest.ufRate ); - setTDTargetDialysateTemperature( startTxRequest.dialTemp ); - - // Set concentrate types, Bypass dialyzer - setTDAcidAndBicarbType( startTxRequest.acidType, startTxRequest.bicarbType ); - setTDDialyzerBypass( startTxRequest.bypassDialyzer ); - - result |= TRUE; - } - } - - sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_DD_2_TD, result ); - - return result; -} - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ Index: firmware/App/Services/Messaging.h =================================================================== diff -u -rbbd8ef64eb4b178ca76a9721908fee7347a71c6a -r6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b --- firmware/App/Services/Messaging.h (.../Messaging.h) (revision bbd8ef64eb4b178ca76a9721908fee7347a71c6a) +++ firmware/App/Services/Messaging.h (.../Messaging.h) (revision 6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b) @@ -60,13 +60,13 @@ // ACK MSG BOOL sendACKMsg( MESSAGE_T *message ); +BOOL sendAckResponseMsg( MSG_ID_T msgID, COMM_BUFFER_T buffer, BOOL ack ); void handleUITDResetInServiceModeRequest( MESSAGE_T* message ); // handler functions **************************************** BOOL handleSetTDOperationMode( MESSAGE_T *message ); -BOOL handleDialysateDeliveryRequestMsg( MESSAGE_T *message ); // Test Support Messaging Functions ************************** Index: firmware/App/Services/TDInterface.c =================================================================== diff -u -rbbd8ef64eb4b178ca76a9721908fee7347a71c6a -r6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b --- firmware/App/Services/TDInterface.c (.../TDInterface.c) (revision bbd8ef64eb4b178ca76a9721908fee7347a71c6a) +++ firmware/App/Services/TDInterface.c (.../TDInterface.c) (revision 6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b) @@ -15,13 +15,16 @@ * ***************************************************************************/ -#include "TDInterface.h" #include "Messaging.h" +#include "MessagePayloads.h" #include "ModeInitPOST.h" +#include "ModeStandby.h" +#include "ModeGenDialysate.h" #include "OperationModes.h" #include "PersistentAlarm.h" #include "SystemCommDD.h" #include "TaskGeneral.h" +#include "TDInterface.h" #include "Timers.h" /** @@ -318,6 +321,58 @@ return tdBicarbType; } +/*********************************************************************//** + * @brief + * The handleDialysateDeliveryRequestMsg function handles a dailysate + * delivery request from TD and updates dialysate flowrate, UF rate, + * dialysate temperature, dialyzer bypass and concentrate types ( acid + * and bicarb types). + * @details Inputs: none + * @details Outputs: message handled + * @param message a pointer to the message to handle + * @return TRUE if message is sucessfully parsed, FALSE if not. + *************************************************************************/ +BOOL handleDialysateDeliveryRequestMsg( MESSAGE_T *message ) +{ + BOOL result = FALSE; + + if ( message->hdr.payloadLen == sizeof( DIALYSATE_DELIVERY_REQ_PAYLOAD_T ) ) + { + DIALYSATE_DELIVERY_REQ_PAYLOAD_T startTxRequest; + DD_OP_MODE_T ddMode = getCurrentOperationMode(); + + memcpy( &startTxRequest, message->payload, sizeof( DIALYSATE_DELIVERY_REQ_PAYLOAD_T ) ); + + if ( ( DD_MODE_STAN == ddMode ) && ( TRUE == startTxRequest.start ) ) + { + result = requestDDStart(); + } + else if ( ( DD_MODE_GEND == ddMode ) && ( FALSE == startTxRequest.start ) ) + { + result = requestDDStop(); + } + + if ( ( DD_MODE_STAN == ddMode ) && ( DD_MODE_GEND == ddMode ) ) + { + // Set dialysate flow rate, UF rate and dialysate temperature + setTDDialysateFlowrate( startTxRequest.dialRate ); + setTDUFRate( startTxRequest.ufRate ); + setTDTargetDialysateTemperature( startTxRequest.dialTemp ); + + // Set concentrate types, Bypass dialyzer + setTDAcidAndBicarbType( startTxRequest.acidType, startTxRequest.bicarbType ); + setTDDialyzerBypass( startTxRequest.bypassDialyzer ); + + result |= TRUE; + } + } + + sendAckResponseMsg( (MSG_ID_T)message->hdr.msgID, COMM_BUFFER_OUT_CAN_DD_2_TD, result ); + + return result; +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ Index: firmware/App/Services/TDInterface.h =================================================================== diff -u -rbbd8ef64eb4b178ca76a9721908fee7347a71c6a -r6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b --- firmware/App/Services/TDInterface.h (.../TDInterface.h) (revision bbd8ef64eb4b178ca76a9721908fee7347a71c6a) +++ firmware/App/Services/TDInterface.h (.../TDInterface.h) (revision 6679a2cd813b21a8cb4c58b3eeb721e0eef9a10b) @@ -38,9 +38,10 @@ // ********** public function prototypes ********** void initTDInterface( void ); - void execTDInterfaceMonitor( void ); +BOOL handleDialysateDeliveryRequestMsg( MESSAGE_T *message ); + TD_OP_MODE_T getTDOpMode( void ); U32 getTDSubMode( void ); void setTDOpMode( U32 opMode, U32 subMode );