Challenge

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

OFFLINE BATCH

#include
typedef enum State
{
Gear_Down,
Check_Before_Takeoff,
Raising_Gear,
Gear_Up,
Check_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
{
Working,
Malfunctioning
}Hydraulic_Mechanism_Status;

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* pilot_lever_status;
char* hydraulic_pump;
char* gas_pressurized_spring_status[2];
}State_Table;
State_Table State_Machine[6]={

{"GearDown","Green","Down","Enabled",0,0},
{"Checking Before Take Off","Green","Down","Enabled",0,0},
{"Raising Gear","Red","Up","Enabled",{"Disabled","Enabled"}},
{"Gear Up","Off","Null","Disabled",0,0},
{"Checking Before Landing","Red","Down","Enabled",0,0},
{"Lowering Gear","Green","Down","Enabled",{"Disabled","Enabled"}}

};
void Lowering_gear()
{
current_state = Lowering_Gear;
printf("\n Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("\n Enter the limit Switch Status,pilot'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("\nLight Status: %s\n",State_Machine[current_state].light_status);
}
else 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("\nLight Status: %s\n",State_Machine[current_state].light_status);
printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump);
}

}

void Checking_Before_Takeoff()
{
current_state = Check_Before_Takeoff;
printf("\n Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("\n Enter the pilot's lever Position, Squat Switch Status and Hydraulic Mechanism Status:");
fflush(stdout);
scanf("%d %d %d",&pilot_lever, &Squat_Switch, &hydraulic_mechanism);
if(pilot_lever == Falling ||Squat_Switch == Close)
{
current_state=Gear_Down;
printf("\n Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("\nLight Status: %s\n",State_Machine[current_state].light_status);

}
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("\nLight Status: %s\n",State_Machine[current_state].light_status);
printf("\nDirection valve Status:%s\n",State_Machine[current_state].pilot_lever_status);
}

}
void Checking_Before_Landing()
{
current_state = Check_Before_Landing;
printf("\n Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("\n Enter the pilot's Lever Position and HydraulicMechanism Status:");

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("\nLight State: %s\n",State_Machine[current_state].light_status);
printf("\nDirection Valve Status:%s\n",State_Machine[current_state].pilot_lever_status);
}
}

void Raising_gear()
{
current_state = Raising_Gear;
printf("\nCurrent State:%s\n",State_Machine[current_state].current_state_indication);
printf("\n Enter the Limit Switch Status,pilots Lever Status:");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);

if(pilot_lever == Falling && limit_switch == Open)
{
current_state=Check_Before_Landing;
printf("\n Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("\nLight State: %s\n",State_Machine[current_state].light_status);
printf("\nHydraulic Control for Landing Gear State:%s\n",State_Machine[current_state].hydraulic_pump);
}
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("\n Light State: %s\n",State_Machine[current_state].light_status);
printf("\n Hydraulic Control for landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump);
}
}
void Gear_down()
{
current_state = Gear_Down;
printf("\nCurrent State:%s\n",State_Machine[current_state].current_state_indication);
printf("\n Enter the pilot's Lever Position, Squat Switch Status ");
fflush(stdout);
scanf("%d %d",&pilot_lever, &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("\nLight State: %s\n",State_Machine[current_state].light_status);
}
}

void Init_State_Machine()
{

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);
}
void Gear_up()
{
current_state = Gear_Up;
printf("\n Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("\n Enter the Pilot's lever Position ");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever == Falling)
{
current_state=Check_Before_Landing;
printf("\n Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("\nLight Status: %s\n",State_Machine[current_state].light_status);
printf("\nHydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump);
}
}
static void (*state_table[])(void) = {Gear_down,Checking_Before_Takeoff, Raising_gear, Gear_up, Checking_Before_Landing, Lowering_gear};

int main()
{
Init_State_Machine();
while(1)
{
state_table[current_state]();
}
}

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.