Challenge

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

CODE

gears.h

#ifndef GEARS_H_
#define GEARS_H_
//preprocessor directive
#include<stdio.h>
//function declaration
void Initiate_State_Machine();
void GearDown();
void CheckingBeforeTakeOFF();
void RaisingGear();
void GearUp();
void CheckBeforeLanding();
void LoweringGear();
//enum for State_Type
static void(*statetable[])(void)={GearDown, CheckingBeforeTakeOFF, RaisingGear, GearUp, CheckBeforeLanding, LoweringGear};
typedef enum State
{
GEAR_DOWN,
CHECKING_BEFORE_TAKEOFF,
RAISING_GEAR,
GEAR_UP,
CHECK_BEFORE_LANDING,
LOWERING_GEAR,
}State_Type;
//enum for Switch_status
typedef enum Switch
{
on,
off//plane is on groung
}Switch_status;
//enum for pilot_lever
typedef enum pilot_lever
{
Raising,
falling
}pilot_lever;
//enum for hydraulic_mechanism
typedef enum hydraulic_mechanism
{
working,
not_working
}hydraulic_mechanism;
//Declaring variables as static volatile for Switch_status,pilot_lever,hydraulic_mechanism
static volatile Switch_status squat_switch;
static volatile Switch_status limit_switch;
static volatile pilot_lever pl;
static volatile hydraulic_mechanism hm;
//Declaring a variable to access State_type
State_Type current_state;
//structure for State_Table
typedef struct
{
char* current_state_indication;
char* light;
char* direction_valve_status;
char* landing_gear_hydraulic_control;
char* Gas_Pressurized_Spring_system_status[2];
}State_Table;
static State_Table State_Machine[6]={{"GearDown","Green","Down","Enabled",{NULL,NULL}},
{"CheckingBeforeTakeOFF","Green","Down","Enabled",{NULL,NULL}},
{"RaisingGear","Red","Up","Enabled",{NULL,NULL}},
{"GearUp","Off","NULL","Disbled",{NULL,NULL}},
{"CheckBeforeLanding","Red","Down","Enabled",{NULL,NULL}},
{"LoweringGear","Green","Down","Enabled",{"Disabled","Enabled"}}};
#endif /* GEARS_H_ */

project_2.c

#include"gears.h" //calling header file
int main()
{
Initiate_State_Machine();//function call
while(1)
{
statetable[current_state]();
}
}

gear_down.c

#include"gears.h" //calling header file
int main()
{
Initiate_State_Machine();//function call
while(1)
{
statetable[current_state]();
}
}

check_before_takeoff.c

#include"gears.h"
void CheckingBeforeTakeOFF(void) //function defenition
{
current_state=CHECKING_BEFORE_TAKEOFF;//enum=CHECKING_BEFORE_TAKEOFF
printf("\nEnter the status of pilot's lever and squat switch and hydraulic mechanism:");
fflush(stdout);
scanf("%d %d",&pl,&squat_switch,&hm);//pl=0 and squat_switch=1
if(pl==falling && squat_switch==off)
{
GearDown();//function call for GearDown()
}
else if(pl==Raising && squat_switch==on && hm==working)
{
current_state=RAISING_GEAR;//enum=RAISING_GEAR
printf("\nCurrent State:%s",State_Machine[current_state].current_state_indication);
printf("\nLight is:%s",State_Machine[current_state].light);
printf("\nStatus of Direction valve:%s",State_Machine[current_state].direction_valve_status);
}
else if(pl==Raising && squat_switch==on && hm==not_working)
{
current_state=RAISING_GEAR; //enum=RAISING_GEAR
printf("\nCurrent State:%s",State_Machine[current_state].current_state_indication);
printf("\nLight is:%s",State_Machine[current_state].light);
printf("\nStatus of Direction valve:%s",State_Machine[current_state].direction_valve_status);
printf("\nStatus of gas pressurised Spring System:%s",State_Machine[current_state].Gas_Pressurized_Spring_system_status);
}
}

raising_gear.c

