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> // Preprocessor header file
// all functions are declared in state.h user defined header file
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_BFR_TKFF,
RSING_GR,
GR_UP,
CHK_BFR_LND,
LWRNG_GR
}State_Type; // define enum for State of gear
typedef enum Switch{
OPEN,
CLOSE
}Switch_Status; // define enum for switch
typedef enum Pilot_Lever{
RISING,
FALLING,
UP,
DOWN
}Pilot_Lever_Status; // define pilot lever status using enum
typedef enum Hydraulic_Mechanism{
WORKING,
MALFUNCTIONING
}Hydraulic_Mechanism_Status; // define hydraulic mechanism status using enum
// input for changing the state
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_valve_status;
char* hydraulic_pump_control_status;
char* gas_pressurized_spring_status[2];
}State_Table; // declaring structure for different status
static State_Table State_Machine[6] = {
{"Gear_Down","Green","Down","Enabled",{0,0}},
{"Checking_Before_Takeoff","Green","Down","Enabled",{0,0}},
{"Rising_Gear","Red","UP","Enabled",{"Disabled","Enabled"}},
{"Gear_Up","OFF","NULL","Disabled",{0,0}},
{"Checking_Before_Landing","Red","DOWN","Enabled",{0,0}},
{"Lowering_Gear","Green","DOWN","Enabled",{"Disabled","Enabled"}}
};
#endif /* STATE_H_ */
#include "state.h" // user defined header file
static void (*state_table [])(void) = {Gear_Down, Checking_Before_Takeoff, Rising_Gear, Gear_Up,
Checking_Before_Landing, Lowering_Gear}; // syntax
int main()
{
Init_State_Machine(); // calling function
while(1)
{
state_table [current_state](); // current state of the gear
}
}