How to read an FSM chart

Fms

How can I take this diagram and translate it into a useful program. I am not quite sure how to read this diagram. If someone could just skip me, maybe show me some code and how it relates to the diagram, that would be great.

Thank!

+5
source share
1 answer

Circles with text inside are states. The text describes what a state is.

The dashed arrow indicates the initial state.

, . , . - , . - . - ( ).

, , .

, , . - , - -, .

- , C ( , , ):

enum State { WaitFor0Call, WaitForAck0, WaitForCall1, WaitForAck1 }

int main() {
   State state = WaitFor0Call;
   while (1) {
      switch (state) {
         case WaitFor0Call:
            if (rdt_rcv(rcvpkt)) continue;
            if (rdt_send(data)) {
               state = WaitForAck0;
               sndpkt = make_pkt(0, data, checksum);
               udt_send(sndpkt);
               start_timer();
            }
            break;
         case WaitForAck0:
            // ...similar code...
            break;
         case WaitForCall1:
            // ...similar code...
            break;
         case WaitForAck1:
            // ...similar code...
            break;
      }
   }
}

, , if (rdt_rcv(rcvpkt)) whatever; , rdt_send, . , FSM , , , .. , , :)

, - ( ), if (there_is_ready_for_consuming_packet_in_the_input_queue) continue; if (data_was_put_to_outgoing_stream_successfully) ...;

+10

All Articles