Challenge

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

LIVE BATCH (PREETI)

#include
#include
void Gear_Down();
void Check_before_Takeoff();
void Raising_Gear();
void Gear_Up();
void Check_before_Landing();
void Lowering_Gear();
//These are the function we're going to implemwnt in this program
typedef enum
{
GEAR_DOWN,
CHECK_BEFORE_TAKEOFF,
RAISING_GEAR,
GEAR_UP,
CHECK_BEFORE_LANDING,
LOWERING_GEAR
}State_Type;

//squat switch conditions
typedef enum
{
Open,
Close
}Switch;

typedef enum
{
Rising,
Falling,

}Pilot_lever;

typedef enum
{
Working,
Not_Working
}Hydraulic_Mechanism;

static volatile Switch Squat;
static volatile Switch Limit;
static volatile Pilot_lever Pilevel;
static volatile Hydraulic_Mechanism Hymech;

State_Type Current_State;

typedef struct{
char* Current_State;
char* Light;
char* Direction_valve;
char* Hydraulic_control;
} State;
//Array of function pointer
static void(*State_Table[])(void)={Gear_Down,Check_before_Takeoff,Raising_Gear,Gear_Up,Check_before_Landing,Lowering_Gear};

static State State_Machine[6]={{"Gear_Down","Green","Down","Enabled"},
{"Check_before_Takeoff","Green","Down","Enabled"},
{"Raising_Gear","Red","Up","Enabled"},
{"Gear_Up","Close","Null","Disabled"},
{"Check_before_Landing","Red","Down","Enabled"},
{"Lowering_Gear","Green","Down","Enabled"}

};
int main()//Main function
{
while(1)
{
State_Table[Current_State]();
}
}
//Gear down State
void Gear_Down()
{
Current_State=GEAR_DOWN;
printf("\n Enter the status of Pilevel and Squat:");
fflush(stdout);
scanf("%d %d", &Pilevel, &Squat);
if(Pilevel==Rising && Squat==Open) // if this condition satisfies the state changes to next state
{
Current_State=CHECK_BEFORE_TAKEOFF;
printf("\n %s",State_Machine[Current_State].Current_State);
printf("\n %s",State_Machine[Current_State].Light);
printf("\n %s",State_Machine[Current_State].Direction_valve);
printf("\n %s",State_Machine[Current_State].Hydraulic_control);

}
else
{
Gear_Down();
}
}
// Cheak before takeoff State
void Check_before_Takeoff()

{
Current_State=CHECK_BEFORE_TAKEOFF;
printf("\n Enter the status of Pilevel,Squat and Hymech:");
fflush(stdout);
scanf("%d %d %d",&Pilevel,&Squat,&Hymech);
if(Pilevel==Falling && Squat==Close) //if this condition satisfies the state changes to previous state
{
Current_State=GEAR_DOWN;
printf("\n %s",State_Machine[Current_State].Current_State);
printf("\n %s",State_Machine[Current_State].Light);
printf("\n %s",State_Machine[Current_State].Direction_valve);
printf("\n %s",State_Machine[Current_State].Hydraulic_control);
}
if(Pilevel==Rising && Hymech==Wor0king)
{
Current_State=RAISING_GEAR;//if this condition satisfies the state changes to next state
printf("\n %s",State_Machine[Current_State].Current_State);
printf("\n %s",State_Machine[Current_State].Light);
printf("\n %s",State_Machine[Current_State].Direction_valve);
printf("\n %s",State_Machine[Current_State].Hydraulic_control);
}
else
{
Check_before_Takeoff();
}
}
//Raising gear State
void Raising_Gear()
{
Current_State=RAISING_GEAR;
printf("\n Enter the status of Pilevel and Limit switch:");
fflush(stdout);
scanf("%d %d",&Pilevel,&Limit);
if(Pilevel==Falling)//if this condition satisfies the state changes to next state
{
Current_State=CHECK_BEFORE_LANDING;
printf("\n %s",State_Machine[Current_State].Current_State);
printf("\n %s",State_Machine[Current_State].Light);
printf("\n %s",State_Machine[Current_State].Direction_valve);
printf("\n %s",State_Machine[Current_State].Hydraulic_control);
}
if(Limit==Close)//if this condition satisfies the state changes to next state
{
Current_State=GEAR_UP;
printf("\n %s",State_Machine[Current_State].Current_State);
printf("\n %s",State_Machine[Current_State].Light);
printf("\n %s",State_Machine[Current_State].Direction_valve);
printf("\n %s",State_Machine[Current_State].Hydraulic_control);
}
}
//gear up State
void Gear_Up()
{
Current_State=GEAR_UP;
printf("\n Enter the status of Pilevel:");
fflush(stdout);
scanf("%d",&Pilevel);
if(Pilevel==Falling)//if this condition satisfies the state changes to next state
{
Current_State=CHECK_BEFORE_LANDING;
printf("\n %s",State_Machine[Current_State].Current_State);
printf("\n %s",State_Machine[Current_State].Light);
printf("\n %s",State_Machine[Current_State].Direction_valve);
printf("\n %s",State_Machine[Current_State].Hydraulic_control);
}
else
{
Gear_Up();
}
}
//check before landing State
void Check_before_Landing()

{
Current_State=CHECK_BEFORE_LANDING;
printf("\n Enter the status of Pilevel and Hymech:");
fflush(stdout);
scanf("%d,%d",&Pilevel,&Hymech);
if(Pilevel==Falling||Hymech==Not_Working)//if this condition satisfies the state changes to next state
{
Current_State=LOWERING_GEAR;
printf("\n %s",State_Machine[Current_State].Current_State);
printf("\n %s",State_Machine[Current_State].Light);
printf("\n %s",State_Machine[Current_State].Direction_valve);
printf("\n %s",State_Machine[Current_State].Hydraulic_control);
}
else
{
Check_before_Landing();
}
}
//Lowering gear State
void Lowering_Gear()
{
Current_State=LOWERING_GEAR;
printf("\n Enter the status of Squat and Pilevel: ");
fflush(stdout);
scanf("%d %d",&Squat,&Pilevel);//if this condition satisfies the state changes to next state
if(Squat==Close)
{
Current_State=GEAR_DOWN;
printf("\n %s",State_Machine[Current_State].Current_State);
printf("\n %s",State_Machine[Current_State].Light);
printf("\n %s",State_Machine[Current_State].Direction_valve);
printf("\n %s",State_Machine[Current_State].Hydraulic_control);
}
if(Pilevel==Rising)//if this condition satisfies the state changes to next state
{
Current_State=CHECK_BEFORE_TAKEOFF;
printf("\n %s",State_Machine[Current_State].Current_State);
printf("\n %s",State_Machine[Current_State].Light);
printf("\n %s",State_Machine[Current_State].Direction_valve);
printf("\n %s",State_Machine[Current_State].Hydraulic_control);
}
else
{
Lowering_Gear();
}
}

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.