/ ***************PROJECT-2******************************
#include<stdio.h>
// function declaration
void runningstatemachine();
void geardown();
void checktakeoffcondition();
void risinggear();
void gearup();
void checklandingcondition();
void lowringgear();
static void(*statelist[])(void)={geardown,checktakeoffcondition,risinggear,gearup,checklandingcondition,lowringgear};
//creating enum type structure to creating the alise number for function
typedef enum state{
gear_down,
check_takeoff_condition,
rising_gear,
lowring_gear,
check_landing_condition,
gear_up,
}state_type;
typedef enum switch_s{
open,
closed,
}switch_s;
typedef enum pilot_lever{
raising,
falling,
}pilot_lever;
typedef enum hydrolic_micanism{
working,
not_working,
}hydrolic_micanism;
typedef enum spring_contol{
high,
low,
}spring_contol;
//create object name for structure
switch_s limiting_switch;
switch_s squat_switch;
pilot_lever pl;
hydrolic_micanism hm;
spring_contol pc;
state_type current_state;
//creating the structure where we are giving the different condition where how to control the gears.
typedef struct{
char *current_stutus;
char *light;
char *valve_direction;
char *hydrolic_control;
char *spring_contol_condition;
}state_list;
//creating the object named as state_machine which is an array in which it contain six different type of condtional output:
static state_list state_machine[6]={{"gear_down","green","down","working","low"},
{"check_takeoff_condition","green","down","working","low"},
{"rising_gear","red","up","working","low"},
{"gear_up","off","null","not_working","high"},
{"check_landing_condition","red","down","working","low"},
{"lowring_gear","green","down","working","low"},};
int main(){
//called the runningstatemachine function
runningstatemachine();
while(1){
statelist[current_state]();
}
}
// defination of runningstatemachine function
void runningstatemachine(){
current_state=gear_down;
printf("aircraft grear is down and light : %s\n",state_machine[current_state].light);
fflush(stdout);
}
//defination of geardown function
void geardown(){
current_state=gear_down;
printf("enter the condition for pilot lever and squat switch");
fflush(stdout);
scanf("%d %d",&pl ,&squat_switch);
if(pl==raising && squat_switch==closed){
current_state=check_takeoff_condition;
printf("current state :%s\n",state_machine[current_state].current_stutus);
fflush(stdout);
printf("light :%s\n",state_machine[current_state].light);
fflush(stdout);
}
else{
geardown();
}
}
// defination of checktakeoffcondition function
void checktakeoffcondition(){
current_state=check_takeoff_condition;
printf("enter the pilot lever, squat switch and hydrolic_micanism condition");
fflush(stdout);
scanf("%d %d %d",&pl,&squat_switch,&hm);
if(pl==falling && squat_switch==open){
geardown();
}
else if(pl==raising && squat_switch==closed && hm==working){
current_state=rising_gear;
printf("current state :%s\n",state_machine[current_state].current_stutus);
fflush(stdout);
printf("light :%s\n",state_machine[current_state].light);
fflush(stdout);
printf("direction valve :%s\n",state_machine[current_state].valve_direction);
fflush(stdout);
}
else if(pl==raising && squat_switch==closed && hm==not_working){
current_state=rising_gear;
printf("current state :%s\n",state_machine[current_state].current_stutus);
fflush(stdout);
printf("light :%s\n",state_machine[current_state].light);
fflush(stdout);
printf("direction valve :%s\n",state_machine[current_state].valve_direction);
fflush(stdout);
printf("spring control :%s\n",state_machine[current_state].spring_contol_condition);
fflush(stdout);
}
}
// defination of risinggear function
void risinggear(){
current_state=rising_gear;
printf("enter the pilot lever and limit switch condition");
fflush(stdout);
scanf("%d %d",&pl,&limiting_switch);
if(pl==falling && limiting_switch==closed){
current_state=check_landing_condition;
printf("current state :%s\n",state_machine[current_state].current_stutus);
fflush(stdout);
printf("light :%s\n",state_machine[current_state].light);
fflush(stdout);
printf("hydrolic control :%s\n",state_machine[current_state].hydrolic_control);
fflush(stdout);
}
else if(pl==raising && limiting_switch==open){
current_state=gear_up;
printf("current state :%s\n",state_machine[current_state].current_stutus);
fflush(stdout);
printf("light :%s\n",state_machine[current_state].light);
fflush(stdout);
printf("hydrolic control :%s\n",state_machine[current_state].hydrolic_control);
fflush(stdout);
}
else{
risinggear();
}
}
// defination of gearup function
void gearup(){
current_state=gear_up;
printf("enter the pilot lever condition");
fflush(stdout);
scanf("%d",&pl);
if(pl==falling){
current_state=check_landing_condition;
printf("current state :%s\n",state_machine[current_state].current_stutus);
fflush(stdout);
printf("light :%s\n",state_machine[current_state].light);
fflush(stdout);
printf("hydrolic control :%s\n",state_machine[current_state].hydrolic_control);
fflush(stdout);
}
else{
gearup();
}
}
// defination of checklandingcondition function
void checklandingcondition(){
current_state=check_landing_condition;
printf("enter the condition for pilot lever and hydrolic_control");
fflush(stdout);
scanf("%d %d",&pl,&hm);
if(pl==falling && hm==working){
current_state=lowring_gear;
printf("current state :%s\n",state_machine[current_state].current_stutus);
fflush(stdout);
printf("light :%s\n",state_machine[current_state].light);
fflush(stdout);
printf("direction valve :%s\n",state_machine[current_state].valve_direction);
fflush(stdout);
}
else if(pl==falling && hm==not_working){
current_state=lowring_gear;
printf("current state :%s\n",state_machine[current_state].current_stutus);
fflush(stdout);
printf("light :%s\n",state_machine[current_state].light);
fflush(stdout);
printf("direction valve :%s\n",state_machine[current_state].valve_direction);
fflush(stdout);
printf("spring control :%s\n",state_machine[current_state].spring_contol_condition);
fflush(stdout);
}
else if(pl==(raising)){
checklandingcondition();
}
}
// defination of lowringgear function
void lowringgear(){
current_state=lowring_gear;
printf("enter the condition for pilot_lever and limiting_switch");
fflush(stdout);
scanf("%d %d",&pl,&limiting_switch);
if(pl==falling && limiting_switch==closed){
current_state=check_takeoff_condition;
printf("current state :%s\n",state_machine[current_state].current_stutus);
fflush(stdout);
printf("light :%s\n",state_machine[current_state].light);
fflush(stdout);
}
else if(pl==raising && limiting_switch==open){
current_state=gear_down;
printf("current state :%s\n",state_machine[current_state].current_stutus);
fflush(stdout);
printf("light :%s\n",state_machine[current_state].light);
fflush(stdout);
printf("hydrolic control :%s\n",state_machine[current_state].hydrolic_control);
fflush(stdout);
}
}