Challenge

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

project-2

project.c file:

// header files
#include<stdio.h>
#include<string.h>
#include"project.h" // custom header file

// fuction declaring
static void (*state_type[])(void)=
{
GearDown,
Checkingbeforetakeoff,
Raisinggear,
GearUp,
Checkingbeforelanding,
Loweringgear,
};

// entry point
int main()
{
printf("\n Press 1 for {Raising,On,working ( hydraulic and gas pressured spring)}\n ");
printf("\n Press 0 for{ Falling,Off, Not working ( hydraulic and gas pressured spring)}\n");
Intiate_State_Machine();
while(1)
{
state_type[current_state]();
}

}

//Gear Down
void GearDown(void)
{
current_state = GEAR_DOWN;
printf("\n Enter the status of the pilot level and squat switch:");
fflush(stdout);
scanf("%d%d",&pilot_lever,&squat_switch);
if(pilot_lever == Raising && squat_switch == On)
{
current_state = CHECKING_BEFORE_TAKEOFF;
printf("\n Current State : %s",State_Machine[current_state].current_state_indication);
printf("\n Light is : %s",State_Machine[current_state].light);
}
else
{
GearDown();
}

}

//checking for take off

void Checkingbeforetakeoff(void)
{
current_state = CHECKING_BEFORE_TAKEOFF;
printf("\n Enter the status of the pilot level,squat switch and hydralic mechanism:");
fflush(stdout);
scanf("%d%d%d",&pilot_lever,&squat_switch,&hydraulic_machanism);
if(pilot_lever == Falling && squat_switch == Off)
{
GearDown();
}
else if(pilot_lever == Raising && squat_switch == On && hydraulic_machanism == Working)
{

for(int i=0;i<4;i++)

{
printf("\n time delay counting: %d",i);
}
current_state = RAISING_GEAR;
printf("\n Current State is : %s ",State_Machine[current_state].current_state_indication);
printf("\n light is : %s ",State_Machine[current_state].light);
printf("\n Direction value is %s ",State_Machine[current_state].direction_value_status);
printf("\n Hydraulic system is %s",State_Machine[current_state].landing_gear_hydralic_control);

}

else if (pilot_lever == Raising && squat_switch == On && hydraulic_machanism == Not_Working)
{
for(int i=0;i<4;i++)

{
printf("\n time delay counting: %d",i);
}
current_state = RAISING_GEAR;
printf("\n Current State is : %s ",State_Machine[current_state].current_state_indication);
printf("\n light is : %s ",State_Machine[current_state].light);
printf("\n Direction value is %s ",State_Machine[current_state].direction_value_status);
printf("\n Spring pressured system is %s",State_Machine[current_state].gas_pressured_spring_system_status);

}
else
{
Checkingbeforetakeoff();
}
}

//Raising Gear
void Raisinggear(void)
{
current_state = RAISING_GEAR;
printf("\n Enter the status of the pilot level and Limit switch:");
fflush(stdout);
scanf("%d%d",&pilot_lever,&limit_switch);
if (pilot_lever == Raising && limit_switch == Off )
{
current_state = GEAR_UP;
printf("\n Current State is : %s ",State_Machine[current_state].current_state_indication);
printf("\n light is : %s ",State_Machine[current_state].light);

}
else if (pilot_lever == Falling && limit_switch == On)
{
current_state = CHECKING_BEFORE_LANDING;
printf("\n Current State is : %s ",State_Machine[current_state].current_state_indication);
printf("\n light is : %s ",State_Machine[current_state].light);
printf("\n Direction value is %s ",State_Machine[current_state].direction_value_status);

}
else
{
Raisinggear();
}
}

// grear up
void GearUp(void)
{
current_state = GEAR_UP;
printf("\n Enter the status of the pilot level:");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever == Falling)
{
current_state = CHECKING_BEFORE_LANDING;
printf("\n Current State is : %s ",State_Machine[current_state].current_state_indication);
printf("\n light is : %s ",State_Machine[current_state].light);
printf("\n Direction value is %s ",State_Machine[current_state].direction_value_status);
}
else
{
GearUp();
}
}

