Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -r425de1be48f86645589caea4ac832c58655f75b2 -rcee5876d8eb2b2d358a178208c5d8b0362e81a20 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision 425de1be48f86645589caea4ac832c58655f75b2) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision cee5876d8eb2b2d358a178208c5d8b0362e81a20) @@ -51,6 +51,7 @@ static BOOL checkValves( VALVES_T valve, VALVE_STATES_T valveState ); ///< check validity of requested valve state U16 fromIntArrayToU16( int array[ NUM_OF_VALVES ] ); ///< convert array of Int to U16 for statesValves preparation +int *fromU16ToIntArray( U16 vStates ); ///< convert U16 valvesStates to array of Int valve states static void publishValvesStates( void ); static DATA_GET_PROTOTYPE( U32, getPublishValvesStatesInterval ); @@ -84,38 +85,42 @@ if ( execValvesCounter <= 2 ) { - //int i = 0; + /*int i; - //for ( valves[ i ]; i <= NUM_OF_VALVES; i++ ) - //{ - // valvesStates = getFPGAValveStates(); + for ( i = 0; i < NUM_OF_VALVES; i++ ) + { + valvesStates = getFPGAValveStates(); - // if ( getValveState( valves [ i ] ) == fromU16ToIntArray( getFPGAValveStates(), i ) - // { - // setFPGAValveStates( valvesStates ); // set valves states via FPGA - // publishValvesStates(); // publish valves states on interval - // execValvesCounter = 0; // reset execValves counter - // } + if ( OVERRIDE_KEY == valves[ i ].override ) + { + if ( getValveState( valves[ i ].ovData ) != fromU16ToIntArray( valvesStates )[ i ] ) + { + valvesStates = fromIntArrayToU16( valves.ovData ); + } + } + else + { + if ( getValveState( valves[ i ].data ) != fromU16ToIntArray( valvesStates )[ i ] ) + { + valvesStates = fromIntArrayToU16( valves.data ); + } + } + }*/ + + //setFPGAValveStates( fromIntArrayToU16( valves.data ) ); // set valves states via FPGA to current valves states + valvesStates = getFPGAValveStates(); // get valves states from FPGA + + //if ( valvesStates == fromIntArrayToU16( valves.data ) + //{ + // execValvesCounter = 0; // reset execValves counter //} - if ( OVERRIDE_KEY == valves[ valve ].override ) - { - valvesStates = valves[ valve ].ovData; - } - else - { - valvesStates = valves[ valve ].data; - } - setFPGAValveStates( valvesStates ); - publishValvesStates(); // publish valves states on interval - execValvesCounter = 0; // reset execValves counter + publishValvesStates(); // publish valves states on interval } else // if requested valve state does not match FPGA-provided valve state three (3) times in row { activateAlarmNoData( ALARM_ID_VALVE_EXEC_COUNTER_ERROR ); } - - publishValvesStates(); // publish valves states on interval } /*********************************************************************//** @@ -248,6 +253,29 @@ /*********************************************************************//** * @brief + * The fromU16ToIntArray function converts U16 valvesStates to array \n + * of Int valve states. + * @details + * Inputs : none + * Outputs : none + * @return converted Int valve states array + *************************************************************************/ +int *fromU16ToIntArray( U16 vStates ) +{ + int *result;//[ NUM_OF_VALVES ] = INIT_VALVES_STATES; // initialize result array to default (de-energized) valves states + int i; + + for ( i = 0; i < NUM_OF_VALVES; i++) + { + result[ i ] = vStates % 2; + vStates /= 2; + } + + return result; +} + +/*********************************************************************//** + * @brief * The fromIntArrayToU16 function converts an array of Int valve states \n * to U16 valvesStates that can be passed to FPGA for setting valves. * @details