Added support for VIEW command to Python client.

This commit is contained in:
Jason Watkins
2015-05-08 13:34:32 -07:00
parent 579cad0655
commit 039c92b2f1
2 changed files with 48 additions and 0 deletions

View File

@@ -326,6 +326,23 @@ class XPlaneConnect(object):
buffer = struct.pack("<4sxiiB" + str(msgLen) + "s", "TEXT", x, y, msgLen, msg)
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):
'''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
@@ -350,3 +367,18 @@ class XPlaneConnect(object):
else:
buffer = struct.pack("<4sxBB" + str(len(points)) + "f", "WYPT", op, len(points), *points)
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

View File

@@ -319,6 +319,22 @@ class XPCTests(unittest.TestCase):
# Cleanup
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):
# Setup
client = xpc.XPlaneConnect()