PING Protocol

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.

Ping Sequence

A simplified sequence diagram is given below:

Mermaid sequence: Ping

The pinging system initially populates a PING message with:

  • time_usec: Current system timestamp.
  • seq: Current PING sequence number (n, n+1, ...). This should be iterated for every PING message sent and overflow back to zero.
  • target_system and 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 PING are sent back in the response.
  • target_system and target_component are set to the ids of the pinging system from the incoming ping message header.

The original pinging system:

  • Receives a PING message with target_system and target_component matching its address. > Tip 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 PING for the matching sequence number.
  • A system that is sending a single PING can use a timeout to detect a dropped packet. A system that is streaming (multiple) PING messages should not start detecting dropped packets until after the first responses have been received (to ensure that dropped packets are not just "late").

C Implementation

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.

PX4 Implementation:

QGroundControl implementation:

results matching ""

    No results matching ""