Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
#include"gears.h" //including gears.h file
void gear_down() // definition of gear down function
{
current_state=Gear_down; //Enum Value - Gear Down
printf("pilot lever and squat switch\n"); //asking pilot to enter the data for printing the value of lever and switch
fflush(stdout); //clearing o/p stream
scanf("%d %d",&a,&squat); //store the value of squat switch and lever
if((a==Rising)&&(squat==Open)) //0 0
{
current_state=Checking_before_Take_off; //enum value current state if true(0 0)
printf("Next state is %s\n",state_machine[current_state].next_state); //printing the value of next state and assign address current state to next state
printf("Light is %s\n",state_machine[current_state].light); //printing light status
printf("Direction valve is %s\n",state_machine[current_state].direction_valve); //printing directipn valve status
printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control); // printing hydroulic pressure ststus
}
else
{
gear_down(); //falling any condition, current state as gear down
}
}
#include"gears.h" //including gears.h file
void checking_before_landing() // defintion of checking before landing function
{
current_state=Checking_before_Landing; //current state assign as cheking before landing
printf("enter the value of pilot lever and hydroulic machine\n"); //asking pilot to enter value
fflush(stdout);
scanf("%d %d",&a,&b);
if(a==Down||b==Not_Working) //lever down or hydroulic disabled
{
current_state=Lowering_Gear;
}
else {
checking_before_landing();
}
}
#include"gears.h" //including gears.h file
void checking_before_take_off() //definition of checking before take off function
{
current_state=Checking_before_Take_off; //assign current state as checking before take off
printf("enter value of pilot lever,switch and hydroulic machine\n"); //asking pilot to enter value of lever, switch and hydroulic pressure status
fflush(stdout); //clearing o/p stream
scanf("%d %d %d",&a,&squat,&b); //store the value of a,b and squat
if((a==Falling)||(squat==Close)) //check either lever falling or squat status
{
current_state=Gear_down; //if fails state is gear down
printf("Next state is %s\n",state_machine[current_state].next_state); //printing the value of next state and assign address current state to next state
printf("Light is %s\n",state_machine[current_state].light); //printing light status
printf("Direction valve is %s\n",state_machine[current_state].direction_valve); //printing directipn valve status
printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control); // printing hydroulic pressure ststus
}
else if((a==Up)&&(b==Working)) //lever up and hydroulic enabled
{
current_state=Raising_Gear; //current state assign as raising gear
printf("Next state is %s\n",state_machine[current_state].next_state); //printing the value of next state and assign address current state to next state
printf("Light is %s\n",state_machine[current_state].light); //printing light status
printf("Direction valve is %s\n",state_machine[current_state].direction_valve); //printing directipn valve status
printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control); // printing hydroulic pressure ststus
}
else {
checking_before_take_off();
}
}
#include"gears.h" //including gears.h file
void raising_gear() //defintion of raising gear
{
current_state=Raising_Gear; // current state assign as raising gear
printf("asking for pilot lever and limit switch\n"); //asking pilot to enter value of lever and switch status
fflush(stdout); //clearing o/p stream
scanf("%d %d",&a,&limit); //store value in lever and limit switch
if(a==Falling)
{
current_state=Checking_before_Landing; //current assign as check before landing
printf("Next state is %s\n",state_machine[current_state].next_state); //printing the value of next state and assign address current state to next state
printf("Light is %s\n",state_machine[current_state].light); //printing light status
printf("Direction valve is %s\n",state_machine[current_state].direction_valve); //printing directipn valve status
printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control); // printing hydroulic pressure ststus
}
else if(limit==Close) //check limit switch status
{
current_state=Gear_Up; // if true then current state assign as gear up
printf("Next state is %s\n",state_machine[current_state].next_state); //printing the value of next state and assign address current state to next state
printf("Light is %s\n",state_machine[current_state].light); //printing light status
printf("Direction valve is %s\n",state_machine[current_state].direction_valve); //printing directipn valve status
printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control); // printing hydroulic pressure ststus
}
}
#include"gears.h" //including gears.h file
void gear_up() //definition of gear up function
{
current_state=Gear_Up; //current state assign as gear up
printf("enter the value of pilot lever\n"); // asking pilot to enter value of lever status
fflush(stdout); // clearing o/p stream
scanf("%d",&a); //store value of lever status in a
if(a==Falling) //if lever falling
{ current_state=Checking_before_Landing; //current assign goes to next state
}
else {
gear_up();
}
}
#include"gears.h" //including gears.h file
void lowering_gear() // defintion nof lowering gear function
{
current_state=Lowering_Gear; //current sate assign as lowering gear
printf("asking for limit switch and pilot lever\n");
fflush(stdout);
scanf("%d %d",&limit,&a);
if(limit==Open)
{
current_state= Gear_down;
}
else if(a==Rising)
{
current_state=Checking_before_Take_off;
}
else
{
lowering_gear();
}
}