简体   繁体   中英

How to represent communication protocol in UML?

In my UML model I have a system and its subcomponents that talk to each other. For Example, I have a computer and a RC robot where they talk via Bluetooth. Currently in the diagrams the flow is something like:

"Computer" triggers "setVelocity()" function of "RC car".

At this point, I want to refine the communication by saying that

  • computer sends "Movement" message
  • with velocity field is set to 100 and direction field is set to 0
  • which is acknowledged by RC car by sending ACK message
  • with message id "Movement" and sequence number X.

How do I do that?

EDIT : Clarification

Normally this is what my diagram looks like without protocol details:

当前型号

But when I tried to add messages, there are at least 2 problems:

  • It seems like Computer first triggered the setVelocity() funciton and then sendBluetoothMessage() sequentially which are not sequential. The followings of setVelocity() are actually what happens inside that.
  • sendBluetoothMessage() is actually a function of Computer. But here it belongs to RC Car. (or am I wrong?) And the same things for ACK.

我试过的

Thanks for the responses. You are gold!

There are two main ways of doing it. A first way is to have a movement() operation, with parameters for the velocity and direction. The ACK would be realized by the return message. You can just label it ACK. You would typically show the exchange in a sequence diagram. Sequence diagrams even allow to represent delay in reception.

Another approach is to use signals. Signals correspond to event messages. In a class diagram, they are represented like a class but with the «signal» keyword, and velocity and direction would be attributes of that signal. ACK would be another signal. The classes that are able to receive the signals show it as reception (looks like an operation, but again with «signal» keyword).

In both cases, you would show the interactions of your communication protocol with an almost identical sequence diagram. But signals are meant for asynchronous communication and better reflect imho the nature of the communication.

Return messages can only be shown in sequence diagrams (no equivalent notation in a communication diagram ). The signal approach doesn't rely on return messages and can show the full protocol either in a sequence or communication diagram. The numbering would be in front of the message name.

Not related, but you may be interested in making protocol state machines, to represent the state of each communication party, based on the reception of signals and/or timing.

If you really want to display this level of detail in a sequence diagram, it would look like this:

在此处输入图像描述

Notes:

  1. For an asynchronous call, use an open arrowhead.
  2. Use stacked bars to represent the call stack.
  3. In the operation's argument list, write "argumentName=argumentValue" or just "argumentValue".
  4. For messages for which the exact operation name is unknown or irrelevant, I use just a description without an argument list.

But be careful about which level of detail you want to show. Often, a sequence diagram becomes too complex if you display every operation in the call stack.

I was dealing with the same issue. I searched online and couldn't find something that I like. Hence I come up with this solution. I show the communication ports on the sequence diagram and I draw communication dependent steps among port lines. Here is a screenshot: my version of your problem.

Note: I haven't used bluetooth before so I am not sure about the acknowledge step. If this is something done automatically by the hardware( Like in the CAN Bus) I wouldn't draw it like this. I probabily wouldn't show it or I wouldn't add the function acknowledge(); and just draw the line between bluetooth port life lines.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM