Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
#ifndef STATE_H_
#define STATE_H_
#include<stdio.h>
/*------------------functions---------------*/
void Init_state_machine();
void Gear_down();
void checking_before_takeoff();
void Rising_gear();
void Gear_up();
void Checking_before_Landing();
void lowering_Gear();
typedef enum state
{
GR_DWN,
CHK_BEF_TKFF,
RISING_GR,
CHK_BFR_LND,
LWRNG_GR
}state_Type;
typedef enum Switch
{
Open,
Close
}Switch_states;
typedef enum Pilot_Lever
{
Rising,
Falling,
Up,
Dwn
}pilot_Lever_ststus;
typedef enum Hydraulic_Machanism
{
Working,
Malfunctioning
}Hydraulic_mechanism_status;
static volatile Switch_status squat_switch;
static volatile switch_status limit_switch;
static volatile pilot_lever_status pilot_lever;
static volatile Hydraulic_Mechanism_Status hydraulic_mechanism;
State_Type current_state;
typedef struct
{
char* current_state_indication;
char* light_status;
char* direction_value_status;
char* hydraulic_pump_control_status;
char* gas_pressurized_spring_stsatus[2];
}State_Table;
static State_Table State_Machine[6]={
{"Gear Down", "Green", "Down",{NULL,NULL}},
{"Checking Before Take Off","Green","Down", "Enabled",{NULL,NULL}},
{"Raising Gear","Red", "Up","Enabled", {"Disabled", "Enabled"}},
{"Gear up", "Off", "Null", "Disabled", {NULL,NULL}},
{"Checking Before Landing","Red","Down","Enabled",{NULL,NULL}},
{"Lowering Gear", "Green", "Down", "Enabled",{"Disabled","Enabled"}}
};
#endif /* STATE_H_ */
#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();
}
}
#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);
}
}
#include "States.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();
}
}
#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();
}
}
#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);
}
#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();
}
}
#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]();
}
}
#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();
}
}