This site is being deprecated.

Please see the official X‑Plane Support page for help.

0 votes
asked by (18 points)
Please, where can I find the full specification for the UDP protocol associated to the Dataref?

By protocol I mean all details associated to RREF, SITU, CMND, etc. and which parameters they accept, etc.

Thanks,

Rodrigo

1 Answer

0 votes
answered by (19.3k points)
I believe the only instructions we have on UDP are found in the "Sending Data to X-Plane.rtfd" file, which is found in Instructions > X-Plane Specs from Austin. There is a list of all datarefs in Resources > Plugins > datarefs.txt.
commented by (18 points)
You were right, I could find the following relevant information (please below I include another issue):

 

"••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••

SEND ME ALL THE DATAREFS I WANT: RREF

••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••

 

So this one is cool: Send in the 5 chars RREF (null-terminated!) plus this struct:

 

struct dref_struct_in

{

    xint dref_freq        ;

    xint dref_en        ;

    xchr dref_string[400]    ;

};

 

Where dref_freq IS ACTUALLY THE NUMBER OF TIMES PER SECOND YOU WANT X-PLANE TO SEND THIS DATA!

Where dref_en is the integer code you want X-Plane to send back with the dataref value so you can tell WHICH dataref X-Plane is giving you! (since you are likely to ask for MANY different datarefs!)

Where dref_string is the dataref string that you want X-Plane to send to you!

 

And, if the dataref is to an ARRAY of values (like engine thrust, since there can be 8 engines), just add [xxx] to the end, where “xxx” is the array index you want X-Plane to send!

The [ and ] should simply surround the number to indicate that the number is the index you want.

So, send in “sim/flightmodel/engine/POINT_thrust[1] “to have X-Plane send the second engine, for example (since we start at 0!)

 

X-Plane will send the message right back to the IP address and port number you sent the RREF command from.

You will get:

 

struct dref_struct_out

{

    xint dref_en    ;

    xflt dref_flt    ;

};

 

Where dref_en is the integer code you sent in for this dataref in the struct above.

Where dref_flt is the dataref value, in machine-native floating-point value, even for ints!

 

So, of course, you can send in all the RREF messages you want, to get all the dataref values back that you want!

Easy!

 

Send in a “dref_freq” of 0 to stop having X-Pane send the dataref values."

 

 

However when I receive the replied message, the field "xint dref_en" does not bring the identifier I provided when I asked for the Dataref information.

 

Please, see my Java source code below:

 

import java.io.*;

import java.net.*;

import java.nio.*;

import java.util.*;

 

public class Dataref {

 

    private static final int LENGTH = 414;

 

       public static void main(String args[]) throws Exception {

 

        DatagramSocket clientSocket = new DatagramSocket();

        InetAddress IPAddress = InetAddress.getByName("localhost");

        byte[] sendData = new byte[LENGTH];

        byte[] receiveData = new byte[13];

 

        System.out.println("Sending...");

 

        ByteBuffer buffer = ByteBuffer.allocate(LENGTH);

        buffer = buffer.order(ByteOrder.LITTLE_ENDIAN);

        String cmd = new String("RREF");

        //String msg = new String("sim/cockpit2/annunciators/stall_warning[0]");

        String msg = new String("sim/flightmodel/engine/POINT_thrust[0]");

        int freq = 1;

        int code = 99;

        byte zero = 0;

        buffer = buffer.put(cmd.getBytes());

        buffer = buffer.put(zero);

        buffer = buffer.order(ByteOrder.LITTLE_ENDIAN).putInt(freq);

        buffer = buffer.order(ByteOrder.LITTLE_ENDIAN).putInt(code);

        buffer = buffer.put(msg.getBytes());

        for (int i = cmd.length() + msg.length() + 9; i < LENGTH; i++) {

            buffer = buffer.put(zero);

        }

        sendData = buffer.array();

 

        for (int i = 0; i < sendData.length; i++) {

            System.out.print(sendData[i]+" ");

        }

        System.out.println();

 

        DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 49000);

        clientSocket.send(sendPacket);

 

        //while (true) {

              System.out.println("Receiving...");

 

              //DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length, IPAddress, 49001);

              DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);

              clientSocket.receive(receivePacket);

 

              String modifiedSentence = new String(receivePacket.getData());

              System.out.println("Message Received: " + modifiedSentence);

 

            for (int i = 0; i < receivePacket.getData().length; i++) {

                System.out.print(receivePacket.getData()[i]+" ");

            }

            System.out.println();

 

              ByteBuffer bt = ByteBuffer.wrap(receivePacket.getData());

              int id = bt.order(ByteOrder.LITTLE_ENDIAN).getInt(5);

              float value = bt.order(ByteOrder.LITTLE_ENDIAN).getFloat(9);

              System.out.println("Id: "+id+" Value: "+value);

        //}

 

              clientSocket.close();

    }

}

 

 

I have no idea what is happening. I indeed receive the replied message, but the code = 99 does not come with it. It comes with some garbage instead.

Thanks for any additional information about this.
...