Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -ra7bf3ca23ea37a61000379facae628a31b3ecc59 -rf308cc4c35eab630ebbbde405cfe47d049afeafb --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision a7bf3ca23ea37a61000379facae628a31b3ecc59) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision f308cc4c35eab630ebbbde405cfe47d049afeafb) @@ -7,8 +7,8 @@ * * @file Valves.c * -* @author (last) Sean Nash -* @date (last) 19-May-2020 +* @author (last) Quang Nguyen +* @date (last) 21-Jul-2020 * * @author (original) Sean * @date (original) 06-May-2020 @@ -49,7 +49,7 @@ static BOOL checkValveStateName( VALVES_T valve, VALVE_STATE_NAMES_T valveStateName ); ///< check validity of requested valve state name for given valve static U32 convertValveStateNameToValveState(VALVE_STATE_NAMES_T valveStateName); ///< Convert valve state name to de-/energized valve state -static U16 fromU32ArrayToU16( OVERRIDE_U32_T array[ NUM_OF_VALVES ] ); ///< convert array of U32 to U16 for statesValves preparation +static U16 fromU32ArrayToU16( void ); ///< convert array of U32 to U16 for statesValves preparation static void publishValvesStates( void ); static DATA_GET_PROTOTYPE( U32, getPublishValvesStatesInterval ); @@ -73,7 +73,7 @@ valveStates[ i ].ovData = DEENERGIZED; valveStates[ i ].override = OVERRIDE_RESET; } - commandedValvesStates = fromU32ArrayToU16( valveStates ); + commandedValvesStates = fromU32ArrayToU16(); setFPGAValveStates( commandedValvesStates ); // initially set all valves to de-energized state via FPGA valvesStatesPublicationTimerCounter = 0; // reset valves states publication timer @@ -106,7 +106,7 @@ } // set valves states (via FPGA) to currently commanded states - commandedValvesStates = fromU32ArrayToU16( valveStates ); + commandedValvesStates = fromU32ArrayToU16(); setFPGAValveStates( commandedValvesStates ); // publish valve states on interval @@ -120,8 +120,8 @@ * @details * Inputs : none * Outputs : none - * @param valveID : ID of valve to check a valve state name for. - * @param valveStateName : valve state name to check for given valve ID. + * @param valveID ID of valve to check a valve state name for + * @param valveStateName valve state name to check for given valve ID * @return TRUE if given valveStateName is appropriate for given valve ID, FALSE if not. *************************************************************************/ static BOOL checkValveStateName( VALVES_T valveID, VALVE_STATE_NAMES_T valveStateName ) @@ -215,7 +215,7 @@ break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_VALVES_INVALID_VALVE_STATE_NAME, valveStateName ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_VALVES_INVALID_VALVE_STATE_NAME, valveStateName ) break; } @@ -252,7 +252,7 @@ * Outputs : none * @return converted U16 bit field for currently commanded valve states *************************************************************************/ -U16 fromU32ArrayToU16( OVERRIDE_U32_T array[ NUM_OF_VALVES ] ) +U16 fromU32ArrayToU16( void ) { U16 result = ALL_VALVES_DEENERGIZED; // start result flag as all valves de-energized U32 i; @@ -273,7 +273,7 @@ * @details * Inputs : none * Outputs : none - * @param valveStateName : valve state name enumeration to convert to energized/de-energized. + * @param valveStateName valve state name enumeration to convert to energized/de-energized * @return converted valve state for given valve state name *************************************************************************/ U32 convertValveStateNameToValveState( VALVE_STATE_NAMES_T valveStateName ) @@ -331,7 +331,7 @@ break; default: - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_VALVES_INVALID_VALVE_STATE_NAME, valveStateName ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_VALVES_INVALID_VALVE_STATE_NAME, valveStateName ) break; } @@ -344,18 +344,25 @@ * @details * Inputs : none * Outputs : none - * @param valveID : ID of valve to set state for. - * @param valveStateName : Name of valve state to set given valve to. + * @param valveID ID of valve to set state for + * @param valveStateName Name of valve state to set given valve to * @return TRUE if new valve state is set for given valve ID, FALSE if not. *************************************************************************/ BOOL setValveState( VALVES_T valveID, VALVE_STATE_NAMES_T valveStateName ) { BOOL result = FALSE; // initialize result flag to FALSE - - if ( checkValveStateName ( valveID, valveStateName ) ) - { - valveStates[ valveID ].data = convertValveStateNameToValveState( valveStateName ); - result = TRUE; + + if ( valveID < NUM_OF_VALVES ) + { + if ( checkValveStateName ( valveID, valveStateName ) ) + { + valveStates[ valveID ].data = convertValveStateNameToValveState( valveStateName ); + result = TRUE; + } + } + else + { + // TODO - s/w fault } return result; @@ -367,7 +374,7 @@ * @details * Inputs : valveStates[] * Outputs : none - * @param valveID : ID of valve to get state for. + * @param valveID ID of valve to get state for * @return the current valve state for given valve *************************************************************************/ U32 getValveState( U32 valveID ) @@ -387,7 +394,7 @@ } else { - SET_ALARM_WITH_2_U32_DATA( ALARM_ID_SOFTWARE_FAULT, SW_FAULT_ID_VALVES_INVALID_VALVE_ID, valveID ) + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_VALVES_INVALID_VALVE_ID, valveID ) } return valveState; @@ -424,7 +431,7 @@ * @details * Inputs : none * Outputs : valvesStatesPublishInterval - * @param value : override valves states publish interval with (in ms) + * @param value override valves states publish interval with (in ms) * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetValvesStatesPublishIntervalOverride( U32 value ) @@ -472,8 +479,8 @@ * specified valve with a given value. * Inputs : none * Outputs : valves[] - * @param valveID : ID of valve to override for - * @param value : override value for the given valve ID + * @param valveID ID of valve to override for + * @param value override value for the given valve ID * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testSetValveStateOverride( U32 valveID, U32 value ) @@ -500,7 +507,7 @@ * @details * Inputs : none * Outputs : valves[] - * @param valveID : ID of valve to reset override state for + * @param valveID ID of valve to reset override state for * @return TRUE if override successful, FALSE if not *************************************************************************/ BOOL testResetValveStateOverride( U32 valveID )