Index: firmware/App/Modes/Dialysis.c =================================================================== diff -u -r7499a42cc0f906f9a4a947c82c5b4615217ce7e5 -r999abe4f616b27de63c39676b05d66e66a3fff11 --- firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 7499a42cc0f906f9a4a947c82c5b4615217ce7e5) +++ firmware/App/Modes/Dialysis.c (.../Dialysis.c) (revision 999abe4f616b27de63c39676b05d66e66a3fff11) @@ -52,6 +52,14 @@ #define MAX_ACTIVE_LOAD_CELL_CHANGE_G 50.0F ///< Maximum delta between new and previous measured UF volume. +/// Defined states for the Load Cell cycles. +typedef enum Load_Cell_Cycle +{ + LOAD_CELL_START = 0, ///< Load Cell use Start + LOAD_CELL_FINAL, ///< Load Cell use Final + NUM_OF_LOAD_CELL_CYCLES ///< Number of Load Cell Cycles +} LOAD_CELL_CYCLE_T; + // ********** private data ********** static DIALYSIS_STATE_T currentDialysisState; ///< Current state of the dialysis sub-mode state machine. @@ -65,7 +73,7 @@ static F32 resCurrVolume[ NUM_OF_DG_RESERVOIRS ]; ///< Reservoir current volume. static F32 resLastVolume[ NUM_OF_DG_RESERVOIRS ]; ///< Reservoir previous volume. static F32 measUFVolumeFromPriorReservoirs; ///< Current total ultrafiltration volume from previous reservoirs in current treatment. -static F32 lcLastSteadyWeight[NUM_OF_LOAD_CELLS]; ///< Load Cell Last Steady Weight for drift test +static F32 lcLastSteadyWeight[NUM_OF_LOAD_CELL_CYCLES][NUM_OF_LOAD_CELLS]; ///< Load Cell Last Steady Weight for drift test Start/Final cycle static U32 uFTimeMS; ///< Current elapsed ultrafiltration time (in ms). Used for calculating UF reference volume. static U32 lastUFTimeStamp; ///< HD timer value when we last took stock of ultrafiltration time (so we can determine how much time has elapsed since). @@ -107,7 +115,7 @@ static void updateUFVolumes( void ); static void publishSalineBolusData( void ); -static void checkLoadCellsStablePrimaryBackupDriftOutOfRange( DG_RESERVOIR_ID_T reservoirID ); +static void checkLoadCellsStablePrimaryBackupDriftOutOfRange( DG_RESERVOIR_ID_T reservoirID, LOAD_CELL_CYCLE_T cycle ); /*********************************************************************//** * @brief @@ -148,7 +156,8 @@ for (i=0; i (LOAD_CELL_ILLEGAL_WEIGHT_VALUE + 1) ) + if ( ( TRUE == cycle ) && ( lcLastSteadyWeight[LOAD_CELL_START][lcPrimaryIndex] > (LOAD_CELL_ILLEGAL_WEIGHT_VALUE + 1) ) ) { - // Weight has been previously saved, ok to test - loadCellPreviousDrift = lcLastSteadyWeight[lcPrimaryIndex] - lcLastSteadyWeight[lcBackupIndex]; + // Start Weight has been previously saved, ok to test + loadCellPreviousDrift = lcLastSteadyWeight[LOAD_CELL_START][lcPrimaryIndex] - lcLastSteadyWeight[LOAD_CELL_START][lcBackupIndex]; driftDiff = fabs ( loadCellCurrentDrift - loadCellPreviousDrift ); } // Save latest reading for next test time - lcLastSteadyWeight[lcPrimaryIndex] = loadCellPrimaryWeight; - lcLastSteadyWeight[lcBackupIndex] = loadCellBackupWeight; + lcLastSteadyWeight[cycle][lcPrimaryIndex] = loadCellPrimaryWeight; + lcLastSteadyWeight[cycle][lcBackupIndex] = loadCellBackupWeight; // Check for drift out of range if ( driftDiff > LOAD_CELL_PRIMARY_BACKUP_MAX_ALLOWED_DRIFT_GRAMS ) { SET_ALARM_WITH_2_F32_DATA( ALARM_ID_HD_LOAD_CELL_PRIMARY_BACKUP_DRIFT_OUT_OF_RANGE, loadCellCurrentDrift, loadCellPreviousDrift ) } + + // TODO remove this debug output + // Send a comma delimited debug message with drift data + U08 tempCharBuffer[ 128 ]; + sprintf( tempCharBuffer, "Rsvr,%d,Cycle,%d,LcOldDrift,%3.3f,LcNewDrift,%3.3f,Diff,%3.3f,Pri,%3.3f,Bak,%3.3f", reservoirID, cycle, loadCellPreviousDrift, loadCellCurrentDrift, driftDiff, loadCellPrimaryWeight, loadCellBackupWeight ); + broadcastData( MSG_ID_HD_DEBUG_EVENT, COMM_BUFFER_OUT_CAN_HD_BROADCAST, tempCharBuffer, strlen( tempCharBuffer ) ); + } /**@}*/