www.PeninsulaSims.com ryan@peninsulasims.com 06.12.2019
X-Plane Commands and Datarefs TCP vs. UDP
UDP Native X-Plane Format Exercise: Turning on the night vision “Easy!” (not, at least it wasn’t for me)
TCP vs. UDP Transmission Control Protocol Reliable, message acknowledgment, handshaking Ordered Heavyweight Streaming User Datagram Protocol Unreliable, no acknowledgment or handshake Lightweight No congestion control Connectionless Multicast Native X-Plane
ExtPlane (TCP) vs. X-Plane UDP UDP Format requires tracking length of packet and padding out to 509 bytes UDP Format makes use of IEEE Float for values being sent, which is complicated to convert (for novices) TCP via ExtPlane is simple and intuitive TCP does not require conversion to IEEE Float (someone has already done that) TCP does not require understanding the underlying packet TCP reply received with each command sent
Laminar’s Instructions for UDP
Set a Dataref to a Value
Let’s turn on the night vision! Dataref needs to be set to 1: Dataref: sim/cockpit/electrical/night_vision_on IEEE Float value of 1 (4 byte byte value), LSB First Hex representation of an ASCII space, and how to pad out to 509 bytes Hex representation of an ASCII 0 (zero) Syntax: DREF0+(4byte byte value of 1)+ sim/cockpit/switches/anti_ice_surf_heat_left+0+ spaces to complete to 509 bytes
IEEE Float IEEE Floating Point Converter https://www.h- schmidt.net/FloatConverter/IEEE754.html Your Value: 1 (e.g., dataref set to “1” or “on”) Hex representation: 0x3f800000 4-byte byte value: 3F 80 00 00 Least significant bit first: 00 00 80 3F
ASCII Character Table Dec Char Dec Char Dec Char Dec Char --------- --------- --------- ---------- 0 NUL (null) 32 SPACE 64 @ 96 ` 1 SOH (start of heading) 33 ! 65 A 97 a 2 STX (start of text) 34 " 66 B 98 b 3 ETX (end of text) 35 # 67 C 99 c 4 EOT (end of transmission) 36 $ 68 D 100 d 5 ENQ (enquiry) 37 % 69 E 101 e 6 ACK (acknowledge) 38 & 70 F 102 f 7 BEL (bell) 39 ' 71 G 103 g 8 BS (backspace) 40 ( 72 H 104 h 9 TAB (horizontal tab) 41 ) 73 I 105 i 10 LF (NL line feed, new line) 42 * 74 J 106 j 11 VT (vertical tab) 43 + 75 K 107 k
Convert letters D R E F to Hex Step 1: Convert D to ASCII decimal value using table D = 68 R = 82 E = 69 F = 70
Convert Decimal to Hex: D/68 Divide by 16 until there is no remainder Read back remainders bottom to top 68 / 16 = 4 remainder 4 4 / 16 = 0 remainder 4 Result = 44 (remainders read bottom to top)
Why in the world Hex? Decimal (base 10): 10 fingers, 10 toes Inefficient: Decimal: 39,321 Hex: 9999 Binary 1001 1001 1001 1001 (bits are ones and zeroes) Hexadecimal (base 16) Natural complement to binary data One hexadecimal value can store 4 pieces of data (e.g., 0101) Good for compression
Convert Decimal to Hex: R/82 Divide by 16 until there is no remainder 82 / 16 = 5 remainder 2 5 / 16 = 0 remainder 5 Result = 52
Convert letters D R E F to Hex Step 1: Convert ASCII decimal value using tabulated values Step 2: Convert decimal to hex (base 10 to base 16) MSB first D = 68 = 44 R = 82 = 52 E = 69 = 45 F = 70 = 46
Set DREF Night Vision On DREF0+(4byte byte value)+dref_path+0+spaces to complete the whole message to 509 bytes DREF\00\00\00\80\3Fsim/cockpit/electrical/night_visi on_on\00 44 52 45 46 00 00 00 80 3f 73 69 6d 2f 63 6f 63 6b 70 69 74 2f 65 6c 65 63 74 72 69 63 61 6c 2f 6e 69 67 68 74 5f 76 69 73 69 6f 6e 5f 6f 6e 00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
Packet sent via UDP 44 52 45 46 00 00 00 80 3f 73 69 6d 2f 63 6f 63 6b 70 69 74 2f 65 6c 65 63 74 72 69 63 61 6c 2f 6e 69 67 68 74 5f 76 69 73 69 6f 6e 5f 6f 6e 00 20 20 20 20 20 20 D R E F 0 1 S I M / c o c k p i t / e l e c t r i c a l / n i g h t _ v i s i o n _ o n 0 sp sp sp sp sp sp sp sp sp sp sp sp sp … ( until 509 bytes total)
Send in packet to port 49000 Night vision turns on 44 52 45 46 00 00 00 80 3f 73 69 6d 2f 63 6f 63 6b 70 69 74 2f 65 6c 65 63 74 72 69 63 61 6c 2f 6e 69 67 68 74 5f 76 69 73 69 6f 6e 5f 6f 6e 00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
Why is this important? Understanding the UDP syntax enables me to send commands to X-Plane without the ExtPlane plugin. Plugins can cause simulator instability or crashes. The downside is the difficulty in setting datarefs, e.g., course (0 to 359 degrees). IEEE Float
Demonstration Packet Sender Example
Via ExtPlane...Stay Tuned! TCP Via ExtPlane...Stay Tuned!
www.PeninsulaSims.com ryan@peninsulasims.com 06.12.2019