Index: firmware/App/Controllers/Valves.c =================================================================== diff -u -rccfd15568f1e3d304320c2babb2fd4bcf0413304 -r3a480399e9fd87f51a12a469cc56242ebeb93539 --- firmware/App/Controllers/Valves.c (.../Valves.c) (revision ccfd15568f1e3d304320c2babb2fd4bcf0413304) +++ firmware/App/Controllers/Valves.c (.../Valves.c) (revision 3a480399e9fd87f51a12a469cc56242ebeb93539) @@ -20,6 +20,7 @@ #include "gio.h" #include "FPGA.h" +#include "MessageSupport.h" #include "SafetyShutdown.h" #include "SystemCommMessages.h" #include "TaskPriority.h" @@ -169,7 +170,8 @@ { VALVE_POSITION_T commandedPosition; ///< Valve commanded position enum VALVE_POSITION_T currentPosition; ///< Valve current position enum - OVERRIDE_S32_T currentPositionInCounts; ///< Valve current position in counts + VALVE_POSITION_T pendingCommandedPosition; ///< Valve pending position enum + OVERRIDE_S32_T currentPositionInCounts; ///< Valve current position in counts S16 targetPositionInCounts; ///< Valve target position in counts BOOL hasTransitionBeenRequested; ///< Valve transition request flag VALVE_STATE_T execState; ///< Valve execution state @@ -330,11 +332,11 @@ // Valve not in position cannot be requested // All the other positions are valid - if ( position != VALVE_POSITION_NOT_IN_POSITION && valve < NUM_OF_VALVES ) + if ( ( position != VALVE_POSITION_NOT_IN_POSITION ) && ( valve < NUM_OF_VALVES ) ) { - valvesStatus[ valve ].commandedPosition = position; + //valvesStatus[ valve ].commandedPosition = position; TODO remove + valvesStatus[ valve ].pendingCommandedPosition = position; valvesStatus[ valve ].hasTransitionBeenRequested = TRUE; - result = TRUE; } else @@ -720,7 +722,7 @@ // Set the current position to Position C and the commanded position to Position A valvesStatus[ valve ].hasValveBeenHomed = TRUE; valvesStatus[ valve ].currentPosition = VALVE_POSITION_C_CLOSE; - valvesStatus[ valve ].commandedPosition = VALVE_POSITION_A_INSERT_EJECT; + valvesStatus[ valve ].pendingCommandedPosition = VALVE_POSITION_A_INSERT_EJECT; valvesStatus[ valve ].hasTransitionBeenRequested = TRUE; valvesStatus[ valve ].hasHomingBeenRequested = FALSE; valvesStatus[ valve ].numberOfFailedHomings = 0; @@ -783,30 +785,27 @@ } #endif - if ( valvesStatus[ valve ].hasHomingBeenRequested ) + if ( TRUE == valvesStatus[ valve ].hasHomingBeenRequested ) { state = VALVE_STATE_HOMING_NOT_STARTED; } - else if ( valvesStatus[ valve ].hasValveBeenHomed && valvesStatus[ valve ].hasTransitionBeenRequested ) + else if ( ( TRUE == valvesStatus[ valve ].hasValveBeenHomed ) && ( TRUE == valvesStatus[ valve ].hasTransitionBeenRequested ) ) { - if ( valvesStatus[ valve ].currentPosition != valvesStatus[ valve ].commandedPosition ) + if ( valvesStatus[ valve ].currentPosition != valvesStatus[ valve ].pendingCommandedPosition ) { // Just set the valves to transition so it will not be in a known position for a while - valvesStatus[ valve ].transitionStartTime = getMSTimerCount(); + valvesStatus[ valve ].commandedPosition = valvesStatus[ valve ].pendingCommandedPosition; + valvesStatus[ valve ].transitionStartTime = getMSTimerCount(); + valvesStatus[ valve ].hasTransitionBeenRequested = FALSE; setValveNextStep( valve, TRANSITION_STEP_CHANGE_IN_COUNTS ); state = VALVE_STATE_IN_TRANSITION; } - else - { - valvesStatus[ valve ].hasTransitionBeenRequested = FALSE; - } } // This option is only available in a debug build #ifdef DEBUG_ENABLED // Check if the valves have been homed and a bypass mode has been requested - else if ( valvesStatus[ valve ].hasValveBeenHomed && - valvesStatus[ valve ].bypassModeStatus.hasBypassModeBeenRequeseted ) + else if ( ( TRUE == valvesStatus[ valve ].hasValveBeenHomed ) && ( TRUE == valvesStatus[ valve ].bypassModeStatus.hasBypassModeBeenRequeseted ) ) { // Set the valve control mode to bypass and set the PWM setValveControlMode( valve, VALVE_CONTORL_MODE_ENABLE_BYPASS ); @@ -848,14 +847,14 @@ // The valve is in range. Set the current position to the commanded position valvesStatus[ valve ].currentPosition = commandedPositionEnum; // Set the transition request to false as it has been serviced - valvesStatus[ valve ].hasTransitionBeenRequested = FALSE; + //valvesStatus[ valve ].hasTransitionBeenRequested = FALSE; TODO remove // If we are in Pos B, enable current relaxation if ( commandedPositionEnum == VALVE_POSITION_B_OPEN ) { // Enable current relaxation setFPGAValveSetPoint( valve, currentPosition, TRUE ); - valvesStatus[ valve ].hasTransitionBeenRequested = TRUE; + //valvesStatus[ valve ].hasTransitionBeenRequested = TRUE; TODO remove } // Go back to Idle state @@ -864,14 +863,14 @@ // Check if the valve's transition time has timed out else if ( didTimeout( valvesStatus[ valve ].transitionStartTime, VALVE_TRANSITION_TIMEOUT_MS ) ) { - valvesStatus[ valve ].hasTransitionBeenRequested = FALSE; + //valvesStatus[ valve ].hasTransitionBeenRequested = FALSE; TODO remove // Go back to Idle state state = VALVE_STATE_IDLE; #ifndef DISABLE_VALVE_ALARMS SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_VALVE_TRANSITION_TIMEOUT, (U32)valve ); #endif // If the valve transition timeout is active and the valve's commanded positions is position C, activate safety shutdown - if ( isAlarmActive( ALARM_ID_HD_VALVE_TRANSITION_TIMEOUT ) && valvesStatus[ valve ].commandedPosition == VALVE_POSITION_C_CLOSE ) + if ( ( TRUE == isAlarmActive( ALARM_ID_HD_VALVE_TRANSITION_TIMEOUT ) ) && ( VALVE_POSITION_C_CLOSE == valvesStatus[ valve ].commandedPosition ) ) { activateSafetyShutdown(); // Set the alarm @@ -1237,8 +1236,10 @@ valveData.pwm = valvesStatus[ valve ].bypassModeStatus.currentPWMInPercent; valveData.airTrapValve = (U32)getValveAirTrapStatus(); - broadcastHDValves( &valveData ); + broadcastData( MSG_ID_HD_VALVES_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&valveData, sizeof( HD_VALVE_DATA_T ) ); + //broadcastHDValves( &valveData ); //TODO remove + valvesStatus[ valve ].dataPublishCounter = 0; } }