Complete the code to define the initial state of the protocol.
enum State { IDLE, RECEIVING, PROCESSING, [1] };The state SENDING is commonly used to represent the state where the protocol is sending data.
Complete the code to transition to the PROCESSING state when data is received.
if (event == DATA_RECEIVED) { current_state = [1]; }
When data is received, the protocol should move to the PROCESSING state to handle the data.
Fix the error in the state transition to IDLE after sending is done.
if (event == SEND_COMPLETE) { current_state = [1]; }
After sending is complete, the protocol should return to the IDLE state to wait for new events.
Fill both blanks to complete the state machine switch-case for handling events.
switch (current_state) {
case IDLE:
if (event == START_RECEIVE) {
current_state = [1];
}
break;
case RECEIVING:
if (event == DATA_RECEIVED) {
current_state = [2];
}
break;
}From IDLE, on START_RECEIVE, move to RECEIVING. From RECEIVING, on DATA_RECEIVED, move to PROCESSING.
Fill all three blanks to complete the dictionary-like state transition table.
State next_state(State current, Event event) {
if (current == [1] && event == START_SEND) {
return [2];
} else if (current == [3] && event == SEND_COMPLETE) {
return IDLE;
}
return current;
}When in IDLE and START_SEND event occurs, move to SENDING. When in SENDING and SEND_COMPLETE event occurs, return to IDLE.