Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
1)Airplane's langing gear:
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <stdio.h>
typedef enum States
{
Gear_down,
Checking_before_Take_off,
Raising_Gear,
Gear_Up,
Checking_before_Landing,
Lowering_Gear
}State_Type;
typedef enum switches
{
On,
Off
}Switch;
typedef enum pilot
{
Rising,
Falling,
Up,
Down,
}Pilot_Lever;
typedef enum Hydraulic
{
Working,
Not_Working
}Hydraulic_Mechanism;
static volatile Switch squat;
static volatile Switch limit;
static volatile Pilot_Lever a;
static volatile Hydraulic_Mechanism b;
State_Type current_state;
typedef struct{
char* next_state;
char* light;
char* direction_valve;
char* hydraulic_control;
}position;
void gear_down();
void checking_before_take_off();
void raising_gear();
void gear_up();
void checking_before_landing();
void lowering_gear();
static void(*Position[])(void)={gear_down,checking_before_take_off,raising_gear,gear_up,checking_before_landing,lowering_gear};
static position state_machine[6]={{"GEAR DOWN","GREEN","DOWN","ENABLED"},
{"CHECKING BEFORE TAKEOFF","GREEN","DOWN","ENABLED"},
{"RAISING GEAR","RED","UP","ENABLED"},
{"GEAR UP","OFF","NULL","DISABLED"},
{"CHECKING BEFORE LANDING","RED","DOWN","ENABLED"},
{"LOWERING GEAR","GREEN","DOWN","ENABLED"}
};
int main()
{
current_state=Gear_down;//Enum Value - Gear Down
while(1)
{
Position[current_state]();
}
}
void gear_down()
{
current_state=Gear_down;//Enum Value - Gear Down
printf("\n enter pilot_lever,squat_switch");
scanf("%d %d",&a,&squat);
if((a==Rising)&&(squat==On))//0 0
{
current_state=Checking_before_Take_off;//enum value
printf("Next state is %s\n",state_machine[current_state].next_state);
printf("Light is %s\n",state_machine[current_state].light);
printf("Direction valve is %s\n",state_machine[current_state].direction_valve);
printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control);
}
else
{
gear_down();
}}
void checking_before_take_off() //checking before take off
{
current_state=Checking_before_Take_off;
scanf("%d %d %d",&a,&squat,&b);
if((a==Falling)||(squat==Off))
{
current_state=Gear_down;
printf("Next state is %s\n",state_machine[current_state].next_state);
printf("Light is %s\n",state_machine[current_state].light);
printf("Direction valve is %s\n",state_machine[current_state].direction_valve);
printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control);
}
else if((a==Up)&&(b==Working))
{
current_state=Raising_Gear;
printf("Next state is %s\n",state_machine[current_state].next_state);
printf("Light is %s\n",state_machine[current_state].light);
printf("Direction valve is %s\n",state_machine[current_state].direction_valve);
printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control);
}
else
{
checking_before_take_off();
}
}
void raising_gear() //raising gear
{
current_state=Raising_Gear;
scanf("%d %d",&a,&limit);
if(a==Falling)
{
current_state=Checking_before_Landing;
printf("Next state is %s\n",state_machine[current_state].next_state);
printf("Light is %s\n",state_machine[current_state].light);
printf("Direction valve is %s\n",state_machine[current_state].direction_valve);
printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control);
}
else if(limit==Off)
{
current_state=Gear_Up;
printf("Next state is %s\n",state_machine[current_state].next_state);
printf("Light is %s\n",state_machine[current_state].light);
printf("Direction valve is %s\n",state_machine[current_state].direction_valve);
printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control);
}
}
void gear_up() //gear up
{
current_state=Gear_Up;
scanf("%d",&a);
if(a==Falling)
{
current_state=Checking_before_Landing;
}
else
{
gear_up();
}
}
void checking_before_landing() //check before landing
{
current_state=Checking_before_Landing;
scanf("%d %d",&a,&b);
if(a==Down||b==Not_Working)
{
current_state=Lowering_Gear;
}
else
{
checking_before_landing();
}
}
void lowering_gear()
{
current_state=Lowering_Gear;
scanf("%d %d",&limit,&a);
if(limit==On)
{
current_state= Gear_down;
}
else if(a==Rising)
{
current_state=Checking_before_Take_off;
}
else
{
lowering_gear();
}
}
//Initiate_State_Machine
void Initiate_State_Machine()
{
current_state=Gear_down;
printf("the finite state machine is initialized and current the program is in "
"GearDown state & light is:%s\n",state_machine[current_state].light);
}