Index: firmware/App/Services/Reservoirs.c =================================================================== diff -u -r3d131237935eb36e56e0d057a713430e31dc6405 -r6f1f269cd7d91f41c51797d17a85a7ea249e21f3 --- firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 3d131237935eb36e56e0d057a713430e31dc6405) +++ firmware/App/Services/Reservoirs.c (.../Reservoirs.c) (revision 6f1f269cd7d91f41c51797d17a85a7ea249e21f3) @@ -19,6 +19,7 @@ #include "LoadCell.h" #include "ModeRecirculate.h" +#include "NVDataMgmt.h" #include "OperationModes.h" #include "Reservoirs.h" #include "SystemCommMessages.h" @@ -63,13 +64,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 reservoirsNVRecord; ///< 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 +96,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 ) { @@ -131,9 +141,7 @@ activeReservoir.data = (U32)resID; cmdResponse.rejected = FALSE; setValveState( VRF, VALVE_STATE_R2_C_TO_NO ); -#ifndef V_2_SYSTEM - setValveState( VRD1, VALVE_STATE_OPEN ); -#else +#ifdef V_2_SYSTEM setValveState( VRD, VALVE_STATE_R2_C_TO_NO ); #endif setValveState( VRO, VALVE_STATE_R1_C_TO_NO ); @@ -143,10 +151,8 @@ case DG_RESERVOIR_2: activeReservoir.data = (U32)resID; cmdResponse.rejected = FALSE; - setValveState( VRF, VALVE_STATE_R1_C_TO_NC ); -#ifndef V_2_SYSTEM - setValveState( VRD2, VALVE_STATE_OPEN ); -#else + setValveState( VRF, VALVE_STATE_R1_C_TO_NC ); +#ifdef V_2_SYSTEM setValveState( VRD, VALVE_STATE_R1_C_TO_NC ); #endif setValveState( VRO, VALVE_STATE_R2_C_TO_NC ); @@ -566,7 +572,49 @@ 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: reservoirsNVRecord + * @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++ ) + { + // 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 flow sensors data is not stored in the NV memory or it was corrupted. + if ( 0 == calData.reservoir[ reservoir ].calibrationTime ) + { +#ifndef DISABLE_CAL_CHECK + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_DG_RESERVOIRS_INVALID_NV_RECORD, (U32)reservoir ); +#endif + status = FALSE; + } + else + { + // The calibration data was valid, update the local copy + reservoirsNVRecord.reservoir[ reservoir ].maxResidualFluid = calData.reservoir[ reservoir ].maxResidualFluid; + reservoirsNVRecord.reservoir[ reservoir ].normalFillVolume = calData.reservoir[ reservoir ].normalFillVolume; + reservoirsNVRecord.reservoir[ reservoir ].rsrvrUnfilledWeight = calData.reservoir[ reservoir ].rsrvrUnfilledWeight; + reservoirsNVRecord.reservoir[ reservoir ].rsrvrVolume = calData.reservoir[ reservoir ].rsrvrVolume; + } + } + + return status; +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/