Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r71a23ba316740818ac4e1f47b13858e570184652 -r67021fbc633259e8e1bce76749dbef7d0cb51998 --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 71a23ba316740818ac4e1f47b13858e570184652) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 67021fbc633259e8e1bce76749dbef7d0cb51998) @@ -36,7 +36,6 @@ #define MIN_RESERVOIR_VOLUME_ML 0 ///< Minimum reservoir volume in mL. #define MAX_RESERVOIR_VOLUME_ML 2000 ///< Maximum reservoir volume in mL. #define DEFAULT_FILL_VOLUME_ML 1700 ///< Default fill volume for treatment in mL. -#define DISINFECT_FILL_VOLUME_ML 2400 ///< Fill volume for disinfection in mL. #define MAX_FILL_VOLUME_ML MAX_RESERVOIR_VOLUME_ML ///< Maximum fill volume in mL. #define DEFAULT_DRAIN_VOLUME_ML 0 ///< Default drain volume in mL. #define MAX_DRAIN_VOLUME_ML MAX_RESERVOIR_VOLUME_ML ///< Maximum drain volume in mL. @@ -63,13 +62,15 @@ static F32 reservoirLowestWeight[ NUM_OF_DG_RESERVOIRS ] = { MAX_RESERVOIR_WEIGHT, MAX_RESERVOIR_WEIGHT }; static U32 reservoirWeightUnchangeStartTime[ NUM_OF_DG_RESERVOIRS ] = { 0, 0 }; ///< The reservoirs' weight start time when weight stop decreasing. static BOOL tareLoadCellRequest; ///< Flag indicates if load cell tare has been requested by HD. +static DG_RESERVOIR_VOLUME_RECORD_T reservoirsCalRecord; ///< DG reservoirs non-volatile record. // ********** private function prototypes ********** static DG_RESERVOIR_ID_T getActiveReservoir( void ); static U32 getReservoirFillVolumeTargetMl( void ); -static U32 getReservoirDrainVolumeTargetMl( void ); +static U32 getReservoirDrainVolumeTargetMl( void ); +static BOOL processCalibrationData( void ); /*********************************************************************//** * @brief @@ -93,7 +94,14 @@ * @return none *************************************************************************/ void execReservoirs( void ) -{ +{ + // Check if a new calibration is available + if ( TRUE == isNewCalibrationRecordAvailable() ) + { + // Get the new calibration data and check its validity + processCalibrationData(); + } + // publish active reservoir, fill/drain volume targets at 1 Hz. if ( ++reservoirDataPublicationTimerCounter >= RESERVOIR_DATA_PUB_INTERVAL ) { @@ -103,6 +111,31 @@ broadcastReservoirData( actRes, filVol, drnVol ); reservoirDataPublicationTimerCounter = 0; } +} + +/*********************************************************************//** + * @brief + * The execDrainPumpSelfTest function executes the drain pump's self-test. + * @details Inputs: none + * @details Outputs: none + * @return PressuresSelfTestResult (SELF_TEST_STATUS_T) + *************************************************************************/ +SELF_TEST_STATUS_T execReservoirsSelfTest( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + + BOOL calStatus = processCalibrationData(); + + if ( TRUE == calStatus ) + { + result = SELF_TEST_STATUS_PASSED; + } + else + { + result = SELF_TEST_STATUS_FAILED; + } + + return result; } /*********************************************************************//** @@ -232,8 +265,7 @@ cmdResponse.rejectCode = DG_CMD_REQUEST_REJECT_REASON_NONE; // fill command only valid in re-circulate mode - if ( ( DG_MODE_CIRC == getCurrentOperationMode() ) && - ( DG_RECIRCULATE_MODE_STATE_RECIRC_WATER == getCurrentRecirculateState() ) ) + if ( ( DG_MODE_CIRC == getCurrentOperationMode() ) && ( DG_RECIRCULATE_MODE_STATE_RECIRC_WATER == getCurrentRecirculateState() ) ) { // validate parameters if ( fillToVolMl < MAX_FILL_VOLUME_ML ) @@ -416,6 +448,19 @@ /*********************************************************************//** * @brief + * The getReservoirsCalRecord function returns the reservoirs' calibration + * record. + * @details Inputs: reservoirsCalRecord + * @details Outputs: none + * @return reservoirs' calibration record + *************************************************************************/ +DG_RESERVOIR_VOLUME_RECORD_T getReservoirsCalRecord( void ) +{ + return reservoirsCalRecord; +} + +/*********************************************************************//** + * @brief * The hasTargetFillVolumeReached function checks if the target fill volume * for specific reservoir has been reached. * @details Inputs: fillVolumeTargetMl @@ -566,7 +611,47 @@ return result; } +/*********************************************************************//** + * @brief + * The processCalibrationData function gets the calibration data and makes + * sure it is valid by checking the calibration date. The calibration date + * should not be 0. + * @details Inputs: none + * @details Outputs: reservoirsCalRecord + * @return TRUE if the calibration record is valid, otherwise FALSE + *************************************************************************/ +static BOOL processCalibrationData( void ) +{ + BOOL status = TRUE; + U32 reservoir; + // Get the calibration record from NVDataMgmt + DG_RESERVOIR_VOLUME_RECORD_T calData = getDGReservoirsVolumeRecord(); + + for ( reservoir = 0; reservoir < NUM_OF_CAL_DATA_RSRVRS; reservoir++ ) + { +#ifndef SKIP_CAL_CHECK + // Check if the calibration data that was received from NVDataMgmt is legitimate + // The calibration date item should not be zero. If the calibration date is 0, + // then the data is not stored in the NV memory or it was corrupted. + if ( 0 == calData.reservoir[ reservoir ].calibrationTime ) + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_RESERVOIRS_INVALID_CAL_RECORD, (U32)reservoir ); + status = FALSE; + } +#endif + + // The calibration data was valid, update the local copy + reservoirsCalRecord.reservoir[ reservoir ].maxResidualFluid = calData.reservoir[ reservoir ].maxResidualFluid; + reservoirsCalRecord.reservoir[ reservoir ].normalFillVolume = calData.reservoir[ reservoir ].normalFillVolume; + reservoirsCalRecord.reservoir[ reservoir ].rsrvrUnfilledWeight = calData.reservoir[ reservoir ].rsrvrUnfilledWeight; + reservoirsCalRecord.reservoir[ reservoir ].rsrvrVolume = calData.reservoir[ reservoir ].rsrvrVolume; + } + + return status; +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/