Challenge

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

#include <stdio.h>
//fucntion prototypes
void gearup();
void cbt();
void raisinggear();
void geardown();
void cbl();
void loweringgear(); //

//Declaring Stages in state machines
typedef enum states{
GEAR_DOWN,//0
CHECK_TAKEOFF,//1
RAISING_GEAR,//2
GEAR_UP,//3
CHECK_LANDING,//4
LOWERING_GEAR,//5
}stages;//alias name for enum states
//Declaring switch values
typedef enum switch1{
OFF,//open(0))
ON,//close(1)
}switch_state;//alias name
//Declaring pilotlever values
typedef enum pilotlever{
RAISING,//0
FALLING,//1
UP,//2
DOWN,//3
}lever;//alias name
//Declaring hydraulic values
typedef enum hydraulic{
LOW,
HIGH,
}direction;//alais names
static volatile switch_state squat,limit;//declaring variables
static volatile lever PL;//declaring variables
static volatile direction HL;//declaring variables
static volatile stages Current_state;//declaring variables
//Declaring structure with Members
typedef struct{
char* Currentstate;// character array=string
char* light;//
char* hydrauliccontrol;//
char* direction;//
}values;
static void (*state_table[])(void)={geardown,cbt,raisinggear,gearup,cbl,loweringgear};//fucntion pointer wit harguments and values
static values state_machine[6]={//declaring values for structure array
{"GearDown","Green","Enabled","Down"},
{"Checkingbefore takeoff","Green","Enabled","Down"},
{"Raising Gear","Red","Enabled","UP"},
{"Gearup","off","Disabled","NULL"},
{"Checking before landing","Red","Down","Enabled"},
{"Loweringgear","Green","Down","Enabled"}
};
int main()
{
Current_state=GEAR_DOWN;//initialising current state with GEAR_DOWN(0)
while(1){
state_table[Current_state]();//function call
}
return 0;
}
//function defintion for geardown
void geardown(){
Current_state=GEAR_DOWN;
printf("Enter the values of Pilotlever and squatswitch \n");
fflush(stdout);
scanf("%d%d",&PL,&squat);//reading values from user
if(PL== RAISING && squat ==ON){//checking condition
Current_state=CHECK_TAKEOFF;
printf("currentstate:%s ,light:%s ,hydrauliccontrol:%s ,direction:%s \n",state_machine[Current_state].Currentstate,state_machine[Current_state].light,state_machine[Current_state].hydrauliccontrol,state_machine[Current_state].direction);
//printing values to the console
}
else{
geardown();//fucntion call
}
}
//function definition for check before takeoff
void cbt(){
Current_state=CHECK_TAKEOFF;//assigning current_state value
printf("Enter the values of Pilotlever,squat switch and Hydraulic level\n ");
fflush(stdout);
scanf("%d %d %d",&PL,&squat,&HL);//reading user inputs
if(squat==OFF && PL==FALLING){//check for confition
Current_state = GEAR_DOWN;
printf("currentstate:%s ,light:%s ,hydrauliccontrol:%s ,direcction:%s \n",state_machine[Current_state].Currentstate,state_machine[Current_state].light,state_machine[Current_state].hydrauliccontrol,state_machine[Current_state].direction);
//print elements into console
}else if(PL== UP && HL== LOW){ //else check conditin
Current_state=RAISING_GEAR;//assigning current state value
printf("currentstate:%s ,light:%s ,hydrauliccontrol:%s ,direcction:%s \n",state_machine[Current_state].Currentstate,state_machine[Current_state].light,state_machine[Current_state].hydrauliccontrol,state_machine[Current_state].direction);
//print elements into console
}else{
cbt();//fucntion call
}

}
//function definition for raisinggear
void raisinggear(){
Current_state=RAISING_GEAR;//assigning value
printf("Enter the values of Pilotlever and Limit switch\n");
fflush(stdout);
scanf("%d %d",&PL,&limit);//read users inputs
if(limit == OFF){//check condition for gearup state
Current_state=GEAR_UP;
printf("currentstate:%s ,light:%s ,hydrauliccontrol:%s ,direcction:%s \n",state_machine[Current_state].Currentstate,state_machine[Current_state].light,state_machine[Current_state].hydrauliccontrol,state_machine[Current_state].direction);

}else if(PL==FALLING){//check condition for falling state
Current_state=CHECK_LANDING;
printf("currentstate:%s ,light:%s ,hydrauliccontrol:%s ,direcction:%s \n",state_machine[Current_state].Currentstate,state_machine[Current_state].light,state_machine[Current_state].hydrauliccontrol,state_machine[Current_state].direction);

}else{
raisinggear();//fucntion call
}
}
//function definition for gearup
void gearup(){
Current_state=GEAR_UP;//assignning value
printf("Enter the value of Pilotlever\n");
fflush(stdout);
scanf("%d",&PL);
if(PL==FALLING){//check condition for check landing
Current_state=CHECK_LANDING;
printf("currentstate:%s ,light:%s ,hydrauliccontrol:%s ,direcction:%s \n",state_machine[Current_state].Currentstate,state_machine[Current_state].light,state_machine[Current_state].hydrauliccontrol,state_machine[Current_state].direction);
}else{
gearup();//fucntion call
}
}
//fucntion definition for check before landing
void cbl(){
Current_state=CHECK_LANDING;//assigning value
printf("Enter the value of Pilotlever\n");
fflush(stdout);
scanf("%d",&PL);
if(PL==DOWN){//check condition for lowering gear
Current_state=LOWERING_GEAR;
printf("currentstate:%s ,light:%s ,hydrauliccontrol:%s ,direcction:%s \n",state_machine[Current_state].Currentstate,state_machine[Current_state].light,state_machine[Current_state].hydrauliccontrol,state_machine[Current_state].direction);
}else{
cbl();//fucntion call
}

}
//fucntion definition for loweringgear
void loweringgear(){
Current_state=LOWERING_GEAR;//assigning value
printf("Enter the values of Pilotlever and Limit switch\n");
fflush(stdout);
scanf("%d %d",&PL,&limit);
if(limit==ON){//check condition for geardown
Current_state=GEAR_DOWN;//assigning value
printf("currentstate:%s ,light:%s ,hydrauliccontrol:%s ,direcction:%s \n",state_machine[Current_state].Currentstate,state_machine[Current_state].light,state_machine[Current_state].hydrauliccontrol,state_machine[Current_state].direction);
}else if(PL==RAISING){//check condition for takeoff
Current_state=CHECK_TAKEOFF;//assigning value
printf("currentstate:%s ,light:%s ,hydrauliccontrol:%s ,direcction:%s \n",state_machine[Current_state].Currentstate,state_machine[Current_state].light,state_machine[Current_state].hydrauliccontrol,state_machine[Current_state].direction);

}else{
loweringgear();//function call
}
}

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.