Challenge

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

#include<stdio.h>

//Functions

void Init_State_machine();
void Gear_Down();
void Checking_Before_Takeoff();
void Raising_Gear();
void Gear_Up();
void Checking_Before_Landing();
void Lowering_Gear();

//creating user defined variable

typedef enum state
{
Gear_down,
Check_before_takeoff,
Raising_gear,
Gear_up,
Checking_before_landing,
Lowering_gear
}State_Type;

typedef enum Switch
{
Open,
Close
}Switch_Status;

typedef enum Pilot_Lever
{
Rising,
Falling,
Up,
Down
}Pilot_Lever_status;

typedef enum Hydraulic_mechanism
{
malfunctioning,
working
}Hydraulic_Mechanism;

// Input for changing the State_type
static volatile Switch_Status squat_switch;
static volatile Switch_Status Limit_Switch;
static volatile Pilot_Lever_status pilot_lever;
static volatile Hydraulic_Mechanism hydraulic_mechanism;

State_Type current_state;

typedef struct
{
//char* State_type;
char* current_state_indication;
char* light_status;
char* direction_valve_status;
char* hydraulic_pump_control_status;
char* gas_pressurized_spring_status[2];
}State_Table;

//Creating array of conditions
static State_Table State_machine[6]={
{"Gear Down","Green","Down","Enabled",{0,0}},
{"Checking before take off","Green","Down","Enabled",{NULL,NULL}},
{"Raising Gear","Red","Up","Enabled",{"Disabled","Enabled"}},
{"Gear Up","Off","NULL","Disabled",{NULL,NULL}},
{"Checking Before Landing","Red","Down","Enabled",{NULL,NULL}},
{"Lowering Gear","Green","Down","Enabled",{"Disabled","Enabled"}}
};

//calling state table with the help of function pointer
static void (*state_table[])(void)={Gear_Down,Checking_Before_Takeoff,Raising_Gear,Gear_Up,
Checking_Before_Landing,Lowering_Gear};

//main function defination
int main()
{
//calling initial function
Init_State_machine();
while(1)
{
state_table[current_state]();
}
}

//initial function defination
void Init_State_machine()
{
//system initialized
current_state=Gear_down;
printf("\n state machine is initialized & program is in Gear_Down state &light status=%s\n",
State_machine[current_state].light_status);
}

//gear down function defination

void Gear_Down(void)
{
current_state=Gear_down;
printf("\n Enter the pilote's lever position=");
fflush(stdout);
scanf("%d",&pilot_lever);
printf("\n Enter the squat switch status=");
fflush(stdout);
scanf("%d",&squat_switch);
if(pilot_lever==Rising && squat_switch==Open)
{
current_state=Check_before_takeoff;
printf("\n Current state=%s\n",State_machine[current_state].current_state_indication);
printf("Light status=%s\n",State_machine[current_state].light_status);
}
else
{
Gear_Down();
}
}

// function defination for checking before take Off

void Checking_Before_Takeoff()
{
current_state=Check_before_takeoff;
printf("\n Enter the pilote's lever position, squat switch status and Hydraulic mechanism status=");
fflush(stdout);
scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);
printf("\n Wait for 2 sec");

if(pilot_lever==Falling || squat_switch==Close)
{
Gear_Down();
}
else if(pilot_lever==Up && squat_switch==Open && hydraulic_mechanism== working)
{
current_state=Raising_gear;
printf("\n Current state=%s\n",State_machine[current_state].current_state_indication);
printf("Light status=%s\n",State_machine[current_state].light_status);
printf("Direction valve status=%s\n",State_machine[current_state].direction_valve_status);
}
else if(pilot_lever==Up && squat_switch==Open && hydraulic_mechanism== malfunctioning)
{
current_state=Raising_gear;
printf("\n Current state=%s\n",State_machine[current_state].current_state_indication);
printf("Light status=%s\n",State_machine[current_state].light_status);
printf("Direction valve status=%s\n",State_machine[current_state].direction_valve_status);
printf("Gas pressurized spring system=%s\n",State_machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}
}

//Function defination for Raising Gear
void Raising_Gear()
{
current_state=Raising_gear;
printf("\n Enter the limit switch status, pilote's lever position =");
fflush(stdout);
scanf("%d %d",&Limit_Switch,&pilot_lever);
printf("\n Wait for 1 sec \n");
if(pilot_lever==Falling || Limit_Switch==Open)
{
current_state=Checking_before_landing;
printf("\n Current state=%s\n",State_machine[current_state].current_state_indication);
printf("Light status=%s\n",State_machine[current_state].light_status);
printf("Hydraulic control for landing gear status=%s\n",State_machine[current_state].hydraulic_pump_control_status);
}
else if(Limit_Switch==Close && pilot_lever==Up)
{
current_state=Gear_up;
printf("\n Current state=%s\n",State_machine[current_state].current_state_indication);
printf("Light status=%s\n",State_machine[current_state].light_status);
printf("Hydraulic control for landing gear status=%s\n",State_machine[current_state].hydraulic_pump_control_status);
}
else
{
Raising_Gear();
}
}

//function defination for lowering gear
void Lowering_Gear()
{
current_state=Lowering_gear;
printf("\n Enter the limit switch status, pilote's lever position =");
fflush(stdout);
scanf("%d %d",&Limit_Switch,&pilot_lever);
if(Limit_Switch==Close && pilot_lever==Rising)
{
current_state=Check_before_takeoff;
printf("\n Current state=%s\n",State_machine[current_state].current_state_indication);
printf("Light status=%s\n",State_machine[current_state].light_status);
}
if(Limit_Switch==Open && pilot_lever==Down)
{
current_state=Gear_down;
printf("\n Current state=%s\n",State_machine[current_state].current_state_indication);
printf("Light status=%s\n",State_machine[current_state].light_status);
printf("Hydraulic control for landing gear status=%s\n",State_machine[current_state].hydraulic_pump_control_status);
}
else
{
Lowering_Gear();
}

}


//Function defination for checking before landing
void Checking_Before_Landing()
{
current_state= Checking_before_landing;
printf("\n Enter the pilote's lever position and status of hydraulic mechanism=");
fflush(stdout);
scanf("%d %d",&pilot_lever,&hydraulic_mechanism);
if(pilot_lever==Down && hydraulic_mechanism==working)
{
current_state=Lowering_gear;
printf("\n Current state=%s\n",State_machine[current_state].current_state_indication);
printf("Light status=%s\n",State_machine[current_state].light_status);
printf("Direction valve status=%s\n",State_machine[current_state].direction_valve_status);
}
else if(pilot_lever==Down && hydraulic_mechanism==malfunctioning)
{
current_state=Lowering_gear;
printf("\n Current state=%s\n",State_machine[current_state].current_state_indication);
printf("Light status=%s\n",State_machine[current_state].light_status);
printf("Direction valve status=%s\n",State_machine[current_state].direction_valve_status);
printf("Gas pressurized spring system=%s\n",State_machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}
if(pilot_lever==(Up|| Rising || Falling))
{
Checking_Before_Landing();
}
}

//Function defination for gear up
void Gear_Up()
{
current_state=Gear_up;
printf("\n Enter the pilote's lever position=");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever==Falling)
{
current_state=Checking_before_landing;
printf("\n Current state=%s\n",State_machine[current_state].current_state_indication);
printf("Light status=%s\n",State_machine[current_state].light_status);
printf("Hydraulic control for landing gear status=%s\n",State_machine[current_state].hydraulic_pump_control_status);
}
else
{
Gear_Up();
}

}

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.