The PING Protocol enables a system to measure system latencies on any connection: serial port, radio modem, UDP etc.
The PING protocol is implemented with just the PING message. The message is sent with a timestamp and a sequence number that are returned by recipients, and can hence be used to determine the round-trip time.
A simplified sequence diagram is given below:
The pinging system initially populates a PING message with:
time_usec: Current system timestamp.
PINGsequence number (n, n+1, ...). This should be iterated for every
PINGmessage sent and overflow back to zero.
target_component: 0 (indicates a PING request).
- The message header automatically includes the sender system.
The message may be received by multiple systems. All pinged systems should respond with another
PING message where:
- The original timestamp and sequence number from the receive
PINGare sent back in the response.
target_componentare set to the ids of the pinging system from the incoming ping message header.
The original pinging system:
- Receives a
target_componentmatching its address.
Any non-zero target system/component indicates a response message. The matching ids inform the system that it is the intended recipient.
- The system calculates the latency from the current system time and the time in the response
PINGfor the matching sequence number.
- A system that is sending a single
PINGcan use a timeout to detect a dropped packet. A system that is streaming (multiple)
PINGmessages should not start detecting dropped packets until after the first responses have been received (to ensure that dropped packets are not just "late").
The protocol has been implemented in C by PX4 and QGroundControl. This implementation can be used in your own code within the terms of their software licenses.