Challenge

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

Embedded c - Offline batch 2 - Kirubhakaran

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

#include <stdio.h>
#include <stdlib.h>//preprocessor

void initstate();
void Gear_up();
void Gear_down();
void chkb4_lnd();
void chkb4_tak();
void Raising_gr();
void Lowering_gr();//sub function declaration

typedef enum state_type
{
    gear_up,
    gear_down,
    raising_gr,
    lowering_gr,
    chkb4_land,
    chkb4_take,
}state;//enum datatype for different states

typedef enum plever
{
    up,
    falling,
    down,
    raising
}pilot;//enum for different position of pilot's lever

typedef enum Switc
{
    closed,
    opened
}Switch;//enum for position of the switch

typedef struct
{
    char* indication;
    char* light;
    char* valve_status;
}state_machine;//structure to print the output according to the input

static volatile state current_state;
static volatile pilot pilot_lever;
static volatile Switch limit,squat;//declaration of enum datatype objects

static state_machine landing_gear[6]={{"Gear_UP","OFF","disabled"},
                                      {"Gear_Down","GREEN","down"},
                                      {"Raising_Gear","RED","up"},
                                      {"Lowering_Gear","RED","down"},
                                      {"Checking_before_landing","RED","down"},
                                      {"Checking_before_takeoff","RED","up"}};//structure definition

static void (*state_table[])(void)={Gear_up,Gear_down,Raising_gr,Lowering_gr,chkb4_lnd,chkb4_tak};//function array to call the sub functions

int main()//main function
{
initstate();//sub function call to initialize the current state

    while(1)
        state_table[current_state]();//infinite loop to call the function based on the current state
}

void Gear_up()//sub function call to gear up
{
    current_state = gear_up;
    printf("\nYou are in %s stage",landing_gear[current_state].indication);
    printf("\nEnter the input for pilot lever status : ");
    scanf("%d",&pilot_lever);//input from user for pilot lever
    if(pilot_lever == falling)
    {
        current_state = chkb4_land;
        printf("\nCurrent state is %s , Light status is %s , Direction valve is %s\n",landing_gear[current_state].indication,landing_gear[current_state].light,landing_gear[current_state].valve_status);
    }//printing the output
}

void Gear_down()//sub function to gear down
{
    current_state = gear_down;
    printf("\nYou are in %s stage",landing_gear[current_state].indication);
    printf("\nEnter the input for pilot lever status and squat switch status : ");
    scanf("%d%d",&pilot_lever,&squat);//input from user for pilot lever and squat switch
    if(pilot_lever == raising && squat == opened)
    {
        current_state = chkb4_take;
        printf("\nCurrent state is %s , Light status is %s , Direction valve is %s\n",landing_gear[current_state].indication,landing_gear[current_state].light,landing_gear[current_state].valve_status);
    }//printing the output
}

void chkb4_lnd()//sub function to check before landing
{
    current_state = chkb4_land;
    printf("\nYou are in %s stage",landing_gear[current_state].indication);
    printf("\nEnter the input for pilot lever status : ");
    scanf("%d",&pilot_lever);//input from user for pilot lever
    if(pilot_lever == down)
    {
        current_state = lowering_gr;
        printf("\nCurrent state is %s , Light status is %s , Direction valve is %s\n",landing_gear[current_state].indication,landing_gear[current_state].light,landing_gear[current_state].valve_status);
    }//printing the output
}

void chkb4_tak()//sub function to check before take-of
{
    current_state = chkb4_take;
    printf("\nYou are in %s stage",landing_gear[current_state].indication);
    printf("\nEnter the input for pilot lever status and squat switch status : ");
    scanf("%d%d",&pilot_lever,&squat);//input from user for pilot lever and squat switch
    if(pilot_lever == up && squat == opened)
    {
        current_state = raising_gr;
        printf("Current state is %s , Light status is %s , Direction valve is %s\n",landing_gear[current_state].indication,landing_gear[current_state].light,landing_gear[current_state].valve_status);
    }//printing the output
    else if(pilot_lever == falling || squat == closed)
    {
        current_state = gear_down;
        printf("\nCurrent state is %s , Light status is %s , Direction valve is %s\n",landing_gear[current_state].indication,landing_gear[current_state].light,landing_gear[current_state].valve_status);
    }//printing the output
}

void Raising_gr()//sub function to raising the gear
{
    current_state = raising_gr;
    printf("\nYou are in %s stage",landing_gear[current_state].indication);
    printf("\nEnter the input for pilot lever status and limit switch status : ");
    scanf("%d%d",&pilot_lever,&limit);//input from user for pilot lever and limit switch

    if(limit == closed)
    {
        current_state = gear_up;
        printf("\nCurrent state is %s , Light status is %s , Direction valve is %s\n",landing_gear[current_state].indication,landing_gear[current_state].light,landing_gear[current_state].valve_status);
    }//printing the output
    else if(pilot_lever == falling)
    {
        current_state = chkb4_land;
        printf("\nCurrent state is %s , Light status is %s , Direction valve is %s\n",landing_gear[current_state].indication,landing_gear[current_state].light,landing_gear[current_state].valve_status);
    }//printing the output
}

void Lowering_gr()//sub function to lowering the gear
{
    current_state = lowering_gr;
    printf("\nYou are in %s stage",landing_gear[current_state].indication);
    printf("\nEnter the input for pilot lever status and limit switch status : ");
    scanf("%d%d",&pilot_lever,&limit);//input from user for pilot lever and limit switch

    if(pilot_lever == raising)
    {
        current_state = chkb4_take;
        printf("\nCurrent state is %s , Light status is %s , Direction valve is %s\n",landing_gear[current_state].indication,landing_gear[current_state].light,landing_gear[current_state].valve_status);
    }//printing the output
    else if(limit == opened)
    {
        current_state = gear_down;
        printf("\nCurrent state is %s , Light status is %s , Direction valve is %s\n",landing_gear[current_state].indication,landing_gear[current_state].light,landing_gear[current_state].valve_status);
    }//printing the output
}

void initstate()//sub function to initiate the current state and program
{
    current_state = gear_up;
    printf("\nThe program is initialized and your current stage is %s\n",landing_gear[current_state].indication);
}   //printing the output

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.