Challenge

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

ans)

#include<stdio.h>
#include<state.h>

static void (*statetable[])(void)=(GearDown, CheckingBeforeTakeoff , RaisingGear , Gearup , CheckBeforeLanding ,
LoweringGear);

int main()
{
initiate_state_machine();
while1(1)
{
statetable[current_state]();
}
}

//Gear Down
void GearDown(void)
{
current_state=GEAR_DOWN;
printf("enter the status of pilot lever and squat switch :");
fflush(stdout);
scanf("%d %d",&pilot_lever, &squat_switch);
if(pilot_lever==raising && squat_switch==on)
{
current_state=CHECK_BEFORE_TAKEOFF;
printf("current state : %s\n",state_machine[current_state].current_state_indication);
printf("Light is :%s\n", state_machine[current_state].lighnt);
}
else
{
GearDown();
}
}

//checkingbefore Take off
void CheckingBeforeTakeOFF(void)
{
current_state=CHECKING_BEFORE_TAKE_OFF;
printf("enter the status of pilot lever and squat switch and hydraulic Mechanism :");
fflush(stdout);
scanf("%d %d", &pilot_lever, &squat_switch , &hydraulic_mechanism);
if(pilot_lever==falling && squat_switc==off)
{
GearDown();
}
else if(pilot_lever==raising && squat_switch==on && hydraulic_mechanism==working)
{
current_state=RAISING_GEAR;
printf("current state:%s\n",state_machine[current_state].current_state_indication);
printf("Light is :%s\n",state_machine[current_state].light);
printf("status of direction valve :%s\n",state_machine[current_state].direction_valve_status);
}
else if(pilot_lever==raising && squat_switch==on && hydraulic_mechanism==not working)
{
current_state=RAISING_GEAR;
printf("current state:%s\n",state_machine[current_state].current_state_indication);
printf("Light is :%s\n",state_machine[current_state].light);
printf("status of direction valve :%s\n",state_machine[current_state].direction_valve_status);
printf("status of gas pressurized spring system :%s\n",
state_machine[current_state].gas_pressurized_spring_system-status);
}
}

//RaisingGear
void RaisingGear(void)
{
current_state=RAISING_GEAR;
printf("enter the status of pilot lever and limit switch :");
fflush(stdout);
scanf("%d %d ",&pilot_lever , &limit_switch);
if(pilot_lever==falling && limit_switch==on)
{
current_state=CHECK_BEFORE_LANDING;
printf("current status : %s\n", state_machine[current_state].current_sate_indication);
printf("Light is :%s\n",state_machine[current_state].light);
printf("Landing Gear Hydraulic control :%s\n",state_machine[current_state].landing_gear_hydraulic_control);
}
else if(pilot_lever==raising && limit_switch==off)
{
current_state=GEAR_UP;
printf("current status : %s\n", state_machine[current_state].current_sate_indication);
printf("Light is :%s\n",state_machine[current_state].light);
printf("Landing Gear Hydraulic control :%s\n",state_machine[current_state].landing_gear_hydraulic_control);
}
else
{
RaisingGear();
}
}

//GearUp
void GearUp(void)
{
current_state=GEAR_UP;
printf("enter the status of pilot lever :");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever==falling)
{
current_state=CHECK_BEFORE_LANDING;
printf("current status : %s\n", state_machine[current_state].current_sate_indication);
printf("Light is :%s\n",state_machine[current_state].light);
printf("Landing Gear Hydraulic control :%s\n",state_machine[current_state].landing_gear_hydraulic_control);
}
else
{
GearUp();
}
}

//CheckbeforeLanding
void CheckinBeforeLanding(void)
{
current_state=CHECK_BEFORE_LANDING;
printf("enter the status of pilot lever and hydraulic mechanism status :");
fflush(stdout);
scanf("%d %d",&pilot_lever, &&hydraulic_mechanism);
if(pilot_lever==falling && hydraulic_mechanism==working)
{
current_state=LOWERING_GEAR;
printf("current status : %s\n", state_machine[current_tate].current_sate_indication);
printf("Light is :%s\n",state_machine[current_state].light);
printf("status of direction valve :%s\n",
state_machine[current_state].direction_valve_status);
}
else if(pilot_lever==falling && squat_switch==on && hydraulic_valve_status)
{
current_state=LOWERING_GEAR;
printf("current status : %s\n", state_machine[current_state].current_sate_indication);
printf("Light is :%s\n",state_machine[current_state].light);
printf("status of direction valve :%s\n",
state_machine[current_state].direction_valve_status);
printf("state of gas pressurized spring system:%s\n",
state_machine[current_state].gas_pressurized_spring_system_status);
}
if(pilot_lever==(raising || falling))
{
CheckBeforeLanding();
}
}

//LoweringGear
void LoweringGear(void)
{
current_state=LOWER_GEAR;
printf("enter the status of pilot lever and limit switch:");
fflush(stdout);
scanf("%d %d",&pilot_lever, && limit_switch);
if(pilot_lever==falling && limit_switch==working==on)
{
current_state=CHECK_BEFORE_TAKEOFF;
printf("current status : %s\n", state_machine[current_state].current_sate_indication);
printf("Light is :%s\n",state_machine[current_state].light);
}
if(pilot_lever==raising && limit_switch==off)
{
current_state=GEAR_DOWN;
printf("current status : %s\n", state_machine[current_state].current_sate_indication);
printf("Light is :%s\n",state_machine[current_state].light);
printf("Landing Gear Hydraulic control :%s\n",
state_machine[current_state].landing_gear_hydraulic_control);
}
if(limit_switch==off)
{
LoweringGear();
}
}

void Initiate_state_machine()
{
current_state=GEAR_DOWN;
printf(" the finite state machine is Initialized and current the program is in"
"GearDown state &Light is : %s\n",state_machine[current_state].light);
}

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.