Challenge

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


#include
typedef enum
{
Geardown,
Checkingbeforetakingoff,
Raisinggear,
Loweringgear,
Checkingbeforelanding,
Gearup
}state;
typedef enum
{
open,
close
}Switch;
typedef enum
{
up,
down,
raising,
faling
}pilotlever;
//void checkingbeforelanding();
void geardown();
void checkingbeforetakingoff();
void raisinggear();
void loweringgear();
void checkingbeforelanding();
void gearup();
static volatile Switch squadswitch;
static volatile Switch limitswitch;
static volatile pilotlever rod;
static state currentstate;
typedef struct
{
char* currentstatus;
char* lightstatus;
char* directionvalvestatus;
}table;
static table state_machine[6]={
{
"gear down" ,"green","down"
},
{
"checkingbeforetakingoff","green","down"
},
{
"raisinggear","red","up"
},
{
"loweringgear","red","down"
},
{
"checkingbeforelanding","red","down"
},
{
"gearup","lightsareoff","null"
}
};
static void (*state_table[])(void)={geardown,checkingbeforetakingoff,raisinggear,loweringgear,checkingbeforelanding,gearup};
void geardown(){
printf("enter the values of pilot rod and squadswitch\n");
fflush(stdout);
scanf("%d %d",&rod,&squadswitch);
if(rod==raising&&squadswitch==open){
currentstate=Checkingbeforetakingoff;
printf("%s\n",state_machine[currentstate].currentstatus);
printf("%s\n",state_machine[currentstate].lightstatus);
printf("%s\n",state_machine[currentstate].directionvalvestatus);
}
else{
geardown();
}
}
void checkingbeforetakingoff(){
printf("enter the values of pilot rod and squdswitch\n");
fflush(stdout);
scanf("%d %d",&rod,&squadswitch);
if(rod==up||squadswitch==close){
currentstate=Raisinggear;
printf("%s\n",state_machine[currentstate].currentstatus);
printf("%s\n",state_machine[currentstate].lightstatus);
printf("%s\n",state_machine[currentstate].directionvalvestatus);
}
else
{
checkingbeforetakingoff();
}
}
void raisinggear(){
printf("enter the values of rod and squadswitch\n");
fflush(stdout);
scanf("%d %d",&rod,&squadswitch);
if(squadswitch==close){
currentstate=Gearup;
printf("%s\n",state_machine[currentstate].currentstatus);
printf("%s\n",state_machine[currentstate].lightstatus);
printf("%s\n",state_machine[currentstate].directionvalvestatus);
}
else if(rod==faling){
currentstate=Checkingbeforelanding;
printf("%s\n",state_machine[currentstate].currentstatus);
printf("%s\n",state_machine[currentstate].lightstatus);
printf("%s\n",state_machine[currentstate].directionvalvestatus);
}
else{
raisinggear();
}
}
void gearup(){
printf("enter the values of rod and squad switch\n");
fflush(stdout);
scanf("%d %d",&rod,&squadswitch);
if(rod==faling){
currentstate=Checkingbeforelanding;
printf("%s\n",state_machine[currentstate].currentstatus);
printf("%s\n",state_machine[currentstate].lightstatus);
printf("%s\n",state_machine[currentstate].directionvalvestatus);
}
else
{
gearup();
}
}
void checkingbeforelanding(){
printf("enter the values of rod and squad switch\n");
fflush(stdout);
scanf("%d %d",&rod,&squadswitch);
if(rod==down){
currentstate=Loweringgear;
printf("%s\n",state_machine[currentstate].currentstatus);
printf("%s\n",state_machine[currentstate].lightstatus);
printf("%s\n",state_machine[currentstate].directionvalvestatus);
}
else{
checkingbeforelanding();
}
}
void loweringgear(){
printf("enter the values of rod and squad switch");
fflush(stdout);
scanf("%d %d",&rod,&squadswitch);
if(squadswitch==open){
currentstate=Geardown;
printf("%s\n",state_machine[currentstate].currentstatus);
printf("%s\n",state_machine[currentstate].lightstatus);
printf("%s\n",state_machine[currentstate].directionvalvestatus);
}
else if(rod==raising){
currentstate=Geardown;
printf("%s\n",state_machine[currentstate].currentstatus);
printf("%s\n",state_machine[currentstate].lightstatus);
printf("%s\n",state_machine[currentstate].directionvalvestatus);
}
else{
loweringgear();
}
}
void init(){
currentstate=Geardown;
printf("the machine is in gear down state\n");
}
int main()
{
init();
while(1)
{
state_table[currentstate]();
}
}

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.