Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
#include
typedef enum {
GEAR_RETRACTED,
GEAR_EXTENDED,
GEAR_TRANSITION
} GearState;
// Function to retract the landing gear
void retractGear() {
printf("Landing gear is retracting...\n");
// Code to retract the landing gear goes here
}
// Function to extend the landing gear
void extendGear() {
printf("Landing gear is extending...\n");
// Code to extend the landing gear goes here
}
// Function to control the direction valve
void controlDirectionValve(int direction) {
printf("Direction valve is set to %s position.\n", (direction == 1) ? "raise" : "lower");
}
void controlLandingGear(GearState *currentState, int retractCommand, int extendCommand) {
switch (*currentState) {
case GEAR_RETRACTED:
if (extendCommand) {
*currentState = GEAR_TRANSITION;
controlDirectionValve(1);
extendGear();
*currentState = GEAR_EXTENDED;
}
break;
case GEAR_EXTENDED:
if (retractCommand) {
*currentState = GEAR_TRANSITION;
controlDirectionValve(0);
retractGear();
*currentState = GEAR_RETRACTED;
}
break;
case GEAR_TRANSITION:
if (extendCommand) {
*currentState = GEAR_EXTENDED;
} else if (retractCommand) {
*currentState = GEAR_RETRACTED;
}
break;
}
}
int main() {
GearState currentState = GEAR_RETRACTED;
// Simulated commands to retract and extend the landing gear
int retractCommand = 1; // 1 to indicate retract command, 0 otherwise
int extendCommand = 0; // 1 to indicate extend command, 0 otherwise
controlLandingGear(¤tState, retractCommand, extendCommand);
return 0;
}