Challenge

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

EMBEDDED BATCH -2

#include//standard input and output header
#include//preprocessor directive

void initial_state();//function protocol
void Gear_down();
void Checking_before_takeoff();
void Raising_gear();
void Gear_up();
void Lowering_gear();
void Checking_before_landing();

enum states//enum is used to assign the numerical constant to the
{ //variable and we can access the variable using number
geardown,
checking_bf_takeoff,
raising_gear,
gear_up,
checking_bf_landing,//declaring the states
lowering_gear
};

enum pilot_lever_state
{
raising,
falling,//declaring pilot lever state using enum
up,
down
};

enum pilot_lever_state lever;//change the variable name

enum switch_state
{
close,
open
};

enum switch_state Switch;//assign the new name

enum hyd_mech
{
working,
not_working
};

enum hyd_mech hydmech;

enum states current_state;

struct airplane
{
char* current_status;
char* light_status;
char* direction_valve;//structure variables
char* hydraulic_pump;

};
struct airplane state_machine[6]=
{
{"gear down","green","down","enabled"},
{"check before takeoff","green","down","enabled"},//structure members
{"raising_gear","red","up","enabled"},
{"gear_up","off","null","disabled"},
{"chkb4_landing","red","down","enabled"},
{"lowring_gear","green","down","enabled"}

};

void Gear_down()//sub function
{
current_state=geardown;

printf("\n\n enter pilot lever state value:");//print the output
scanf("%d",&lever);//scan the output from console

printf("\n enter squat switch value:");//print the output
scanf("%d",&Switch);
if(lever==raising && Switch==open)//if condition is right means print the function or its go to else part
{//if lever raising and switch open means its print checking before takeoff
current_state=checking_bf_takeoff;
printf("\n Current state =%s",state_machine[current_state].current_status);
printf("\n Light status =%s",state_machine[current_state].light_status);
printf("\n Direction valve status=%s",state_machine[current_state].direction_valve);
printf("\n Hydraulic pump status =%s",state_machine[current_state].hydraulic_pump);
}
else
{
printf("\n\nplease enter the correct value:");
Gear_down();//user input wrong means its go to Gear_down function again
}
}

void Checking_before_takeoff()//function
{
current_state=checking_bf_takeoff;
printf("\n\n enter pilot lever state value:");
scanf("%d",&lever);
printf("\n enter squat switch value:");
scanf("%d",&Switch);
if(lever==up &&Switch==open)//if the pilot lever is open and the squat switch is open it will go to the next state otherwise it will come out of the loop
{
current_state=raising_gear;//current state
printf("\n Current state =%s",state_machine[current_state].current_status);
printf("\n Light status =%s",state_machine[current_state].light_status);
printf("\n Direction valve status=%s",state_machine[current_state].direction_valve);
printf("\n Hydraulic pump status =%s",state_machine[current_state].hydraulic_pump);
}
}

void Raising_gear()//raising gear function
{
current_state=raising_gear;
printf("\n\n enter limit switch value:");
scanf("%d",&Switch);
if(Switch==close)//the switch is close it will go to the gear up state other wise it will go and check next if condition
{
current_state=gear_up;
printf("\n Current state =%s",state_machine[current_state].current_status);
printf("\n Light status =%s",state_machine[current_state].light_status);
printf("\n Direction valve status=%s",state_machine[current_state].direction_valve);
printf("\n Hydraulic pump status =%s",state_machine[current_state].hydraulic_pump);

}
printf("\n\n enter pilot lever state value:");
scanf("%d",&lever);
if(lever==falling)//begining of the raising gear function is not satisfying it will come this loop in this loop
//the pilot lever is falling it will go to the chkb4 landing state
{
current_state=checking_bf_landing;
printf("\n Current state =%s",state_machine[current_state].current_status);
printf("\n Light status =%s",state_machine[current_state].light_status);
printf("\n Direction valve status=%s",state_machine[current_state].direction_valve);
printf("\n Hydraulic pump status =%s",state_machine[current_state].hydraulic_pump);

}

}


