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

// here am uploading both source file and spreadsheet. in code i have explained each routine with comments
Source code for above :
#include<stdio.h>
//defining function prototypes
// we have a total 6 states in our process so am defining 6.
void Geardown(void);
void Checkingbeforetakeoff(void);
void RaisingGear(void);
void Gearup(void);
void Checkbeforelanding(void);
void Loweringgear(void);
//this is the pointer array which stores the addresses of the functions which are created above in the same order.
void (*execute[])(void) = {Geardown,Checkingbeforetakeoff,RaisingGear,Gearup,Checkbeforelanding,Loweringgear};
//here is the amazing thing i learn through this project that is
// this enum declaration is using for index of the above array of functions and better code readability
typedef enum { // if we didnt initiates the value to data types compiler gives values to like below
Gear_down, // 0
Checkingbefore_takeoff,// 1
Raising_Gear, // 2
Gear_up,// 3
Checkbefore_landing, // 4
Lowering_gear, // 5
}states;
states current_state;
// enumarted datatype for switches limit and squat switch
typedef enum {
close = 1,
open = 0,
}Switch;
Switch limit_switch,squat_switch;
//enumarted datatype for pilot lever
typedef enum{
sliding_up = 1,
sliding_down = 0,
}pilot_lever;
pilot_lever p_lever;
/* enumarted datatype for hydraulic_mechanism -- nolonger needed because this is output accidentaly i created
typedef enum{
working = 1,
not_working = 0,
}hydraulic_mechanism;
hydraulic_mechanism hydrau_pump_mechanism;*/
//created structure for user panel information of the running system
typedef struct{
char* gear_currentposition;
char* light_indication;
char* valve_direction;
char* hydraulic_control;
}Gearpanel_info;
//above structure created into array fashion to store the info of the each state of the gear system.
//while displaying the array content we use "current_state" as index.
Gearpanel_info Gearpanel[6] = {{"Gear down","Green","Down","Enabled"},
{"Check before take off","Green","Down","Enabled"},
{"Raising Gear","Red","Up","Enabled"},
{"Gear Up","off","Null","Disabled"},
{"Check before landing","Red","Down","Enabled"},
{"Lowering Gear","Green","Down","Enabled"}};
int main(){
// intilising the system with Gear_down function
current_state=Gear_down;
printf(" The gear syatem is initiated !\n the initial state of the gear is: %s\n Light indication is: %s\n",Gearpanel[current_state].gear_currentposition,Gearpanel[current_state].light_indication);
while(1){
// in this inifinite loop, system will continuously calls the current function based on the input values and state of the process
execute[current_state]();
}
return 0;
}
void Geardown(){
//Geardown() - if pilot lever raising / sliding up and squat switch is open state will move to - check before takeoff
printf("\nPlease enter the pilot lever and squat switch status:");
scanf("%d %d",&p_lever,&squat_switch);
if(p_lever==sliding_up && squat_switch== open){//check before takeoff
current_state = Checkingbefore_takeoff;
printf("State of the system: %s\n",Gearpanel[current_state].gear_currentposition);
printf("Light indication is: %s\n",Gearpanel[current_state].light_indication);}
else{ Geardown();}}
void Checkingbeforetakeoff(){
//Checkingbeforetakeoff - if pilot lever is sliding up and squat switch is open state move to raising gear
printf("\nPlease enter the pilot lever and squat switch status:");
scanf("%d %d",&p_lever,&squat_switch);
if(p_lever == sliding_up && squat_switch == open){//raising gear
current_state = Raising_Gear;
printf("State of the system: %s\n",Gearpanel[current_state].gear_currentposition);
printf("Light indication is: %s\n",Gearpanel[current_state].light_indication);
printf("Direction of the vlave is: %s\n",Gearpanel[current_state].valve_direction);
}
else if (p_lever == sliding_down && squat_switch == close){//gear down
//if pilot lever is sliding down and squat switch is close state move to gear down
current_state = Gear_down;
printf("State of the system: %s\n",Gearpanel[current_state].gear_currentposition);
printf("Light indication is: %s\n",Gearpanel[current_state].light_indication);}
}
void RaisingGear(){
//RaisingGear - if pilot lever is sliding down / falling down and limit switch open state change to cheching before landing
printf("\nPlease enter the pilot lever and limit switch status:");
scanf("%d %d",&p_lever,&limit_switch);
if(p_lever == sliding_down && limit_switch == open){//cheching before landing
current_state = Checkbefore_landing;
printf("State of the system: %s\n",Gearpanel[current_state].gear_currentposition);
printf("Light indication is: %s\n",Gearpanel[current_state].light_indication);}
else if(limit_switch == close){//Gear up
//RaisingGear - if limit switch close state change to cheching before landing
current_state = Gear_up;
printf("State of the system: %s\n",Gearpanel[current_state].gear_currentposition);
printf("Light indication is: %s\n",Gearpanel[current_state].light_indication);
printf("Hydraulic Control for landing is: %s\n",Gearpanel[current_state].hydraulic_control);
}
}
void Gearup(){
//Gearup - if pilot lever is sliding_down state change to cheching before landing
printf("\nPlease enter the pilot lever status:");
scanf("%d",&p_lever);
if(p_lever==sliding_down)
{//cheching before landing
current_state = Checkbefore_landing;
printf("State of the system: %s\n",Gearpanel[current_state].gear_currentposition);
printf("Light indication is: %s\n",Gearpanel[current_state].light_indication);
printf("Hydraulic Control for landing is: %s\n",Gearpanel[current_state].hydraulic_control);
}
else{Gearup();}
}
void Checkbeforelanding(){
//Checkbeforelanding - if pilot lever is sliding down / falling state changes to lowering the gear
printf("\nPlease enter the pilot lever status:");
scanf("%d",&p_lever);
if(p_lever==sliding_down)
{//lowering the gear
current_state = Lowering_gear;
printf("State of the system: %s\n",Gearpanel[current_state].gear_currentposition);
printf("Light indication is: %s\n",Gearpanel[current_state].light_indication);
printf("Control for landing is: %s\n",Gearpanel[current_state].valve_direction);
}
}
void Loweringgear(){
//Loweringgear - pilot lever is sliding up and limit switch close state is changes to checking before takeoff
printf("\nPlease enter the pilot lever and limit switch status:");
scanf("%d %d",&p_lever,&limit_switch);
if(p_lever== sliding_up && limit_switch == close){//checking before takeoff
current_state = Checkingbefore_takeoff;
printf("State of the system: %s\n",Gearpanel[current_state].gear_currentposition);
printf("Light indication is: %s\n",Gearpanel[current_state].light_indication);}
else if(p_lever== sliding_down && limit_switch == open){//gear down
// pilot lever is sliding down and limit switch open state is changes to gear down
current_state = Gear_down;
printf("State of the system: %s\n",Gearpanel[current_state].gear_currentposition);
printf("Light indication is: %s\n",Gearpanel[current_state].light_indication);}
}
Output of project:
