Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
p2)Implement the Code for controlling the retraction and extension of Airplane’s landing gear
#include <stdio.h>
#include<string.h>
typedef enum {
gear_down,
checking_before_take_off,
rising_gear,
gear_up,
checking_before_landing,
lowering_gear
//checking_before_landing,
//raising_gear
//checking_before_take_off,
//checking_before_landing
}state_type;//naming the enum
typedef enum {
close,
open
//close
}Switch;//naming the enum
//typedef enum Light{
//off,
//red,
//green
//}color;
typedef enum {
lowering,
rising
}Lever;//naming the enum
static volatile Switch Squat;//using the enum as datatype
//static volatile int Color;
static volatile Lever Pilot;//using the enum as datatype
state_type current_state;//using the enum as datatype
void init_state_machine()
{
current_state=gear_down;
char light[100]="green";//giving output to print output
printf("the position of the gear is %s\n",light);
}
void Gear_down()
{
current_state=gear_down;
printf("pilot_lever and squat_switch:");
scanf("%d\n %d",&Pilot,&Squat);
if(Pilot==rising&&Squat==open)
char pilot_lever[100]="Rising";//
char light[100]="Green";//giving output to print output
//pilot_lever[100]="Rising";
char squat_switch[100]="Open";//
printf("light:%s\n",light);
printf("pilot lever:%s\n", pilot_lever);
printf("squat_switch:%s",
current_state=checking_
}
if(Pilot==lowering&&Squat==
char light[100]="Red";//giving output to print output
char pilot_lever[100]="Lowering";//
//char light[100]="Red";
//char pilot_lever[100]="Rising";
char squat_switch[100]="Close";//
printf("light:%s\n",light);
printf("pilot_lever:%s\n",
printf("squat_switch:%s",
current_state=gear_down;
}
}
void Checking_Before_take_off(){
current_state=checking_
printf("\npilot_lever and squat_switch:");
scanf("%d\n %d",&Pilot, &Squat);
if(Pilot==rising&&Squat==
char light[100]="Red";//giving output to print output
char pilot_lever[100]="Rising";//
char squat_switch[100]="Open";//
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",
current_state=rising_gear;
}
}
void Rising_gear(){
current_state=rising_gear;
printf("\npilot_lever and squat_switch:");
scanf("%d\n %d",&Pilot, &Squat);
if(Pilot==lowering&&Squat==
char light[100]="Off";//giving output to print output
char pilot_lever[100]="Lowering";/
char squat_switch[100]="Closed";//
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",
current_state=gear_up;
}
if(Pilot==lowering&&Squat==
char light[100]="Red";//giving output to print output
char pilot_lever[100]="Lowering";/
char squat_switch[100]="Closed";//
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",
current_state=checking_
}
}
void Gear_up(){
current_state=gear_up;
printf("\npilot_lever and squat_switch:");
scanf("%d\n %d",&Pilot, &Squat);
if(Pilot==lowering&&Squat==
char light[100]="Red";//giving output to print output
char pilot_lever[100]="Lowering";/
char squat_switch[100]="Closed";//
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",
current_state=checking_
}
}
void Checking_before_landing(){
current_state=checking_
printf("\npilot_lever and squat_switch:");
scanf("%d\n %d",&Pilot, &Squat);
if(Pilot==lowering&&Squat==
char light[100]="Red";//giving output to print output
char pilot_lever[100]="Lowering";/
char squat_switch[100]="Closed";//
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",
current_state=lowering_gear;
}
}
void Lowering_gear(){
current_state=lowering_gear;
printf("\npilot_lever and squat_switch:");
scanf("%d\n %d",&Pilot, &Squat);
if(Pilot==rising&&Squat==open)
char light[100]="Green";//giving output to print output
char pilot_lever[100]="Rising";//
char squat_switch[100]="Opened";//
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",
current_state=gear_down;
}
if(Pilot==rising&&Squat==
char light[100]="Red";//giving output to print output
char pilot_lever[100]="Rising";//
char squat_switch[100]="Opened";//
printf("light:%s\n",light);
printf("pilot lever:%s\n",pilot_lever);
printf("squat_switch:%s",
current_state=checking_before_
}
}
static void(*state_table[])(void)={
Lowering_gear,};//here we mentioning in small letters to calling
//functions
int main()
{
init_state_machine();
while(1){
state_table[current_state]();
}
return 0;
}