void Gear_up()//gearup function
{
current_state=gear_up;
printf("\n\n enter pilot lever state value:");
scanf("%d",&lever);
if(lever==falling)//if the lever is falling it will go to the chkb4 landing state
{
current_state=checking_bf_landing;//current state
printf("\n Current state =%s",state_machine[current_state].current_status);
printf("\n Light status =%s",state_machine[current_state].light_status);
printf("\n Direction valve status=%s",state_machine[current_state].direction_valve);
printf("\n Hydraulic pump status =%s",state_machine[current_state].hydraulic_pump);

}
}

void Checking_before_landing()//chkb4 landing function
{
current_state=checking_bf_landing;
printf("\n\n enter pilot lever state value:");
scanf("%d",&lever);
if(lever==down)//in this state the pilot lever is down it will go to the lowering gear state
{
current_state=lowering_gear;
printf("\n Current state =%s",state_machine[current_state].current_status);
printf("\n Light status =%s",state_machine[current_state].light_status);
printf("\n Direction valve status=%s",state_machine[current_state].direction_valve);
printf("\n Hydraulic pump status =%s",state_machine[current_state].hydraulic_pump);

}
}

void Lowering_gear()//lowering gear function
{
current_state=lowering_gear;
printf("\n\n enter limit switch value:");
scanf("%d",&Switch);
if(Switch==open)//in this state if the switch is open it will go to the geardown state
{
current_state=geardown;

printf("\n Current state =%s",state_machine[current_state].current_status);
printf("\n Direction valve status=%s",state_machine[current_state].direction_valve);
printf("\n Light status =%s",state_machine[current_state].light_status);
printf("\n Hydraulic pump status =%s",state_machine[current_state].hydraulic_pump);

}
printf("\n\n enter pilot lever state value:");
scanf("%d",&lever);
if(lever==raising)// in lowering gear state first if condition is not satisfying it will come to this loop in this loop
//the pilot lever is raising it will go to chkb4 takeof state
{
current_state=checking_bf_takeoff;
printf("\n Current state =%s",state_machine[current_state].current_status);
printf("\n Light status =%s",state_machine[current_state].light_status);
printf("\n Direction valve status=%s",state_machine[current_state].direction_valve);
printf("\n Hydraulic pump status =%s",state_machine[current_state].hydraulic_pump);

}

}
void inital_state()//initial state of the program
{
current_state=geardown;//declere initial state of this program is gear down state
}

void(*airplane[])(void)= {Gear_down,Checking_before_takeoff,Raising_gear,
Gear_up, Checking_before_landing,Lowering_gear
};
int main()//main function
{
printf("\n pilot lever state");//in console block we can able to check the enum value of pilot lever state
printf("\n raising = 0");
printf("\n falling = 1");
printf("\n up = 2");
printf("\n down = 3");
printf("\n\nsquat switch");//in console block we can able to check the enum value of squat switch
printf("\n close =0");
printf("\n open =1");

while(1)//this loop is running untill its satisfying
{
airplane[current_state]();
}
return 0;
}

OUTPUT:

pilot lever state
raising = 0
falling = 1
up = 2
down = 3

squat switch
close =0
open =1

enter pilot lever state value:0 1

enter squat switch value:
Current state =check before takeoff
Light status =green
Direction valve status=down
Hydraulic pump status =enabled

enter pilot lever state value:2 1

enter squat switch value:
Current state =raising_gear
Light status =red
Direction valve status=up
Hydraulic pump status =enabled

enter limit switch value:0

Current state =gear_up
Light status =off
Direction valve status=null
Hydraulic pump status =disabled

enter pilot lever state value:1

Current state =chkb4_landing
Light status =red
Direction valve status=down
Hydraulic pump status =enabled

enter pilot lever state value:3

Current state =lowring_gear
Light status =green
Direction valve status=down
Hydraulic pump status =enabled

enter limit switch value:1

Current state =gear down
Direction valve status=down
Light status =green
Hydraulic pump status =enabled

enter pilot lever state value:

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.