Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
//Gear down
#include "state.h"
void Gear_Down(void)
{
current_state = GR_DWN;
printf("\nEnter the pilot lever position and squat switch status: ");
fflush(stdout);
scanf("%d %d",&pilot_lever, &squat_switch);
if(pilot_lever == Raising && squat_switch == open)
{
current_state = CHK_BFR_TKFF;
printf("\nCurrent state : %s\n",State_Machine[current_state].current_state_indication);
printf("light is : %s\n", State_Machine[current_state].light_status);
}
else
{
Gear_Down();
}
}
//Raising gear
#include "states.h"
void Raising_Gear()
{
current_state = RSING_GR;
printf("\nEnter the limit switch status,pilot lever status:");
fflush(stdout);
scanf("%d %d",&pilot_lever, &limit_switch);
printf("\nWait for 1 sec\n");
if(pilot_lever == Falling && limit_switch == open)
{
current_state = CHK_BFR_LND;
printf("Current 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 if (limit_switch == close && pilot_lever == UP)
{
current_state = GR_UP;
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
{
Raising_Gear();
}
}
#include "states.h"
void Checking__Before_Landing()
{
current_state = CHK_BFR_LND;
printf(" Enter the pilot 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("Current state : %s\n",State_Machine[current_state].current_state_indication);
printf("light is :%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]);
}
if(pilot_lever == (UP || Raising || Falling))
{
Checking__Before_Landing();
}
}
//checking before landing
#include "states.h"
void Checking__Before_Landing()
{
current_state = CHK_BFR_LND;
printf(" Enter the pilot 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("Current state : %s\n",State_Machine[current_state].current_state_indication);
printf("light is :%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]);
}
if(pilot_lever == (UP || Raising || Falling))
{
Checking__Before_Landing();
}
}
//Gear up
#include "states.h"
void Gear_Up()
{
current_state = GR_UP;
printf("enter the pilot 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();
}
}
//checking before take off
#include "states.h"
void Checking_Before_Takeoff()
{
current_state=CHK_BFR_TKFF;
printf(" Enter the pilot lever position squat switch status and hydraulic mechanism status");
fflush(stdout);
scanf("%d %d %d", &pilot_lever, &squat_switch, &hydraulic_mechanism);
printf("\nWait for 2 sec\n");
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("Current state : %s\n", State_Machine[current_state].current_state_indication);
printf("light : %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 == UP && squat_switch == open && hydraulic_mechanism == Malfunctioning)
{
current_state = RSING_GR;
printf("Current state :%s \n",State_Machine[current_state].current_state_indication);
printf("light : %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);
}
}
//Initiallising machine state
#include "states.h"
void Init_State_Machine()
{
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);
}
//Lowering gear
#include "states.h"
void Lowering_Gear()
{
current_state = LWRNG_GR;
printf("Enter the limit switch status,pilot leaver status:");
fflush(stdout);
scanf("%d %d", &limit_switch, &pilot_lever);
if(pilot_lever == Raising)
{
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)
{
current_state = GR_DWN;
printf("Current 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);
}
if(limit_switch == close)
{
Lowering_Gear();
}
}
//Stable state (main)
#include "states.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]();
}
}