Added getCTRL and getPOSI support to python client.
This commit is contained in:
@@ -143,7 +143,29 @@ class XPlaneConnect(object):
|
|||||||
buffer += struct.pack("<I8f", *row)
|
buffer += struct.pack("<I8f", *row)
|
||||||
self.sendUDP(buffer)
|
self.sendUDP(buffer)
|
||||||
|
|
||||||
# Position
|
# Position
|
||||||
|
def getPOSI(self, ac = 0):
|
||||||
|
'''Gets position information for the specified aircraft.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
ac: The aircraft to set the control surfaces of. 0 is the main/player aircraft.
|
||||||
|
'''
|
||||||
|
# Send request
|
||||||
|
buffer = struct.pack("<4sxB", "GETP", ac)
|
||||||
|
self.sendUDP(buffer)
|
||||||
|
|
||||||
|
# Read response
|
||||||
|
resultBuf = self.readUDP()
|
||||||
|
if len(resultBuf) != 34:
|
||||||
|
raise ValueError("Unexpected response length.")
|
||||||
|
|
||||||
|
result = struct.unpack("<4sxBfffffff", resultBuf)
|
||||||
|
if result[0] != "POSI":
|
||||||
|
raise ValueError("Unexpected header: " + result[0])
|
||||||
|
|
||||||
|
# Drop the header & ac from the return value
|
||||||
|
return result[2:]
|
||||||
|
|
||||||
def sendPOSI(self, values, ac = 0):
|
def sendPOSI(self, values, ac = 0):
|
||||||
'''Sets position information on the specified aircraft.
|
'''Sets position information on the specified aircraft.
|
||||||
|
|
||||||
@@ -155,8 +177,8 @@ class XPlaneConnect(object):
|
|||||||
* Latitude (deg)
|
* Latitude (deg)
|
||||||
* Longitude (deg)
|
* Longitude (deg)
|
||||||
* Altitude (m above MSL)
|
* Altitude (m above MSL)
|
||||||
* Roll (deg)
|
|
||||||
* Pitch (deg)
|
* Pitch (deg)
|
||||||
|
* Roll (deg)
|
||||||
* True Heading (deg)
|
* True Heading (deg)
|
||||||
* Gear (0=up, 1=down)
|
* Gear (0=up, 1=down)
|
||||||
ac: The aircraft to set the control surfaces of. 0 is the main/player aircraft.
|
ac: The aircraft to set the control surfaces of. 0 is the main/player aircraft.
|
||||||
@@ -179,6 +201,29 @@ class XPlaneConnect(object):
|
|||||||
self.sendUDP(buffer)
|
self.sendUDP(buffer)
|
||||||
|
|
||||||
# Controls
|
# Controls
|
||||||
|
def getCTRL(self, ac = 0):
|
||||||
|
'''Gets the control surface information for the specified aircraft.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
ac: The aircraft to set the control surfaces of. 0 is the main/player aircraft.
|
||||||
|
'''
|
||||||
|
# Send request
|
||||||
|
buffer = struct.pack("<4sxB", "GETC", ac)
|
||||||
|
self.sendUDP(buffer)
|
||||||
|
|
||||||
|
# Read response
|
||||||
|
resultBuf = self.readUDP()
|
||||||
|
if len(resultBuf) != 31:
|
||||||
|
raise ValueError("Unexpected response length.")
|
||||||
|
|
||||||
|
result = struct.unpack("<4sxffffbfBf", resultBuf)
|
||||||
|
if result[0] != "CTRL":
|
||||||
|
raise ValueError("Unexpected header: " + result[0])
|
||||||
|
|
||||||
|
# Drop the header from the return value
|
||||||
|
result =result[1:7] + result[8:]
|
||||||
|
return result
|
||||||
|
|
||||||
def sendCTRL(self, values, ac = 0):
|
def sendCTRL(self, values, ac = 0):
|
||||||
'''Sets control surface information on the specified aircraft.
|
'''Sets control surface information on the specified aircraft.
|
||||||
|
|
||||||
|
|||||||
@@ -202,6 +202,29 @@ class XPCTests(unittest.TestCase):
|
|||||||
expected = 0.0
|
expected = 0.0
|
||||||
do_test()
|
do_test()
|
||||||
|
|
||||||
|
def test_getCTRL(self):
|
||||||
|
values = None
|
||||||
|
ac = 0
|
||||||
|
expected = None
|
||||||
|
def do_test():
|
||||||
|
with xpc.XPlaneConnect() as client:
|
||||||
|
# Execute
|
||||||
|
client.sendCTRL(values, ac)
|
||||||
|
result = client.getCTRL(ac)
|
||||||
|
|
||||||
|
# Test
|
||||||
|
self.assertEqual(len(result), len(expected))
|
||||||
|
for a, e in zip(result, expected):
|
||||||
|
self.assertAlmostEqual(a, e, 4)
|
||||||
|
|
||||||
|
values = [0.0, 0.0, 0.0, 0.8, 1.0, 0.5, -1.5]
|
||||||
|
expected = values
|
||||||
|
ac = 0
|
||||||
|
do_test()
|
||||||
|
|
||||||
|
ac = 3
|
||||||
|
do_test()
|
||||||
|
|
||||||
|
|
||||||
def test_sendCTRL(self):
|
def test_sendCTRL(self):
|
||||||
# Setup
|
# Setup
|
||||||
@@ -270,6 +293,31 @@ class XPCTests(unittest.TestCase):
|
|||||||
ctrl[6] = 0.0
|
ctrl[6] = 0.0
|
||||||
do_test()
|
do_test()
|
||||||
|
|
||||||
|
def test_getPOSI(self):
|
||||||
|
values = None
|
||||||
|
ac = 0
|
||||||
|
expected = None
|
||||||
|
def do_test():
|
||||||
|
with xpc.XPlaneConnect() as client:
|
||||||
|
# Execute
|
||||||
|
client.pauseSim(True)
|
||||||
|
client.sendPOSI(values, ac)
|
||||||
|
result = client.getPOSI(ac)
|
||||||
|
client.pauseSim(False)
|
||||||
|
|
||||||
|
# Test
|
||||||
|
self.assertEqual(len(result), len(expected))
|
||||||
|
for a, e in zip(result, expected):
|
||||||
|
self.assertAlmostEqual(a, e, 4)
|
||||||
|
|
||||||
|
values = [ 37.524, -122.06899, 2500, 45, -45, 15, 1 ]
|
||||||
|
expected = values
|
||||||
|
ac = 0
|
||||||
|
do_test()
|
||||||
|
|
||||||
|
ac = 3
|
||||||
|
do_test()
|
||||||
|
|
||||||
def test_sendPOSI(self):
|
def test_sendPOSI(self):
|
||||||
# Setup
|
# Setup
|
||||||
drefs = ["sim/flightmodel/position/latitude",\
|
drefs = ["sim/flightmodel/position/latitude",\
|
||||||
|
|||||||
Reference in New Issue
Block a user