Question
Your supervisor has assigned you to build a finite state machine (FSM) in C code to control the o…
Your supervisor has assigned you to build a finite state machine (FSM) in C code to control the operation of a gas pump. You determine that the required states are: . idle, payment card verifying payment approved, payment denied, nozzle removed, waiting for grade selection, e pumping. finalizing transaction (i.e. the nozzle has been returned) . emergency (someone drove off before removing the nozzle, fire detected, etc. The first thing you decide to do is to create a custom C data type to represent the states. Using the typedef keyword, create your custom data type in the answer space
Solutions
Expert Solution
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;
}