Challenge

Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear

#include <stdio.h>
// function prototypes

void Gear_dowN();
void Gear_Up();
void Lowering_GeaR();
void Raising_geaR();
void Check_beforE_TakeofF();
void ChecK_Before_LandinG();

// various states of the landing gear
typedef enum Status{GEAR_DOWN, CHECK_BEFORE_TAKEOFF, RAISING_GEAR, GEAR_UP,CHECK_BEFORE_LANDING, LOWERING_GEAR }states;

//various states of the limit switch ans squat switch
typedef enum switch_s{ OPEN, CLOSE}switch_states;

//various states of the pilot liver
typedef enum pilot_lever{RISING,FALLING,UP,DOWN}Lever_States;

//various states of the hydraulic pump
typedef enum hydraulic_pump{WORKING,MALFUNCTIONING}hydraulic_pump_states;


switch_states squat_switch_status;
switch_states limit_switch_status;
Lever_States pilot_lever_status;
hydraulic_pump_states pump_status;
states current_status;

typedef struct
{
char *current_state;
char *light_status;
char *direction_valve_status;
char *hydraulic_pump_status;
}state_table;


state_table Landing_Gear_States[6]={
{"Gear down","green","down","enabled"},
{"Checking before takeoff","green","down","enabled"},
{"Raising gear","red","up","enabled"},
{"Gear up","off","null","disabled"},
{"Checking before landing","red","down","enabled"},
{"Lowering gear","green","down","enabled"}
};


void Gear_dowN()
{
current_status = GEAR_DOWN;
printf("The current status of the landing gear is GEAR_DOWN and the led staus is %s\n",Landing_Gear_States[current_status].light_status);
printf("Enter the pilot_lever_status and squat_switch status \n");
fflush(stdout);
scanf("%d %d",&pilot_lever_status,&squat_switch_status);
if(pilot_lever_status == RISING && squat_switch_status == OPEN)
{
current_status = CHECK_BEFORE_TAKEOFF;
printf("Current status of the gear is %s and the led = %s\n",Landing_Gear_States[current_status].current_state,Landing_Gear_States[current_status].light_status);
}
else
{
Gear_dowN();
}
}


void Check_beforE_TakeofF()
{
printf("Enter the 1. pilot_lever_status and 2. squat_switch_status and 3. pump_status \n");
fflush(stdout);
scanf("%d %d %d",&pilot_lever_status,&squat_switch_status,&pump_status);

if(pilot_lever_status == FALLING || squat_switch_status == CLOSE)
{
Gear_dowN();
}
else if(pilot_lever_status== UP && squat_switch_status == OPEN && pump_status==WORKING )
{
current_status = RAISING_GEAR;
printf("current status of the lever is %s \n",Landing_Gear_States[current_status].current_state);
printf("current status of the led is %s \n",Landing_Gear_States[current_status].light_status);
printf("current status of the dirction valve is %s\n",Landing_Gear_States[current_status].direction_valve_status);
}
else if(pilot_lever_status== UP && squat_switch_status == OPEN && pump_status==MALFUNCTIONING )
{
current_status = RAISING_GEAR;
printf("current status of the lever is %s \n",Landing_Gear_States[current_status].current_state);
printf("current status of the led is %s \n",Landing_Gear_States[current_status].light_status);
printf("current status of the dirction valve is %s\n",Landing_Gear_States[current_status].direction_valve_status);
}
}

void Raising_geaR()
{
printf("Enter the limit switch status and pillot lever status\n");
fflush(stdout);
scanf("%d %d",&limit_switch_status,&pilot_lever_status);

if(pilot_lever_status == FALLING && limit_switch_status == OPEN)
{
current_status = CHECK_BEFORE_LANDING;
printf("Current state of landing gear is %S\n",Landing_Gear_States[current_status].current_state);
printf("Current state of led is %S\n",Landing_Gear_States[current_status].light_status);
printf("Current state of hydraulic pump is %S\n",Landing_Gear_States[current_status].hydraulic_pump_status);
}
else if(pilot_lever_status == UP && limit_switch_status == CLOSE)
{
current_status = GEAR_UP;
printf("Current state of landing gear is %S\n",Landing_Gear_States[current_status].current_state);
printf("Current state of led is %S\n",Landing_Gear_States[current_status].light_status);
printf("Current state of hydraulic pump is %S\n",Landing_Gear_States[current_status].hydraulic_pump_status);
}
else
{
Raising_geaR();
}
}

void Gear_Up()
{
current_status == GEAR_UP;
printf("Enter the pilots lever's position \n");
fflush(stdout);
scanf("%d %d", &pilot_lever_status);

if(pilot_lever_status == FALLING)
{
printf("Current state of landing gear is %S\n",Landing_Gear_States[current_status].current_state);
printf("Current state of led is %S\n",Landing_Gear_States[current_status].light_status);
printf("Current state of hydraulic pump is %S\n",Landing_Gear_States[current_status].hydraulic_pump_status);
}
else{
Gear_Up();
}
}

void ChecK_Before_LandinG()
{
current_status = CHECK_BEFORE_LANDING;

printf("Enter the pilot_lever_status and pump_status\n ");
fflush(stdout);
scanf("%d %d",&pilot_lever_status,&pump_status);

if(pilot_lever_status == DOWN && pump_status == WORKING)
{
current_status = LOWERING_GEAR;
printf("Current state of landing gear is %S\n",Landing_Gear_States[current_status].current_state);
printf("Current state of led is %S\n",Landing_Gear_States[current_status].light_status);
printf("Current state of hydraulic pump is %S\n",Landing_Gear_States[current_status].direction_valve_status);

}
else if(pilot_lever_status == DOWN && pump_status == MALFUNCTIONING)
{
current_status = LOWERING_GEAR;
printf("Current state of landing gear is %S\n",Landing_Gear_States[current_status].current_state);
printf("Current state of led is %S\n",Landing_Gear_States[current_status].light_status);
printf("Current state of hydraulic pump is %S\n",Landing_Gear_States[current_status].direction_valve_status);

}

if(pilot_lever_status == UP || RISING || FALLING)
{
ChecK_Before_LandinG();
}


}

void Lowering_GeaR()
{

current_status == LOWERING_GEAR;
printf("Enter the pilot lever and limit switch status \n");
fflush(stdout);
scanf("%d %d",&pilot_lever_status,&limit_switch_status);

if(pilot_lever_status == RISING)
{
current_status == CHECK_BEFORE_TAKEOFF;
printf("Current state of landing gear is %S\n",Landing_Gear_States[current_status].current_state);
printf("Current state of led is %S\n",Landing_Gear_States[current_status].light_status);

}

if(limit_switch_status == OPEN)
{
current_status = GEAR_DOWN;
printf("Current state of landing gear is %S\n",Landing_Gear_States[current_status].current_state);
printf("Current state of led is %S\n",Landing_Gear_States[current_status].light_status);
printf("Current state of hydraulic pump is %S\n",Landing_Gear_States[current_status].direction_valve_status);

}

if(limit_switch_status == CLOSE)
{
Lowering_GeaR();
}

}


int main()
{

while(1)
{


Gear_dowN();
if(current_status == CHECK_BEFORE_TAKEOFF)
{
Check_beforE_TakeofF();
}
else if(current_status == RAISING_GEAR)
{
Raising_geaR();
}
else if(current_status == CHECK_BEFORE_LANDING)
{
ChecK_Before_LandinG();
}
else if(current_status == GEAR_UP)
{
Gear_Up();
}
else if(current_status == LOWERING_GEAR)
{
Lowering_GeaR();
}


}

return 0;
}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.