Challenge

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

(offline)

#include <stdio.h>
#include<string.h>
typedef enum {
geardown,
checking_before_takeoff,
rising_gear,
gear_up,
checking_before_landing,
loweringgear
}state_type;//naming the enum
typedef enum {
close,
open
}Switch;
typedef enum {
lowering,
rising

}Lever;//naming the enum

static volatile Switch jet;//using the enum as datatype
static volatile Lever sec;
state_type current_state;

void init_state_machine()
{
current_state=geardown;
char light[100]="green";//giving output to print output
printf("the position of the gear is %s\n",light);


}
void Gear_down()
{
current_state=geardown;
printf("pilot_lever and squat_switch:");
scanf("%d\n %d",&jet,&sec);
if(jet==rising&&sec==open){//condition checking two at a time
char light[100]="Green";//giving output to print output
char sec[100]="Open";//giving output to print output
printf("light:%s\n",light);
printf("sswitch:%s",sec);
current_state=checking_before_takeoff;
}
if(jet==lowering&&sec==close){
char light[100]="Red";//giving output to print output
//char light[100]="Red";
char sec[100]="Close";//giving output to print output
printf("light:%s\n",light);
printf("sswitch:%s",sec);
current_state=geardown;

}

}
void Checking_Before_take_off(){
current_state=checking_before_takeoff;
printf("\npilot_lever and squat_switch:");
scanf("%d\n %d",&jet, &sec);
if(jet==rising&&sec==close){//condition checking two at a time
char light[100]="Red";//giving output to print output
char sec[100]="Closed";//giving output to print output
printf("light:%s\n",light);
printf("sswitch:%s",sec);
current_state=rising_gear;
}




}
void Rising_gear(){
current_state=rising_gear;
printf("\npilot_lever and squat_switch:");
scanf("%d\n %d",&jet, &sec);
if(jet==rising&&sec==close){//condition checking two at a time
char light[100]="Off";//giving output to print output
char sec[100]="Closed";//giving output to print output
printf("light:%s\n",light);
printf("sswitch:%s",sec);
current_state=gear_up;
}
if(jet==lowering&&sec==close){
char light[100]="Red";//giving output to print output
char sec[100]="Closed";//giving output to print output
printf("light:%s\n",light);
printf("sswitch:%s",sec);
current_state=checking_before_landing;

}
}
void Gear_up(){
current_state=gear_up;
printf("\npilot_lever and squat_switch:");
scanf("%d\n %d",&jet, &sec);
if(jet==lowering&&sec==close){//condition checking two at a time
char light[100]="Red";//giving output to print output
char sec[100]="Closed";
printf("light:%s\n",light);
printf("Switch:%s",sec);
current_state=checking_before_landing;
}
}
void Checking_before_landing(){
current_state=checking_before_landing;
printf("\npilot_lever and squat_switch:");
scanf("%d\n %d",&jet, &sec);
if(jet==lowering&&sec==close){//condition checking two at a time
char light[100]="Red";//giving output to print output
char sec[100]="Closed";//giving output to print output
printf("light:%s\n",light);
printf("sswitch:%s",sec);
current_state=loweringgear;
}

}
void Lowering_gear(){
current_state=loweringgear;
printf("\npilot_lever and squat_switch:");
scanf("%d\n %d",&jet, &sec);
if(jet==rising&&sec==open){//condition checking two at a time
char light[100]="Green";
char sec[100]="Opened";
printf("light:%s\n",light);
printf("sswitch:%s",sec);
current_state=geardown;
}
if(jet==rising&&sec==open){
char light[100]="Red";//giving output to print output
char squat_switch[100]="Opened";//giving output to print output
printf("light:%s\n",light);
printf("sswitch:%s",squat_switch);
current_state=checking_before_takeoff;
}


}
static void(*state_table[])(void)={Gear_down,Checking_Before_take_off,Rising_gear,Gear_up,Checking_before_landing,
Lowering_gear,};//here we mentioning in small letters to calling
//functions
int main()
{
init_state_machine();
while(1){
state_table[current_state]();

}
return 0;

}

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.