Challenge

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

#main.c

#include<stdio.h>
#include<states.h>

static void(*stateTable[])(void)=(GearDown,CheakingBeforeTakeOFF,RaisingGear,GearUp,CheckingBeforeLanding,LoweringGear);

int main()
{
Initiate_State_Machine();
while(1)
{
stateTable[current_state]();
}
}
//GearDown
void GearDown(void)
{
current_state=CHEAKING_BEFORE_TAKEOFF;
printf("Enter the status of pilot's lever and squat switch and hydraulic mechanism:");
fflush(stdout);
scanf("%d %d",&pilot_lever,&squat_switch,&hydraulic_mechanism);
if(pilot_lever==falling && squat_switch==Off)
{
GearDown();

}
else if(pilot_lever==raising && Squat_switch==On && hudraulic_mechanism==working)
{
current_state=RAISNG_GEAR;
printf("current state :%s\n",State_Machine[current_state].current_state_indication);
printf("Light is :%s\n",State_Machine[current_state].light);
printf("Loading Gear Hydraulic Control :%s\n", State_Machine[current_state].landing_gear_hydraulic_control);


}
else
{
RaisingGear();
}
}
//GearUp
void GearUP(void)
{
current_state==GEAR_UP;
printf("Enter the state of pilot's lever:");
fflush(stdout);
scanf("%d",&pilot_lever);
if(pilot_lever==falling)
{
current_state=CHEAKING_BEFORE_LANDING;
printf("current state :%s\n",State_Machine[current_state].current_state_indication);
printf("Light is :%s\n",State_Machine[current_state].light);
printf("Loading Gear Hydraulic Control :%s\n", State_Machine[current_state].landing_gear_hydraulic_control);


}
else
{
GearUP();
}
}

//cheakingBeforeLanding
void CheakingBeforeLanding(void)
{
currenty_state=CHECK_BEFORE_LANDING;
printf("Enter the state of pilot's lever and hydraulic mechanism status:");
fflush(stdout);
scanf("%d %d",&pilot_lever,&hydraulic_mechanism);
if(pilot_lever==falling && hydraulic_mechanism==working)
{
current_state=LOWERING_GEAR;
printf("current state :%s\n",State_Machine[current_state].current_state_indication);
printf("Light is :%s\n",State_Machine[current_state].light);
printf("Status of Direction valve :%s\n", State_Machine[current_state].direction_valve_status);


}
State_Machine[current_state].direction_valve_status;

}
else if(pilot_lever==falling && squat_switch==On && hydraulic_mechanism==not_working)
{
current_state=LOWERING_GEAR;
printf("current state :%s\n",State_Machine[current_state].current_state_indication);
printf("Light is :%s\n",State_Machine[current_state].light);
printf("status of direction valve : %s\n",State_Machine[current_state].direction_valve_status);
printf("status of gas Pressuring spring system : %s\n",State_Machine[current_state].Gas_pressurized_Spring_system_status);

}
if(pilot_lever==(raising || falling))
{
CheckBeforeLanding();

}
}

//LoweringGear
void LoweringGear(void)
{
currenty_state=LOWERING-GEAR;
printf("Enter the state of pilot's lever and limit switch:");
fflush(stdout);
scanf("%d %d",&pilot_lever,&limit_switch);
if(pilot_lever== raising && limit_switch==On)
{
current_state=CHECK_BEFORE_TAKEOFF;
printf("current state :%s\n",State_Machine[current_state].current_state_indication);
printf("Light is :%s\n",State_Machine[current_state].light);

}

else if(pilot_lever==raising && limit_switch==Off)
{
current_state=GEAR_DOWN;
printf("current state :%s\n",State_Machine[current_state].current_state_indication);
printf("Light is :%s\n",State_Machine[current_state].light);
printf("landing gear Hydraulic control:%s\n",State_Machine[current_state].landing_gear_hydraulic_control);

}
if(limit_switch==Off)
{
LoweringGear();

}
}
void Initiate_State_Machine()
{
current_state=GEAR_DOWN;
printf("The Finite State Machine is Initialized and current the program is in"
"GearDown State & Light is : %s\n", State_Machine[current_state].light);
}

#Header file (Header.h)

#ifndef FSM_H_
#define FSM_H_

#include<stdio.h>
void Initiate_state_Machine();
void GearDown();
void CheckingBeforeTakeOFf();
void RaisingGear();
void GearUP();
void CheckBeforeLanding();
void LoweringGear();

typedef enum State
{
GEAR_DOWN,
CHECKING_BEFORE_TAKEOFF,
RAISING_GEAR,
GEAR_UP,
CHECK_BEFORE_LANDING,
LOWERING_GEAR,

}State_type;
typedef enum Switch
{
On
Off

}Switch_status;

typedef enum pilot_lever
{
Raising,
falling,

}pilot_lever;

typedef enum hydraulic_mechanism
{
working,
not working,

}hydraulic_mechanism;

static volatile Switch_Status squat_switch;
static volatile Switch_Status limit_switch;
static volatile Pilot_lever pilot_lever;
static volatile Hydraulic_Mechanism hydraulic_mechanism;

State_Type current_state;

typedef struct
{
char* current_state_indication;
char* light;
char* direction_valve_status;
char* Gas_Pressurized_Spring_system_status[2];
char* landing_gear_hydraulic_control;
}State_Table;

static State_Table;
State_Machine[6]=
{
{"GearDown","Green","Down","Enabled",{NULL,NULL}},
{"CheckingBeforetakeOFF","Green","Down","Enabled",{NULL,NULL}},
{"RaisingGear","Red","Up","Enabled",{"Disabled","Enabled"}},
{"GearUp","Off","Null","Disabled",{NULL,NULL}},
{"CheakingBeforeLanding","Red","Down","Enabled",{NULL,NULL}},
{"LoweringGear","Green","Down","Enabled",{"Disabled","Enabled"}}
};
#endif /* FSM_H_ */

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.

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.