Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -r7278aeac8fdd894067a05c3bd3a177d38c0b0803 -ra08213c3d131203c21554d743c3ccb02575b70da --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 7278aeac8fdd894067a05c3bd3a177d38c0b0803) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision a08213c3d131203c21554d743c3ccb02575b70da) @@ -208,8 +208,12 @@ *************************************************************************/ void transitionToBalChamberFill( void ) { + printf("[TRACE3] transitionToBalChamberFill ENTRY: tick=%lu priorPeriod=%lu priorLastQd=%.2f priorSwOnly=%d\n", + getMSTimerCount(), balChamberSwitchingPeriod, lastTdDialysateFlowrate, balanceChamberSwitchingOnly); initBalanceChamber(); updateBalChamberSwitchingPeriod(); + printf("[TRACE3b] transitionToBalChamberFill EXIT: tick=%lu newPeriod=%lu newLastQd=%.2f\n", + getMSTimerCount(), balChamberSwitchingPeriod, lastTdDialysateFlowrate); } /*********************************************************************//** @@ -223,18 +227,21 @@ void updateBalChamberSwitchingPeriod( void ) { F32 tdDialysateFlowrate = getTDDialysateFlowrate(); - + printf("[TRACE4] updateBalChamberSwitchingPeriod: tick=%lu lastQd=%.4f newQd=%.4f isSwActive=%d execState=%d\n", + getMSTimerCount(), lastTdDialysateFlowrate, tdDialysateFlowrate, isBalChamberSwitchingActive, balChamberExecState); if ( lastTdDialysateFlowrate != tdDialysateFlowrate ) { // Defer Qd timing update to FillEnd at end of the current BC switch if ( ( TRUE == isBalChamberSwitchingActive ) && ( BAL_CHAMBER_STATE_IDLE != balChamberExecState ) ) { pendingTdDialysateFlowrate = tdDialysateFlowrate; isBalChamberSwitchingPeriodUpdatePending = TRUE; + printf("[TRACE4a] Qd CHANGED branch taken\n"); } // Apply immediately when BC is inactive or still idle else { + printf("[TRACE4b] Qd UNCHANGED branch taken -- period NOT recalculated, stays at %lu\n", balChamberSwitchingPeriod); pendingTdDialysateFlowrate = tdDialysateFlowrate; isBalChamberSwitchingPeriodUpdatePending = TRUE; applyBalChamberSwitchingPeriod( pendingTdDialysateFlowrate ); @@ -298,6 +305,8 @@ // finish the balancing chamber fill 50 ms prior completing the regular cycle time. balChamberSwitchingPeriod -= 1; + printf("[TRACE5] Period calculated: tick=%lu switchFreq=%.4f period=%lu\n", + getMSTimerCount(), getBalChamberSwitchingFreq(), balChamberSwitchingPeriod); //Update last td dialysate flow rate lastTdDialysateFlowrate = tdDialysateFlowrate; @@ -314,6 +323,8 @@ //Testing balChamberValveClosePeriod = balChamberSwitchingPeriod; balChamberValveClosePeriod -= 1; // Close valves prior 50 msecond for testing + printf("[TRACE5b] ValveClosePeriod set: tick=%lu period=%lu closePeriod=%lu (CHECK FOR UNDERFLOW)\n", + getMSTimerCount(), balChamberSwitchingPeriod, balChamberValveClosePeriod); currentBalChamberFillCounter = 0; currentBalChamberSwitchingCounter = 0; @@ -890,6 +901,8 @@ { if ( TRUE == isBalChamberSwitchingPeriodUpdatePending ) { + printf("[TRACE7] BC forced IDLE via isBalChamberSwitchingOffRequested: tick=%lu D51=%.2f execState=%d\n", + getMSTimerCount(), getFilteredPressure(D51_PRES), balChamberExecState); applyBalChamberSwitchingPeriod( pendingTdDialysateFlowrate ); scheduleFirstCycleRelaxAfterQdApply(); } @@ -1161,6 +1174,8 @@ { if ( TRUE == isBalChamberSwitchingPeriodUpdatePending ) { + printf("[TRACE7] BC forced IDLE via isBalChamberSwitchingOffRequested: tick=%lu D51=%.2f execState=%d\n", + getMSTimerCount(), getFilteredPressure(D51_PRES), balChamberExecState); applyBalChamberSwitchingPeriod( pendingTdDialysateFlowrate ); scheduleFirstCycleRelaxAfterQdApply(); } @@ -1477,6 +1492,12 @@ return isBalChamberFillInProgress; } + +BOOL getBalancingChamberStatus( void ) +{ + return isBalChamberSwitchingActive; +} + /*********************************************************************//** * @brief * The getBalChamberSwitchingFreq function gets the balancing chamber switching @@ -1616,6 +1637,8 @@ return balancingError; } + + /*********************************************************************//** * @brief * The publishBalChamberData function broadcasts the balancing chamber