X-Plane Export Lat/Lng From UDP Packet

I’ve been working recently on a CIVA unit for X-plane/DCS. Now X-plane allows you to export almost any data over UDP and/or send commands back. The CIVA IV unit has a series of commands for this so I figured it would be rather easy to read the data from the displays.

Alas, it was not. I hopped into my 737 and checked the lattitude and longtitude positions and then went on to request the data and check it in Wireshark(an application to sniff out network packets).

This yielded weird results, couldn’t make head or tails of it, I got hex value’s like 0x000000005c42 back that just didn’t translate into any known value through normal means.

This boggled me for a few days since I expected the value’s on the displays to be normal integer value’s, doubles or even float value’s transmitted in hex format. Perhaps even ASCII or UNICODE Characters since it can display more then numbers. But nope.

It was a lot simpler. the 42 at end was a terminator and the two digits before simply shift from a base value. I think in the back end it’s a shift of a pointer in a database or something like that, and well the datarefs are often times directly taken from the backend and not formatted for ease of use.

So yeah, a dictionary and the problem is solved… woops…

1 Like

^ I understood this

3 Likes

Maybe I could get you to teach me how to extract the lat/long position from a UDP packet? I spent hours recently trying to extract the data so that I could inject it into a planetarium program (Stellarium). The idea being that from the planetarium I could use angle measurement to create the effect of a rudimentary sextant. This would make long range oceanic flights much more interesting.

Unfortunately, I was unable to get a string out of the packet.

1 Like

@PaulRix so here you go!

Here’s the data view in X-plane, you can turn on a series of default options for data export over UDP so you don’t have to ‘ask’ X-plane to start transmitting(which is really simple anyway).

afbeelding

To export it first turn it on in the options. Settings > Data Input and Output:

of the 4 checkboxes the first is internet(UDP, LAN etc, second is writing to disk, third is graphical, and the last is cockpit display).

now we need to tell X-plane to start transmitting, you do this by going to Settings > Net Connection > Data tab. In there select the IP and port of the datareceiver:

Then on the other side I get a neat packet in wireshark:

Anything before the DATA@ is default UDP stuff and is not part of the information of the package so we can happily discard that. What we are left with is this:

afbeelding

From this point onwards it’s just figuring out the size of each data bit. We can presume that 00 00 is often times padding to create neat spacing so lets start at the end.

00 00 94 c2. Now I know it’s probably coded as a little endian hex value and most likely a float so lets start with that:

boom, -74! The last value shown in the cockpit display window!

afbeelding

Let’s continue this way.

00 00 20 42 becomes 40 if we use the same conversian, again makes sense. So far twice our data has been stored in 4 bytes, which is the amount of bytes in a float value in programming(double is 8 bytes).

Next up is 78 8f 18 c3 which becomes -152.56 which yup, makes sense as well! Let’s just finish the list right to left:

00 00 20 42 = 40
78 8f 18 c3 = -152.56
00 00 80 3f = 1
ab 6b 19 be = -0.149825
92 f0 27 42 = 41.9849
c6 7e 90 c2 = -72.2476
fe d8 23 42 = 40.9619

So as you can see, not all value’s are equal to what is shown in the cockpit display. I get a feeling that this information is a lot more raw and unrounded then that is shown to us. The first two value’s are the lattitude and longtitude.

So, you could try and first process the datapacket as a string, then split at the DATA@ + 3 to also remove the padding, then take the next 8 bytes and split em in half and treat them as a float value you need to decode little endian first. There’s fancier ways to deconstruct the package using struct classes and padding rules and such but I doubt that is really needed for a project like this.

I used this website to do the quick conversion as opposed to writing my own code:

https://gregstoll.dyndns.org/~gregstoll/floattohex/

I take it you know how to take it into stellarium?

1 Like

No-one would ever find this in the ‘Where You Are’ photos topic, so split off. @TheAlmightySnark - you will be rewarded a whole forum point for your next use of the ‘New Topic’ button. :slight_smile:

4 Likes

It really was just a quick reply to paul’s question that I pondered over whilst enjoying a cup of coffee! :smile:

1 Like

I had a look at how to handle this in stellarium, enabling the external remote control gives you a webpage you can send HTTP commands to but from this point on I am a bit too far out of my depth, I never cared for networking so… yeah… Maybe one of our more talented programmers can shed a light on that if you have any further questions!

https://stellarium.org/doc/0.18/remoteControlApi.html

CIVA for XP… something like this ?

I am not sure what you mean by that. I’ve been quite an advocate of the CIVA over the past two years :wink:

The forum title…I was thinking more of “Where You Are in Extremely Complex Math Equations that Make My Head Hurt” but I guess you wanted it more specific.

2 Likes

It’s really not that complicated, it’s much like counting in base 8 as opposed to our human base 10! Americans use Base-12 a lot anyway(inches, feet etc) so hexadecimal is base 16! We use 0 through 9 and A through F to count to 16, then you only need to remember a few specials rules that tell you decimal points and what the sign is(negative or not). It’s really just addition and a bit of multiplication if you know the rules!

2 Likes

I actually understood that.

Yep, sure is!…and that’s what former Math Major Ensigns are for. :slightly_smiling_face:

1 Like

If you are ever bored check out Computerphile on youtube, especially a very old looking professor that is always so joyful about explaining every computer concept!

2 Likes

@TheAlmightySnark, thanks very much for taking the time to go through all of that. Very much appreciated!

I’m on the road right now but I will sit down next week with a large cup of coffee and see if I can get my sextant project working. I feel I have a much better chance of success now!

1 Like

Let us know if you get stuck somewhere! Pretty sure we’ve got enough knowledge here to fix you up with your virtual sextant!

I am sure I will need more help at some point, but this is a huge step in the right direction. :sunglasses:

Well…yes, the is true. However, I thought that’s why they invented the inflight movie…to “make long range oceanic flights much more interesting.” :wink:

1 Like

Bit of an hack job, but atleast I can have fun now with my touchscreen laptop!

Anyway, been trying to browbeat the Arduino into handling serial input in a sensible way. The String class is pretty horrid when it comes to memory management and really… It’s starting to become confusing.

Right now I send a display(left, right, wpt), followed by a character index(0 through 7) and then the value to display(1 through 9).

This seemed like a nice way to have it be relatively extendable but so far it’s not working… woops.

1 Like

It’s an app!

Made with Kivy and Python, should run on all operating systems you can install Python or on Android. Not quite done yet but it’s getting there!

Just needs an options window and some backend coding.

2 Likes

Very cool! :sunglasses:

2 Likes