Challenge

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

#include<stdio.h>

typedef enum State
{


GR_DWN,
CHK_BFR_TKFF,
RSING_GR,
GR_UP,
CHK_BFR_LND,
LWRNG_GR
}State_Type;

typedef enum Switch
{
Open,
Close
}Switch_Status;

typedef enum Pilot_Lever
{
Raising,
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* direction_value_status;
char* hydraulic_pump_control_status;
char* gas_pressurized_spring_status[2];
}State_Table;

static 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"}
}
};

static void (*state_table[])(void)= {GearDown, CheckingBeforeTakeoff, RaisingGear, GearUp, CheckingBeforeLanding, LoweringGear};

int main()
{
Init_State_machine();
while(1)
{
state_table[current_state]();
}
}
void GearDown(void)
{
current_state = GR_DWN;
printf("\n Enter the Pilot's Lever Position and Squat Switch Status:");
fflush(stdout);
scanf("%d %d",&pilot_lever,&squat_switch);

if (pilot_lever == Raising && squat_switch == Open)
{
current_state = CHK_BFR_TKFF;
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
{
GearDown();
}
}
void CheckingBeforeTakeoff(void)
{
current_state = CHK_BFR_TKFF;
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);
printf("\n Wait for 2 secs\n");
if(pilot_lever == Falling || squat_switch == Close)
{
GearDown();
}
else if (pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Working)
{
current_state = RSING_GR;
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 Value Status:%s\n\n",State_Machine[current_state].direction_value_status);
}
else if (pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Malfunctioning)
{
printf("Light Status:%s\n",State_Machine[current_state].light_Status);
printf("Direction Value Status:%s\n",State_Machine[current_state].direction_value_status);
printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}
}
void RaisingGear(void)
{
current_state = RSING_GR;
printf("\n Enter the Limit Switch Status, Pilot's Lever Position :");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
printf("\nWait for 1 sec\n");
if(pilot_lever == Falling && limit_switch == Open)
{
current_state = CHK_BFR_LND;
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 = GR_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
{
RaisingGear();
}
}
void GearUp(void)
{
current_state = GR_UP;
printf("\n Enter the Pilot's Lever Position:");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever ==Falling)
{
current_state = CHK_BFR_LND;
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
{
GearUp();
}
}
void CheckingBeforeLanding(void)
{
current_state = CHK_BFR_LND;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("\nEnter 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 = LWRNG_GR;
printf("\nCurrent 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_value_status);
}
else if(pilot_lever == DOWN && hydraulic_mechanism == Malfunctioning)
{
current_state = LWRNG_GR;
printf("\nCurrent 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_value_status);
printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}

if(pilot_lever == (UP || Raising || Falling))
{
CheckingBeforeLanding();
}
}
void LoweringGear(void)
{
current_state = LWRNG_GR;
printf("\n Enter the Limit_Switch Status,Pilot_Lever Status ::");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
if(limit_switch == Close && pilot_lever == Raising)
{
current_state = CHK_BFR_TKFF;
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 = GR_DWN;
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
{
LoweringGear();
}
}

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.