Advanced, XL Family

Sequence Numbers

AckData and NoAckData commands use sequence numbers to help provide reliable communication. Sequence numbers are just integers from 0 to 15 which are used in order to label each packet sent. They should always be used in order.

Sequence numbers are important because radio is not a "perfect" medium. Although almost every transmission made will be received, there is no way to guarantee zero loss. Signals can be blocked when a receiver moves behind an obstacle, for example. Even in sites where the radios do not move, there is a risk of data loss. When two radios transmit at once, one or both messages are sure to be lost since radios cannot receive two messages simulataneously.

Sequence numbers serve two important functions. First, they help identify lost data, and second, they identify repeated data.

Lost Data

The first case, detecting lost data, is pretty easy to visualize. Anyone who has ever talked on a cell phone can associate with the frustration of lost data. Imagine someone is telling you how to do something, there is a pause, and then the next instruction doesn't seem to follow naturally from the one before it.

  • Carefully remove the cover.
    pause...
  • Cut the blue wire.

Did you miss something, or not? There's really no way to be certain. But by using sequence numbers, we can tell for sure if any step was missed:

  • 1. Carefully remove the cover.
    pause...
  • 3. Cut the blue wire.

Now we know that we missed something. We can even remedy the situation easily at this point by asking the person to repeat step #2.

This is quite similar to how AckData packets work. After every transmission of an AckData packet, the receiver will respond with a Ack packet to acknowledge the packet's receipt.

Note:

Ack transmission is handled automatically by the radio. Do not send an Ack packet over the serial connection to try and acknowledge a packet's receipt.

In our example, above, the instructor would hear an acknowledgement for step #1 and an acknowledgement for step #3. After waiting a reasonable amount of time for an acknowledgment of step #2, the transmitter presumes step #2 was lost and repeats its transmission automatically:

  • 1. Carefully remove the cover.
    Got step #1.
  • 2. Cut the red wire.
  • 3. Cut the blue wire.
    Got step #3.
    pause
  • 2. Cut the red wire.
    Got step #2.

Once the second step makes it through successfully, the receiver will get all three instructions (in the order they were intended, even though step #2 was transmitted after step #3) and the transmitter will get three acknowledgments (again, in order).

Repeated Data

The second case, detecting repeated data, is necessary because acknowledgement transmissions — just like data transmissions — can be lost too.

Let's re-imagine the previous conversation from the instructor's point of view:

  • 1. Carefully remove the cover.
    Got step #1.
  • 2. Cut the red wire.
  • 3. Cut the blue wire.
    Got step #3.
    pause
  • 2. Cut the red wire.
    Got step #2.

As you can see, we didn't get a confirmation, initially, that step #2 was received, so we repeated it. But do we know for a fact that it wasn't received? Perhaps the acknowledgement for step #2 was the packet lost and not the instruction itself.

If the acknowledgment was the packet lost, then the repeat of step #2 is unneeded. Fortunately, the radio will automatically ignore repeated packets and so there is no need to test for them manually.

Sequence Number Rotation

There are only 16 sequence numbers available, but the number of packets you can send between radios is unlimited. So, after using sequence number 15, you will need to wrap back around to sequence number 0.

NoAckData Packets

NoAckData packets support sequence numbers as a convenience. They are not strictly required. NoAckData packets are not acknowledged, and so are never repeated.

If you wish, you can use sequence number 0 for every NoAckData packet. This is not recommended, but it should not hurt anything.

The main advantage to using sequence numbers with NoAckData packets is that it gives you an easy way to recognize when a packet has been lost, even though NoAckData packets do not include any sort of auto-correction mechanism like AckData packets do.

AckData Packets

AckData packets require the use of sequence numbers. You should always use sequence number 0 first, progress up to 15, and then wrap back around to 0.

In general, using sequence numbers in order is not much of a challenge. However, special precaution must be taken when one radio is used to talk to more than one other radio. Each of those other radios expects to receive packets with no missing sequence numbers, and so it is vital to keep a sequence number counter in your code for each target.

After all, a radio isn't going to know that the packet with sequence number 4 (for example) was sent to another radio. All it knows is that if it received packet number 3 and packet number 5, then something in the middle was lost.