Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
Embedded Offline-Batch2
#include
#include
typedef enum//enum declaration for lever position
{
down,
raising,
up,
falling
}liverpos;
liverpos a;
typedef enum//enum declaration for limit switch
{
open,
close
}limit;
typedef enum//enum declaration for squat switch
{
closee,
openn
}squat;
typedef struct finit //structure declaration for various states of airplane
{
char *currentstatus;
char *light;
char *nextstate;
char *gearstate;
}state;
//creating the instance as an array
state machine[6]={{"gear down","green","check before takeoff","gear is down"},
{"check before takeoff","red","gear raising","gear is down"},
{"gear raising","red","gear up","gear is up"},
{"gear up","off","checking for landing","gear is up"},
{"checking for landing","red","gear lowering","gear is down"},
{"gear lowering","green","gear down","gear is down"}};
void geardown()//function definition
{
int lp,ss,ls;
printf("enter the lever position : ");
scanf("%d",&lp);
printf("enter the squat switch condition: ");
scanf("%d",&ss);
printf("enter the limit switch condition: ");
scanf("%d",&ls);
if(lp==down && ss==openn && ls==open) //check the condition for gear down status
{
printf("light status is:%s\n",machine[0].light);
printf("current status :%s\n",machine[0].currentstatus);
printf("gear status :%s\n",machine[0].gearstate);
printf("next state :%s\n",machine[0].nextstate);
checkbeforetakeoff(); // if its true it will move on the next state
}
else
{
geardown();// if its false it will return to the same function
}
}
void checkbeforetakeoff()//function definition
{
int lp,ss,ls;
printf("enter the lever position : ");
scanf("%d",&lp);
printf("enter the squat switch condition: ");
scanf("%d",&ss);
printf("enter the limit switch condition: ");
scanf("%d",&ls);
if(lp==raising &&ss==openn && ls==open)//check the condition for checkbeforetakeoff
{
printf("light status is:%s\n",machine[1].light);
printf("current status :%s\n",machine[1].currentstatus);
printf("gear status :%s\n",machine[1].gearstate);
printf("next state :%s\n",machine[1].nextstate);
gearrising(); // if its true it will move on the next state
}
else //if the lever is not raising it will return to the gear down function
{
printf("mission failed.....(control inputs are not satisfied so it return to the same function)\n");
geardown();
}
}
void gearrising()//function definition
{
int lp,ss,ls;
printf("enter the lever position : ");
scanf("%d",&lp);
printf("enter the squat switch condition: ");
scanf("%d",&ss);
printf("enter the limit switch condition: ");
scanf("%d",&ls);
if(lp==raising &&ss==openn && ls==close)//check the condition for gear raising
{
printf("light statu.s is:%s\n",machine[2].light);
printf("current status :%s\n",machine[2].currentstatus);
printf("gear status :%s\n",machine[2].gearstate);
printf("next state :%s\n",machine[2].nextstate);
gearup(); // if its true it will move on the next state
}
else if(lp==falling ) //if the lever is not raising it will return to the check before landing function
{
printf("gear doesn't work......\n");
checkbeforelanding();
}
else // if the inputs are not satisfied the condition it will return the same function
{
gearrising();
}
}
void gearup()//function definition
{
int lp,ss,ls;
printf("enter the lever position : ");
scanf("%d",&lp);
printf("enter the squat switch condition: ");
scanf("%d",&ss);
printf("enter the limit switch condition: ");
scanf("%d",&ls);
if(lp==up &&ss==openn && ls==close)//check the condition for gearup
{
printf("\n light status is:%s\n",machine[3].light);
printf("current status :%s\n",machine[3].currentstatus);
printf("gear status :%s\n",machine[3].gearstate);
printf("next state :%s\n",machine[3].nextstate);
checkbeforelanding(); // if its true it will move on the next state
}
else // if the inputs are not satisfied the condition it will return the same function
{
gearup();
}
}
void checkbeforelanding()//function definition
{
int lp,ss,ls;
printf("enter the lever position : ");
scanf("%d",&lp);
printf("enter the squat switch condition: ");
scanf("%d",&ss);
printf("enter the limit switch condition: ");
scanf("%d",&ls);
if(lp==falling &&ss==openn && ls==open)//check the condition for checkbeforelanding
{
printf("\n light status is:%s\n",machine[4].light);
printf("current status :%s\n",machine[4].currentstatus);
printf("gear status :%s\n",machine[4].gearstate);
printf("next state :%s\n",machine[4].nextstate);
gearlanding(); // if its true it will move on the next state
}
else// if the inputs are not satisfied the condition it will return the same function
{
printf("mission failed......(control inputs are not satisfied, it return to the same function)\n");
gearup();
}
}
void gearlanding()//function definition
{
int lp,ss,ls;
printf("enter the lever position : ");
scanf("%d",&lp);
printf("enter the squat switch condition: ");
scanf("%d",&ss);
printf("enter the limit switch condition: ");
scanf("%d",&ls);
if(lp==down &&ss==closee && ls==open) //check the condition for gear landing
{
printf("\n light status is:%s\n",machine[5].light);
printf("current status :%s\n",machine[5].currentstatus);
printf("gear status :%s\n",machine[5].gearstate);
printf("next state :%s\n",machine[5].nextstate);
geardown(); // if its true it will move on the next state
}
else if(lp==raising) //if the lever is not down it will return to the check before take off
{
printf("due to bad weather, pilot proceed to takeoff\n");
checkbeforetakeoff();
}
else // if the inputs are not satisfied the condition it will return the same function
{
gearlanding();
}
}
int main() // main function
{
printf("lever position states \n0.Down\n1.Raising\n2.Up\n3.Falling\n"); // user defined inputs for the various states
printf("squat switch states \n0.closee\n1.openn\n");
printf("limit switch states \n0.open\n1.close\n\n");
geardown(); // calling the subfunction
}