Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
#include
enum state
{
geardown, //0
checktakeoffcondition, //1
risinggear, //2
gearup, //3
checkbeforelanding, //4
loweringgear //5
};
enum pilot
{
rising, //0
falling, //1
up, //2
down //3
};
struct airplane
{
char squatswitch[10];
char light[10];
char direction[5];
char limitswitch[8];
char control[10];
};
struct airplane table[] = {{"close", "red", "", "opened", ""},{"open", "green", "", "", ""},{"", "RED","up", "", ""},
{"", "OFF", "", "Closed", "disabled"},{"", "RED", "", "", "Enabled"},{"", "GREEN", "Down", "Opened", ""}};
void gear_down();
void check_takeoff_condition();
void rising_gear();
void Gear_up();
void checking_before_landing();
void lowering_gear();
void (*function[])(void) = {gear_down, check_takeoff_condition, rising_gear, Gear_up, checking_before_landing, lowering_gear};
enum state currentstate = geardown;
enum pilot pilotlever;
int main()
{
while (1)
{
function[currentstate]();
}
return 0;
}
void gear_down()
{
printf("\nThe current state is geardown");
printf("\nEnter 0.rising, 1.falling, 2.up, 3.down: ");
scanf("%d",(int*)&pilotlever);
if (pilotlever == rising)
{
currentstate = checktakeoffcondition;
printf("\nSquat switch: %s", table[currentstate].
printf("\nLight: %s", table[currentstate].light);
}
else if (pilotlever == falling)
{
currentstate = geardown;
printf("\nSquat switch: %s", table[currentstate].
printf("\nLight: %s", table[currentstate].light);
}
}
void check_takeoff_condition()
{
printf("\nThe current state is check_takeoff_condition");
printf("\nEnter 0.rising, 1.falling, 2.up, 3.down: ");
scanf("%d",(int*)&pilotlever);
if (pilotlever == rising)
{
currentstate = checktakeoffcondition;
printf("\nSquat switch: %s", table[currentstate].
printf("\nLight: %s", table[currentstate].light);
}
else if (pilotlever == falling)
{
currentstate = geardown;
printf("\nSquat switch: %s", table[currentstate].
printf("\nLight: %s", table[currentstate].light);
}
else if (pilotlever == up)
{
currentstate = risinggear;
printf("\ndirection: %s", table[currentstate].direction)
printf("\nLight: %s", table[currentstate].light);
}
}
void rising_gear()
{
printf("\nThe current state is rising_gear");
printf("\nEnter 0.rising, 1.falling, 2.up, 3.down: ");
scanf("%d",(int*)&pilotlever);
if(pilotlever == falling)
{
currentstate = checkbeforelanding;
// printf("\ndirection: %s", table[currentstate].direction)
printf("\npilot lever is falling");
printf("\nLight: %s", table[currentstate].light);
}
else if(pilotlever == rising)
{
currentstate = gearup;
printf("\nlimitswitch: %s", table[currentstate].
printf("\nLight: %s", table[currentstate].light);
printf("\nctrl for landing gear: %s", table[currentstate].control);
}
}
void Gear_up()
{
if(currentstate == gearup)
{
printf("\n");
printf("\nEntering the GearUp condition");
currentstate = checkbeforelanding;
printf("\nSwitching to check before landing");
printf("\nLight: %s", table[currentstate].light);
printf("\nctrl for landing gear: %s", table[currentstate].control);
}
}
void checking_before_landing()
{
printf("\nThe current state is check before landing");
printf("\nEnter 0.rising, 1.falling, 2.up, 3.down: ");
scanf("%d",(int*)&pilotlever);
if(pilotlever == down)
{
currentstate = loweringgear;
printf("\ndirection: %s", table[currentstate].direction)
//printf("\nLight: %s", table[currentstate].light);
}
}
void lowering_gear()
{
printf("\nThe current state is lowering gear");
printf("\nEnter 0.rising, 1.falling, 2.up, 3.down: ");
scanf("%d",(int*)&pilotlever);
if(pilotlever == rising)
{
currentstate = checktakeoffcondition;
printf("\nLight: %s", table[currentstate].light);
}
else
{
currentstate = geardown;
printf("\nlimitswitch: %s", table[currentstate].
printf("\nLight: %s", table[currentstate].light);
printf("\n squatswitch: %s",table[currentstate].
}
}