#include"gears.h"
void RaisingGear(void) //function definition
{
current_state=RAISING_GEAR;//enum=RAISING_GEAR
printf("\nEnter the status of pilot's lever and limit switch:");
fflush(stdout);
scanf("%d %d",&pl,&limit_switch);
if(pl==falling && limit_switch==on)
{
current_state=CHECK_BEFORE_LANDING;//enum=CHECK_BEFORE_LANDING
printf("\nCurrent State:%s",State_Machine[current_state].current_state_indication);
printf("\nLight is:%s",State_Machine[current_state].light);
printf("\nLanding Gear Hydraulic Control:%s",State_Machine[current_state].landing_gear_hydraulic_control);
}
else if(pl==Raising && limit_switch==off)
{
current_state=GEAR_UP;//enum=GEAR_UP
printf("\nCurrent State:%s",State_Machine[current_state].current_state_indication);
printf("\nLight is:%s",State_Machine[current_state].light);
printf("\nLanding Gear Hydraulic Control:%s",State_Machine[current_state].landing_gear_hydraulic_control);
}
else
{
RaisingGear();//function recall
}
}

gear_up.c

#include"gears.h"
void GearUp(void) //function definition
{
current_state=GEAR_UP;//enum=GEAR_UP
printf("\nEnter the status of pilot's lever:");
fflush(stdout);
scanf("%d",&pl);
if(pl==falling)
{
current_state=CHECK_BEFORE_LANDING;//enum=CHECK_BEFORE_LANDING
printf("\nCurrent State:%s",State_Machine[current_state].current_state_indication);
printf("\nLight is:%s",State_Machine[current_state].light);
printf("\nLanding Gear Hydraulic Control:%s",State_Machine[current_state].landing_gear_hydraulic_control);
}
else
{
GearUp();
}
}
check_before_landing.c
#include"gears.h"
void CheckBeforeLanding(void) //function definition
{
current_state=CHECK_BEFORE_LANDING;//enum=CHECK_BEFORE_LANDING
printf("\nEnter the status of pilot's lever and hydraulic mechanism status:");
fflush(stdout);
scanf("%d %d",&pl,&hm);
if(pl==falling && hm==working)
{
current_state=LOWERING_GEAR;//enum=LOWERING_GEAR
printf("\nCurrent State:%s",State_Machine[current_state].current_state_indication);
printf("\nLight is:%s",State_Machine[current_state].light);
printf("\nStatus of Direction valve:%s",State_Machine[current_state].direction_valve_status);
}
else if(pl==falling && hm==not_working)
{
current_state=LOWERING_GEAR;//enum=LOWERING_GEAR
printf("\nCurrent State:%s",State_Machine[current_state].current_state_indication);
printf("\nLight is:%s",State_Machine[current_state].light);
printf("\nStatus of Direction valve:%s",State_Machine[current_state].direction_valve_status);
printf("\nStatus of gas pressurised Spring System:%s",State_Machine[current_state].Gas_Pressurized_Spring_system_status);
}
else if(pl==(Raising))
{
CheckBeforeLanding();//function recall
}
}

lowering_gear.c

#include"gears.h"
void LoweringGear(void) //function definition
{
current_state=LOWERING_GEAR;//enum=LOWERING_GEAR
printf("Enter the status of pilot's lever and limit switch:");
fflush(stdout);
scanf("%d %d",&pl,&limit_switch);
if(pl==falling && limit_switch==on)
{
current_state=CHECKING_BEFORE_TAKEOFF;//enum=CHECK_BEFORE_LANDING
printf("Current State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light is:%s\n",State_Machine[current_state].light);
}
else if(pl==Raising && limit_switch==off)
{
current_state=GEAR_DOWN;//enum=GEAR_DOWN
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);
}
if(limit_switch==off)
{
LoweringGear();//function recall
}
}

state_machine.c

#include"gears.h"

void Initiate_State_Machine() //function definition
{
current_state==GEAR_DOWN; //enum=GEAR_DOWN
printf("The Finite State Machine is Intialized and current the program is in""GearDown State & Light is:%s\n",State_Machine[current_state].light);
}

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.