All Courses
All Courses
Courses by Software
Courses by Semester
Courses by Domain
Tool-focused Courses
Machine learning
POPULAR COURSES
Success Stories
Solution: //Preprocessor section/Header files#include //Standard input/output library#include //Standard library#include //Standard string library //Function prototypevoid Initiate_State_Machine(); //Initialize the state machinevoid GearDown(); //Shift the gear to the down positionvoid CheckingBeforeTakeOFF(); //Checking…
Rishabh Bhojankar
updated on 04 Sep 2023
Solution:
//Preprocessor section/Header files
#include
#include
#include
//Function prototype
void Initiate_State_Machine(); //Initialize the state machine
void GearDown(); //Shift the gear to the down position
void CheckingBeforeTakeOFF(); //Checking before take off
void RaisingGear(); // Raise the landing gear
void GearUp(); //Shift the gear to the up position
void CheckBeforeLanding(); //Checking before landing
void LoweringGear(); //Lower the landing gear
static void (*statetable[])(void) = {GearDown, CheckingBeforeTakeOFF, RaisingGear, GearUp, CheckBeforeLanding, LoweringGear};
//Define enumerations for different states and statuses
typedef enum State
{
GEAR_DOWN, //Gear is in the down position
CHECKING_BEFORE_TAKEOFF, //State for checking before take-off
RAISING_GEAR, //State for raising the gear
GEAR_UP, //Gear is in the up position
CHECK_BEFORE_LANDING, //State for check before landing
LOWERING_GEAR, //State for lowering the gear
} State_Type;
//Define enumeration for representing 'switch'
typedef enum Switch
{
on, //Switch is in the 'on' position
off //Switch is in the 'off' position
} Switch_status;
//Define an enumeration type 'pilot_lever'
typedef enum pilot_lever
{
Raising, //Lever is in the "raising" position
Falling //Lever is in the "falling" position
} pilot_lever;
//Define enumeration type the 'hydraulic mechanism'
typedef enum hydraulic_mechanism
{
working, //Hydraulic mechanism is in working
not_working //Hydraulic mechanism is not working
} hydraulic_mechanism;
// Static volatile variables to store status
static volatile Switch_status squat_switch;
static volatile Switch_status limit_switch;
static volatile pilot_lever pl;
static volatile hydraulic_mechanism hm;
//Variable to keep track of the current state
State_Type current_state;
//Define a Structure to represent the state table
typedef struct
{
char *current_state_indication; //Pointer to a string indicating the current state of the system
char *light; //Pointer to a string indicating the state of the light
char *direction_valve_status; //Pointer to a string indicating the status of the direction valve
char *landing_gear_hydraulic_control; //Pointer to a string indicating the control of the landing gear hydraulic system
} State_Table;
//Define a static array of State_Table structures
static State_Table State_Machine[6] =
{
{"GearDown", "Green", "Down", "Enabled"}, //Define the first state: "GearDown"
{"CheckingBeforeTakeOFF", "Green", "Up", "Enabled"}, //Define the second state: "CheckingBeforeTakeOFF"
{"RaisingGear", "Red", "Up", "Enabled"}, //Define the third state: "RaisingGear"
{"GearUp", "Off", "Up", "Disabled"}, //Define the fourth state: "GearUp"
{"CheckBeforeLanding", "Red", "Down", "Enabled"}, //Define the fifth state: "CheckBeforeLanding"
{"LoweringGear", "Red", "Down", "Enabled"} //Define the sixth state: "LoweringGear"
};
//Main function
int main()
{
Initiate_State_Machine();
while (1)
{
statetable[current_state]();
}
return 0;
}
//function Definition
void GearDown(void) //Implementation for GEAR_DOWN state
{
current_state = GEAR_DOWN; //Set the current state to GEAR_DOWN
printf("Enter the status of pilot's lever and squat switch (0 for Raising, 1 for Falling, 0 for On, 1 for Off): ");
fflush(stdout);
scanf("%d %d", (int *)&pl, (int *)&squat_switch);
if (pl == Raising && squat_switch == on) //Check if pilot lever is Raising and squat switch is On
{
current_state = CHECKING_BEFORE_TAKEOFF; //Update the current state to CHECKING_BEFORE_TAKEOFF
printf("Current state: %s\n", State_Machine[current_state].current_state_indication); //Print current state indication
printf("Light is: %s\n", State_Machine[current_state].light); //Print the light status
printf("Status of Direction valve: %s\n", State_Machine[current_state].direction_valve_status); //Print direction valve status
}
else
{
GearDown();
}
}
void CheckingBeforeTakeOFF(void) //Implementation for CHECKING_BEFORE_TAKEOFF state
{
current_state = CHECKING_BEFORE_TAKEOFF; //Set the current state to CHECKING_BEFORE_TAKEOFF
printf("Enter the status of pilot's lever and squat switch (0 for Raising, 1 for Falling, , 0 for On, 1 for Off): ");
fflush(stdout); //
scanf("%d %d %d", (int *)&pl, (int *)&squat_switch, (int *)&hm);
if (pl == Falling && squat_switch == off) //Check if pilot lever is Falling and squat switch is off
{
GearDown();
}
else if (pl == Raising && squat_switch == on && hm == working) //Check if pilot lever is Raising, squat switch is on and hydraulic mechanism is working
{
current_state = RAISING_GEAR; //Update the current state to RAISING_GEAR
printf("Current State: %s\n", State_Machine[current_state].current_state_indication);
printf("Light is: %s\n", State_Machine[current_state].light);
printf("Status of Direction valve: %s\n", State_Machine[current_state].direction_valve_status);
}
else if (pl == Raising && squat_switch == on && hm == not_working) //Check if pilot lever is Raising, squat switch is on and hydraulic mechanism is not working
{
current_state = RAISING_GEAR; //Update the current state to RAISING_GEAR
printf("Current State: %s\n", State_Machine[current_state].current_state_indication);
printf("Light is: %s\n", State_Machine[current_state].light);
printf("Status of Direction valve: %s\n", State_Machine[current_state].direction_valve_status);
}
}
void RaisingGear(void) //Implementation for RAISING_GEAR state
{
current_state = RAISING_GEAR; //Set the current state to RAISING_GEAR
printf("Enter the status of pilot's lever and squat switch (0 for Raising, 1 for Falling, , 0 for On, 1 for Off): ");
fflush(stdout);
scanf("%d %d %d", (int *)&pl, (int *)&squat_switch, (int *)&hm);
if (pl == Falling || squat_switch == off) //Check if the pilot lever is in the falling position or squat switch is off
{
GearDown();
}
else if (pl == Raising && squat_switch == on && hm == working) //Check if the pilot lever is in the raising position, squat switch is on, and hydraulic mechanism is working
{
current_state = GEAR_UP; //Set the current state to GEAR_UP
printf("Current State: %s\n", State_Machine[current_state].current_state_indication);
printf("Light is: %s\n", State_Machine[current_state].light);
printf("Status of Direction valve: %s\n", State_Machine[current_state].direction_valve_status);
}
else if (pl == Raising && squat_switch == on && hm == not_working) //Check if the pilot's lever is in the raising position, squat switch is on,and hydraulic mechanism is not working
{
current_state = RAISING_GEAR; //Set the current state back to RAISING_GEAR
printf("Current State: %s\n", State_Machine[current_state].current_state_indication);
printf("Light is: %s\n", State_Machine[current_state].light);
printf("Status of Direction valve: %s\n", State_Machine[current_state].direction_valve_status);
}
}
void GearUp(void) //Implementation for GEAR_UP state
{
current_state = GEAR_UP; //Set the current state to GEAR_UP
printf("Enter the status of pilot's lever and squat switch (0 for Raising, 1 for Falling, , 0 for On, 1 for Off): ");
fflush(stdout);
scanf("%d %d %d", (int *)&pl, (int *)&squat_switch, (int *)&hm);
if (pl == Raising && squat_switch == on && hm == working) //Check if the pilot lever is in the raising position, squat switch is on, and hydraulic mechanism is working
{
current_state = CHECK_BEFORE_LANDING; //Update the current state and provide information about it
printf("Current State: %s\n", State_Machine[current_state].current_state_indication);
printf("Light is: %s\n", State_Machine[current_state].light);
printf("Status of Direction valve: %s\n", State_Machine[current_state].direction_valve_status);
}
else
{
GearUp();
}
}
void CheckBeforeLanding(void) //Implementation for CHECK_BEFORE_LANDING state
{
current_state = CHECK_BEFORE_LANDING; //Set the current state to CHECK_BEFORE_LANDING
printf("Enter the status of pilot's lever and squat switch (0 for Raising, 1 for Falling, , 0 for On, 1 for Off): ");
fflush(stdout);
scanf("%d %d %d", (int *)&pl, (int *)&squat_switch, (int *)&hm);
if (pl == Raising && squat_switch == on && hm == working) //Check if the pilot lever is in the raising position, squat switch is on, and hydraulic mechanism is working
{
current_state = GEAR_UP; //Update to GEAR_UP state if conditions are met
printf("Current State: %s\n", State_Machine[current_state].current_state_indication);
printf("Light is: %s\n", State_Machine[current_state].light);
}
else if (pl == Raising && squat_switch == on && hm == not_working)
{
current_state = GEAR_UP; //Update to GEAR_UP state if conditions are met
printf("Current State: %s\n", State_Machine[current_state].current_state_indication);
printf("Light is: %s\n", State_Machine[current_state].light);
printf("Status of Direction valve: %s\n", State_Machine[current_state].direction_valve_status);
}
else
{
CheckBeforeLanding();
}
}
void LoweringGear(void) //Implementation for LOWERING_GEAR state
{
current_state = LOWERING_GEAR; //Set the current state to LOWERING_GEAR
printf("Enter the status of pilot's lever and squat switch (0 for Raising, 1 for Falling, , 0 for On, 1 for Off): ");
fflush(stdout);
scanf("%d", &squat_switch);
if (squat_switch == on) //Check if the squat_switch is in the 'on' position
{
current_state = GEAR_DOWN;
printf("Current state: %s\n", State_Machine[current_state].current_state_indication);
printf("Light is: %s\n", State_Machine[current_state].light);
printf("Status of Direction valve: %s\n", State_Machine[current_state].direction_valve_status);
}
else
{
LoweringGear();
}
}
void Initiate_State_Machine() //Function to initialize the state machine
{
current_state = GEAR_DOWN; //Set the current state to GEAR_DOWN
printf("The Finite State Machine is Initialized, and the program is in GearDown State. Light is: %s\n", State_Machine[current_state].light);
}
Output :
The Finite State Machine is Initialized, and the program is in GearDown State. Light is: Green
Enter the status of pilot's lever and squat switch (0 for Raising, 1 for Falling, 0 for On, 1 for Off): 0 0 0
Current state: CheckingBeforeTakeOFF
Light is: Green
Status of Direction valve: Up
Enter the status of pilot's lever and squat switch (0 for Raising, 1 for Falling, , 0 for On, 1 for Off): 0 0 0
Current State: RaisingGear
Light is: Red
Status of Direction valve: Up
Enter the status of pilot's lever and squat switch (0 for Raising, 1 for Falling, , 0 for On, 1 for Off): 0 0 0
Current State: GearUp
Light is: Off
Status of Direction valve: Up
Enter the status of pilot's lever and squat switch (0 for Raising, 1 for Falling, , 0 for On, 1 for Off): 0 0 0
Current State: CheckBeforeLanding
Light is: Red
Status of Direction valve: Down
Enter the status of pilot's lever and squat switch (0 for Raising, 1 for Falling, , 0 for On, 1 for Off): 0 0 0
Current State: GearUp
Light is: Off
Enter the status of pilot's lever and squat switch (0 for Raising, 1 for Falling, , 0 for On, 1 for Off):
Leave a comment
Thanks for choosing to leave a comment. Please keep in mind that all the comments are moderated as per our comment policy, and your email will not be published for privacy reasons. Please leave a personal & meaningful conversation.
Other comments...
Project 2 - Design and develop the web based Temperature control system using Beagle Bone Black.
Overview of the Project: Device Driver Write the device driver for MCP9808 Temperature Sensor. Probe function: Register the Platform device under driver/misc. Read function: It should send the i2c message to read the data from sensor and copy it to the user space. Alert pin connected to BBB as gpio interrupt. The…
02 Dec 2023 10:59 PM IST
Project 1 - Develop the full featured char driver as a loaded module
Overview of the Project: • Device Driver o Write the device driver for MCP9808 Temperature Sensor. Probe function: Register the Platform device under driver/misc. Read function: It should send the i2c message to read the data from sensor and copy it to the user space. Alert pin connected to BBB as gpio…
01 Dec 2023 10:07 AM IST
Project 3
Que. Program an attack terminal 1. The user should be able to select from the following CAN based attacks a. Full Bus DoS - The program should allow the user to set a duration for the attack b. Partial DoS - The program should ask the user “what priority should I DoS at?” - The program should allow the…
01 Dec 2023 02:28 AM IST
Project 2
Que. Write a program that performs a binary search for any given signal (The instrument cluster can be used as a source for CAN traffic) - It should record a log, assisted by user prompt, and replay all other subsequent logs according to a prompt that the user checks (Did the signal occur again? Y/N) - After every…
30 Nov 2023 10:50 PM IST
Related Courses
0 Hours of Content
Skill-Lync offers industry relevant advanced engineering courses for engineering students by partnering with industry experts.
© 2025 Skill-Lync Inc. All Rights Reserved.