Challenge

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

PROJECT 2

<!-- [if gte mso 9]><xml> </xml><![endif]--><!-- [if gte mso 9]><xml> Normal 0 false false false EN-US X-NONE X-NONE </xml><![endif]--><!-- [if gte mso 9]><xml> </xml><![endif]--><!-- [if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:8.0pt; mso-para-margin-left:0in; line-height:107%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri",sans-serif; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt; mso-ligatures:standardcontextual;} </style> <![endif]-->

#include

#include

 enum Statetype { GEAR_DOWN, CHECKING_BEFORE_TAKEOFF, RAISING_GEAR, GEAR_UP, CHECKING_BEFORE_LANDING, LOWERING_GEAR };// here we used enum function named as statetype and inside it we provided all the airplane states

 enum Switch { OPEN ,CLOSE };// here we switch as a enum function by which we assigning the integer value for the open =0 and close =1

 enum Pilot_lever { RISING, FALLING, UP, DOWN };//same done here and inside the hydraulic .

 enum Hydraulic_mechanism { WORKING, NOT_WORKING };

enum Statetype Currentstate;// here we declares a global variable named Currentstate of type enum Statetype

typedef struct State_table// here we declares the structure as state table and inside it, we declares the string type variables for printing the all outputs of the state machine.

{

    char *currentstate;// because it is inside the structure so we declares these variables as pointer

    char *light;

    char *direction_valve;

    char *hydraulic_control;

};

 

// these all are the Function prototypes

void GearDownState(void);

void CheckingBeforeTakeoffState(void);

void RaisingGearState(void);

void GearUpState(void);

void CheckingBeforeLandingState(void);

void LoweringGearState(void);

 

 

static void (*state_table[])(void) = {

    GearDownState,

    CheckingBeforeTakeoffState,

    RaisingGearState,

    GearUpState,

    CheckingBeforeLandingState,

    LoweringGearState

};//here Array of function pointers representing the state transition table

 

static struct State_table state_machine[6] =

{

    {"Gear Down", "Green", "Down", "Enabled"},

    {"Checking before take off", "Green", "Down", "Enabled"},

    {"Raising Gear", "Red", "Up", "Enabled"},

    {"Gear up", "off", "Null", "Disabled"},

    {"Checking before landing", "Red", "Down", "Enabled"},

    {"Lowering gear", "Green", "Down", "Enabled"}

};// Array of structures representing the state machine and here we takes the size of array as 6 because we have total 6 states and 4 variables i.e. inside the structure.

 

int main() {

      Currentstate=GEAR_DOWN;// here we assigning the initial state of the airplane

    while (1)

    {

        state_table[Currentstate]();// state_table[GEAR_DOWN=0] , means according to static void state table array our state_table[0] is the geardownstate function. so first we go to inside the geardownstate function.

    }

}

void GearDownState(void)// here we provided the specific details inside this state transition function

{

    Currentstate = GEAR_DOWN;

    int pil, squat;// here we declares the integer type variables for asking to the user that what he wants to do first

    printf("\n Enter 0= pilot lever rising \n Enter 1 = pilot lever falling\n");

    fflush(stdout);

    scanf("%d", &pil);

    printf("\n Enter 0= squat switch open \n Enter 1= squat switch close");

    fflush(stdout);

    scanf("%d", &squat);

    if (pil == RISING && squat == OPEN)// here we used && operator that means both the condition should be matched for going to the next state as checking before takeoff.

    {

        Currentstate = CHECKING_BEFORE_TAKEOFF;

        printf("\ncurrent state : %s, Light: %s, Direction Valve: %s, Hydraulic Control: %s\n",

               state_machine[Currentstate].currentstate,

               state_machine[Currentstate].light,

               state_machine[Currentstate].direction_valve,

               state_machine[Currentstate].hydraulic_control);// here we printing all the condition i.e. written inside state_machine[1] array.

    } else{

        GearDownState();

    }

}

 

void CheckingBeforeTakeoffState(void)// similarly we provides the all necessary details for the execution of the checkingbeforetakeoffstate function.

{

    Currentstate = CHECKING_BEFORE_TAKEOFF;

    int pil, squat, hyd;

    printf("\n Enter 0= pilot lever rising \n Enter 1 = pilot lever falling\n Enter 2= pilot lever is UP \n Enter 3 = pilot lever is DOWN");

    fflush(stdout);

    scanf("%d", &pil);

    printf("\n Enter 0= squat switch open \n Enter 1= squat switch close");

    fflush(stdout);

    scanf("%d", &squat);

    printf("\n Enter 0= hydraulic mechanism is working\n Enter 1= hydraulic mechanism is not working");

    fflush(stdout);

    scanf("%d", &hyd);

    if (pil == FALLING && squat == CLOSE)

    {

        Currentstate = GEAR_DOWN;

        printf("\ncurrent state : %s, Light: %s, Direction Valve: %s, Hydraulic Control: %s\n",

                  state_machine[Currentstate].currentstate,

               state_machine[Currentstate].light,

               state_machine[Currentstate].direction_valve,

               state_machine[Currentstate].hydraulic_control);// here when the condition gets satisfy then the current state will become the GEAR_DOWN that means 0 as integer. so we are going to print the statements of the state_machine[0].

    }

    else if (pil == UP && hyd == WORKING)// this will execute when the above condition will not satisfy but these both condition got satisfy then we are going to execute the written program, currentstate as rising gear.

    {

        Currentstate = RAISING_GEAR;

        printf("\ncurrent state : %s, Light: %s, Direction Valve: %s, Hydraulic Control: %s\n",

                  state_machine[Currentstate].currentstate,

               state_machine[Currentstate].light,

               state_machine[Currentstate].direction_valve,

               state_machine[Currentstate].hydraulic_control);

    } else

    {

        CheckingBeforeTakeoffState();

    }

}

 

void RaisingGearState(void)

{

    Currentstate = RAISING_GEAR;

    int pil, squat;

    printf("\n Enter 0= pilot lever rising \n Enter 1 = pilot lever falling\n Enter 2= pilot lever is UP \n Enter 3 = pilot lever is DOWN");

    fflush(stdout);

    scanf("%d", &pil);

 

    if (pil == FALLING)// here by giving the instruction only falling after the rising gear state , this statement will going to print all

    {

        Currentstate = CHECKING_BEFORE_LANDING;

        printf("\ncurrent state : %s, Light: %s, Direction Valve: %s, Hydraulic Control: %s\n",

                  state_machine[Currentstate].currentstate,

               state_machine[Currentstate].light,

               state_machine[Currentstate].direction_valve,

               state_machine[Currentstate].hydraulic_control);

    }

    else// here if user don't wants to go on falling then in this else condition we are going to ask user about the condition of limit switch

    {

        printf("\n Enter 0= limit switch open \n Enter 1= limit switch close");

        fflush(stdout);

        scanf("%d", &squat);

    }

    if (squat == CLOSE)// only by giving the close condition to the limit switch this will tell you the currentstate as a gear_up and then will going to print the values of the state_machine[3].

    {

        Currentstate = GEAR_UP;

        printf("\ncurrent state : %s, Light: %s, Direction Valve: %s, Hydraulic Control: %s\n",

                  state_machine[Currentstate].currentstate,

               state_machine[Currentstate].light,

               state_machine[Currentstate].direction_valve,

               state_machine[Currentstate].hydraulic_control);

    }

    else{

      RaisingGearState();

    }

}

 

void GearUpState(void)

{

    Currentstate = GEAR_UP;

    int pil;

    printf("\n Enter 0= pilot lever rising \n Enter 1 = pilot lever falling\n Enter 2= pilot lever is UP \n Enter 3 = pilot lever is DOWN");

    fflush(stdout);

    scanf("%d", &pil);

    if (pil == FALLING)

    {

        Currentstate = CHECKING_BEFORE_LANDING;

        printf("\ncurrent state : %s, Light: %s, Direction Valve: %s, Hydraulic Control: %s\n",

                  state_machine[Currentstate].currentstate,

               state_machine[Currentstate].light,

               state_machine[Currentstate].direction_valve,

               state_machine[Currentstate].hydraulic_control);

    } else {

        GearUpState();

    }

}

 

void CheckingBeforeLandingState(void) {

    Currentstate = CHECKING_BEFORE_LANDING;

    int pil;

    printf("\n Enter 0= pilot lever rising \n Enter 1 = pilot lever falling\n Enter 2= pilot lever is UP \n Enter 3 = pilot lever is DOWN \n");

    fflush(stdout);

    scanf("%d", &pil);

    if (pil == DOWN)

    {

        Currentstate = LOWERING_GEAR;

        printf("\ncurrent state : %s, Light: %s, Direction Valve: %s, Hydraulic Control: %s\n",

                  state_machine[Currentstate].currentstate,

               state_machine[Currentstate].light,

               state_machine[Currentstate].direction_valve,

               state_machine[Currentstate].hydraulic_control);

    } else {

        CheckingBeforeLandingState();

    }

}

 

void LoweringGearState(void)

{

    Currentstate = LOWERING_GEAR;

    int squat, pil;

    printf("\n Enter 0= pilot lever rising \n Enter 1 = pilot lever falling\n Enter 2= pilot lever is UP \n Enter 3 = pilot lever is DOWN");

    fflush(stdout);

    scanf("%d", &pil);

     if (pil == RISING)

     {

    Currentstate = CHECKING_BEFORE_TAKEOFF;

    printf("\ncurrent state : %s, Light: %s, Direction Valve: %s, Hydraulic Control: %s\n",

            state_machine[Currentstate].currentstate,

           state_machine[Currentstate].light,

           state_machine[Currentstate].direction_valve,

           state_machine[Currentstate].hydraulic_control);

      }else{

          printf("\n Enter 0= limit switch open \n 1= limit switch close");

          fflush(stdout);

          scanf("%d", &squat);

      }

 if (squat==OPEN){

          Currentstate = GEAR_DOWN;

          printf("\ncurrent state : %s, Light: %s, Direction Valve: %s, Hydraulic Control: %s\n",

                  state_machine[Currentstate].currentstate,

                 state_machine[Currentstate].light,

                 state_machine[Currentstate].direction_valve,

                 state_machine[Currentstate].hydraulic_control);

 }

 else{

        LoweringGearState();

    }

}

 

 

// same we did inside the gearupstate , checkingbeforelanding and loweringgearstate function.

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.