Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
1)landing gear
#include<stdio.h>
#include "fsm.h"
//geardown
void Gear_Down(void)
{
current_state = GR_DWN;
printf("\n Enter the Pilot's Lever Position and Squat Switch Status:");
fflush(stdout);
scanf("%d %d",&pilot_lever,&squat_switch);
if(pilot_lever == Rising && squat_switch == Open)
{
current_state = CHK_BFR_TKFF;
printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n", State_Machine[current_state].light_status);
}
else
{
Gear_Down();
}
}
main.c
#include<stdio.h>
#include "fsm.h"
static void(*state_table[])(void) = {Gear_Down, Checking_Before_Takeoff,Raising_Gear,
Gear_Up, Checking_Before_Landing, Lowering_Gear};
int main()
{
Init_State_Machine();
while(1)
{
state_table[current_state]();
}
}
checkingtakeoff.c
#include<stdio.h>
#include "fsm.h"
void Checking_Before_Takeoff(void)
{
current_state = CHK_BFR_TKFF;
printf("\nEnter the Pilot's Lever Position,Squat Switch Status and Hydraulic Mechanism Status:");
fflush(stdout);
scanf("%d %d ",&pilot_lever,&squat_switch,&hydraulic_mechanism);
if(pilot_lever == Falling || squat_switch == Close)
{
Gear_Down();
}
else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Working)
{
current_state = RSING_GR;
printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);
printf("Light Status: %s\n", State_Machine[current_state].light_status);
printf("Direction Valve Status:%s\n\n", State_Machine[current_state].direction_valve_status);
}
else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Malfunctioning)
{
current_state = RSING_GR;
printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);
printf("Light Status: %s\n", State_Machine[current_state].light_status);
printf("Direction Valve Status:%s\n", State_Machine[current_state].direction_valve_status);
printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}
}
raising gear.c
#include<stdio.h>
#include "fsm.h"
void Checking_Before_Takeoff(void)
{
current_state = CHK_BFR_TKFF;
printf("\nEnter the Pilot's Lever Position,Squat Switch Status and Hydraulic Mechanism Status:");
fflush(stdout);
scanf("%d %d ",&pilot_lever,&squat_switch,&hydraulic_mechanism);
if(pilot_lever == Falling || squat_switch == Close)
{
Gear_Down();
}
else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Working)
{
current_state = RSING_GR;
printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);
printf("Light Status: %s\n", State_Machine[current_state].light_status);
printf("Direction Valve Status:%s\n\n", State_Machine[current_state].direction_valve_status);
}
else if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Malfunctioning)
{
current_state = RSING_GR;
printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);
printf("Light Status: %s\n", State_Machine[current_state].light_status);
printf("Direction Valve Status:%s\n", State_Machine[current_state].direction_valve_status);
printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}
}
gearup.c
#include<stdio.h>
#include "fsm.h"
void Gear_Up(void)
{
current_state = GR_UP;
printf("\nEnter the Pilot's Lever Position:");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever == Falling)
{
current_state = CHK_BFR_LND;
printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n", State_Machine[current_state].light_status);
printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);
}
else
{Gear_Up();
}
}
checkinglanding.c
#include<stdio.h>
#include "fsm.h"
void Checking_Before_Landing(void)
{
current_state = CHK_BFR_LND;
printf("\nEnter the Pilot's Lever Position and Status of Hydraulic Mechanism:");
fflush(stdout);
scanf("%d %d",&pilot_lever,&hydraulic_mechanism);
if(pilot_lever == DOWN && hydraulic_mechanism == Working)
{
current_state = LWRNG_GR;
printf("\nCurrent State:%s\n", State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n", State_Machine[current_state].light_status);
printf("Direction Valve Status:%s\n", State_Machine[current_state].direction_valve_status);
}
else if(pilot_lever == DOWN && hydraulic_mechanism == Malfunctioning)
{
current_state = LWRNG_GR;
printf("\nCurrent State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n", State_Machine[current_state].light_status);
printf("Direction Valve Status:%s\n", State_Machine[current_state].direction_valve_status);
printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);
}
else if(pilot_lever == (UP || Rising || Falling))
{
Checking_Before_Landing();
}
}
lowergear.c
#include<stdio.h>
#include "fsm.h"
void Lowering_Gear(void)
{
current_state = LWRNG_GR;
printf("\nEnter the Limit Switch Status,Pilots Leaver Status:");
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);
if(limit_switch == Close && pilot_lever == Rising )
{
current_state = CHK_BFR_TKFF;
printf("\nCurrent State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n",State_Machine[current_state].light_status);
}
if(limit_switch == Open && pilot_lever == DOWN)
{
current_state = GR_DWN;
printf("\nCurrent State:%s\n",State_Machine[current_state].current_state_indication);
printf("Light Status:%s\n",State_Machine[current_state].light_status);
printf("Hydraulic Controlfor Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);
}
else
{
Lowering_Gear();
}
}
initialize.c
#include "fsm.h"
void Init_State_Machine(void)
{
current_state = GR_DWN;
printf("\nState Machine is initialized & Program is in Gear_Down State & Light Status: %s\n",State_Machine[current_state].light_status);
}
fsm.h
#include "fsm.h"
void Init_State_Machine(void)
{
current_state = GR_DWN;
printf("\nState Machine is initialized & Program is in Gear_Down State & Light Status: %s\n",State_Machine[current_state].light_status);
}