Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
#include<stdio.h>
#include"states.h"
static void(*stateTable[])(void)={GearDown,checkingbefortakeOFF,RaisingGear,gearup,checkbeforelanding,LoweringGear};
int main()
{
initiate_static_Machince();
while(1)
{
stateTable[current_state]();
}
}
void Gear_Down(void)
{
current_state=Gear_Down;;
printf("Enther the status of pilot lever and Squat switch: ");
fflush(stdout);
scanf("%d %d",&pilot_lever,&squat_switch);
if(pilot_lever==raising&&squat_switch==open)
{
current_state=CHECK_BEFORE_TAKEOFF;
printf("current states:%s\n",State_Machine[current_state],current_state_indication);
printf("Light is :%s\n",State_Machine[current_state].light);
}
else
{
GearDown();
}
}
void CheckingBeforeTakeOFF(void)
{
current_state=CHECKING_BEFORE_TAKEOFF;
printf("Enter the status of pilot,s lever and squat switch and hydraulic machanicm:");
fflush(stdout);
printf("%d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);
if(pilot_lever==falling && hydraulic_mechanism==working)
{
current_state=lowering_gear;
printf("current:%s\n",State_Machine[current_state],current_state_indication);
printf("light is :%s\n",State_Machine[current_state].light);
printf("status of Direction value:%s\n",State_Machine[current_state].direction_value_status);
}
else if(pilot_lever==falling&&squat_switch==open&&hydraulic_mechanism==Malfunctioning)
{
current_state=lowering_gear;
printf("current states:%s\n",State_Machine[current_state].current_state_indication);
printf("light is :%s\n",State_Machine[current_state].light);
printf("status of Direction value:%s\n",State_Machine[current_state].direction_value_status);
}
if(pilot_lever==(raising||falling))
{
CheckBeforelanding();
}
}
void LoweringGear(void)
{
current_state=lowering_gear;
printf("Enter the status of pilot lever and the limits switch");
fflush(stdout);
scanf("%d %d",&pilot_lever,&limit_switch);
if(pilot_lever==raising&&limit_switch)
{
current_state=check_before_takeoff;
printf("current state:%s\n",State_Machine[current_state].current_state_indication);
printf("light is :%s\n",State_Machine[current_state].light);
}
if(pilot_lever==raising&&limit_switch)
{
current_state=gear_down;
printf("current state:%s\n",State_Machine[current_state].current_state_indication);
printf("light is :%s\n",State_Machine[current_state].light);
printf("landing gear Hydraulic control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);
}
if(limit_switch==close)
{
LoweringGear();
}
}
void Initiate_state_Machine()
{
current_state=gear_down;
printf("The finite State machince in initailzed and current program is in ","geardown state light is %s\n ",State_Machine[current_state].light);
}
void Initiate_state_Machine();
void GearDown();
void CheckingBeforeTakeoff();
void RaisingGear();
void GearUp();
void CheckingBeforeLanding();
void LoweringGear();
typedef enum state
{
gear_down,
check_before_takeoff,
raising_gear,
gear_up,
checking_before_landing,
lowering_gear
}state_type;
typedef enum switch_
{
open,
close
}switch_status;
typedef enum pilot_lever
{
rising,
falling,
up,
down
}pilot_lever;
typedef enum Hydraulic_Mechanism_Statu
{
Malfunctioning,
working
}Hydraulic_Mechanism;
static volatile switch_status squat_switch;
static volatile switch_status limit_switch;
static volatile pilot_lever pilot_lever;
static volatile Hydraulic_Mechanism hydraulic_mechanism;
State_Type current_state;
typedef struct
{
char*current_state_induction;
char*light;
char*direction_value_status;
char*landing_gear_hydraulic_control;
}State_Table;
static State_Table;
state_Machin[6]=
{
{"Gear down","green","down","Enable",{NULL,NULL}},
{"checkingbeforeTakeOFF","green","down","Enable",{NULL,NULL}},
{"Raisinggear","Red","up","Enable",{NULL,NULL}},
{"checkbeforelading","Red","down","Enable",{NULL,NULL}},
{"loweringgear","green","down","Enable",{"disable","Enable"}}
};
#endif /* STATES_H_ */



