Challenge

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

#include
#include

void initial_state();
void gear_down();
void checking_before_takeoff();
void raising_gear();
void lowering_gear();
void checking_before_landing();
void gear_up();

enum states
{
    geardown,
    chkb4_takeoff,
    raisinggear,
    gearup,
    chkb4_landing,
    loweringgear
};

enum pilot_lever_state
{
    raising,
    falling,
    up,
    down
};

enum switch_state
{
    close,
    open
};
enum hyd_mech
{
    working,
    malfunction
};
int   squat_switch;
int  limit_switch;
int pilot_lever;
int hyd_machism;


enum states current_state;

struct airplane
{
    char* current_status;
    char* light_status;
    char* direction_valve_status;
    char* hydraulic_pump_status;
    //char* gas_pressurized;

};
struct airplane state_machine[6]=
{
    {"gear down","green","down","enabled"},
    {"chkbtakeof","green","down","enabled"},
    {"raising_gear","red","up","enabled"},
    {"gear_up","off","null","disabled"},
    {"chkb4_landing","red","down","enabled"},
    {"lowring_gear","green","down","enabled"}

};
void gear_down()
{
    current_state=geardown;
    printf("\n enter the pilot lever state and squat switch state");
    scanf("%d%d",&pilot_lever,&squat_switch);
    if(pilot_lever==raising && squat_switch==open)
    {
        current_state=chkb4_takeoff;
        printf("\n the current state is :%s",state_machine[current_state].current_status);
        printf("\n light status is %s",state_machine[current_state].light_status);
    }
    else
    {
        gear_down();
    }

}
void checking_before_takeoff()
{
    current_state=chkb4_takeoff;
    printf("\n enter the pilot lever state and the squat swwitch state");
    scanf("%d%d",&pilot_lever,&squat_switch);
    if(pilot_lever ==up && squat_switch==open)
    {
        current_state=raisinggear;
        printf("\n the current state is :%s",state_machine[current_state].current_status);
        printf("\n light status is :%s",state_machine[current_state].light_status);
        printf("\n direction valve states:%s",state_machine[current_state].direction_valve_status);
    }
}
void raising_gear()
{
    current_state=raisinggear;
    printf("\n enter the limit switch state");
    scanf("%d",&limit_switch);
    if(limit_switch==close)
    {
        current_state=gearup;
        printf("\n the current state is :%s",state_machine[current_state].current_status);
        printf("\n light states is :%s",state_machine[current_state].light_status);
        printf("\n direction valve states is :%s",state_machine[current_state].direction_valve_status);
        printf("\n hydraulic_pump_status is :%s",state_machine[current_state].hydraulic_pump_status);

    }
    printf("\n enter the pilot lever state");
    scanf("%d",&pilot_lever);
    if(pilot_lever==falling)
    {
       current_state=chkb4_landing;
        printf("\n the current state is :%s",state_machine[current_state].current_status);
        printf("\n light states is :%d",state_machine[current_state].light_status);
        printf("\n direction valve states is :%s",state_machine[current_state].direction_valve_status);
        printf("\n hydraulic_pump_status is :%s",state_machine[current_state].hydraulic_pump_status);


    }

}
void gear_up()
{
    current_state=gearup;
    printf("\n enter the pilot_valve_state");
    scanf("%d",&pilot_lever);
    if(pilot_lever==falling)
    {
        current_state=chkb4_landing;
        printf("\n the current state is:%s",state_machine[current_state].current_status);
        printf("\n light states is :%s",state_machine[current_state].light_status);
        printf("\n direction valve status is :%s",state_machine[current_state].direction_valve_status);
        printf("\n hydraulic pumb status is :%s",state_machine[current_state].hydraulic_pump_status);

    }
}
void checking_before_landing()
{
    current_state=chkb4_landing;
    printf("\n enter pilot lever state");
    scanf("%d",&pilot_lever);
    if(pilot_lever==falling)
    {
        current_state=loweringgear;
        printf("\n the current state is:%s",state_machine[current_state].current_status);
        printf("\n light states is :%s",state_machine[current_state].light_status);
        printf("\n direction valve status is :%s",state_machine[current_state].direction_valve_status);
        printf("\n hydraulic pumb status is :%s",state_machine[current_state].hydraulic_pump_status);

    }
}
void lowering_gear()
{
    current_state=loweringgear;
    printf("\n limit switch state");
    scanf("%d",&limit_switch);
    if(limit_switch==open)
    {
        current_state=geardown;
        printf("\n the current state is:%s",state_machine[current_state].current_status);
        printf("\n light states is :%s",state_machine[current_state].light_status);
        printf("\n direction valve status is :%s",state_machine[current_state].direction_valve_status);
        printf("\n hydraulic pumb status is :%s",state_machine[current_state].hydraulic_pump_status);
    }
    printf("\n enter the pilot lever status");
    scanf("%d",&pilot_lever);
    if(pilot_lever==raising)
    {
        current_state=chkb4_takeoff;
        printf("\n the current state is:%s",state_machine[current_state].current_status);
        printf("\n light states is :%s",state_machine[current_state].light_status);
        printf("\n direction valve status is :%s",state_machine[current_state].direction_valve_status);
        printf("\n hydraulic pumb status is :%s",state_machine[current_state].hydraulic_pump_status);
    }

}
void inital_state()
{
    current_state=geardown;
}

void(*airplane[])(void)= {gear_down,checking_before_takeoff,raising_gear,gear_up,checking_before_landing,lowering_gear};
int main()
{
    //initial_state();
    while(1)
    {
        airplane[current_state]();
    }
    return 0;
}

 
 
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.