Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -r788a0b1a638d815df1e83af80cba7be03af2020c -r05ab87b4de779f06243fa1e87a0402b659a6fa3e --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 788a0b1a638d815df1e83af80cba7be03af2020c) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 05ab87b4de779f06243fa1e87a0402b659a6fa3e) @@ -61,6 +61,8 @@ #define BICARB_CHAMBER_PERIODIC_FILL_TIME ( 1 * SEC_PER_MIN * \ ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ) ///< Periodic bicarb chamber fill request 60 sec x 20 = 1200 #define BAL_CHAMBER_FILL_TIMEOUT_FACTOR 3.0F ///< Balancing Chamber fill timeout factor (300% of observed fill count) +#define COMP_SLOPE -0.000376F ///< Balancing chamber temperature compensation slope factor +#define COMP_INTERCEPT 1.007269F ///< Balancing chamber temperature compensation intercept factor /// Payload record structure for balancing chamber switch only request typedef struct @@ -107,9 +109,10 @@ static F32 pendingTdDialysateFlowrate; ///< Pending TD dialysate flow rate; applied at FillEnd after a BC switch completes. static BOOL isBalChamberSwitchingPeriodUpdatePending; ///< BC switching period update pending apply at fill end. static U32 bcSwitchingBasedOnClosedPeriodCounter; ///< Valve-close segments remaining before first-cycle relaxations clear after Qd timing apply. +static F32 balancingError; ///< Balancing error that has been calculated during balancing chamber switching. //TODO: remove later once level sensor working -static U32 bicarbChamberPeriodicFillCounter; +static U32 bicarbChamberPeriodicFillCounter; // Balancing chamber state change tracker static BAL_CHAMBER_EXEC_STATE_T prevBalChamberState; ///< Balancing chamber Previous State tracking variable @@ -130,6 +133,7 @@ static void applyBalChamberSwitchingPeriod( F32 tdDialysateFlowrate ); static BOOL isBalChamberTimeBasedSwitching( void ); static void scheduleFirstCycleRelaxAfterQdApply( void ); +static void calculateBalancingChamberError( void ); /*********************************************************************//** * @brief @@ -188,6 +192,7 @@ pendingTdDialysateFlowrate = 0.0F; isBalChamberSwitchingPeriodUpdatePending = FALSE; bcSwitchingBasedOnClosedPeriodCounter = 0; + balancingError = 0.0F; prevBalChamberState = BAL_CHAMBER_STATE_IDLE; //TODO:remove once level sensor working bicarbChamberPeriodicFillCounter = 0; @@ -675,7 +680,7 @@ freshDialPressure = getFilteredPressure( D18_PRES ); spentDialPressure = getFilteredPressure( D51_PRES ); - if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_0_HW ) == TRUE ) + if ( TRUE == getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_0_HW ) ) { //Set Trimmer heater Target temp every BC cycle to catch up fresh dialysate temp setHeaterTargetTemperature( D45_HEAT, getFilteredTemperatureValue( D4_TEMP ) ); @@ -989,10 +994,11 @@ acidVolume = getF32OverrideValue( &acidDoseVolume ); bicarbVolume = getF32OverrideValue( &bicarbDoseVolume ); } + freshDialPressure = getFilteredPressure( D18_PRES ); spentDialPressure = getFilteredPressure( D51_PRES ); - if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_0_HW ) == TRUE ) + if ( TRUE == getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_0_HW ) ) { //Set Trimmer heater Target temp every BC cycle to catch up fresh dialysate temp setHeaterTargetTemperature( D45_HEAT, getFilteredTemperatureValue( D4_TEMP ) ); @@ -1262,7 +1268,7 @@ // Check if a request made was to activate the balancing chamber switching. if ( TRUE == isBalChamberSwitchingOnRequested ) { - //Clear the request flag to indicate that the request was processed. + //Clear request was processed. isBalChamberSwitchingOnRequested = FALSE; // Set flag to indicate that balancing chamber switching is active @@ -1569,6 +1575,50 @@ /*********************************************************************//** * @brief + * The calculateBalancingChamberError function calculates the balancing error + * based on the fresh and spent dialysate temperature differences. + * @details \b Inputs: D4 and D50 temperature + * @details \b Outputs: balancing error + * @return balancing error the balancing error that impacts ultrafilteration. + *************************************************************************/ +static void calculateBalancingChamberError( void ) +{ + F32 freshDensity = 0.0F; + F32 spentDensity = 0.0F; + F32 compFreshFlowrate = 0.0F; + F32 compSpentFlowrate = 0.0F; + + // Fresh side dialysate density + if ( getTestConfigStatus( TEST_CONFIG_DD_FP_ENABLE_BETA_1_0_HW ) == TRUE ) + { + freshDensity = ( COMP_SLOPE * getFilteredTemperatureValue( D4_TEMP ) ) + COMP_INTERCEPT; + } + else + { + freshDensity = ( COMP_SLOPE * getFilteredTemperatureValue( D99_TEMP ) ) + COMP_INTERCEPT; + } + + spentDensity = ( COMP_SLOPE * getFilteredTemperatureValue( D50_TEMP ) ) + COMP_INTERCEPT; // spent side dialysate density + compFreshFlowrate = getTDDialysateFlowrate() * freshDensity; // Qd * fresh density + compSpentFlowrate = getTDDialysateFlowrate() * spentDensity; // Qd * spent density + balancingError = compFreshFlowrate - compSpentFlowrate; // Error in g/min +} + +/*********************************************************************//** + * @brief + * The getBalancingChamberError function gets the calculated balancing chamber + * error that may be used for adjusting the ultrafiltration rate. + * @details \b Inputs: balancingError + * @details \b Outputs: none + * @return balancing chamber error + *************************************************************************/ +F32 getBalancingChamberError( void ) +{ + return balancingError; +} + +/*********************************************************************//** + * @brief * The publishBalChamberData function broadcasts the balancing chamber * execution data at defined interval. * @details \b Inputs: balChamberDataPublicationTimerCounter Index: firmware/App/Controllers/DryBiCart.c =================================================================== diff -u -rc0e1f5f4c4657c156a87cc8be6c3db38bb14db33 -r05ab87b4de779f06243fa1e87a0402b659a6fa3e --- firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision c0e1f5f4c4657c156a87cc8be6c3db38bb14db33) +++ firmware/App/Controllers/DryBiCart.c (.../DryBiCart.c) (revision 05ab87b4de779f06243fa1e87a0402b659a6fa3e) @@ -24,6 +24,7 @@ #include "DryBiCart.h" #include "Level.h" #include "Messaging.h" +#include "MessageSupport.h" #include "MixingControl.h" #include "ModeGenDialysate.h" #include "OperationModes.h" @@ -144,6 +145,8 @@ static BOOL dryBiCartPressureDecayStartTimeFlag; ///< Dry bicart d66 pressure decay start timer. static DRY_BICART_OPERATION_T dryBicartStartRequest; ///< Dry bicart operation, fill or supply or drain request +static DRY_BICART_OPERATION_T prevDryBicartState; ///< Dry BiCart State Change Tracker + // ********** private function prototypes ********** static void updateDrybicartOperation(void); @@ -250,6 +253,7 @@ dryBiCartDrainTimePeriod = 0; dryBiCartPersistenceStartTime = 0; drybicartPersistenceOnLowercartPressureStartTime = 0; + prevDryBicartState = DRY_BICART_IDLE; } /*********************************************************************//** @@ -269,8 +273,8 @@ * @brief * The execDryBicart function executes the set of dry bicarbonate cartridge fill, * bicarbonate chamber fill and bicarbonate cartridge drain related state machines one at time - * @details \b Inputs: dryBicartStartRequest - * @details \b Outputs: none + * @details \b Inputs: dryBicartStartRequest, prevDryBicartState + * @details \b Outputs: prevDryBicartState * @details \b Alarm: ALARM_ID_DD_SOFTWARE_FAULT when wrong dry bicart state machine is * invoked. * @return none. @@ -314,6 +318,12 @@ break; } + if ( prevDryBicartState != dryBicartStartRequest ) + { + SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_DRY_BICART_STATE_CHANGE, prevDryBicartState, dryBicartStartRequest ); + prevDryBicartState = dryBicartStartRequest; + } + // Publish dry bicart data publishDryBicartData(); } Index: firmware/App/Controllers/Heaters.c =================================================================== diff -u -rc0e1f5f4c4657c156a87cc8be6c3db38bb14db33 -r05ab87b4de779f06243fa1e87a0402b659a6fa3e --- firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision c0e1f5f4c4657c156a87cc8be6c3db38bb14db33) +++ firmware/App/Controllers/Heaters.c (.../Heaters.c) (revision 05ab87b4de779f06243fa1e87a0402b659a6fa3e) @@ -207,6 +207,7 @@ static U32 startTimeToInitiateOuterloopTimeout; ///< Time to wait for temperature uptrend to seen,else initiate the outer loop control static U32 startTimeToCheckUpTrendTemperature; ///< Time to wait for measured dialyzer temperature uptrend check. static U32 startTimeToUndoOffsetFromHeatlossEstimation; ///< Time to remove the offset that is added to heatloss model for Low Qds. +static BOOL previousHeaterState[ NUM_OF_DD_HEATERS ]; ///< Previous State of Heater. //For testing #ifdef __HEATERS_DEBUG__ @@ -276,6 +277,10 @@ d5OuterLoopControlInterval = D5_TARGET_TEMP_ADJUST_HIGH_QD_INTERVAL; tempRiseMonitoringInterval = TEMP_RISE_MONITORING_LOW_QD_INTERVAL; + //Initialize Previous Heater State + previousHeaterState[ D5_HEAT ] = FALSE; + previousHeaterState[ D45_HEAT ] = FALSE; + // Assign counter close to the target period heatersStatus[ D5_HEAT ].controlIntervalCounter = D5_HEAT_CONTROL_INTERVAL_START_COUNT; heatersStatus[ D45_HEAT ].controlIntervalCounter = 0; @@ -797,8 +802,8 @@ /*********************************************************************//** * @brief * The execHeatersControl function executes the heaters state machine. - * @details \b Inputs: heaterStatus - * @details \b Outputs: heaterStatus + * @details \b Inputs: heaterStatus, previousHeaterState + * @details \b Outputs: heaterStatus, previousHeaterState * @details \b Alarms: ALARM_ID_DD_SOFTWARE_FAULT when invalid heater * executive state found. * @return none @@ -839,6 +844,13 @@ // stop the heater stopHeater( heater ); } + + if ( heatersStatus[ heater ].heaterOnState != previousHeaterState[ heater ] ) + { + SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_HEATER_STATE_CHANGE, heater, + heatersStatus[ heater ].heaterOnState ); + previousHeaterState[ heater ] = heatersStatus[ heater ].heaterOnState; + } } } Index: firmware/App/Controllers/Ultrafiltration.c =================================================================== diff -u -r78dc7a98fb2a3d28bbdeb4eade1bba03641433d3 -r05ab87b4de779f06243fa1e87a0402b659a6fa3e --- firmware/App/Controllers/Ultrafiltration.c (.../Ultrafiltration.c) (revision 78dc7a98fb2a3d28bbdeb4eade1bba03641433d3) +++ firmware/App/Controllers/Ultrafiltration.c (.../Ultrafiltration.c) (revision 05ab87b4de779f06243fa1e87a0402b659a6fa3e) @@ -147,8 +147,9 @@ *************************************************************************/ static void updateUFRequest( void ) { - F32 qd = getTDDialysateFlowrate(); - BOOL bypass = getTDDialyzerBypass(); + F32 qd = getTDDialysateFlowrate(); + BOOL bypass = getTDDialyzerBypass(); + BOOL prevUFState = isUltrafiltrationRequested; // update latest UF run/pause request // if qd is zero or dialyzer is bypassed, UF pump should be turn off @@ -160,6 +161,12 @@ { isUltrafiltrationRequested = FALSE; } + + // event update on state switch + if( prevUFState != isUltrafiltrationRequested ) + { + SEND_EVENT_WITH_2_U32_DATA( DD_EVENT_UF_PUMP_ON_OFF, prevUFState, isUltrafiltrationRequested ); + } } /*********************************************************************//**