Challenge

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

OFFLINE EMBEDDED BATCH1

PROJECT 2:

#include<stdio.h>
//#include<stdlib.h>

//Declare the prototypes
void Init_State_Machine();
void GearDown();
void Check_Bef_Takeoff();
void RaisingGear();
void GearUp();
void Check_Bef_Landing();
void LoweringGear();

//Using user defined datatype
typedef enum State{
GEAR_DOWN,
CHECK_BEF_TAKEOFF,
RAISING_GEAR,
GEAR_UP,
CHECK_BEF_LANDING,
LOWERING_GEAR
}State_Type;

//Initialize the switch status with typedef
typedef enum Switch{
close,
open
}Switch_Status;

//Initialize the lever status with typedef
typedef enum Lever{
lowering,
rising
}Pilot_Lever;

//Initialize the hydraulic mechanism status with typedef
typedef enum Hydraulic{
working,
not_working
}Hydraulic_Mechanism;

static int squat_switch;
static int limit_switch;
static int pilot_lever;
static int hydraulic_mechanism;
State_Type current_state;

//Created the structure with members
typedef struct{
char* current_state_indication;
char* light;
char* direction_valve_status;
char* landing_gear_hydraulic_control;
char* gas_pressurised_spring_system_status;

}State;

//static State_Table;
State State_Machine[6]={
{{"geardown","geardown"},{"green","green"},{"down","down"},{"enabled","enabled"},{"NULL","NULL"}},
{{"check_bef_takeoff","check_bef_takeoff"},{"green","green"},{"down","down"},{"enabled","enabled"},{"NULL","NULL"}},
{{"raising_gear","raising_gear"},{"red","red"},{"up","up"},{"enabled","enabled"},{"disabled","enabled"}},
{{"gearup","gearup"},{"off","off"},{"NULL","NULL"},{"disabled","disabled"},{"NULL","NULL"}},
{{"check_bef_landing","check_bef_landing"},{"red","red"},{"down","down"},{"enabled","enabled"},{"NULL","NULL"}},
{{"lowering_gear","lowering_gear"},{"green","green"},{"down","down"},{"enabled","enabled"},{"disabled","enabled"}}
};

static void(*State_Table[])(void)={
GearDown,Check_Bef_Takeoff,RaisingGear,GearUp,Check_Bef_Landing,LoweringGear};

//main function
int main()
{
Init_State_Machine();
while(1)
State_Table[current_state]();
}

//Defined the Gear down
void GearDown(void)
{
current_state=GEAR_DOWN;
printf("Enter the status of pilot lever and squat switch : ");
scanf("%d %d",&pilot_lever,&squat_switch);
if(pilot_lever==rising && squat_switch==open)
{
current_state=CHECK_BEF_TAKEOFF;
printf("current state : %s\n",State_Machine[current_state].current_state_indication);
printf("light is : %s\n",State_Machine[current_state].light);
}
else
{
GearDown();
}
}

//Defined the Check_Bef_Takeoff
void Check_Bef_Takeoff(void)
{
current_state=CHECK_BEF_TAKEOFF;
printf("Enter the status of pilot lever and squat switch and hydraulic mechanism :");
scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);
if(pilot_lever==lowering && squat_switch==close && hydraulic_mechanism==not_working)
{
GearDown();
}
else if(pilot_lever==rising && squat_switch==open && 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==rising && squat_switch==open && 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_pressurised_spring_system_status);
}
}

//Defined the RaisingGear
void RaisingGear(void)
{
current_state=RAISING_GEAR;
printf("Enter the status of pilot lever and limit switch :");
scanf("%d %d",&pilot_lever,&limit_switch);
if(pilot_lever==lowering && limit_switch==open)
{
current_state=CHECK_BEF_LANDING;
printf("current state : %s\n",State_Machine[current_state].current_state_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==rising && limit_switch==close)
{
current_state=GEAR_UP;
printf("current state : %s\n",State_Machine[current_state].current_state_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();
}
}

//Defined the GearUp
void GearUp(void)
{
current_state=GEAR_UP;
printf("Enter the status of pilot lever :");
scanf("%d",&pilot_lever);
if(pilot_lever==lowering)
{
current_state=CHECK_BEF_LANDING;
printf("current state : %s\n",State_Machine[current_state].current_state_indication);
printf("light : %s\n",State_Machine[current_state].light);
printf("landing gear hydraulic control :%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
else
{
GearUp();
}
}

//Defined the Check_Bef_Landing
void Check_Bef_Landing(void)
{
current_state=CHECK_BEF_LANDING;
printf("Enter the status of pilot lever and hydraulic mechanism :");
scanf("%d %d",&pilot_lever,&hydraulic_mechanism);
if(pilot_lever==lowering && hydraulic_mechanism==working)
{
current_state=LOWERING_GEAR;
printf("current state :%s\n",State_Machine[current_state].current_state_indication);
printf("light : %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==lowering && squat_switch==open && hydraulic_mechanism==not_working)
{

current_state=LOWERING_GEAR;
printf("current state :%s\n",State_Machine[current_state].current_state_indication);
printf("light : %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_pressurised_spring_system_status);
}
if(pilot_lever==(rising||lowering))
{
Check_Bef_Landing();
}
}

//Defined the LoweringGear
void LoweringGear(void)
{
current_state=LOWERING_GEAR;
printf("Enter the status of pilot lever and limit switch :");
scanf("%d %d",&pilot_lever,&limit_switch);
if(pilot_lever==lowering && limit_switch==open)
{
current_state=CHECK_BEF_TAKEOFF;
printf("current state : %s\n",State_Machine[current_state].current_state_indication);
printf("light is :%s\n",State_Machine[current_state].light);
}
if(pilot_lever==rising && limit_switch==close)
{
current_state=GEAR_DOWN;
printf("current state : %s\n",State_Machine[current_state].current_state_indication);
printf("lightn 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==close)
{
LoweringGear();
}
}

//Defined the Init_State_Machine
void Init_State_Machine()
{
current_state=GEAR_DOWN;
printf("Current program is in %s state\n\n",State_Machine[current_state].current_state_indication);
}

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.