Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
/*
* main.h
*
* Created on: 05-Dec-2022
* Author: S Leena Theresa
*/
#ifndef MAIN_H_
#define MAIN_H_
#include
typedef enum //Enumerated Data Types for Airplane's Different States
{
Gear_Down,
Checking_Before_Take_Off,
Rising_Gear,
Gear_Up,
Checking_Before_Landing,
Lowering_Gear
}State_Type; //Data type name is State_Type
typedef enum //Data types for switches name as Switch_Status
{
Open,
Close
}Switch_Status;
typedef enum //Data type for pilot lever status
{
Rising,
Falling,
Up,
Down
}Pilot_Lever_status;
typedef enum //Data Type for Hydraulic pressure controlled by the software
{
Working,
NotWorking
}Hydrolic_Pressure_Status;
State_Type Current_State; //Variable to access the different kinds of states of State_Type
static volatile Switch_Status Limit_Switch; //Variable Limit_Switch of type Switch States
static volatile Switch_Status Squat_Switch;
static volatile Pilot_Lever_status Pilot_Lever;
static volatile Hydrolic_Pressure_Status Hydrolic_Pressure;
typedef struct //Structure to shoe the output to the user
{
char *Current_State_Indication;
char *Light_Status;
char *Direction_valve_Status;
char *Hydraulic_Pump_Control_Status;
}State_Table;
static State_Table State_Machine[] = {
{"GearDown","Green","Down","Enabled"},
{"CheckingBeforeTakingOff","Green","Down","Enabled"},
{"RisingGear","Red","Up","Enabled"},
{"GearUp","OFF","NULL","Disabled"},
{"CheckingBeforeLanding","Red","Down","Enabled"},
{"LoweringGear","Green","Up","Enabled"}
}; //Structure initialized with the 6 state values
void Initialize_State_Machine(void);
void GearDown (void);
void CheckingBeforeTakeOff (void); //Functions prototypes that we are using in this project
void RisingGear (void);
void GearUp (void);
void CheckingBeforeLanding (void);
void LoweringGear (void);
#endif /* MAIN_H_ */
/*
* main.c
*
* Created on: 05-Dec-2022
* Author: S Leena Theresa
* Description: Implement the code for controlling the retraction and extension of Airplane's
* Landing gear.
*/
#include "main.h" //Including the programmer created header file
static void (*StateTable[])(void) = { GearDown, CheckingBeforeTakeOff, RisingGear,
GearUp, CheckingBeforeLanding, LoweringGear };
//Function pointer to get the address of
//the functions and called using funtion pointers
int main() //Execution start from this file
{
Initialize_State_Machine(); //Intializing the state machine
while (1)
{
StateTable[Current_State]();//Calling function depends on state using function pointers
}
return 0;
}
/*
* Initialisation.c
*
* Created on: 05-Dec-2022
* Author: S LeenaTheresa
*/
#include "main.h"
//Initializing the state
void Initialize_State_Machine(void)
{
Current_State = Gear_Down;
printf("The FSM is Initialized and the current state is "
" Gear Down State & Light Status is %s\n",State_Machine[Current_State].Light_Status);
}
/*
* GearDown.c
*
* Created on: 05-Dec-2022
* Author: S Leena Theresa
*/
#include "main.h"
void GearDown (void)
{
Current_State = Gear_Down; //Airplane is in gear down state
printf("Enter the Status Pilet's Lever and Squat Switch : ");
fflush(stdout);
scanf("%d%d",&Pilot_Lever,&Squat_Switch); //Reading the input from the user
if (Pilot_Lever == Rising && Squat_Switch == Open) //Condition for state 2
{
Current_State = Checking_Before_Take_Off;
printf("Current State is : %s\n",State_Machine[Current_State].Current_State_Indication);
printf("Light_Status is : %s\n",State_Machine[Current_State].Light_Status);
printf("Direction Valve Status is : %s\n",State_Machine[Current_State].Direction_valve_Status);
printf("Status of Hydraulic Pump control is : %s\n",State_Machine[Current_State].Hydraulic_Pump_Control_Status);
}
else
{
GearDown();
}
}
/*
* CheckingBeforeTakeOff.c
*
* Created on: 05-Dec-2022
* Author: S Leena Theresa
*/
#include "main.h"
void CheckingBeforeTakeOff(void)
{
Current_State = Checking_Before_Take_Off;
printf("Enter the Status of Pilot's Lever, Squat Switch and Hydraulic Pressure :");
fflush(stdout);
scanf("%d%d%d", &Pilot_Lever, &Squat_Switch, &Hydrolic_Pressure);
if ((Pilot_Lever == Falling) && (Squat_Switch == Close)) //Condition for go back to state 1
{
GearDown();
}
else if ((Pilot_Lever == Up) && (Squat_Switch == Open) && (Hydrolic_Pressure == Working))
{ //Condition for go to state 3
Current_State = Rising_Gear;
printf("Current State is : %s\n",State_Machine[Current_State].Current_State_Indication);
printf("Light_Status is : %s\n",State_Machine[Current_State].Light_Status);
printf("Direction Valve Status is : %s\n",State_Machine[Current_State].Direction_valve_Status);
printf("Status of Hydraulic Pump control is : %s\n",State_Machine[Current_State].Hydraulic_Pump_Control_Status);
}
}
/*
* RisingGear.c
*
* Created on: 05-Dec-2022
* Author: S Leena Theresa
*/
#include "main.h"
//Airplane should go to either Gear up state(4) or the Checking before landing State(5)
void RisingGear (void)
{
Current_State = Rising_Gear;
printf("Enter the status of Pilot's Lever and Limit Switch :");
fflush (stdout);
scanf("%d%d",&Pilot_Lever,&Limit_Switch);
if ((Pilot_Lever == Rising) && (Limit_Switch == Close)) //Condition to go to state 4
{
Current_State = Gear_Up;
printf("Current State is : %s\n",State_Machine[Current_State].Current_State_Indication);
printf("Light_Status is : %s\n",State_Machine[Current_State].Light_Status);
printf("Direction Valve Status is : %s\n",State_Machine[Current_State].Direction_valve_Status);
printf("Status of Hydraulic Pump control is : %s\n",State_Machine[Current_State].Hydraulic_Pump_Control_Status);
}
else if ((Pilot_Lever == Falling) && (Limit_Switch == Open)) //Condition for state 5
{
Current_State = Checking_Before_Landing;
printf("Current State is : %s\n",State_Machine[Current_State].Current_State_Indication);
printf("Light_Status is : %s\n",State_Machine[Current_State].Light_Status);
printf("Direction Valve Status is : %s\n",State_Machine[Current_State].Direction_valve_Status);
printf("Status of Hydraulic Pump control is : %s\n",State_Machine[Current_State].Hydraulic_Pump_Control_Status);
}
else
{
RisingGear();
}
}
/*
* GearUp.c
*
* Created on: 05-Dec-2022
* Author: S Leena Theresa
*/
#include "main.h"
//It should go to checking before landing state(5)
void GearUp (void)
{
Current_State = Gear_Up;
printf("Enter the Status of Pilot's Lever ");
fflush(stdout);
scanf("%d",&Pilot_Lever);
if (Pilot_Lever == Falling) //If pilot lever having 1 value should go to state 5
{
Current_State = Checking_Before_Landing;
printf("Current State is : %s\n",State_Machine[Current_State].Current_State_Indication);
printf("Light_Status is : %s\n",State_Machine[Current_State].Light_Status);
printf("Direction Valve Status is : %s\n",State_Machine[Current_State].Direction_valve_Status);
printf("Status of Hydraulic Pump control is : %s\n",State_Machine[Current_State].Hydraulic_Pump_Control_Status);
}
else
{
GearUp();
}
}
/*
* CheckingBeforeLanding.c
*
* Created on: 05-Dec-2022
* Author: S Leena Theresa
*/
#include "main.h"
//It should go to State 6
void CheckingBeforeLanding (void)
{
Current_State = Checking_Before_Landing;
printf("Enter the Status of Pilot's Lever and Hydraulic Pressure ");
fflush(stdout);
scanf("%d%d",&Pilot_Lever,&Hydrolic_Pressure);
if (Pilot_Lever == Down && Hydrolic_Pressure == Working) //Condition for State 6
{
printf("Wait for 5 seconds\n");
Current_State = Lowering_Gear;
printf("Current State is : %s\n",State_Machine[Current_State].Current_State_Indication);
printf("Light_Status is : %s\n",State_Machine[Current_State].Light_Status);
printf("Direction Valve Status is : %s\n",State_Machine[Current_State].Direction_valve_Status);
printf("Status of Hydraulic Pump control is : %s\n",State_Machine[Current_State].Hydraulic_Pump_Control_Status);
}
else
{
CheckingBeforeLanding();
}
}
/*
* LoweringGear.c
*
* Created on: 05-Dec-2022
* Author: S Leena Theresa
*/
#include "main.h"
//It should either go to state 2(Checking before take off) or state 1 (Gear down)
void LoweringGear (void)
{
Current_State = Lowering_Gear;
printf("Enter the Status Pilot's Lever and Limit Switch ");
fflush(stdout);
scanf("%d%d",&Pilot_Lever,&Limit_Switch);
if ((Limit_Switch == Open) && (Pilot_Lever == Rising)) //Condition for State 2
{
Current_State = Checking_Before_Take_Off;
printf("Current State is : %s\n",State_Machine[Current_State].Current_State_Indication);
printf("Light_Status is : %s\n",State_Machine[Current_State].Light_Status);
printf("Direction Valve Status is : %s\n",State_Machine[Current_State].Direction_valve_Status);
printf("Status of Hydraulic Pump control is : %s\n",State_Machine[Current_State].Hydraulic_Pump_Control_Status);
}
else if ((Limit_Switch == Close) && (Pilot_Lever == Rising)) //Condition for state 1
{
Current_State = Gear_Down;
printf("Current State is : %s\n",State_Machine[Current_State].Current_State_Indication);
printf("Light_Status is : %s\n",State_Machine[Current_State].Light_Status);
printf("Direction Valve Status is : %s\n",State_Machine[Current_State].Direction_valve_Status);
printf("Status of Hydraulic Pump control is : %s\n",State_Machine[Current_State].Hydraulic_Pump_Control_Status);
}
else if (Limit_Switch == Close) //condition for same state
{
LoweringGear();
}
}