/************************************************************************** * * Copyright (c) 2020-2023 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file ConcentratePumps.c * * @author (last) Dara Navaei * @date (last) 16-Aug-2023 * * @author (original) Quang Nguyen * @date (original) 22-Oct-2020 * ***************************************************************************/ #include #include "ConcentratePumps.h" #include "FPGA.h" #include "MessageSupport.h" #include "PersistentAlarm.h" #include "SystemCommMessages.h" #include "TaskGeneral.h" #include "Utilities.h" #include "OperationModes.h" /** * @addtogroup ConcentratePumps * @{ */ // ********** private definitions ********** #define CONCENTRATE_PUMP_ON_CONTROL 0x1A ///< Configuration to turn on concentrate pump with 16 microsteps. #define CONCENTRATE_PUMP_OFF_CONTROL 0x3A ///< Configuration to turn off concentrate pump. #define CONCENTRATE_PUMP_FORWARD_DIR 0x1 ///< Concentrate pump forward direction configuration. #define CONCENTRATE_PUMP_REVERSE_DIR 0x0 ///< Concentrate pump reverse direction configuration. #define CONCENTRATE_PUMP_SPEED_INCREMENT 2.0F ///< Speed increase (mL/min) when controlling concentrate pump to target step speed. #define CONCENTRATE_PUMP_MIN_SPEED 3.0F ///< Minimum speed for concentrate pump in mL per min. #define CONCENTRATE_PUMP_SPD_OUT_OF_RANGE_TOL_WHEN_ON_PCT 0.02F ///< Concentrate pump speed out of range tolerance when on in percentage. #define CONCENTRATE_PUMP_SPD_OUT_OF_RANGE_TOL_WHEN_SLOW_MLPM 1.0F ///< Concentrate pump speed out of range tolerance when slow in mL/min. #define CONCENTRATE_PUMP_LOW_SPEED_THRESHOLD_MLPM 10.0F ///< Concentrate pump low speed threshold in mL/min. #define CONCENTRATE_PUMP_ZERO_FLOW_RATE 0xFFFF ///< Pulse width value when zero flow rate or pump is off. #define CONCENTRATE_PUMP_VOLUME_PER_REV 0.1F ///< Volume output every revolution (mL). #define CONCENTRATE_PUMP_PULSE_PER_REV 2.0F ///< Number of pulses generate for every revolution. #define CONCENTRATE_PUMP_STEP_PER_REV 200.0F ///< Number of steps for every revolution. #define CONCENTRATE_PUMP_HALL_SENSE_PERIOD_RESOLUTION 100.0F ///< Hall sense period resolution in microseconds. #define CONCENTRATE_PUMP_MIN_ALLOWED_HALL_SENSOR_COUNT 1000 ///< Hall sensors minimum allowed value. #define CONCENTRATE_PUMP_HALL_SENSORS_OUT_OF_RANGE_TIME_MS ( 5 * MS_PER_SECOND ) ///< Hall sensors out of range time in milliseconds. #define CONCENTRATE_PUMP_MICRO_STEPS_PER_STEP 8.0F ///< Number of micro-steps ( fractions of step) per step. #define CONCENTRATE_PUMP_STEP_PERIOD_RESOLUTION ( 0.5F / ( US_PER_SECOND * SEC_PER_MIN ) ) ///< Convert step period resolution (0.5 us) to minute. /// Volume output per pulse. #define CONCENTRATE_PUMP_VOLUME_PER_PULSE ( CONCENTRATE_PUMP_VOLUME_PER_REV / CONCENTRATE_PUMP_PULSE_PER_REV ) #define CONCENTRATE_PUMP_DATA_PUBLISH_INTERVAL ( 1000 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the concentrate pump is monitored. #define CONCENTRATE_PUMP_CONTROL_INTERVAL ( 1 * MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the concentrate pump is controlled. #define CONCENTRATE_PUMP_SPEED_OUT_OF_RANGE_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Concentrate pumps speed out of range timeout in milliseconds. #define NUMBER_OF_ACID_AND_BICARB_NV_DATA_TO_CHECK 1 ///< Number of acid and bicarb non-volatile data to check. #define DATA_PUBLISH_COUNTER_START_COUNT 0 ///< Data publish counter start count. #define CONENTREATE_PUMP_PARK_FAULT_TIMEOUT_MS ( 1 * MS_PER_SECOND ) ///< Concentrate pump park fault timeout in milliseconds. #define CONCENTRATE_PUMP_FAULT_PERSISTENCE_PERIOD 500 ///< Concentrate pump fault persistence period in milliseconds. #define CONCENTRATE_PUMP_TRANS_TO_RAMP_SPEED_THRESHOLD_MLPM 5.0F ///< Concentrate pump transition to ramp to target speed threshold in mL/min. /*************************DVT Definitions********************************************/ #define CONCENTRATE_PUMP_CONTROL_EIGHTH_STEP 0x07 ///< Concentrate pump control 1/8th step. #define CONCENTRATE_PUMP_CONTROL_REVERSE_DIR 0x00 ///< Concentrate pump control reverse direction. #define CONCENTRATE_PUMP_CONTROL_FORWARD_DIR 0x08 ///< Concentrate pump control forward direction. #define CONCENTRATE_PUMP_CONTROL_ENABLE 0x00 ///< Concentrate pump control enable pump. #define CONCENTRATE_PUMP_CONTROL_DISABLE 0x01 ///< Concentrate pump control disable pump. #define CONCENTRATE_PUMP_CONTROL_NOT_RESET 0x20 ///< Concentrate pump control not reset. #define CONCENTRATE_PUMP_CONTROL_SLEEP_OFF 0x40 ///< Concentrate pump control sleep off. static const U32 CONCENTRATE_PUMP_CONTROL_FORWARD = CONCENTRATE_PUMP_CONTROL_SLEEP_OFF | CONCENTRATE_PUMP_CONTROL_NOT_RESET | CONCENTRATE_PUMP_CONTROL_ENABLE | CONCENTRATE_PUMP_CONTROL_FORWARD_DIR | CONCENTRATE_PUMP_CONTROL_EIGHTH_STEP; ///< Concentrate pump control forward. static const U32 CONCENTRATE_PUMP_CONTROL_REVERSE = CONCENTRATE_PUMP_CONTROL_SLEEP_OFF | CONCENTRATE_PUMP_CONTROL_NOT_RESET | CONCENTRATE_PUMP_CONTROL_ENABLE | CONCENTRATE_PUMP_CONTROL_REVERSE_DIR | CONCENTRATE_PUMP_CONTROL_EIGHTH_STEP; ///< Concentrate pump control reverse. /*************************DVT Definitions********************************************/ /// Enumeration of concentrate pump states. typedef enum ConcentratePumpState { CONCENTRATE_PUMP_OFF_STATE = 0, ///< Concentrate pump off state. CONCENTRATE_PUMP_RAMP_TO_TARGET_SPEED_STATE, ///< Concentrate pump ramp to target state. CONCENTRATE_PUMP_CONTROL_TARGET_SPEED_STATE, ///< Concentrate pump on state. NUM_OF_CONCENTRATE_PUMP_STATES ///< Number of concentrate pump states. } CONCENTRATE_PUMP_STATE_T; /// Concentrate pump data structure typedef struct { U32 controlTimerCounter; ///< Timer counter to perform control on concentrate pump. CONCENTRATE_PUMP_STATE_T execState; ///< Concentrate pump execute current state. BOOL hasTurnOnPumpsBeenRequested; ///< Flag indicates a request to turn concentrate pumps on. BOOL hasParkBeenRequested; ///< Flag indicates a request to park the pump. F32 pumpTargetSpeed; ///< Target concentrate pumps' speed (mL/min). F32 currentPumpSpeed; ///< Current controlled concentrate pumps' speed (mL/min). OVERRIDE_F32_T measuredPumpSpeed; ///< Measured concentrate pump speed (mL/min). U16 togglePeriodCount; ///< Converted pump speed (mL/min) to toggle period counts (0.5 uS increment counts per step). U08 direction; ///< Concentrate pump motor direction. U08 controlSet; ///< Concentrate pump control set. (Used in DVT) F32 pulseWidthUS; ///< Concentrate pump pulse width in microseconds. OVERRIDE_U32_T parked; ///< Concentrate pump is currently parked (T/F). OVERRIDE_U32_T parkFaulted; ///< Concentrate pump park command has faulted (T/F). } CONCENTRATE_PUMP_T; // ********** private data ********** static U32 concentratePumpMonitorTimerCounter; ///< Timer counter to perform monitor on concentrate pump. static BOOL acidConcentratePumpParkPersistenceClear; ///< Boolean acid park persistence clearing. static BOOL bicarbConcentratePumpParkPersistenceClear; ///< Boolean for bicard park persistence clearing. /// Concentrate pump data publish interval. static OVERRIDE_U32_T concentratePumpDataPublishInterval = { CONCENTRATE_PUMP_DATA_PUBLISH_INTERVAL, CONCENTRATE_PUMP_DATA_PUBLISH_INTERVAL, 0, 0 }; static CONCENTRATE_PUMP_T concentratePumps[ NUM_OF_CONCENTRATE_PUMPS ]; ///< Array of concentrate pumps' data structure. static DG_ACID_CONCENTRATES_RECORD_T acidConcentrateCalRecord; ///< Acid concentrate calibration record. static DG_BICARB_CONCENTRATES_RECORD_T bicarbConcentrateCalRecord; ///< Bicarb concentrate calibration record. static DG_CONC_PUMPS_CAL_RECORD_T concentratePumpsCalRecord; ///< Concentrate pumps calibration record. // ********** private function prototypes ********** static void stopConcentratePump( CONCENTRATE_PUMPS_T pumpId ); static CONCENTRATE_PUMP_STATE_T handleConcentratePumpOffState( CONCENTRATE_PUMPS_T pumpId ); static CONCENTRATE_PUMP_STATE_T handleConcentratePumpRampToTargetSpeedState( CONCENTRATE_PUMPS_T pumpId ); static CONCENTRATE_PUMP_STATE_T handleConcentratePumpControlTargetSpeedState( CONCENTRATE_PUMPS_T pumpId ); static BOOL stepConcentratePumpToTargetSpeed( CONCENTRATE_PUMPS_T pumpId ); static void calcMeasuredPumpsSpeed( void ); static void monitorPumpSpeed( CONCENTRATE_PUMPS_T pumpId, ALARM_ID_T alarm ); static void checkConcentratePumpControlSet( CONCENTRATE_PUMPS_T pumpId ); /*********************************************************************//** * @brief * The initConcentratePump function initializes the ConcentratePumps module. * @details Inputs: none * @details Outputs: ConcentratePumps module initialized * @return none *************************************************************************/ void initConcentratePump( void ) { CONCENTRATE_PUMPS_T pumpId; concentratePumpMonitorTimerCounter = DATA_PUBLISH_COUNTER_START_COUNT; acidConcentratePumpParkPersistenceClear = FALSE; ///< Boolean acid park persistence clearing. bicarbConcentratePumpParkPersistenceClear = FALSE; for ( pumpId = CONCENTRATEPUMPS_CP1_ACID; pumpId < NUM_OF_CONCENTRATE_PUMPS; pumpId++ ) { concentratePumps[ pumpId ].controlTimerCounter = 0; concentratePumps[ pumpId ].execState = CONCENTRATE_PUMP_OFF_STATE; concentratePumps[ pumpId ].measuredPumpSpeed.data = 0.0F; concentratePumps[ pumpId ].hasTurnOnPumpsBeenRequested = FALSE; concentratePumps[ pumpId ].hasParkBeenRequested = FALSE; concentratePumps[ pumpId ].parked.data = FALSE; concentratePumps[ pumpId ].parkFaulted.data = FALSE; concentratePumps[ pumpId ].pumpTargetSpeed = 0.0F; concentratePumps[ pumpId ].direction = CONCENTRATE_PUMP_FORWARD_DIR; // For V3 concentratePumps[ pumpId ].controlSet = CONCENTRATE_PUMP_CONTROL_FORWARD; // For DVT stopConcentratePump( pumpId ); } initPersistentAlarm( ALARM_ID_DG_CP1_SPEED_CONTROL_ERROR, 0, CONCENTRATE_PUMP_SPEED_OUT_OF_RANGE_TIMEOUT_MS ); initPersistentAlarm( ALARM_ID_DG_CP2_SPEED_CONTROL_ERROR, 0, CONCENTRATE_PUMP_SPEED_OUT_OF_RANGE_TIMEOUT_MS ); initPersistentAlarm( ALARM_ID_DG_CONC_PUMP_HALL_SENSOR_OUT_OF_RANGE, CONCENTRATE_PUMP_HALL_SENSORS_OUT_OF_RANGE_TIME_MS, CONCENTRATE_PUMP_HALL_SENSORS_OUT_OF_RANGE_TIME_MS ); initPersistentAlarm( ALARM_ID_DG_ACID_CONCENTRATE_PUMP_PARK_FAULT, CONENTREATE_PUMP_PARK_FAULT_TIMEOUT_MS, CONENTREATE_PUMP_PARK_FAULT_TIMEOUT_MS ); initPersistentAlarm( ALARM_ID_DG_BICARB_CONCENTRATE_PUMP_PARK_FAULT, CONENTREATE_PUMP_PARK_FAULT_TIMEOUT_MS, CONENTREATE_PUMP_PARK_FAULT_TIMEOUT_MS ); initPersistentAlarm( ALARM_ID_DG_CONCENTRATE_PUMP_FAULT, CONCENTRATE_PUMP_FAULT_PERSISTENCE_PERIOD, CONCENTRATE_PUMP_FAULT_PERSISTENCE_PERIOD ); } /*********************************************************************//** * @brief * The execConcentratePumpMonitor function executes the concentrate pump monitor. * @details Inputs: none * @details Outputs: publish concentrate pump data * @return none *************************************************************************/ void execConcentratePumpMonitor( void ) { U08 fpgaConcPumpsFault = getFPGAConcentratePumpsFault(); BOOL isConcPumpFault = ( fpgaConcPumpsFault > 0 ? TRUE : FALSE ); // Check if a new calibration is available if ( TRUE == isNewCalibrationRecordAvailable() ) { // Get the calibration values of acid and bicarb getNVRecord2Driver( GET_CAL_ACID_CONCENTREATES, (U08*)&acidConcentrateCalRecord, sizeof( acidConcentrateCalRecord ), NUMBER_OF_ACID_AND_BICARB_NV_DATA_TO_CHECK, ALARM_ID_DG_ACID_CONCENTRATE_INVALID_CAL_RECORD ); getNVRecord2Driver( GET_CAL_BICARB_CONCENTRATES, (U08*)&bicarbConcentrateCalRecord, sizeof( bicarbConcentrateCalRecord ), NUMBER_OF_ACID_AND_BICARB_NV_DATA_TO_CHECK, ALARM_ID_DG_BICARB_CONCENTRATE_INVALID_CAL_RECORD ); } // Calculate pump speed for each defined pump calcMeasuredPumpsSpeed(); concentratePumps[ CONCENTRATEPUMPS_CP1_ACID ].parked.data = (U32)getFPGAAcidPumpIsParked(); concentratePumps[ CONCENTRATEPUMPS_CP2_BICARB ].parked.data = (U32)getFPGABicarbPumpIsParked(); concentratePumps[ CONCENTRATEPUMPS_CP1_ACID ].parkFaulted.data = (U32)getFPGAAcidPumpParkFault(); concentratePumps[ CONCENTRATEPUMPS_CP2_BICARB ].parkFaulted.data = (U32)getFPGABicarbPumpParkFault(); // Don't monitor persistence for cp speed alarms if we parked. if ( TRUE == acidConcentratePumpParkPersistenceClear ) { // Clear flag and resume persistence checking once park bit is set. if ( TRUE == getConcPumpIsParked( CONCENTRATEPUMPS_CP1_ACID ) ) { acidConcentratePumpParkPersistenceClear = FALSE; } else { resetPersistentAlarmTimer( ALARM_ID_DG_CP1_SPEED_CONTROL_ERROR ); } } if ( TRUE == bicarbConcentratePumpParkPersistenceClear ) { // Clear flag and resume persistence checking once park bit is set. if ( TRUE == getConcPumpIsParked( CONCENTRATEPUMPS_CP2_BICARB ) ) { bicarbConcentratePumpParkPersistenceClear = FALSE; } else { resetPersistentAlarmTimer( ALARM_ID_DG_CP2_SPEED_CONTROL_ERROR ); } } #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_CONC_PUMPS_SPEED_ALARM ) != SW_CONFIG_ENABLE_VALUE ) #endif { monitorPumpSpeed( CONCENTRATEPUMPS_CP1_ACID, ALARM_ID_DG_CP1_SPEED_CONTROL_ERROR ); monitorPumpSpeed( CONCENTRATEPUMPS_CP2_BICARB, ALARM_ID_DG_CP2_SPEED_CONTROL_ERROR ); } #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_CONCENTRATE_PUMPS_PARK ) != SW_CONFIG_ENABLE_VALUE ) #endif { BOOL isAcidPumpParked = getConcPumpParkIsFaulted( CONCENTRATEPUMPS_CP1_ACID ); BOOL isBicarbPumpParked = getConcPumpParkIsFaulted( CONCENTRATEPUMPS_CP2_BICARB ); checkPersistentAlarm( ALARM_ID_DG_ACID_CONCENTRATE_PUMP_PARK_FAULT, isAcidPumpParked, isAcidPumpParked, CONENTREATE_PUMP_PARK_FAULT_TIMEOUT_MS ); checkPersistentAlarm( ALARM_ID_DG_BICARB_CONCENTRATE_PUMP_PARK_FAULT, isBicarbPumpParked, isBicarbPumpParked, CONENTREATE_PUMP_PARK_FAULT_TIMEOUT_MS ); } checkPersistentAlarm( ALARM_ID_DG_CONCENTRATE_PUMP_FAULT, isConcPumpFault, fpgaConcPumpsFault, CONCENTRATE_PUMP_FAULT_PERSISTENCE_PERIOD ); if ( ++concentratePumpMonitorTimerCounter >= getU32OverrideValue( &concentratePumpDataPublishInterval ) ) { CONCENTRATE_PUMP_DATA_T data; U08 cp1Direction = concentratePumps[ CONCENTRATEPUMPS_CP1_ACID ].direction; F32 cp1SetSpeed = concentratePumps[ CONCENTRATEPUMPS_CP1_ACID ].currentPumpSpeed; F32 cp1TgtSpeed = concentratePumps[ CONCENTRATEPUMPS_CP1_ACID ].pumpTargetSpeed; BOOL cp1Parked = getConcPumpIsParked( CONCENTRATEPUMPS_CP1_ACID ); BOOL cp2ParkFault = getConcPumpParkIsFaulted( CONCENTRATEPUMPS_CP1_ACID ); U08 cp2Direction = concentratePumps[ CONCENTRATEPUMPS_CP2_BICARB ].direction; F32 cp2SetSpeed = concentratePumps[ CONCENTRATEPUMPS_CP2_BICARB ].currentPumpSpeed; F32 cp2TgtSpeed = concentratePumps[ CONCENTRATEPUMPS_CP2_BICARB ].pumpTargetSpeed; // Use the above values to prepare the broadcast data data.cp1CurrentSetSpeed = ( CONCENTRATE_PUMP_REVERSE_DIR == cp1Direction ? cp1SetSpeed * -1.0F : cp1SetSpeed ); data.cp1MeasuredSpeed = getMeasuredPumpSpeedMLPM( CONCENTRATEPUMPS_CP1_ACID ); data.cp1TargetSpeed = ( CONCENTRATE_PUMP_REVERSE_DIR == cp1Direction ? cp1TgtSpeed * -1.0F : cp1TgtSpeed ); data.cp2CurrentSetSpeed = ( CONCENTRATE_PUMP_REVERSE_DIR == cp2Direction ? cp2SetSpeed * -1.0F : cp2SetSpeed ); data.cp2MeasuredSpeed = getMeasuredPumpSpeedMLPM( CONCENTRATEPUMPS_CP2_BICARB ); data.cp2TargetSpeed = ( CONCENTRATE_PUMP_REVERSE_DIR == cp2Direction ? cp2TgtSpeed * -1.0F : cp2TgtSpeed ); data.cp1State = concentratePumps[ CONCENTRATEPUMPS_CP1_ACID ].execState; data.cp2State = concentratePumps[ CONCENTRATEPUMPS_CP2_BICARB ].execState; data.cp1PulseUS = concentratePumps[ CONCENTRATEPUMPS_CP1_ACID ].pulseWidthUS; data.cp2PulseUS = concentratePumps[ CONCENTRATEPUMPS_CP2_BICARB ].pulseWidthUS; data.cp1Parked = getConcPumpIsParked( CONCENTRATEPUMPS_CP1_ACID ); data.cp2Parked = getConcPumpIsParked( CONCENTRATEPUMPS_CP2_BICARB ); data.cp1ParkFault = getConcPumpParkIsFaulted( CONCENTRATEPUMPS_CP1_ACID ); data.cp2ParkFault = getConcPumpParkIsFaulted( CONCENTRATEPUMPS_CP2_BICARB ); concentratePumpMonitorTimerCounter = 0; broadcastData( MSG_ID_DG_CONCENTRATE_PUMP_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&data, sizeof( CONCENTRATE_PUMP_DATA_T ) ); } } /*********************************************************************//** * @brief * The execConcentratePumpController function executes the concentrate pump controller. * @details Inputs: execState * @details Outputs: execState * @return none *************************************************************************/ void execConcentratePumpController( void ) { CONCENTRATE_PUMPS_T pumpId; for ( pumpId = CONCENTRATEPUMPS_CP1_ACID; pumpId < NUM_OF_CONCENTRATE_PUMPS; pumpId++ ) { switch ( concentratePumps[ pumpId ].execState ) { case CONCENTRATE_PUMP_OFF_STATE: concentratePumps[ pumpId ].execState = handleConcentratePumpOffState( pumpId ); break; case CONCENTRATE_PUMP_RAMP_TO_TARGET_SPEED_STATE: concentratePumps[ pumpId ].execState = handleConcentratePumpRampToTargetSpeedState( pumpId ); break; case CONCENTRATE_PUMP_CONTROL_TARGET_SPEED_STATE: concentratePumps[ pumpId ].execState = handleConcentratePumpControlTargetSpeedState( pumpId ); break; #ifndef _VECTORCAST_ // The switch case is in a for loop so the default case cannot be covered in VectorCAST default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_CONCENTRATE_PUMP_EXEC_INVALID_STATE, pumpId ) concentratePumps[ pumpId ].execState = CONCENTRATE_PUMP_OFF_STATE; break; #endif } } } /*********************************************************************//** * @brief * The execConcenratePumpsSelfTest function executes the concentrate pumps * self-test. * @details Inputs: none * @details Outputs: none * @return PressuresSelfTestResult (SELF_TEST_STATUS_T) *************************************************************************/ SELF_TEST_STATUS_T execConcenratePumpsSelfTest( void ) { SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; BOOL calStatus = FALSE; calStatus |= getNVRecord2Driver( GET_CAL_ACID_CONCENTREATES, (U08*)&acidConcentrateCalRecord, sizeof( DG_ACID_CONCENTRATES_RECORD_T ), NUMBER_OF_ACID_AND_BICARB_NV_DATA_TO_CHECK, ALARM_ID_DG_ACID_CONCENTRATE_INVALID_CAL_RECORD ); calStatus |= getNVRecord2Driver( GET_CAL_BICARB_CONCENTRATES, (U08*)&bicarbConcentrateCalRecord, sizeof( DG_BICARB_CONCENTRATES_RECORD_T ), NUMBER_OF_ACID_AND_BICARB_NV_DATA_TO_CHECK, ALARM_ID_DG_BICARB_CONCENTRATE_INVALID_CAL_RECORD ); calStatus |= getNVRecord2Driver( GET_CAL_CONCENTRATE_PUMPS_RECORD, (U08*)&concentratePumpsCalRecord, sizeof( DG_CONC_PUMPS_CAL_RECORD_T ), NUM_OF_CAL_DATA_DG_CONC_PUMPS, ALARM_ID_NO_ALARM ); result = ( TRUE == calStatus ? SELF_TEST_STATUS_PASSED : SELF_TEST_STATUS_FAILED ); return result; } /*********************************************************************//** * @brief * The requestConcentratePumpOn function requests the module to turn on * the concentrate pumps. * @details Inputs: none * @details Outputs: set flag isPumpOnRequested to TRUE * @param pumpId concentrate pump id * @return none *************************************************************************/ void requestConcentratePumpOn( CONCENTRATE_PUMPS_T pumpId ) { if ( pumpId < NUM_OF_CONCENTRATE_PUMPS ) { #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_CONC_PUMPS ) != SW_CONFIG_ENABLE_VALUE ) #endif { concentratePumps[ pumpId ].hasTurnOnPumpsBeenRequested = TRUE; } } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_CONCENTRATE_PUMP_INVALID_PUMP_ID, pumpId ); } } /*********************************************************************//** * @brief * The handleConcentratePumpParkRequest function accepts/rejects the park * concentrate pumps request. * @details Inputs: Pump state and DG operating mode * @details Outputs: command response set to true if able to perform parking pump. * @return result as true if park is accomplished. *************************************************************************/ BOOL handleConcentratePumpParkRequest( void ) { CONCENTRATE_PUMPS_T pumpId; DG_CMD_RESPONSE_T cmdResponse; BOOL result = FALSE; DG_OP_MODE_T opMode = getCurrentOperationMode(); cmdResponse.commandID = DG_CMD_PARK_CONCENTRATE_PUMPS; cmdResponse.rejected = FALSE; cmdResponse.rejectCode = DG_CMD_REQUEST_REJECT_REASON_NONE; for ( pumpId = CONCENTRATEPUMPS_CP1_ACID; pumpId < NUM_OF_CONCENTRATE_PUMPS; pumpId++ ) { // check if pump is not ON and DG mode is not in filling or fault mode, then park the concentrate pumps if ( ( concentratePumps[ pumpId ].execState == CONCENTRATE_PUMP_OFF_STATE ) && ( ( DG_MODE_FILL != opMode ) || ( DG_MODE_FAUL != opMode ) ) ) { // Park concentrate pump requestConcentratePumpOff( pumpId, PARK_CONC_PUMPS ); result |= TRUE; } else { cmdResponse.rejected = TRUE; cmdResponse.rejectCode = DG_CMD_REQUEST_REJECT_REASON_INVALID_MODE; result |= FALSE; } } sendCommandResponseMsg( &cmdResponse ); return result; } /*********************************************************************//** * @brief * The requestConcentratePumpOff function requests the module to turn off * the concentrate pumps. * @details Inputs: none * @details Outputs: set flag isPumpOffRequested to TRUE * @param pumpId concentrate pump id * @param park TRUE if pump should be parked, FALSE if not * @return none *************************************************************************/ void requestConcentratePumpOff( CONCENTRATE_PUMPS_T pumpId, BOOL park ) { if ( pumpId < NUM_OF_CONCENTRATE_PUMPS ) { concentratePumps[ pumpId ].hasTurnOnPumpsBeenRequested = FALSE; concentratePumps[ pumpId ].hasParkBeenRequested = park; concentratePumps[ pumpId ].pumpTargetSpeed = 0.0F; } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_CONCENTRATE_PUMP_INVALID_PUMP_ID, pumpId ); } } /*********************************************************************//** * @brief * The setConcentratePumpTargetSpeed function sets the target step speed based on * given speed in mL/min to specified concentrate pump. * @details Inputs: none * @details Outputs: set target step speed for given pump * @param pumpId pump id to set step speed * @param targetSpeed_ml_min target speed in mL/min * @return none *************************************************************************/ void setConcentratePumpTargetSpeed( CONCENTRATE_PUMPS_T pumpId, F32 targetSpeed_ml_min ) { if ( pumpId < NUM_OF_CONCENTRATE_PUMPS ) { if ( targetSpeed_ml_min >= 0.0 ) { concentratePumps[ pumpId ].direction = CONCENTRATE_PUMP_FORWARD_DIR; // For V3 concentratePumps[ pumpId ].controlSet = CONCENTRATE_PUMP_CONTROL_FORWARD; // For DVT } else { concentratePumps[ pumpId ].direction = CONCENTRATE_PUMP_REVERSE_DIR; // For V3 concentratePumps[ pumpId ].controlSet = CONCENTRATE_PUMP_CONTROL_REVERSE; // For DVT targetSpeed_ml_min *= -1.0; } if ( ( CONCENTRATE_PUMP_MIN_SPEED <= targetSpeed_ml_min ) && ( targetSpeed_ml_min <= CONCENTRATE_PUMP_MAX_SPEED ) ) { concentratePumps[ pumpId ].pumpTargetSpeed = targetSpeed_ml_min; } else if ( targetSpeed_ml_min < CONCENTRATE_PUMP_MIN_SPEED ) { concentratePumps[ pumpId ].pumpTargetSpeed = 0.0; } else if ( targetSpeed_ml_min > CONCENTRATE_PUMP_MAX_SPEED ) { concentratePumps[ pumpId ].pumpTargetSpeed = CONCENTRATE_PUMP_MAX_SPEED; } } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_CONCENTRATE_PUMP_INVALID_PUMP_ID, pumpId ); } } /*********************************************************************//** * @brief * The getConcentratePumpTargetFlowMLPM function returns the concentrate pump's * flow rate in mL/min. * @details Inputs: concentratePumps * @details Outputs: none * @param pumpId concentrate pump id to get its target flow * @return the current concentrate pump flow rate (in mL/min). *************************************************************************/ F32 getConcentratePumpTargetFlowMLPM( CONCENTRATE_PUMPS_T pumpId ) { F32 flow = 0.0; if ( pumpId < NUM_OF_CONCENTRATE_PUMPS ) { flow = concentratePumps[ pumpId ].pumpTargetSpeed; } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_CONCENTRATE_PUMP_INVALID_PUMP_ID, pumpId ); } return flow; } /*********************************************************************//** * @brief * The getMeasuredPumpSpeedMLPM function gets the measured concentrate pump flow rate. * @details Inputs: measuredPumpSpeed * @details Outputs: none * @param pumpId concentrate pump id to increase current step speed * @return the current concentrate pump flow rate (in mL/min). *************************************************************************/ F32 getMeasuredPumpSpeedMLPM( CONCENTRATE_PUMPS_T pumpId ) { F32 speed = 0.0F; if ( pumpId < NUM_OF_CONCENTRATE_PUMPS ) { speed = getF32OverrideValue( &concentratePumps[ pumpId ].measuredPumpSpeed ); speed = ( CONCENTRATE_PUMP_REVERSE_DIR == concentratePumps[ pumpId ].direction ? speed * -1.0F : speed ); } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_CONCENTRATE_PUMP_INVALID_PUMP_ID, pumpId ); } return speed; } /*********************************************************************//** * @brief * The getConcPumpIsParked function gets the current parked state for a * given pump. * @details Inputs: parked * @details Outputs: none * @param pumpId concentrate pump id to get parked state for * @return the current concentrate pump parked state. *************************************************************************/ BOOL getConcPumpIsParked( CONCENTRATE_PUMPS_T pumpId ) { BOOL result = FALSE; if ( pumpId < NUM_OF_CONCENTRATE_PUMPS ) { result = (BOOL)getU32OverrideValue( &concentratePumps[ pumpId ].parked ); } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_CONCENTRATE_PUMP_INVALID_PUMP_ID, pumpId ); } return result; } /*********************************************************************//** * @brief * The getConcPumpParkIsFaulted function gets the current park command * fault state for a given pump. * @details Inputs: parkFaulted * @details Outputs: none * @param pumpId concentrate pump id to get park faulted state for * @return the current concentrate pump park faulted state. *************************************************************************/ BOOL getConcPumpParkIsFaulted( CONCENTRATE_PUMPS_T pumpId ) { BOOL result = FALSE; if ( pumpId < NUM_OF_CONCENTRATE_PUMPS ) { result = (BOOL)getU32OverrideValue( &concentratePumps[ pumpId ].parkFaulted ); } else { SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_CONCENTRATE_PUMP_INVALID_PUMP_ID, pumpId ); } return result; } /*********************************************************************//** * @brief * The stopConcentratePump function sets the concentrate pump step speed * to zero and turns off concentrate pump. Also parks the pump if requested. * @details Inputs: none * @details Outputs: concentratePumps * @param pumpId concentrate pump id * @return none *************************************************************************/ static void stopConcentratePump( CONCENTRATE_PUMPS_T pumpId ) { BOOL parkPump = concentratePumps[ pumpId ].hasParkBeenRequested; concentratePumps[ pumpId ].hasParkBeenRequested = FALSE; // reset park request for next time concentratePumps[ pumpId ].currentPumpSpeed = 0.0F; // set target rate to zero #ifndef _RELEASE_ // Beta units require a stop command in addition to the zero rate if ( HW_CONFIG_BETA == getHardwareConfigStatus() ) { if ( CONCENTRATEPUMPS_CP1_ACID == pumpId ) { setFPGAV3AcidPumpControl( CONCENTRATE_PUMP_OFF_CONTROL ); } else { setFPGAV3BicarbPumpControl( CONCENTRATE_PUMP_OFF_CONTROL ); } } #endif // Send zero rate command to stop the pump if ( CONCENTRATEPUMPS_CP1_ACID == pumpId ) { setFPGAAcidPumpSetStepSpeed( CONCENTRATE_PUMP_ZERO_FLOW_RATE ); } else { setFPGABicarbSetStepSpeed( CONCENTRATE_PUMP_ZERO_FLOW_RATE ); } // Park concentrate pump too if requested #ifndef _RELEASE_ if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_CONCENTRATE_PUMPS_PARK ) != SW_CONFIG_ENABLE_VALUE ) { if ( HW_CONFIG_BETA == getHardwareConfigStatus() ) { if ( TRUE == parkPump ) { if ( CONCENTRATEPUMPS_CP1_ACID == pumpId ) { setFPGAV3AcidPumpParkCmd(); acidConcentratePumpParkPersistenceClear = TRUE; } else { setFPGAV3BicarbPumpParkCmd(); bicarbConcentratePumpParkPersistenceClear = TRUE; } } } else #endif { if ( TRUE == parkPump ) { if ( CONCENTRATEPUMPS_CP1_ACID == pumpId ) { setFPGAAcidPumpParkCmd(); acidConcentratePumpParkPersistenceClear = TRUE; } else { setFPGABicarbPumpParkCmd(); bicarbConcentratePumpParkPersistenceClear = TRUE; } } } #ifndef _RELEASE_ } #endif } /*********************************************************************//** * @brief * The handleConcentratePumpOffState function turns on concentrate pumps and * switch to on state upon request. * @details Inputs: none * @details Outputs: concentrate pumps turn on * @param pumpId concentrate pump id * @return state *************************************************************************/ static CONCENTRATE_PUMP_STATE_T handleConcentratePumpOffState( CONCENTRATE_PUMPS_T pumpId ) { CONCENTRATE_PUMP_STATE_T state = CONCENTRATE_PUMP_OFF_STATE; if ( TRUE == concentratePumps[ pumpId ].hasTurnOnPumpsBeenRequested ) { U08 controlSet = 0; #ifndef _RELEASE_ if ( HW_CONFIG_BETA == getHardwareConfigStatus() ) { controlSet = ( CONCENTRATE_PUMP_ON_CONTROL | concentratePumps[ pumpId ].direction ); if ( CONCENTRATEPUMPS_CP1_ACID == pumpId ) { setFPGAV3AcidPumpControl( controlSet ); } else { setFPGAV3BicarbPumpControl( controlSet ); } } else #endif { controlSet = concentratePumps[ pumpId ].controlSet; if ( CONCENTRATEPUMPS_CP1_ACID == pumpId ) { setFPGAAcidPumpControl( controlSet ); } else { setFPGABicarbPumpControl( controlSet ); } } state = CONCENTRATE_PUMP_RAMP_TO_TARGET_SPEED_STATE; } // In case we are in a mode that the concentrate pumps are off but they still need to be parked, then the stop function // is called to park the pumps if ( TRUE == concentratePumps[ pumpId ].hasParkBeenRequested ) { stopConcentratePump( pumpId ); } return state; } /*********************************************************************//** * @brief * The handleConcentratePumpRampToTargetSpeedState function executes the * concentrate pump ramp up to target speed state. Once the speed is close * to target the state is transitioned to control target state. * @details Inputs: none * @details Outputs: none * @param pumpId concentrate pump id * @return next state of the state machine *************************************************************************/ static CONCENTRATE_PUMP_STATE_T handleConcentratePumpRampToTargetSpeedState( CONCENTRATE_PUMPS_T pumpId ) { CONCENTRATE_PUMP_STATE_T state = CONCENTRATE_PUMP_RAMP_TO_TARGET_SPEED_STATE; if ( TRUE == stepConcentratePumpToTargetSpeed( pumpId ) ) { state = CONCENTRATE_PUMP_CONTROL_TARGET_SPEED_STATE; } if ( FALSE == concentratePumps[ pumpId ].hasTurnOnPumpsBeenRequested ) { state = CONCENTRATE_PUMP_OFF_STATE; stopConcentratePump( pumpId ); } return state; } /*********************************************************************//** * @brief * The handleConcentratePumpControlTargetSpeedState function turns off concentrate * pumps switch to off state upon request. While in on state, the function * controls concentrate pumps to a target step speed. * @details Inputs: currentPumpSpeed[] * @details Outputs: control concentrate pumps to target step speed * @param pumpId concentrate pump id * @return state *************************************************************************/ static CONCENTRATE_PUMP_STATE_T handleConcentratePumpControlTargetSpeedState( CONCENTRATE_PUMPS_T pumpId ) { CONCENTRATE_PUMP_STATE_T state = CONCENTRATE_PUMP_CONTROL_TARGET_SPEED_STATE; F32 targetToCurreSpeedDiffMLPM = fabs( concentratePumps[ pumpId ].pumpTargetSpeed - concentratePumps[ pumpId ].currentPumpSpeed ); if ( ++concentratePumps[ pumpId ].controlTimerCounter >= CONCENTRATE_PUMP_CONTROL_INTERVAL ) { concentratePumps[ pumpId ].controlTimerCounter = 0; stepConcentratePumpToTargetSpeed( pumpId ); } if ( targetToCurreSpeedDiffMLPM >= CONCENTRATE_PUMP_TRANS_TO_RAMP_SPEED_THRESHOLD_MLPM ) { // If the requested target speed is greater than the threshold, transition back to ramp state regardless of the status of the // control interval stepConcentratePumpToTargetSpeed( pumpId ); state = CONCENTRATE_PUMP_RAMP_TO_TARGET_SPEED_STATE; } if ( FALSE == concentratePumps[ pumpId ].hasTurnOnPumpsBeenRequested ) { state = CONCENTRATE_PUMP_OFF_STATE; stopConcentratePump( pumpId ); } return state; } /*********************************************************************//** * @brief * The stepConcentratePumpToTargetSpeed function steps current step speed * toward target speed with predefined step increase. * @details Inputs: none * @details Outputs: currentPumpSpeed[] * @param pumpId concentrate pump id to increase current step speed * @return TRUE if the pump has reached to target otherwise, FALSE *************************************************************************/ static BOOL stepConcentratePumpToTargetSpeed( CONCENTRATE_PUMPS_T pumpId ) { F32 speedIncrease; BOOL hasTgtBeenReached = FALSE; F32 currentToTargetDiff = fabs( concentratePumps[ pumpId ].pumpTargetSpeed - concentratePumps[ pumpId ].currentPumpSpeed ); if ( currentToTargetDiff > NEARLY_ZERO ) { if ( currentToTargetDiff > CONCENTRATE_PUMP_SPEED_INCREMENT ) { speedIncrease = CONCENTRATE_PUMP_SPEED_INCREMENT; } else { speedIncrease = currentToTargetDiff; hasTgtBeenReached = TRUE; } // Subtract current speed when target speed is smaller if ( concentratePumps[ pumpId ].pumpTargetSpeed < concentratePumps[ pumpId ].currentPumpSpeed ) { speedIncrease *= -1.0F; } concentratePumps[ pumpId ].currentPumpSpeed += speedIncrease; // If the pump's target speed is set to be 0, do not ramp down set it to zero immediately if ( fabs( concentratePumps[ pumpId ].pumpTargetSpeed < NEARLY_ZERO ) ) { concentratePumps[ pumpId ].currentPumpSpeed = 0.0F; } } if ( concentratePumps[ pumpId ].currentPumpSpeed > NEARLY_ZERO ) { F32 timePerStep = CONCENTRATE_PUMP_VOLUME_PER_REV / ( concentratePumps[ pumpId ].currentPumpSpeed * CONCENTRATE_PUMP_STEP_PER_REV ); F32 stepPeriodCounts = timePerStep / ( CONCENTRATE_PUMP_STEP_PERIOD_RESOLUTION * CONCENTRATE_PUMP_MICRO_STEPS_PER_STEP ); concentratePumps[ pumpId ].togglePeriodCount = (U16)( stepPeriodCounts + FLOAT_TO_INT_ROUNDUP_OFFSET ); } else { concentratePumps[ pumpId ].togglePeriodCount = CONCENTRATE_PUMP_ZERO_FLOW_RATE; } // Check if the control set bit is set as desired and if not, correct it checkConcentratePumpControlSet( pumpId ); if ( CONCENTRATEPUMPS_CP1_ACID == pumpId ) { setFPGAAcidPumpSetStepSpeed( concentratePumps[ pumpId ].togglePeriodCount ); } else { setFPGABicarbSetStepSpeed( concentratePumps[ pumpId ].togglePeriodCount ); } return hasTgtBeenReached; } /*********************************************************************//** * @brief * The calcMeasuredPumpsSpeed function iterates through the concentrate * pumps and calculates the concentrate pump flow. It also checks that * the hall sensor pulse width count for the concentrate pump is valid. * @details Inputs: none * @details Outputs: measuredPumpSpeed * @return none *************************************************************************/ static void calcMeasuredPumpsSpeed( void ) { U16 pulseWidthCount = 0; F32 pulseWidthInMicroSeconds = 0.0F; BOOL isPulseWidthOut = FALSE; CONCENTRATE_PUMPS_T pumpId; CONCENTRATE_PUMPS_T pumpInAlarm = CONCENTRATEPUMPS_FIRST; F32 pumpInAlarmPulseWidthInMicroSeconds = 0.0F; BOOL isPumpPulseWidthOut = FALSE; for ( pumpId = CONCENTRATEPUMPS_FIRST; pumpId < NUM_OF_CONCENTRATE_PUMPS; pumpId++ ) { switch (pumpId) { case CONCENTRATEPUMPS_CP1_ACID: pulseWidthCount = getFPGACP1HallSensePulseWidth(); break; case CONCENTRATEPUMPS_CP2_BICARB: pulseWidthCount = getFPGACP2HallSensePulseWidth(); break; default: // Loop only allows for valid concentrate pump Ids. break; } pulseWidthInMicroSeconds = pulseWidthCount * CONCENTRATE_PUMP_HALL_SENSE_PERIOD_RESOLUTION; concentratePumps[ pumpId ].pulseWidthUS = pulseWidthInMicroSeconds; isPumpPulseWidthOut = ( pulseWidthInMicroSeconds <= (F32)CONCENTRATE_PUMP_MIN_ALLOWED_HALL_SENSOR_COUNT ? TRUE : FALSE ); // Determine measured speed for the pump if ( CONCENTRATE_PUMP_ZERO_FLOW_RATE == pulseWidthCount ) { concentratePumps[ pumpId ].measuredPumpSpeed.data = 0.0F; } else if ( FALSE == isPumpPulseWidthOut ) { concentratePumps[ pumpId ].measuredPumpSpeed.data = ( US_PER_SECOND / pulseWidthInMicroSeconds ) * CONCENTRATE_PUMP_VOLUME_PER_PULSE * SEC_PER_MIN; } // If pulse width is out of range capture pump out of range, pumpId and pulse width if ( TRUE == isPumpPulseWidthOut) { // Pulse width for this concentrate pump is out of range isPulseWidthOut = TRUE; pumpInAlarm = pumpId; pumpInAlarmPulseWidthInMicroSeconds = pulseWidthInMicroSeconds; } } checkPersistentAlarm( ALARM_ID_DG_CONC_PUMP_HALL_SENSOR_OUT_OF_RANGE, isPulseWidthOut, pumpInAlarm, pumpInAlarmPulseWidthInMicroSeconds ); } /*********************************************************************//** * @brief * The monitorPumpSpeed function monitors the concentrate pumps speed and * triggers the alarms if they are out of range. * @details Inputs: concentratePumps * @details Outputs: none * @param pumpId pump id to set step speed * @param alarm which the corresponding alarm of the concentrate pump * @return none *************************************************************************/ static void monitorPumpSpeed( CONCENTRATE_PUMPS_T pumpId, ALARM_ID_T alarm ) { F32 cpTargetSpeed = concentratePumps[ pumpId ].currentPumpSpeed; F32 cpError = fabs( fabs( getMeasuredPumpSpeedMLPM( pumpId ) ) - cpTargetSpeed ); BOOL isCpSpeedOut = FALSE; F32 tolerance = CONCENTRATE_PUMP_SPD_OUT_OF_RANGE_TOL_WHEN_SLOW_MLPM; if ( cpTargetSpeed > CONCENTRATE_PUMP_LOW_SPEED_THRESHOLD_MLPM ) { // Check if the pump is not in the off state and if it is not and greater than the minimum threshold, divide the error // to target speed. If the pump is off the target speed is 0 so the speed check is done differently cpError = cpError / cpTargetSpeed; tolerance = CONCENTRATE_PUMP_SPD_OUT_OF_RANGE_TOL_WHEN_ON_PCT; } isCpSpeedOut = ( cpError > tolerance ? TRUE : FALSE ); checkPersistentAlarm( alarm, isCpSpeedOut, cpError, tolerance ); } /*********************************************************************//** * @brief * The checkConcentratePumpControlSet function monitors the status of the * concentrate pumps control set bit and if they are different from the * required set bit, they are set again. * @details Inputs: concentratePumps * @details Outputs: none * @param pumpId pump id to check its control set bit * @return none *************************************************************************/ static void checkConcentratePumpControlSet( CONCENTRATE_PUMPS_T pumpId ) { U08 controlSetBits; switch ( pumpId ) { case CONCENTRATEPUMPS_CP1_ACID: controlSetBits = getFPGAAcidPumpControlStatus(); if ( controlSetBits != concentratePumps[ pumpId ].controlSet ) { setFPGAAcidPumpControl( concentratePumps[ pumpId ].controlSet ); } break; case CONCENTRATEPUMPS_CP2_BICARB: controlSetBits = getFPGABicarbPumpControlStatus(); if ( controlSetBits != concentratePumps[ pumpId ].controlSet ) { setFPGABicarbPumpControl( concentratePumps[ pumpId ].controlSet ); } break; default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_CONCENTRATE_PUMP_INVALID_PUMP_ID, pumpId ); break; } } /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/ /*********************************************************************//** * @brief * The testSetConcentratePumpDataPublishIntervalOverride function overrides the * concentrate pump data publish interval. * @details Inputs: none * @details Outputs: concentratePumpDataPublishInterval * @param value override concentrate pump data publish interval with (in ms) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetConcentratePumpDataPublishIntervalOverride( U32 value ) { BOOL result = FALSE; if ( TRUE == isTestingActivated() ) { U32 intvl = value / TASK_GENERAL_INTERVAL; result = TRUE; concentratePumpDataPublishInterval.ovData = intvl; concentratePumpDataPublishInterval.override = OVERRIDE_KEY; } return result; } /*********************************************************************//** * @brief * The testResetConcentratePumpDataPublishIntervalOverride function resets the * override of the concentrate pump data publish interval. * @details Inputs: none * @details Outputs: concentratePumpDataPublishInterval * @return TRUE if override reset successful, FALSE if not *************************************************************************/ BOOL testResetConcentratePumpDataPublishIntervalOverride( void ) { BOOL result = FALSE; if ( TRUE == isTestingActivated() ) { result = TRUE; concentratePumpDataPublishInterval.override = OVERRIDE_RESET; concentratePumpDataPublishInterval.ovData = concentratePumpDataPublishInterval.ovInitData; } return result; } /*********************************************************************//** * @brief * The testSetConcentratePumpTargetSpeedOverride function overrides the target * speed value of given concentrate pump id. * @details Inputs: none * @details Outputs: targetPumpSpeed[] * @param pumpId concentrate pump id * @param value override concentrate pump target speed * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetConcentratePumpTargetSpeedOverride( U32 pumpId, F32 value ) { BOOL result = FALSE; if ( pumpId < NUM_OF_CONCENTRATE_PUMPS && ( TRUE == isTestingActivated() ) ) { F32 const absSpeed = fabs( value ); if ( absSpeed <= CONCENTRATE_PUMP_MAX_SPEED ) { result = TRUE; setConcentratePumpTargetSpeed( (CONCENTRATE_PUMPS_T)pumpId, value ); } } return result; } /*********************************************************************//** * @brief * The testSetConcentratePumpMeasuredSpeedOverride function overrides the * measured speed value of given concentrate pump id. * @details Inputs: none * @details Outputs: measuredPumpSpeed[] * @param pumpId concentrate pump id * @param value override concentrate pump measured speed * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetConcentratePumpMeasuredSpeedOverride( U32 pumpId, F32 value ) { BOOL result = FALSE; if ( ( pumpId < NUM_OF_CONCENTRATE_PUMPS ) && ( TRUE == isTestingActivated() ) ) { result = TRUE; concentratePumps[ pumpId ].measuredPumpSpeed.ovData = value; concentratePumps[ pumpId ].measuredPumpSpeed.override = OVERRIDE_KEY; } return result; } /*********************************************************************//** * @brief * The testResetConcentratePumpMeasuredSpeedOverride function resets the * measured speed value of given concentrate pump id. * @details Inputs: none * @details Outputs: measuredPumpSpeed[] * @param pumpId concentrate pump id * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testResetConcentratePumpMeasuredSpeedOverride( U32 pumpId ) { BOOL result = FALSE; if ( ( pumpId < NUM_OF_CONCENTRATE_PUMPS ) && ( TRUE == isTestingActivated() ) ) { result = TRUE; concentratePumps[ pumpId ].measuredPumpSpeed.ovData = 0.0; concentratePumps[ pumpId ].measuredPumpSpeed.override = OVERRIDE_RESET; } return result; } /*********************************************************************//** * @brief * The testSetConcentratePumpParkedOverride function overrides the parked * status of given concentrate pump id. * @details Inputs: none * @details Outputs: parked[] * @param pumpId concentrate pump id * @param value override concentrate pump parked status * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetConcentratePumpParkedOverride( U32 pumpId, U32 value ) { BOOL result = FALSE; if ( ( pumpId < NUM_OF_CONCENTRATE_PUMPS ) && ( TRUE == isTestingActivated() ) ) { result = TRUE; concentratePumps[ pumpId ].parked.ovData = value; concentratePumps[ pumpId ].parked.override = OVERRIDE_KEY; } return result; } /*********************************************************************//** * @brief * The testResetConcentratePumpParkedOverride function resets the parked * status of given concentrate pump id. * @details Inputs: none * @details Outputs: parked[] * @param pumpId concentrate pump id * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testResetConcentratePumpParkedOverride( U32 pumpId ) { BOOL result = FALSE; if ( ( pumpId < NUM_OF_CONCENTRATE_PUMPS ) && ( TRUE == isTestingActivated() ) ) { result = TRUE; concentratePumps[ pumpId ].parked.ovData = 0.0; concentratePumps[ pumpId ].parked.override = OVERRIDE_RESET; } return result; } /*********************************************************************//** * @brief * The testSetConcentratePumpParkCmdFaultedOverride function overrides the * park command fault status of given concentrate pump id. * @details Inputs: none * @details Outputs: parkFaulted[] * @param pumpId concentrate pump id * @param value override concentrate pump park command faulted status * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetConcentratePumpParkCmdFaultedOverride( U32 pumpId, U32 value ) { BOOL result = FALSE; if ( ( pumpId < NUM_OF_CONCENTRATE_PUMPS ) && ( TRUE == isTestingActivated() ) ) { result = TRUE; concentratePumps[ pumpId ].parkFaulted.ovData = value; concentratePumps[ pumpId ].parkFaulted.override = OVERRIDE_KEY; } return result; } /*********************************************************************//** * @brief * The testResetConcentratePumpParkCmdFaultedOverride function resets the * park command fault status given concentrate pump id. * @details Inputs: none * @details Outputs: parkFaulted[] * @param pumpId concentrate pump id * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testResetConcentratePumpParkCmdFaultedOverride( U32 pumpId ) { BOOL result = FALSE; if ( ( pumpId < NUM_OF_CONCENTRATE_PUMPS ) && ( TRUE == isTestingActivated() ) ) { result = TRUE; concentratePumps[ pumpId ].parkFaulted.ovData = 0.0F; concentratePumps[ pumpId ].parkFaulted.override = OVERRIDE_RESET; } return result; } /*********************************************************************//** * @brief * The testSetConcentratePumpParkCommand function commands the given pump * to park. * @details Inputs: concentratePumps * @details Outputs: concentratePumps * @param pumpId concentrate pump id * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetConcentratePumpParkCommand( U32 pumpId ) { BOOL result = FALSE; if ( ( pumpId < NUM_OF_CONCENTRATE_PUMPS ) && ( TRUE == isTestingActivated() ) ) { result = TRUE; // If pump is running, stop it w/ park option if ( TRUE == concentratePumps[ pumpId ].hasTurnOnPumpsBeenRequested ) { requestConcentratePumpOff( (CONCENTRATE_PUMPS_T)pumpId, TRUE ); } // If pump is already stopped, just send park command else { concentratePumps[ pumpId ].hasParkBeenRequested = TRUE; stopConcentratePump( (CONCENTRATE_PUMPS_T)pumpId ); } } return result; } /**@}*/