Added support for VIEW command to Python client.
This commit is contained in:
@@ -326,6 +326,23 @@ class XPlaneConnect(object):
|
|||||||
buffer = struct.pack("<4sxiiB" + str(msgLen) + "s", "TEXT", x, y, msgLen, msg)
|
buffer = struct.pack("<4sxiiB" + str(msgLen) + "s", "TEXT", x, y, msgLen, msg)
|
||||||
self.sendUDP(buffer)
|
self.sendUDP(buffer)
|
||||||
|
|
||||||
|
def sendVIEW(self, view):
|
||||||
|
'''Sets the camera view in X-Plane
|
||||||
|
|
||||||
|
Args:
|
||||||
|
view: The view to use. The ViewType class provides named constants
|
||||||
|
for known views.
|
||||||
|
'''
|
||||||
|
# Preconditions
|
||||||
|
if view < ViewType.Forwards or view > ViewType.FullscreenNoHud:
|
||||||
|
raise ValueError("Unknown view command.")
|
||||||
|
|
||||||
|
# Pack buffer
|
||||||
|
buffer = struct.pack("<4sxi", "VIEW", view)
|
||||||
|
|
||||||
|
# Send message
|
||||||
|
self.sendUDP(buffer)
|
||||||
|
|
||||||
def sendWYPT(self, op, points):
|
def sendWYPT(self, op, points):
|
||||||
'''Adds, removes, or clears waypoints. Waypoints are three dimensional points on or
|
'''Adds, removes, or clears waypoints. Waypoints are three dimensional points on or
|
||||||
above the Earth's surface that are represented visually in the simulator. Each
|
above the Earth's surface that are represented visually in the simulator. Each
|
||||||
@@ -350,3 +367,18 @@ class XPlaneConnect(object):
|
|||||||
else:
|
else:
|
||||||
buffer = struct.pack("<4sxBB" + str(len(points)) + "f", "WYPT", op, len(points), *points)
|
buffer = struct.pack("<4sxBB" + str(len(points)) + "f", "WYPT", op, len(points), *points)
|
||||||
self.sendUDP(buffer)
|
self.sendUDP(buffer)
|
||||||
|
|
||||||
|
class ViewType(object):
|
||||||
|
Forwards = 73
|
||||||
|
Down = 74
|
||||||
|
Left = 75
|
||||||
|
Right = 76
|
||||||
|
Back = 77
|
||||||
|
Tower = 78
|
||||||
|
Runway = 79
|
||||||
|
Chase = 80
|
||||||
|
Follow = 81
|
||||||
|
FollowWithPanel = 82
|
||||||
|
Spot = 83
|
||||||
|
FullscreenWithHud = 84
|
||||||
|
FullscreenNoHud = 85
|
||||||
|
|||||||
@@ -319,6 +319,22 @@ class XPCTests(unittest.TestCase):
|
|||||||
# Cleanup
|
# Cleanup
|
||||||
client.close()
|
client.close()
|
||||||
|
|
||||||
|
def test_sendView(self):
|
||||||
|
# Setup
|
||||||
|
dref = "sim/graphics/view/view_type"
|
||||||
|
fwd = 1000
|
||||||
|
chase = 1017
|
||||||
|
|
||||||
|
#Execution
|
||||||
|
with xpc.XPlaneConnect() as client:
|
||||||
|
client.sendVIEW(xpc.ViewType.Forwards)
|
||||||
|
result = client.getDREF(dref)
|
||||||
|
self.assertAlmostEqual(fwd, result[0], 1e-4)
|
||||||
|
client.sendVIEW(xpc.ViewType.Chase)
|
||||||
|
result = client.getDREF(dref)
|
||||||
|
self.assertAlmostEqual(chase, result[0], 1e-4)
|
||||||
|
|
||||||
|
|
||||||
def test_sendWYPT(self):
|
def test_sendWYPT(self):
|
||||||
# Setup
|
# Setup
|
||||||
client = xpc.XPlaneConnect()
|
client = xpc.XPlaneConnect()
|
||||||
|
|||||||
Reference in New Issue
Block a user