Skip to content

Commit

Permalink
UDP protocol support added
Browse files Browse the repository at this point in the history
  • Loading branch information
vranki committed Mar 3, 2021
1 parent d40e92b commit a9f5e78
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ExtPlane.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ defined(XPLANE_SDK_PATH, var) {
warning("No X-Plane SDK found in ../XPlaneSDK or ~/SDK - not building X-Plane plugin")
}

OTHER_FILES += README.md clients/extplane-client-qt/README Dockerfile scripts/*
OTHER_FILES += README.md UDP.md clients/extplane-client-qt/README Dockerfile scripts/*
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This will eventually be fixed.
* Simulate key and button presses
* Execute commands
* Load situations
* High-performance UDP option
* Free & open source under GPLv3
* Client libraries available for Qt (c++), Java and C#

Expand Down Expand Up @@ -249,6 +250,13 @@ sub sim/flightmodel/engine/ENGN_thro
WRONG: sub sim/flightmodel/engine/ENGN_thro[1]
```

### High-performance UDP output ###

ExtPlane supports tight UDP protocol for basic dataref types (int, float, double)
from simulator to client. Add modifier udp to ref name to request it in UDP.
UDP datarefs are sent every flight loop using lightweight protocol.

See [this file](UDP.md) for details.

### Keys and Buttons ###

Expand Down Expand Up @@ -286,12 +294,11 @@ Command identifiers are strings that look like datarefs.
Supported settings are:
* **update_interval {value}** How often ExtPlane should update its data from X-Plane, in seconds. Use as high value as possible here for best performance. For example 0.16 would mean 60Hz, 0.33 = 30Hz, 0.1 = 10Hz etc.. Must be a positive float. Default is 0.33.



## Protocol Output ##

* **EXTPLANE {protocol}** Sent when connected. Protocol is currently 1.
* **EXTPLANE-VERSION {version}** Sent when connected. Feature version integer, which is incremented with each new bug fix or feature.
* **CLIENT-ID {clientid}** Client ID used with UDP protocol
* **EXTPLANE-WARNING {message}** Show warning message for developer and/or user
* **u{type} {dataref} {value}** Dataref has changed in value based on accuracy.
* Types may be `i` (int), `f` (float), `d` (double), `ia` (int array), `fa` (float array), or `b` (data).
Expand Down
75 changes: 75 additions & 0 deletions UDP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# ExtPlane UDP protocol #

So you want to get frame-perfect datarefs with high performance?
You are reading the right file.

Note that currently you can only subscribe (not write) dataref.
Datarefs are limited to only basic types (int, float, double).
Arrays or other more complex values are not supported via UDP.

Writing via UDP might be implemented some day.. PR welcome.

## Get the client ID ##

When connected to ExtPlane, store the number after CLIENT-ID.
That is your unique client ID used by UDP.

## Listen to UDP

Bind to UDP port 52000 + client_id

Different ports make it easy to run multiple clients on same machine
and reduce error probability.

## Subscribe to datarefs

Add modifier udp to dataref name. Do not set accuracy, UDP datarefs are sent
every flight loop. For example:

```
sub sim/flightmodel/misc/h_ind:udp
```

ExtPlane will reply with "udp", ref_id, ref type, and ref name.

Example:

```
udp 42 f sim/flightmodel/misc/h_ind:udp
```

Store the ref_id value, you'll need it later. You also need to know
the datatype of the ref - in this case f = float. Ref_id is
unsigned int 16 bits.

ExtPlane will now send this ref in UDP packet every flight loop (usually
60hz).

## UDP Datagram content ##

Here is the spec for the data content and size in bytes for each part.

"EXTP_" (5) - header string
client_id (1, uint8) - client id, should be same as CLIENT-ID sent earlier
int_count (2, uint16) - number of integer values to read

Repeated int_count times:

ref_id (2, uint16) - ref id, same you got when subscribing
value (4, int32) - value of the int dataref

"Ef" (2) - header for float data
float_count (2, uint16) - number of float values to read

Repeated float_count times:

ref_id (2, uint16) - ref id
value (4, float) - value of the float dataref

"Ed" (2) - header for double data
double_count (2, uint16) - number of double values to read

Repeated float_count times:

ref_id (2, uint16) - ref id
value (8, double) - value of the double dataref

0 comments on commit a9f5e78

Please sign in to comment.