Challenge

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

/*
* main.c
*
* Created on: 27-Aug-2022
* Author: Viraj
*/


#include<stdio.h>
#include "states.h" /*Including header file*/

static void(*StateTable[])(void)={GearDown,CheckingBeforeTakeoff,RaisingGear,GearUp,CheckingBeforeLanding,LoweringGear};

int main()
{
Initiate_State_Machine(); //Calling the state initialization function

while(1)
{
StateTable[Current_State]();
}

}

//Gear Down
void GearDown()
{
Current_State=GEAR_DOWN;

printf("\nCurrent state:%s",State_Machine[Current_State].Current_State_Indication);
printf("\nLight is:%s\n",State_Machine[Current_State].Light);

printf("\nEnter the status of pilot's lever and squat switch:");
fflush(stdout);
scanf("%d%d",&pilot_lever,&squat_switch);

if((pilot_lever==raising)&&(squat_switch==on))
{
Current_State=CHECKING_BEFORE_TAKEOFF;

printf("\nCurrent state:%s",State_Machine[Current_State].Current_State_Indication);
printf("\nLight is:%s\n",State_Machine[Current_State].Light);
}
else
{
GearDown();
}
}

void CheckingBeforeTakeoff(void)
{
Current_State=CHECKING_BEFORE_TAKEOFF;

printf("\nEnter the status of pilot's lever,squat switch and hydraulic mechanism:");
fflush(stdout);
scanf("%d%d%d",&pilot_lever,&squat_switch,&hydraulic_mechanism);

if((pilot_lever==falling)||(squat_switch==off))
{
GearDown();
}

else if((pilot_lever==raising)&&(squat_switch==on)&&(hydraulic_mechanism==working))
{
Current_State=RAISING_GEAR;
printf("\nCurrent state:%s",State_Machine[Current_State].Current_State_Indication);
printf("\nLight is:%s",State_Machine[Current_State].Light);
printf("\nStatus of direction valve:%s",State_Machine[Current_State].Status_Direction_Valve);
}

else if((pilot_lever==raising)&&(squat_switch==on)&&(hydraulic_mechanism==not_working))
{
Current_State=RAISING_GEAR;
printf("\nCurrent state:%s",State_Machine[Current_State].Current_State_Indication);
printf("\nLight is:%s",State_Machine[Current_State].Light);
printf("\nStatus of direction valve:%s",State_Machine[Current_State].Status_Direction_Valve);
printf("\nStatus of gas pressurized spring system:%s",State_Machine[Current_State].Status_Gas_Pressure_Spring);
}
}

void RaisingGear(void)
{
Current_State=RAISING_GEAR;
printf("\nCurrent state:%s",State_Machine[Current_State].Current_State_Indication);
printf("\nLight is:%s",State_Machine[Current_State].Light);
printf("\nStatus of direction valve:%s",State_Machine[Current_State].Status_Direction_Valve);

printf("\nEnter the status of pilot's lever and limit switch:");
fflush(stdout);
scanf("%d%d",&pilot_lever,&limit_switch);

if((pilot_lever==falling)&&(limit_switch==on))
{
Current_State=CHECKING_BEFORE_LANDING;
printf("\nCurrent state:%s",State_Machine[Current_State].Current_State_Indication);
printf("\nLight is:%s",State_Machine[Current_State].Light);
printf("\nStatus of landing gear hydraulic control:%s",State_Machine[Current_State].Landing_Gear_Hydraulic_Control);
}

else if((pilot_lever==raising)&&(limit_switch==off))
{
Current_State=GEAR_UP;
printf("\nCurrent state:%s",State_Machine[Current_State].Current_State_Indication);
printf("\nLight is:%s",State_Machine[Current_State].Light);
printf("\nStatus of direction valve:%s",State_Machine[Current_State].Status_Direction_Valve);
}

else
{
RaisingGear();
}
}

void GearUp(void)
{
Current_State=CHECKING_BEFORE_LANDING;
printf("\nCurrent state:%s",State_Machine[Current_State].Current_State_Indication);
printf("\nLight is:%s\n",State_Machine[Current_State].Light);

printf("\nEnter the status of pilot's lever:");
fflush(stdout);
scanf("%d",&pilot_lever);

if(pilot_lever==falling)
{
Current_State=CHECKING_BEFORE_LANDING;
printf("\nCurrent state:%s",State_Machine[Current_State].Current_State_Indication);
printf("\nLight is:%s",State_Machine[Current_State].Light);
printf("\nStatus of landing gear hydraulic control:%s",State_Machine[Current_State].Landing_Gear_Hydraulic_Control);
}
else
{
GearUp();
}
}

void CheckingBeforeLanding(void)
{
Current_State=CHECKING_BEFORE_LANDING;
printf("\nCurrent state:%s",State_Machine[Current_State].Current_State_Indication);
printf("\nLight is:%s\n",State_Machine[Current_State].Light);

printf("\nEnter the status 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("\nCurrent state:%s",State_Machine[Current_State].Current_State_Indication);
printf("\nLight is:%s",State_Machine[Current_State].Light);
printf("\nStatus of direction valve:%s",State_Machine[Current_State].Status_Direction_Valve);
}

else if((pilot_lever==raising)&&(squat_switch==on)&&(hydraulic_mechanism==not_working))
{
Current_State=LOWERING_GEAR;
printf("\nCurrent state:%s",State_Machine[Current_State].Current_State_Indication);
printf("\nLight is:%s",State_Machine[Current_State].Light);
printf("\nStatus of direction valve:%s",State_Machine[Current_State].Status_Direction_Valve);
printf("\nStatus of gas pressurized spring system:%s",State_Machine[Current_State].Status_Gas_Pressure_Spring);
}

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

void LoweringGear(void)
{
Current_State=LOWERING_GEAR;
printf("\nCurrent state:%s",State_Machine[Current_State].Current_State_Indication);
printf("\nLight is:%s\n",State_Machine[Current_State].Light);

printf("\nEnter the status 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=CHECKING_BEFORE_TAKEOFF;
printf("\nCurrent state:%s",State_Machine[Current_State].Current_State_Indication);
printf("\nLight is:%s",State_Machine[Current_State].Light);
}

if((pilot_lever==raising)&&(limit_switch==on))
{
Current_State=GEAR_DOWN;
printf("\nCurrent state:%s",State_Machine[Current_State].Current_State_Indication);
printf("\nLight is:%s",State_Machine[Current_State].Light);
printf("\nStatus of landing gear hydraulic control:%s",State_Machine[Current_State].Landing_Gear_Hydraulic_Control);
}

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

void Initiate_State_Machine()
{
Current_State=GEAR_DOWN;
printf("Finite state machine is initiated and current program is in Gear down state and light is %s\n",State_Machine[Current_State].Light);
printf("\nThe choices are as follow\n-----------------------------------------\n");
printf("Pilot lever RAISING=1\tPilot lever FALLING=0\nLimit switch OPEN=1\tLimit switch CLOSED=0\nSquat switch OPEN=1\tSquat switch CLOSED=0\nHydraulic mechanism WORKING=1\tHydraulic mechanism NOT WORKING=0\n\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.