Challenge

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

plane.h:


#ifndef PLANE_H_
#define PLANE_H_
//function calling for state types
void ini_state_machine();
void gearDown();
void checking_bfr_takeoff();
void raisingGear();
void gearUp();
void checking_bfr_landing();
void loweringGear();
typedef enum State //user define data type
{
gr_dwn,chk_bfr_tkf,rai_gr,gr_up,chk_bfr_land,lwr_gr
}State_type; //object
typedef enum Switch
{
open,close
}Switch_status;
typedef enum Pilot_lever
{
rising,falling,up,down
}Pilot_lever_status;
typedef enum Hydra_mechanism
{
working,malfunction
}hydra_mechanism_status;
static Switch_status squat_switch; //declare a variable with userdefine data type
static Switch_status limit_switch;
static Pilot_lever_status pilot_lvr;
hydra_mechanism_status hydralic_mech;
State_type current_state;
typedef struct //creating a structure
{
char* current_state_indication; //calling the status of the struct//
char* light_Status;
char* direction_value_status;
char* hydraulic_pump_control_status;
char* gas_pressurized_spring_status[2];
}State_table; //object
static State_table State_Machine[6] = { //calling the state_ Table//
{"GearDown","Green","Down","Enabled",{"disbled","disabled"}},
{"Checking Before Take Off ","Green","Down","Enabled",{"disbled","disabled"}},
{"Raising Gear","Red","Up","Enabled",{"Disabled","Enabled"}},
{"Gear Up","Off","Null","Disabled",{"disbled","disabled"}},
{"Checking Before Landing","Red","Down","Enabled",{"disbled","disabled"}},
{"Lowering Gear","Green","Down","Enabled",{"Disabled","Enabled"}}
};
#endif /* PLANE_H_ */

plane.c:

#include<stdio.h>
#include"plane.h"
void ini_state_machine() //func definations
{
current_state = gr_dwn; //In GEAR_DOWN light =GREEN//
printf("\n Gear_Down State & Light_Status : %s\n",State_Machine[current_state].light_Status);

}
void gearDown() //fun defination
{
current_state = gr_dwn; //gear down starts//
printf("\n Enter the Pilot's Lever Position and Squat Switch Status:");
fflush(stdout);
scanf("%d %d",&pilot_lvr,&squat_switch);

if (pilot_lvr == rising && squat_switch == open) //condition for checking next state
{
current_state = chk_bfr_tkf;
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 checking_bfr_takeoff()
{
current_state = chk_bfr_tkf;
printf("\n Enter the Pilot's Lever Position,Squat Switch Status and Hydraulic Mechanism Status:");//console//
fflush(stdout);
scanf("%d %d %d",&pilot_lvr,&squat_switch,&hydralic_mech);//reads the address//
printf("\n Wait for 2 secs\n");
if(pilot_lvr == falling || squat_switch == close)
{
gearDown();
}
else if (pilot_lvr == up&& squat_switch == open && hydralic_mech == working)
{ //chk_bfr_tkf= up(2),squat_switch=(0) and working=(0)//
current_state = rai_gr;
printf(" 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_lvr == up && squat_switch == open && hydralic_mech == malfunction)
{ //chk_bfr_tkf= up(2),squat_switch=(0) and working=(1)//
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[hydralic_mech]);
}
}
void raisingGear()
{
current_state = rai_gr;
printf("\n Enter the Limit Switch Status, Pilot's Lever Position :");// enter the console of t limt switch and pilot lever posistions//
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lvr); // read the address//
printf("\nWait for 1 sec\n");
if(pilot_lvr == falling && limit_switch == open) //if statment will starts//
{
current_state =chk_bfr_land;
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_lvr == up) //chk_bfr_lnd= close(1) and pilot_lever =(2)//
{
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()
{
current_state = gr_up;
printf("\n Enter the Pilot's Lever Position:"); //enter the cosole pilot lever position//
fflush(stdout);
scanf("%d",&pilot_lvr); //reads the address//
if(pilot_lvr ==falling) // if statement will starts// //pilot_lever == falling means "1"//
{
current_state = chk_bfr_land;
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 checking_bfr_landing()
{
current_state = chk_bfr_land;
printf("\nCurrent State : %s\n",State_Machine[current_state].current_state_indication);
printf("\nEnter the Pilot's Lever Position and Status of Hydraulic Mechanism:"); // print the console//
fflush(stdout);
scanf("%d %d",&pilot_lvr,&hydralic_mech); //reads the address//
if(pilot_lvr == down&& hydralic_mech== working)
{
current_state = lwr_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_lvr == down && hydralic_mech == malfunction) // pilot_ lever= down(3)and hydr_mech=malfun(1)//
{
current_state = lwr_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[hydralic_mech]);
}

if(pilot_lvr == (up || rising || falling))
{
checking_bfr_landing();
}
}
void loweringGear()
{
current_state = lwr_gr;
printf("\n Enter the Limit_Switch Status,Pilot_Lever Status ::"); //enter the console//
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lvr); //reads the address//
if( limit_switch == close && pilot_lvr == rising) // limit_switch =close(1) and pilot__ lever=rising(0)//

{
current_state = chk_bfr_tkf;
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_lvr == 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();
}
}

main.c:


#include <stdio.h> //header//
#include "plane.h" //header//

static void (*state_table[])(void) = { gearDown, checking_bfr_takeoff,raisingGear,gearUp,
checking_bfr_landing,loweringGear}; //inputs based some condition//
int main()
{
ini_state_machine(); //while loop start hear//
while(1)
{
state_table[current_state]();
}
}

makefile:

all main.c plane.c plane.h
gcc main.c plane.c plane.h -o make I.

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.