Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Live batch 10 embedded
main code
/*
* main.c
*
* Created on: 27-Sep-2022
* Author: Vedang More
*/
#include<stdio.h>
#include "States.h"//states header file
static void(*state_table[])(void) = {Gear_Down, Checking_Before_Takeoff,Raising_Gear, Gear_Up, Checking_Before_Landing, Lowering_Gear};//using state table the condition controlling the retraction and extension of airplane landing gear are called
int main()
{
Init_State_Machine(); //intial state machine is declared
while(1)
{
state_table[current_state]();//current state is declared in the state table
}
}
states file
/*
* states.h
*
* Created on: 27-Sep-2022
* Author: Vedang More
*/
#ifndef STATES_H_
#define STATES_H_
void Init_State_Machine();//intial state of the machine is declared using void
void Gear_Down();//gear down is declared using void
void Checking_Before_Takeoff();//checking before takeoff is declared using void
void Raising_Gear();//raising gear operation is declared using void
void Gear_Up();//gear up operation is declared using
void Checking_Before_Landing();//checking before landing is declared using void
void Lowering_Gear();//lowering gear is declared using void
typedef enum State//declares an alternative name as state
{
GR_DWN,
CHK_BFR_TKFF,
RSING_GR,
GR_UP,
CHK_BFR_LND,
LWRNG_GR
}State_Type;//state type is declared
typedef enum Switch//declares the alternative name as switch
{
Open,
Close
}Switch_Status;//status of switch
typedef enum Pilot_Lever//declares the alternative name as pilot lever
{
Rising,
Falling,
UP,
DOWN
}Pilot_Lever_Status;//the pilot lever status
typedef enum Hydraulic_Mechanism//alternative name as hydraulic mechanism
{
Working,
Malfunctioning
}Hydraulic_Mechanism_Status;//hydraulic mechanism status is declared
static volatile Switch_Status squat_switch;//switch status stored in main memory as squat switch
static volatile Switch_Status limit_switch;//switch status stored in main memory as limit switch
static volatile Pilot_Lever_Status pilot_lever;//pilot lever status stored in main memory as pilot lever
static volatile Hydraulic_Mechanism_Status hydraulic_mechanism;//hydraulic mechanism status stored in main memory as hydraulic mechanism
State_Type current_state;//current state is the state type
typedef struct//structure is declared using typedef
{
char* current_state_indication;//current state indication is declared using character
char* light_status;//light status declared using character
char* direction_valve_status;//direction_valve_status declared using character
char* hydraulic_pump_control_status;//hydraulic_pump_control_status declared using character
char* gas_pressurized_spring_status[2];//gas_pressurized_spring_status declared using character
}State_Table;//state table declaration
static State_Table State_Machine[6] = {
{"GearDown","Green","Down","Enabled",0,0},
{"Checking Before Take Off","Green","Down","Enabled",0,0},
{"Raising 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 /* STATES_H_ */
Init_State_Machine
/*
* Init_State_Machine.c
*
* Created on: 27-Sep-2022
* Author: Vedang More
*/
#include"States.h"// state header file is declared
void Init_State_Machine()//initial state machine condition
{
current_state = GR_DWN;//current state is gear down condition
printf("\nState Machine is initialized & Program is in Gear_Down State & Light Status: %s\n",State_Machine[current_state].light_status);//display state machine is initialized and gear down state with status of light
}
/*
* geardown.c
*/
#include"States.h"
#include<stdio.h>
void Gear_Down(void)//gear down condition
{
current_state = GR_DWN;//current state is gear down
printf("\n Enter the Pilot's Lever Position and Squat Switch Status:");//display enter the pilot lever position and squat switch status
fflush(stdout);//clears cache memory
scanf("%d %d",&pilot_lever,&squat_switch);//reads pilot lever and squat switch
if(pilot_lever == Rising && squat_switch == Open)//if pilot lever is rising and switch is open
{
current_state = CHK_BFR_TKFF;//current state is check before takeoff
printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display current state
printf("Light Status:%s\n", State_Machine[current_state].light_status);//display light status
}
else//else condition
{
current_state = GR_DWN;//current state is gear down
printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display current state
printf("Light Status:%s\n", State_Machine[current_state].light_status);//display light status
Gear_Down();//gear down state
}
}
checkingbeforetakeoff
/*
* checkingbeforetakeoff.c
*
* Created on: 27-Sep-2022
* Author: Vedang More
*/
#include"States.h"
#include<stdio.h>
void Checking_Before_Takeoff()//checking before takeoff condition
{
current_state = CHK_BFR_TKFF;//current state is checking before takeoff
printf("\nEnter the Pilot's Lever Position,Squat Switch Status and Hydraulic Mechanism Status:");//display the pilot lever position , switch status and hydraulic mechanism status
fflush(stdout);
scanf("%d %d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);//read pilot lever, switch and hydraulic mechanism
printf("\nWait for 3 secs\n");
if(pilot_lever == UP && squat_switch == Open && hydraulic_mechanism == Working)
{
current_state = RSING_GR;//current state is rising gear
printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);//display current state
printf("Light Status: %s\n", State_Machine[current_state].light_status);//display light status
printf("Direction Valve Status:%s\n\n", State_Machine[current_state].direction_valve_status);//display 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);//display current state
printf("Light Status: %s\n", State_Machine[current_state].light_status);//display light status
printf("Direction Valve Status:%s\n", State_Machine[current_state].direction_valve_status);//display direction valve status
printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);//display gas pressurized spring system status
}
else if(pilot_lever == Falling || squat_switch == Close)
{
current_state = GR_DWN;
printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display current state
printf("Light Status:%s\n", State_Machine[current_state].light_status);//display light status
Gear_Down();
}
}
risinggear
/*
* risinggear.c
*
* Created on: 27-Sep-2022
* Author: Vedang More
*/
#include"States.h"
#include<stdio.h>
void Raising_Gear()
{
current_state = RSING_GR;
printf("\nEnter the Limit Switch Status,Pilots Leaver Status:");//display the pilot lever position , switch status
fflush(stdout);
scanf("%d %d",&limit_switch,&pilot_lever);//read pilot lever, limit switch
printf("\nWait for 3 sec\n");
if(pilot_lever == Falling && limit_switch == Open)
{
current_state = CHK_BFR_LND;//current state is checking before landing
printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display current state
printf("Light Status:%s\n",State_Machine[current_state].light_status);//display light status
printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);//display hydraulic control for landing gear status
}
else if(limit_switch == Close && pilot_lever == UP)
{
current_state = GR_UP;//current state is gear up
printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display current state
printf("Light Status: %s\n", State_Machine[current_state].light_status);//display current state
printf("Hydraulic Control for Landing Gear Status:%s\n", State_Machine[current_state].hydraulic_pump_control_status);//display hydraulic control for landing gear status
}
else
{
current_state = RSING_GR;
printf("\nCurrent State :%s\n",State_Machine[current_state].current_state_indication);//display current state
printf("Light Status: %s\n", State_Machine[current_state].light_status);//display current state
printf("Direction Valve Status:%s\n", State_Machine[current_state].direction_valve_status);//display hydraulic control for landing gear status
printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);//display gas pressurized spring status
Raising_Gear();
}
}
/*
* gearup.c
*
* Created on: 27-Sep-2022
* Author: Vedang More
*/
#include<stdio.h>
#include"States.h"
void Gear_Up()//gear up condition
{
current_state = GR_UP;//current state is gear up operation
printf("\nEnter the Pilot's Lever Position:");//display to Enter the Pilot's Lever Position
fflush(stdout);
scanf("%d",&pilot_lever);// read the pilot lever
if(pilot_lever == Falling)
{
current_state = CHK_BFR_LND;//current state is checking before landing
printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display current state
printf("Light Status:%s\n", State_Machine[current_state].light_status);//display current state
printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);//display hydraulic control for landing gear status
}
else
{
current_state = GR_UP;//current state is gear up
printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display current state
printf("Light Status: %s\n", State_Machine[current_state].light_status);//display current state
printf("Hydraulic Control for Landing Gear Status:%s\n", State_Machine[current_state].hydraulic_pump_control_status);//display hydraulic control for landing gear status
Gear_Up();
}
}
/*
* checkingbeforelanding.c
*
* Created on: 27-Sep-2022
* Author: Vedang More
*/
#include "States.h"
#include<stdio.h>
void Checking_Before_Landing()//checking before landing condition
{
current_state = CHK_BFR_LND;//current state is checking before landing
printf("\nEnter the Pilot's Lever Position and Status of Hydraulic Mechanism:");// display Enter the Pilot's Lever Position and Status of Hydraulic Mechanism
fflush(stdout);
scanf("%d %d",&pilot_lever,&hydraulic_mechanism);// read the pilot lever is down and hydraulic mechanism
if(pilot_lever == DOWN && hydraulic_mechanism == Working)
{
current_state = LWRNG_GR;//current state is lowering gear
printf("\nCurrent State:%s\n", State_Machine[current_state].current_state_indication);//display the current state
printf("Light Status:%s\n", State_Machine[current_state].light_status);//display the light status
printf("Direction Valve Status:%s\n", State_Machine[current_state].direction_valve_status);//display the direction valve status
}
else if(pilot_lever == DOWN && hydraulic_mechanism == Malfunctioning)
{
current_state = LWRNG_GR;//current state is lowering gear
printf("\nCurrent State:%s\n",State_Machine[current_state].current_state_indication);//display the current state
printf("Light Status:%s\n", State_Machine[current_state].light_status);//display the light status
printf("Direction Valve Status:%s\n", State_Machine[current_state].direction_valve_status);//display the direction valve status
printf("Gas Pressurized Spring System Status:%s\n",State_Machine[current_state].gas_pressurized_spring_status[hydraulic_mechanism]);//display the gas_pressurized_spring_status
}
else if(pilot_lever == (UP || Rising || Falling))
{
current_state = CHK_BFR_LND;//current state is checking before landing
printf("\nCurrent State: %s\n",State_Machine[current_state].current_state_indication);//display the current state
printf("Light Status:%s\n",State_Machine[current_state].light_status);//display the light status
printf("Hydraulic Control for Landing Gear Status:%s\n",State_Machine[current_state].hydraulic_pump_control_status);//display the direction valve status
Checking_Before_Landing();
}
}
output