Challenge

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

#include
#include "fsm.h"

static void(*stateTable[])(void)={GearDown, CheckingBeforeLand, RisingGear, GearUp, CheckingBeforeTakeoff, LoweringGear};
int main(){
	current_state= GEAR_DOWN;
	printf("The Finite State Machine is Initialized");
	printf("\nCurrent State is: %s", ¤t_state);
	printf("\nLight is: GREEN\n");
	while(1)
	{
		stateTable[current_state]();
	}
}
/*
 * fsm.h
 *
 *  Created on: 20-Jan-2023
 *      Author: lenovo
 */

#ifndef FSM_H_
#define FSM_H_

#include
void GearDown();
void CheckingBeforeTakeoff();
void RisingGear();
void GearUp();
void CheckingBeforeLand();
void LoweringGear();


// declaring all the state
typedef enum State
{
	GEAR_DOWN,
	CHECK_BEFORE_TAKEOFF,
	RISING_GEAR,
	GEAR_UP,
	CHECK_BEFORE_LAND,
	LOWERING_GEAR
} State_Type;
enum State current_state;

// declaring the status of switch
typedef enum Switch
{
	OPEN,
	CLOSE
} Switch_State;

//Initializing 2 switch
enum Switch limit_switch, squat_switch;

// declaring the status of Pilot lever
typedef enum Pilot
{
	RISING,
	FALLING,
	UP,
	DOWN
};

//Initializing pilot lever
enum Pilot pilot_lever;

// declaring the status of hydraulic machine
typedef enum Hydraulic_Machine
{
	MALFUNCTIONING,
	WORKING
} ;
enum Hydraulic_Machine Hydraulic_Status;

#endif /* FSM_H_ */
#include "fsm.h"

// Function for Gear Down
void GearDown(void)
{
	current_state = GEAR_DOWN;
	// Taking the input
	printf("Enter the status of pilot's lever & squat switch: ");
	fflush(stdout);
	scanf("%d %d", &pilot_lever, &squat_switch);
	if(pilot_lever==RISING && squat_switch==OPEN)
	{
		current_state = CHECK_BEFORE_TAKEOFF;
		printf("\nCurrent State: %s\n", current_state);
		printf("Light is: GREEN\n");
	}
	else
	{
		GearDown();
	}
}
#include "fsm.h"

void CheckingBeforeTakeOff(void)
{
	current_state = CHECK_BEFORE_TAKEOFF;
	printf("Enter the status of pilot's lever & squat switch and hydraulic machine state: ");
	fflush(stdout);
	scanf("%d %d %d", &pilot_lever, &squat_switch, &Hydraulic_Status);
	if(pilot_lever==FALLING && squat_switch==CLOSE)
	{
		GearDown();
	}
	else if(pilot_lever==RISING && squat_switch==OPEN && Hydraulic_Status==WORKING)
	{
		current_state = RISING_GEAR;
		printf("\nCurrent State: %s\n", current_state);
		printf("Light is: RED\n");
		printf("Status of Direction valve: UP\n");
	}
	else if(pilot_lever==RISING && squat_switch==OPEN && Hydraulic_Status==MALFUNCTIONING)
	{
		current_state = RISING_GEAR;
		printf("\nCurrent State: %s\n", current_state);
		printf("Light is: RED\n");
		printf("Status of Direction valve: DOWN\n");
	}

}
#include "fsm.h"

// Method for Rising gear
void RisingGear(void)
{
	current_state = RISING_GEAR;
	printf("Enter the status of pilot's lever & squat switch: ");
	fflush(stdout);
	scanf("%d %d", &pilot_lever, &limit_switch);
	if(pilot_lever==FALLING && limit_switch==OPEN)
	{
		current_state = CHECK_BEFORE_LAND;
		printf("\nCurrent State: %s\n", current_state);
		printf("Light is: RED\n");
	}
	else if(pilot_lever==UP && limit_switch==CLOSE)
	{
		current_state = GEAR_UP;
		printf("\nCurrent State: %s\n", current_state);
		printf("Light is: OFF\n");
		printf("Landing Gear Hydraulic Control: DISABLED\n");
	}
	else
	{
		RisingGear();
	}
}
#include "fsm.h"

// Method for Gear Up
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)
	{
		current_state = CHECK_BEFORE_LAND;
		printf("\nCurrent State: %s\n", current_state);
		printf("Light is: RED\n");
		printf("Landing Gear Hydraulic Control: ENABLED\n");
	}
	else
	{
		GearUp();
	}
}
#include "fsm.h"

// Method to check before land
void CheckingBeforeLand(void)
{
	current_state = CHECK_BEFORE_LAND;
	printf("Enter the status of pilot's lever and hydraulic machine state: ");
	fflush(stdout);
	scanf("%d %d", &pilot_lever, &Hydraulic_Status);
	if(pilot_lever==FALLING && Hydraulic_Status==WORKING)
	{
		current_state = LOWERING_GEAR;
		printf("\nCurrent State: %s\n", current_state);
		printf("Light is: GREEN\n");
		printf("Status of Direction valve: DOWN\n");
	}
	else if(pilot_lever==FALLING && Hydraulic_Status==MALFUNCTIONING)
	{
		current_state = LOWERING_GEAR;
		printf("\nCurrent State: %s\n", current_state);
		printf("Light is: GREEN\n");
		printf("Status of Direction valve: UP\n");
	}
	else{
		CheckingBeforeLand();
	}

}
#include "fsm.h"

void LoweringGear(void)
{
	current_state = LOWERING_GEAR;
	printf("Enter the status of pilot's lever & limit switch: ");
	fflush(stdout);
	scanf("%d %d", &pilot_lever, &limit_switch);
	if(pilot_lever==RISING && limit_switch==OPEN)
	{
		current_state = CHECK_BEFORE_TAKEOFF;
		printf("\nCurrent State: %s\n", current_state);
		printf("Light is: RED\n");
	}
	else if(pilot_lever==DOWN && limit_switch==OPEN)
	{
		current_state = GEAR_DOWN;
		printf("\nCurrent State: %s\n", current_state);
		printf("Light is: GREEN\n");
	}
}
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.