Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
#include <stdio.h>
#include <stdlib.h>
typedef enum{
gear_down,
checking,
moving_up,
gear_up,
lowering,
}plane_status;
typedef enum{
on,
off,
}s_s;
typedef enum{
not_working,
working,
}h_c;
typedef enum{
yellow,
red,
green
}l_s;
typedef enum{falling,raising}p_l;
typedef struct
{
char* current_status;
char* light_status;
char* direction_valve;
char* landing_gear;
char* gas_spring[2];
}state;
state state_machine[5]={
{"geardwn","green","down","down",{"enabled","disabled"}},
{"checking","green","down","down",{"enabled","disabled"}},
{"movingup","red","up","going_up",{"enabled","disabled"}},
{"gearup","yellow","up","up",{"enabled","disabled"}},
{"lowering","red","down","lowering",{"enabled","disabled"}},
};
s_s squat_switch,limit_switch;
l_s light_state;
p_l pilot_lever;
h_c hydraulic;
plane_status current_state;
int control_input;
int main()
{
current_state=gear_down;//initial state gear is down
int c=1;
while(c==1)
{
printf("\n enter pilot liver and squat switch inputs");
fflush(stdout);
scanf("%d %d",&pilot_lever,&squat_switch);//getting input from user
if(pilot_lever==raising&&squat_switch==off)
{
current_state=checking;
printf("\n current state is %s",state_machine[current_state].current_status);
printf("\n light status is %s",state_machine[current_state].light_status);
}
else
{
printf("\n gear down");
}
current_state=checking;
printf("\n Enter the inputs for pilot lever squat switch and hydraulics");
scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic);
if(pilot_lever==raising&&squat_switch==off&&hydraulic==working)
{
current_state=moving_up;
printf("\n The landing gear is %s ",state_machine[current_state].current_status);
printf("\n light status %s",state_machine[current_state].light_status);
printf("\n direction valve is %s",state_machine[current_state].direction_valve);
printf("\n landing gear is %s",state_machine[current_state].landing_gear);
printf("\n gas spring system is %s",state_machine[current_state].gas_spring[hydraulic]);
}
else if(pilot_lever==raising&&squat_switch==off&&hydraulic==not_working)
{
printf("\n gas spring system is %s",state_machine[current_state].gas_spring[hydraulic]);
}
current_state=moving_up;
printf("\n Enter the inputs for pilot lever limit switch and hydraulics");
scanf("%d %d %d",&pilot_lever,&limit_switch,&hydraulic);
if(pilot_lever==raising&&limit_switch==on&&hydraulic==working)
{
current_state=gear_up;
printf("\n The landing gear is %s ",state_machine[current_state].current_status);
printf("\n light status %s",state_machine[current_state].light_status);
printf("\n direction valve is %s",state_machine[current_state].direction_valve);
printf("\n landing gear is %s",state_machine[current_state].landing_gear);
printf("\n gas spring system is %s",state_machine[current_state].gas_spring[hydraulic]);
}
else if(pilot_lever==raising&&limit_switch==on&&hydraulic==not_working)
{
printf("\n gas spring system is %s",state_machine[current_state].gas_spring[hydraulic]);
}
else if(pilot_lever==raising&&limit_switch==off&&hydraulic==not_working)
{
printf("\n gas spring system is %s",state_machine[current_state].gas_spring[hydraulic]);
printf("\n the current state is gear is moving up");
}
current_state=gear_up;
printf("\n Enter the inputs for pilot lever limit switch and hydraulics");
scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic);
if(pilot_lever==falling&&squat_switch==on&&hydraulic==working)
{
current_state=lowering;
printf("\n The landing gear is %s ",state_machine[current_state].current_status);
printf("\n light status %s",state_machine[current_state].light_status);
printf("\n direction valve is %s",state_machine[current_state].direction_valve);
printf("\n landing gear is %s",state_machine[current_state].landing_gear);
printf("\n gas spring system is %s",state_machine[current_state].gas_spring[hydraulic]);
}
else if(pilot_lever==raising&&limit_switch==on&&hydraulic==not_working)
{
printf("\n gas spring system is %s",state_machine[current_state].gas_spring[hydraulic]);
}
}
}