Challenge

Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear


#include<stdio.h>
#include<stdlib.h> //Header files
#include<stdint.h>
#include<string.h>
void Gear_down();
void Checking_Before_TakeOFF();
void Raising_Gear();
void Gear_up();
void Checking_before_landing();
void Lowering_gear();
typedef enum // declaring the stages in state machines
{
GEAR_DOWN,
CHECKING_BEFORE_TAKEOFF,
RAISING_GEAR,
GEAR_UP,
CHECKING_BEFORE_LANDING,
LOWERING_GEAR
}State_Types;
typedef enum //declaring switch values
{
open,
close
}Switch;
typedef enum // declaring pilot lever valves
{
raising,
falling,
up,
down
}pilot_Lever;
typedef enum //declaring hydralic controls
{
Working,
Not_working
}Hydralic;
static volatile Switch limit_switch,Squat_switch; //
static volatile pilot_Lever pil;
static volatile Hydralic operation;
State_Types current_state;
typedef struct //declaring structure
{
char* currentstate; //6 states
char* lightvalue; //3
char* directionValve; //2
char* Hydraliccontrol; //2
}state;
static void(*state1[])(void)={Gear_down,Checking_Before_TakeOFF,Raising_Gear,Gear_up,Checking_before_landing,Lowering_gear};
state state_machine[6]={{"GearDown", "Green", "Down", "Enabled"},
{"Checkingbeforetakeoff", "Green","Down", "Enabled"},
{"Raising Gear", "Red", "Up", "Enabled"},
{"Gearup", "off", "Null", "Disabled"},
{"Checking before landing", "Red","Down", "Enabled"},
{"Loweringgear", "Green", "Down", "Enabled"}};
int main()
{
current_state=GEAR_DOWN;
while(1)
{
state1[current_state]();
}
}
void Gear_down()
{
current_state=GEAR_DOWN;
printf("Enter the values of pil and Squatswitch: ");
fflush(stdout);
scanf("%d %d",&pil,&Squat_switch);
if(pil==raising && Squat_switch==close)
{
current_state=CHECKING_BEFORE_TAKEOFF;
printf("\n status of currentstate is %s",state_machine[current_state].currentstate);
printf("\n status of lightvalue is %s",state_machine[current_state].lightvalue);
printf("\n status of directionValve is %s",state_machine[current_state].directionValve);
printf("\n status of Hydraliccontrol is %s",state_machine[current_state].Hydraliccontrol);
}
else
{
Gear_down();
}
}
void Checking_Before_TakeOFF()
{
current_state= CHECKING_BEFORE_TAKEOFF;
printf("Enter the values of pil and squatswitch");
fflush(stdout);
scanf("%d %d %d",&pil,&Squat_switch);
if(pil==falling && Squat_switch==close)
{
current_state=GEAR_DOWN;
printf("\n status of currentstate is %s",state_machine[current_state].currentstate);
printf("\n status of lightvalue is %s",state_machine[current_state].lightvalue);
printf("\n status of directionValve is %s",state_machine[current_state].directionValve);
printf("\n status of Hydraliccontrol is %s",state_machine[current_state].Hydraliccontrol);
}
if(pil==up && operation==Working)
{
current_state=RAISING_GEAR;
printf("\n status of currentstate is %s",state_machine[current_state].currentstate);
printf("\n status of lightvalue is %s",state_machine[current_state].lightvalue);
printf("\n status of directionValve is %s",state_machine[current_state].directionValve);
printf("\n status of Hydraliccontrol is %s",state_machine[current_state].Hydraliccontrol);
}
else
{
Checking_Before_TakeOFF();
}
}
void Raising_Gear()
{
current_state=RAISING_GEAR;
printf("Enter the values of pil and limit_switch");
fflush(stdout);
scanf("%d %d",&pil,&limit_switch);
if(pil==falling)
{
current_state=CHECKING_BEFORE_LANDING;
printf("\n status of currentstate is %s",state_machine[current_state].currentstate);
printf("\n status of lightvalue is %s",state_machine[current_state].lightvalue);
printf("\n status of directionValve is %s",state_machine[current_state].directionValve);
printf("\n status of Hydraliccontrol is %s",state_machine[current_state].Hydraliccontrol);
}
if(limit_switch==close)
{
current_state=GEAR_UP;
printf("\n status of currentstate is %s",state_machine[current_state].currentstate);
printf("\n status of lightvalue is %s",state_machine[current_state].lightvalue);
printf("\n status of directionValve is %s",state_machine[current_state].directionValve);
printf("\n status of Hydraliccontrol is %s",state_machine[current_state].Hydraliccontrol);
}
else
{
Raising_Gear();
}
}
void Gear_up()
{
current_state=GEAR_UP;
printf("Enter the values of pil ");
fflush(stdout);
scanf("%d",&pil);
if(pil==falling)
{
current_state=CHECKING_BEFORE_LANDING;
printf("\n status of currentstate is %s",state_machine[current_state].currentstate);
printf("\n status of lightvalue is %s",state_machine[current_state].lightvalue);
printf("\n status of directionValve is %s",state_machine[current_state].directionValve);
printf("\n status of Hydraliccontrol is %s",state_machine[current_state].Hydraliccontrol);
}
else
{
Gear_up();
}
}
void Checking_before_landing()
{
current_state=CHECKING_BEFORE_LANDING;
printf("Enter the values of pil and operation");
fflush(stdout);
scanf("%d %d",&pil,&operation);
if(pil==down || operation==Not_working)
{
current_state=LOWERING_GEAR;
printf("\n status of currentstate is %s",state_machine[current_state].currentstate);
printf("\n status of lightvalue is %s",state_machine[current_state].lightvalue);
printf("\n status of directionValve is %s",state_machine[current_state].directionValve);
printf("\n status of Hydraliccontrol is %s",state_machine[current_state].Hydraliccontrol);
}
else
{
Checking_before_landing();
}
}
void Lowering_gear()
{
current_state=LOWERING_GEAR;
printf("Enter the values of pil and limit_switch");
fflush(stdout);
scanf("%d %d",&pil,&limit_switch);
if(limit_switch==close)
{
current_state=GEAR_DOWN;
printf("\n status of currentstate is %s",state_machine[current_state].currentstate);
printf("\n status of lightvalue is %s",state_machine[current_state].lightvalue);
printf("\n status of directionValve is %s",state_machine[current_state].directionValve);
printf("\n status of Hydraliccontrol is %s",state_machine[current_state].Hydraliccontrol);
}
if(pil==raising)
{
current_state=CHECKING_BEFORE_TAKEOFF;
printf("\n status of currentstate is %s",state_machine[current_state].currentstate);
printf("\n status of lightvalue is %s",state_machine[current_state].lightvalue);
printf("\n status of directionValve is %s",state_machine[current_state].directionValve);
printf("\n status of Hydraliccontrol is %s",state_machine[current_state].Hydraliccontrol);
}
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.