Project 2 - Implement the Code for controlling the retraction and extension of Airplane’s landing gear
/*
* landing gare fms project.c
*
* Created on: 19 Dec 2022
* Author: Simulator
*/
#include<stdio.h>
#include<unistd.h>
unsigned int plane_status = 0; // Initialise with plane at ground program will ask if plane is air born or ground
unsigned char landing_gear_position;
unsigned char landing_gear_switch;
unsigned char extension_limit;
unsigned char retraction_limit;
unsigned char extension_solenoid_valve;
unsigned char retraction_solenoid_valve;
int main(){
while(1){ // infinite loop for to put gear up or down although program will ask fist airborne/grounded
unsigned int i;
if(0 == plane_status){
landing_gear_position = 1;
printf("landing gear is down because plane is on ground\n");
landing_gear_switch = 1;
extension_limit=1;
retraction_limit=0;
extension_solenoid_valve=0;
retraction_solenoid_valve=0;
}
/* in below if function it will check plane is airborne or not. if it is airborne then it will ask what do you want to do
dear up or down. if user press any condition up/ down it will check current status of landing gear if user input condition(up/down)
match with current status then nothing will happen. if user input condition differ then action will happen like gear will go up or down */
/*this program will every component status on console*/
if(plane_status==1){
printf("lanfing_gaer_switch(up-0/down-1):");
fflush(stdout);
scanf("%d",&i);
if(i == landing_gear_switch){
printf("user input is a match of previous landing gear status\n");
}
if(i !=landing_gear_switch){
landing_gear_switch=i;
if(0 == landing_gear_switch){
printf("landing gear up switch pressed\n");
extension_solenoid_valve=0;
printf("extension solenoid valve off\n");
retraction_solenoid_valve=1;
printf("retraction_solenoid_valve ON\n");
extension_limit=0;
printf("extension limit become LOW\n");
fflush(stdout);
sleep(3);
retraction_limit=1;
printf("retraction limit become high after gear retraction\n");
retraction_solenoid_valve=0;
printf("retraction solenoid valve turned off after hitting retraction limit\n");
landing_gear_position=0;
printf("landing gear is up now\n");
}
if(1 == landing_gear_switch){
printf("landing gear down switch pressed\n");
retraction_solenoid_valve=0;
printf("retraction solenoid valve off\n");
extension_solenoid_valve=1;
printf("extension solenoid valve ON\n");
retraction_limit=0;
printf("retraction limit become LOW\n");
fflush(stdout);
sleep(3);
extension_limit=1;
printf("extension limit become high after gear retraction\n");
extension_solenoid_valve=0;
printf("extension solenoid valve turned off after hitting extension limit\n");
landing_gear_position=1;
printf("landing gear is down now\n");
}
}
}
printf("enter the plane status(airborne-1/grounded-0)");
fflush(stdout);
scanf("%d",&plane_status);
printf("plane is airborne\n");
}
}