//checking before landing
void Checkingbeforelanding(void)
{
current_state = CHECKING_BEFORE_LANDING;
printf("\n Enter the status of the pilot level Hydraulic system staus:");
fflush(stdout);
scanf("%d%d",&pilot_lever,&hydraulic_machanism);
if(pilot_lever == Falling && hydraulic_machanism == Working)
{
current_state = LOWERING_GEAR;
printf("\n Current State is : %s ",State_Machine[current_state].current_state_indication);
printf("\n light is : %s ",State_Machine[current_state].light);
printf("\n Direction value is %s ",State_Machine[current_state].direction_value_status);
printf("\n Hydraulic system is %s",State_Machine[current_state].landing_gear_hydralic_control);

}
else if (pilot_lever == Falling && hydraulic_machanism == Not_Working)
{
current_state = LOWERING_GEAR;
printf("\n Current State is : %s ",State_Machine[current_state].current_state_indication);
printf("\n light is : %s ",State_Machine[current_state].light);
printf("\n Direction value is %s ",State_Machine[current_state].direction_value_status);
printf("\n Spring pressured system is %s",State_Machine[current_state].gas_pressured_spring_system_status);

}
else
{
Checkingbeforelanding();
}

}

// lowering gear

void Loweringgear()
{
current_state = LOWERING_GEAR;
printf("\n Enter the status of the pilot level and Limit switch:");
fflush(stdout);
scanf("%d%d",&pilot_lever,&limit_switch);
if (pilot_lever == Raising && limit_switch == On)
{
current_state = CHECKING_BEFORE_TAKEOFF;
printf("\n Current State : %s",State_Machine[current_state].current_state_indication);
printf("\n Light is : %s",State_Machine[current_state].light);

}
else if (pilot_lever == Falling && limit_switch == Off)
{
current_state = GEAR_DOWN;
printf("\n Current State : %s",State_Machine[current_state].current_state_indication);
printf("\n Light is : %s",State_Machine[current_state].light);

}
else
{
Loweringgear();
}
}

// Initiate state machine
void Intiate_State_Machine(void)
{
current_state = GEAR_DOWN;
printf("\n Finiate state Machine is initialize \n");
printf("\n Current State : %s",State_Machine[current_state].current_state_indication);
printf("\n Light is : %s",State_Machine[current_state].light);
}

project.h file

#ifndef PROJECT_H_
#define PROJECT_H_

#include<stdio.h>
#include<string.h>


// fuction calls
void Intiate_State_Machine();
void GearDown();
void Checkingbeforetakeoff();
void Raisinggear();
void Loweringgear();
void Checkingbeforelanding();
void GearUp();

// declaring the state of the landing gear
typedef enum state
{
GEAR_DOWN,
CHECKING_BEFORE_TAKEOFF,
RAISING_GEAR,
GEAR_UP,
CHECKING_BEFORE_LANDING,
LOWERING_GEAR
}State_type;

// declaring the switch position of the squat switch and limit switch
typedef enum Switch
{
Off,
On
}Switch_state;

// declaring the pilot input
typedef enum Pilot_lever
{
Falling,
Raising

}Pilot_lever;

//declaring the state of the hydraulic mechanism
typedef enum Hydraulic_mechanism
{
Not_Working,
Working

}Hydraulic_mechanism;

// declairng the variables
static volatile Switch_state squat_switch;
static volatile Switch_state limit_switch;
static volatile Pilot_lever pilot_lever;
static volatile Hydraulic_mechanism hydraulic_machanism;

State_type current_state; // declaring the current state

// declaring the table format
typedef struct
{
char* current_state_indication;
char* light;
char* direction_value_status;
char* landing_gear_hydralic_control;
char* gas_pressured_spring_system_status;

}state_table;

static state_table State_Machine[6]=
{
{"Gear Down","Green","Down","Null","Null"},
{"Checking before take off","Green","Down","Enable","Enable"},
{"Raising Gear","Red","Up","Enable","Enable"},
{"Gear Up","Off","Disable","Null","Null"},
{"Checking before landing","Red","Down","Enable","Enable"},
{"Lowering gear","Red","Down","Enable","Enable"}

};


#endif /* PROJECT_H_ */

note: the c file and header files are attached to the it with the screenshot of the output.

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.