Challenge

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
 
/*
 * gears.h
 *
 *  Created on: 11-Jul-2023
 *      Author: shant
 */
//header file for gears
 
#ifndef GEARS_H_            //undefining the name if already defined
#define GEARS_H_            // define the name of library
#include           // pre- processor directive
#include          //  adding library to use it
typedef enum States          //declare enumerated type state
{
Gear_down,                    //state position
Checking_before_Take_off,
Raising_Gear,
Gear_Up,
Checking_before_Landing,
Lowering_Gear }State_Type;
typedef enum switches        //declare enumerated type switch
{
Open,               //0
Close               //1
}Switch;
typedef enum pilot         //declare enumerated type lever condition
{
Rising,                   //0
Falling,
Up,
Down,
}Pilot_Lever;
typedef enum Hydraulic      //declare enumerated type hydraulic pressure condition
{
Working,
Not_Working
}Hydraulic_Mechanism;
 
static volatile Switch limit;      //compiler assign any value given by user
static volatile Switch squat;
static volatile Pilot_Lever a;
static volatile Hydraulic_Mechanism b;
State_Type current_state;
typedef struct{                  //declare  structre with variable
char* next_state;             //declare next state position
char* light;
char* direction_valve;
char* hydraulic_control;
}position;                           //calling position state
void gear_down();                 //calling gear down function
void checking_before_take_off();   //calling checking before take off function
void raising_gear();               //calling raising gear function
void gear_up();                    //calling gear up function
void checking_before_landing();     //calling checking before time function
void lowering_gear();                //calling lowering gear function
 
static void(*Position[])(void)={gear_down,checking_before_take_off,raising_gear,gear_up,checking_before_landing,lowering_gear};
static position state_machine[6]={{"GEAR DOWN","GREEN","DOWN","ENABLED"},
                     {"CHECKING BEFORE TAKEOFF","GREEN","DOWN","ENABLED"},
             {"RAISING GEAR","RED","UP","ENABLED"},
             {"GEAR UP","OFF","NULL","DISABLED"},
                              {"CHECKING BEFORE LANDING","RED","DOWN","ENABLED"},
  {"LOWERING GEAR","GREEN","DOWN","ENABLED"}};
 
#endif /* GEARS_H_ */        //end of library
#include"gears.h"                  //including gears.h file
 
 
 
int main()                          //main function
{
current_state=Gear_down;       //Enum Value - Gear Down
while(1)                     //using while loop iterate position of state
{
Position[current_state]();
}
}

#include"gears.h" //including gears.h file
void gear_down() // definition of gear down function
{
current_state=Gear_down; //Enum Value - Gear Down
printf("pilot lever and squat switch\n"); //asking pilot to enter the data for printing the value of lever and switch
fflush(stdout); //clearing o/p stream
scanf("%d %d",&a,&squat); //store the value of squat switch and lever
if((a==Rising)&&(squat==Open)) //0 0
{
current_state=Checking_before_Take_off; //enum value current state if true(0 0)
printf("Next state is %s\n",state_machine[current_state].next_state); //printing the value of next state and assign address current state to next state
printf("Light is %s\n",state_machine[current_state].light); //printing light status
printf("Direction valve is %s\n",state_machine[current_state].direction_valve); //printing directipn valve status
printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control); // printing hydroulic pressure ststus
}
else
{
gear_down(); //falling any condition, current state as gear down
}
}

#include"gears.h" //including gears.h file
void checking_before_landing() // defintion of checking before landing function
{
current_state=Checking_before_Landing; //current state assign as cheking before landing
printf("enter the value of pilot lever and hydroulic machine\n"); //asking pilot to enter value
fflush(stdout);
scanf("%d %d",&a,&b);
if(a==Down||b==Not_Working) //lever down or hydroulic disabled
{
current_state=Lowering_Gear;
}
else {
checking_before_landing();
}
}

#include"gears.h" //including gears.h file
void checking_before_take_off() //definition of checking before take off function
{
current_state=Checking_before_Take_off; //assign current state as checking before take off
printf("enter value of pilot lever,switch and hydroulic machine\n"); //asking pilot to enter value of lever, switch and hydroulic pressure status
fflush(stdout); //clearing o/p stream
scanf("%d %d %d",&a,&squat,&b); //store the value of a,b and squat
if((a==Falling)||(squat==Close)) //check either lever falling or squat status
{
current_state=Gear_down; //if fails state is gear down
printf("Next state is %s\n",state_machine[current_state].next_state); //printing the value of next state and assign address current state to next state
printf("Light is %s\n",state_machine[current_state].light); //printing light status
printf("Direction valve is %s\n",state_machine[current_state].direction_valve); //printing directipn valve status
printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control); // printing hydroulic pressure ststus
}
else if((a==Up)&&(b==Working)) //lever up and hydroulic enabled
{
current_state=Raising_Gear; //current state assign as raising gear
printf("Next state is %s\n",state_machine[current_state].next_state); //printing the value of next state and assign address current state to next state
printf("Light is %s\n",state_machine[current_state].light); //printing light status
printf("Direction valve is %s\n",state_machine[current_state].direction_valve); //printing directipn valve status
printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control); // printing hydroulic pressure ststus
}
else {
checking_before_take_off();
}
}

#include"gears.h" //including gears.h file
void raising_gear() //defintion of raising gear
{
current_state=Raising_Gear; // current state assign as raising gear
printf("asking for pilot lever and limit switch\n"); //asking pilot to enter value of lever and switch status
fflush(stdout); //clearing o/p stream
scanf("%d %d",&a,&limit); //store value in lever and limit switch
if(a==Falling)
{
current_state=Checking_before_Landing; //current assign as check before landing
printf("Next state is %s\n",state_machine[current_state].next_state); //printing the value of next state and assign address current state to next state
printf("Light is %s\n",state_machine[current_state].light); //printing light status
printf("Direction valve is %s\n",state_machine[current_state].direction_valve); //printing directipn valve status
printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control); // printing hydroulic pressure ststus
}
else if(limit==Close) //check limit switch status
{
current_state=Gear_Up; // if true then current state assign as gear up
printf("Next state is %s\n",state_machine[current_state].next_state); //printing the value of next state and assign address current state to next state
printf("Light is %s\n",state_machine[current_state].light); //printing light status
printf("Direction valve is %s\n",state_machine[current_state].direction_valve); //printing directipn valve status
printf("Hydraulic control is %s\n",state_machine[current_state].hydraulic_control); // printing hydroulic pressure ststus
}
}

#include"gears.h" //including gears.h file
void gear_up() //definition of gear up function
{
current_state=Gear_Up; //current state assign as gear up
printf("enter the value of pilot lever\n"); // asking pilot to enter value of lever status
fflush(stdout); // clearing o/p stream
scanf("%d",&a); //store value of lever status in a
if(a==Falling) //if lever falling
{ current_state=Checking_before_Landing; //current assign goes to next state
}
else {
gear_up();
}
}

#include"gears.h" //including gears.h file
void lowering_gear() // defintion nof lowering gear function
{
current_state=Lowering_Gear; //current sate assign as lowering gear
printf("asking for limit switch and pilot lever\n");
fflush(stdout);
scanf("%d %d",&limit,&a);
if(limit==Open)
{
current_state= Gear_down;
}
else if(a==Rising)
{
current_state=Checking_before_Take_off;
}
else
{
lowering_gear();
}
}

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.