Challenge

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

#include<stdio.h>
#include<stdlib.h>
void Init_state_machine();
void Gear_Down();
void Checking_Before_Takeoff();
void Raising_Gear();
void Gear_up();
void Checking_Before_Landing();
void Lowering_Gear();
typedef enum state
{
GEAR_DOWN,
CHECKING_BEFORE_TAKEOFF,
RAISING_GEAR,
GEAR_UP,
CHECKING_BEFORE_LANDING,
LOWERING_GEAR
}State_Type;
typedef enum switch
{
open
close //plane is in ground
}Switch_Status;
typedef enum pilot_lever
{
Rising,
Falling,
up,
Down
}pilot lever status;
typedef enum Hydraulic_Mechanism
{
Working malfunctioning
}Hydraulic_Mechanism_Status;
/*input for changing the state....*/
static volatile switch_status squat_switch;
static volatile switch_status limit_switch;
static volatile Pilot_Lever_status pilot_lever;
static volatile Hydraulic_Mechanism_status hydraulic_mechanism;
state_type current_state;
typedef struct
{
char* current_state_indication;
char* light_status;
char* direction_value_status;
char* hydraulic_pump_control_status;
char* gas_pressurized_spring_status[2];
}State_Table;
static State_Table State_Machine[6]=1
{"GearDown","Green","Down","Enabled",{NULL,NULL}};
{"Checking Before Take On","Green","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",{"Disabledd","Enabledd"}
}
void Gear_Down(void)
{
printf("\n enter the pilot lever position and squat switch status");
fflush(stdout);
scanf("%d%d",&pilot_lever,&squat_switch);
if(pilot_lever==Rising && squat_switch==open)
{
currrent state=CHECKING_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();
}
}
void Checking_Before_Takeoff()
{
current state=CHECKING_BEFORE_TAKEOFF;
printf("\n enter the pilot 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 sea\n");
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\n",state_Machine[current_state].direction_valve_status);
}
else if(pilot_lever==UP &&ssquat_switch==open&&hydraulic_machine==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 status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[Hydraulic_Mechanism]);
}
}
void Raising_Gear()
{
current_state=RAISING_GEAR;
PRINTF("\n enter the limit switch status.pilots lever status:");
fflush(stdout);
scanf("%d%d,& limit_switch,& pilot lever");
printf("\n wait for 1 sea\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_staste].light_status);
printf("Hydraulic control for landing gear status:%s\n",State_Machine[current_state].hhydraulic_pump_control_status);
}
else
{
Raising_Gear();
}
}
void Gear_UP()
{
current_state=GEAR_UP;
printf("\n enter the pilot 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();
}
}
void Checking_Before_Landing()
{
current_state=CHECKING_BEFORE_LANDING;
printf("\n enter the pilot'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_Machiine[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);
}
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 status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[Hydraulic_mechanism]);
}
if(pilot_lever==up||Rising||Falling)
{
Checking_Before_Landing();
}
}
void Lowerring_Gear()
{
current_state=LOWERING_GEAR;
printf("\n enter the limit switch status,pilots lever status::");
fflush(stdout);
scanf("%d%d",&limit_switch,&pilot_lever);
if(pilot_lever==Rising)
{
current_state=CHECKING_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);
}
if(limit_switch==close)
{
LOWERING_GEAR();
}
}
void Init_State_Machine()
{
current_state=GEAR_DOWN;
printf("\n state machine is initialized & program is in Gear_Down state & status is green\n");
}

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.