Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Implement the Code for controlling the retraction and extension of Airplane’s landing gear.
#include <stdio.h>
#include<conio.h>
typedef enum { //Gear state
gr_down,
gr_chk_takeoff,
gr_raising,
gr_up,
gr_chk_landing,
gr_lowering
}state_type;
state_type current_state;
typedef enum { //Limit switch
open,
close
}Switch;
typedef enum { //Lever
down,
raising,
up,
falling
}
pilot_lever;
typedef enum { //hydraulic_mechanism
working,
malfunctioning
}hydraulic_mechanism;
typedef struct{ //state table
char* current_state_indication;
char* LED_indication;
char* direction_valve;
char* hydraulic_pump_status;
char* gas_pressurized_spring_status[2];
}state_table;
state_table state[6]={{"gear_down","green","down","enabled",{0,0}},
{"checking_before_takeoff","green","down","enabled",{0,0}},
{"raising_gear","red","up","enabled",{"enabled","disabled"}},
{"gear_up","off","Null","disabled",{0,0}},
{"checking_before_landing","red","down","enabled",{0,0}},
{"lowering_gear","green","down","enabled",{"enabled","disabled"}}};
int main()
{
printf("\n current_state = Gear down");
printf("\n Lights = Green ");
printf("\n Parked at bay or Landed");
while(1)
{
int pilot_lever;
/*
pilot lever act as input pilot lever
raising=1,
up=2,
limit switch closed=3,
control enabled=4
falling=0
*/
printf("\n\n pilot_lever position= :");
fflush(stdout);
scanf("%d",&pilot_lever);
switch(pilot_lever)
{
case 0:
printf("\n Emergency state");
printf("\n moving_state =Gear Down");
printf("\n Pilot’s Lever Falling or Squat Switch = close ");
printf("\n Lights = RED");
break;
case 1:
//checking_before_takeoff Delay 3s
printf("\n current_state = checking_before_takeoff Delay 3s");
printf("\n Lights = Green ");
printf("\n Pilot’s Lever Rising = open && Squat Switch = open");
break;
case 2: //raising_gear
printf("\n current_state =raising_gear ");
printf("\n Lights = RED");
printf("\n Pilot’s Lever Rising && Squat Switch = open");
break;
case 3: //gear_up
printf("\n current_state =gear_up ");
printf("\n Lights = OFF");
printf("\n Control for landing gear disabled ");
break;
case 4:
printf("\n current_state =checking_before_landing"); //checking_before_landing
printf("\n Lights = RED");
printf("\n Control for landing gear disabled ");
break;
case 5:
printf("\n current_state =lowering_gear"); //lowering_gear
printf("\n Pilot’s Lever Down");
printf("\n Direction Valve = DOWN");
break;
case 6: // Pilot’s Lever Falling THEN GO TO Checking before Landing State
printf("\n current_state =Checking before Landing");
printf("\n Pilot’s Lever Falling");
printf("\n Lights = RED");
break;
}
}
return 0;
}
output:
