Following is the custom type created using the keyword typedef in C. If the combination of these states and triggered event match, the corresponding event handler is called..
//Different states of Gas Pump using typedef
typedef enum
{
Idle_State,
Payment_Card_Verifying_State,
Payment_Approved,
Payment_Denied,
Nozzle_Removed,
Waiting_Grade_Selection,
Pumping,
Finalizing_Transaction,
Emergency
}sysState;
//Prototype of event handlers
sysState IdleStateHandler(void)
{
return Idle_State;
}
sysState PaymentCardVerifyingStateHandler(void)
{
return Payment_Card_Verifying_State;
}
sysState PaymentApprovedHandler(void)
{
return Payment_Approved;
}
sysState PaymentDeniedHandler(void)
{
return Payment_Denied;
}
sysState NozzleRemovedHandler(void)
{
return Nozzle_Removed;
}
sysState WaitingGradeSelectionHandler(void)
{
return Waiting_Grade_Selection;
}
sysState PumpingHandler(void)
{
return Pumping;
}
sysState FinalizingTransactionHandler(void)
{
return Finalizing_Transaction;
}
sysState EmergencyHandler(void)
{
return Emergency;
}
Your supervisor has assigned you to build a finite state machine (FSM) in C code to control the o...