getPOSI and sendPOSI fix to handle Lat/Lon/h doubles
getPOSI now can interpret either float or double Lat/Lon/h messages. sendPOSI now sends double Lat/Lon/h messages. Also fixed integer conversion bug in sendCTRL.
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
|
|
||||||
class XPlaneConnect(object):
|
class XPlaneConnect(object):
|
||||||
"""XPlaneConnect (XPC) facilitates communication to and from the XPCPlugin."""
|
"""XPlaneConnect (XPC) facilitates communication to and from the XPCPlugin."""
|
||||||
socket = None
|
socket = None
|
||||||
@@ -158,10 +157,13 @@ class XPlaneConnect(object):
|
|||||||
|
|
||||||
# Read response
|
# Read response
|
||||||
resultBuf = self.readUDP()
|
resultBuf = self.readUDP()
|
||||||
if len(resultBuf) != 34:
|
if len(resultBuf) == 34:
|
||||||
|
result = struct.unpack(b"<4sxBfffffff", resultBuf)
|
||||||
|
elif len(resultBuf) == 46:
|
||||||
|
result = struct.unpack(b"<4sxBdddffff", resultBuf)
|
||||||
|
else:
|
||||||
raise ValueError("Unexpected response length.")
|
raise ValueError("Unexpected response length.")
|
||||||
|
|
||||||
result = struct.unpack(b"<4sxBfffffff", resultBuf)
|
|
||||||
if result[0] != b"POSI":
|
if result[0] != b"POSI":
|
||||||
raise ValueError("Unexpected header: " + result[0])
|
raise ValueError("Unexpected header: " + result[0])
|
||||||
|
|
||||||
@@ -197,6 +199,9 @@ class XPlaneConnect(object):
|
|||||||
val = -998
|
val = -998
|
||||||
if i < len(values):
|
if i < len(values):
|
||||||
val = values[i]
|
val = values[i]
|
||||||
|
if i < 3:
|
||||||
|
buffer += struct.pack(b"<d", val)
|
||||||
|
else:
|
||||||
buffer += struct.pack(b"<f", val)
|
buffer += struct.pack(b"<f", val)
|
||||||
|
|
||||||
# Send
|
# Send
|
||||||
@@ -257,7 +262,7 @@ class XPlaneConnect(object):
|
|||||||
val = values[i]
|
val = values[i]
|
||||||
if i == 4:
|
if i == 4:
|
||||||
val = -1 if (abs(val + 998) < 1e-4) else val
|
val = -1 if (abs(val + 998) < 1e-4) else val
|
||||||
buffer += struct.pack(b"b", val)
|
buffer += struct.pack(b"b", int(val))
|
||||||
else:
|
else:
|
||||||
buffer += struct.pack(b"<f", val)
|
buffer += struct.pack(b"<f", val)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user