Index: firmware/App/Controllers/DGInterface.c =================================================================== diff -u -r491bddb51ce331490567666795549c17f78a0e68 -rb1f086e7cd292d5a97a7265075400274d60d4fbf --- firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision 491bddb51ce331490567666795549c17f78a0e68) +++ firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision b1f086e7cd292d5a97a7265075400274d60d4fbf) @@ -8,12 +8,14 @@ * @file DGInterface.c * * @author (last) Dara Navaei -* @date (last) 03-Apr-2022 +* @date (last) 13-Jul-2022 * * @author (original) Sean * @date (original) 08-Apr-2020 * ***************************************************************************/ + +#include // To check for NaN #include "DialInFlow.h" #include "Dialysis.h" @@ -69,11 +71,14 @@ static OVERRIDE_F32_T loadCellWeightInGrams[ NUM_OF_LOAD_CELLS ]; /// Filtered (32 sample) weight of reservoirs. static F32 lgFilteredReservoirWeightInGrams[ NUM_OF_DG_RESERVOIRS ]; +static F32 lgFilteredReservoirBackupWeightInGrams[ NUM_OF_DG_RESERVOIRS ]; // Load cell filtering data static F32 lgLoadCellReadings[ NUM_OF_DG_RESERVOIRS ][ SIZE_OF_LARGE_LOAD_CELL_AVG ]; ///< Holds load cell samples for large load cell moving average. static U32 lgLoadCellReadingsIdx = 0; ///< Index for next sample in large load cell rolling average sample array. static F32 lgLoadCellReadingsTotal[ NUM_OF_DG_RESERVOIRS ]; ///< Rolling total - used to calc large load cell moving average. +static F32 lgLoadCellBackupReadings[ NUM_OF_DG_RESERVOIRS ][ SIZE_OF_LARGE_LOAD_CELL_AVG ]; ///< Holds load cell samples for large load cell moving average. +static F32 lgLoadCellBackupReadingsTotal[ NUM_OF_DG_RESERVOIRS ]; ///< Rolling total - used to calc large load cell moving average. // DG Dialysate flow rate static F32 dgDialysateFlowRateMlMin = 0.0; ///< Latest dialysate flow rate reported by the DG. @@ -132,6 +137,7 @@ for ( j = 0; j < SIZE_OF_LARGE_LOAD_CELL_AVG; j++ ) { lgLoadCellReadings[ i ][ j ] = 0.0; + lgLoadCellBackupReadings[ i ][ j ] = 0.0; } } @@ -146,6 +152,8 @@ lgLoadCellReadingsIdx = 0; lgLoadCellReadingsTotal[ DG_RESERVOIR_1 ] = 0.0; lgLoadCellReadingsTotal[ DG_RESERVOIR_2 ] = 0.0; + lgLoadCellBackupReadingsTotal[ DG_RESERVOIR_1 ] = 0.0; + lgLoadCellBackupReadingsTotal[ DG_RESERVOIR_2 ] = 0.0; initPersistentAlarm( ALARM_ID_DIALYSATE_TEMPERATURE_HIGH, DIALYSATE_TEMP_PERSISTENCE_PERIOD, DIALYSATE_TEMP_PERSISTENCE_PERIOD ); initPersistentAlarm( ALARM_ID_DIALYSATE_TEMPERATURE_LOW, DIALYSATE_TEMP_PERSISTENCE_PERIOD, DIALYSATE_TEMP_PERSISTENCE_PERIOD ); @@ -329,6 +337,27 @@ /*********************************************************************//** * @brief + * The getReservoirBackupWeightLargeFilter function gets the backup load cell weight + * of the given reservoir after large (32 sample) filter applied. + * @details Inputs: lgFilteredReservoirWeightInGrams[] + * @details Outputs: none + * @param resID ID of reservoir to get filtered weight for + * @return the current filtered weight of the given reservoir in grams + *************************************************************************/ +F32 getReservoirBackupWeightLargeFilter( DG_RESERVOIR_ID_T resID ) +{ + F32 result = 0.0; + + if ( resID < NUM_OF_DG_RESERVOIRS ) + { + result = lgFilteredReservoirBackupWeightInGrams[ resID ]; + } + + return result; +} + +/*********************************************************************//** + * @brief * The getDGDisinfectsStates function returns the DG disinfects readings. * @details Inputs: none * @details Outputs: none @@ -455,6 +484,12 @@ *************************************************************************/ void setDialysateFlowData( F32 flowRate ) { + // Check if the sent value by DG is a NaN + if ( isnan( flowRate ) ) + { + flowRate = 0.0; + } + dgDialysateFlowRateMlMin = flowRate; dgDialysateFlowDataFreshFlag = TRUE; } @@ -492,6 +527,12 @@ lgLoadCellReadings[ res ][ lgLoadCellReadingsIdx ] = wt; lgLoadCellReadingsTotal[ res ] += wt; lgFilteredReservoirWeightInGrams[ res ] = lgLoadCellReadingsTotal[ res ] / (F32)SIZE_OF_LARGE_LOAD_CELL_AVG; + + wt = ( res == DG_RESERVOIR_1 ? res1Backup : res2Backup ); + lgLoadCellBackupReadingsTotal[ res ] -= lgLoadCellBackupReadings[ res ][ lgLoadCellReadingsIdx ]; + lgLoadCellBackupReadings[ res ][ lgLoadCellReadingsIdx ] = wt; + lgLoadCellBackupReadingsTotal[ res ] += wt; + lgFilteredReservoirBackupWeightInGrams[ res ] = lgLoadCellBackupReadingsTotal[ res ] / (F32)SIZE_OF_LARGE_LOAD_CELL_AVG; } lgLoadCellReadingsIdx = INC_WRAP( lgLoadCellReadingsIdx, 0, SIZE_OF_LARGE_LOAD_CELL_AVG - 1 ); @@ -586,7 +627,7 @@ dgTrimmerHeaterOn = TRUE; dgCmdResp[ DG_CMD_START_TRIMMER_HEATER ].commandID = DG_CMD_NONE; - sendDGStartStopTrimmerHeaterCommand( START_DG_CMD, dgTrimmerTempSet ); + sendDGStartStopTrimmerHeaterCommand( START_DG_CMD ); } /*********************************************************************//** @@ -602,7 +643,7 @@ dgTrimmerHeaterOn = FALSE; dgCmdResp[ DG_CMD_STOP_TRIMMER_HEATER ].commandID = DG_CMD_NONE; - sendDGStartStopTrimmerHeaterCommand( STOP_DG_CMD, 0 ); + sendDGStartStopTrimmerHeaterCommand( STOP_DG_CMD ); } /*********************************************************************//**