Rev | Line | |
---|
[97] | 1 | #!/usr/bin/env python3
|
---|
[84] | 2 | #
|
---|
| 3 | # Program to automatically save the situation at certain intervals
|
---|
| 4 |
|
---|
| 5 | from xplra import XPlane, ProtocolException
|
---|
| 6 |
|
---|
| 7 | import sys
|
---|
| 8 | import os
|
---|
| 9 | import time
|
---|
| 10 |
|
---|
| 11 | if __name__ == "__main__":
|
---|
| 12 | interval = float(sys.argv[1])
|
---|
| 13 | xplanePath = sys.argv[2]
|
---|
| 14 | name = sys.argv[3]
|
---|
| 15 |
|
---|
| 16 | newName = name + ".new.sit"
|
---|
| 17 | savePath = "output/situations/" + newName
|
---|
| 18 |
|
---|
| 19 | basePath = os.path.join(xplanePath, "Output", "situations", name)
|
---|
| 20 | path = basePath + ".sit"
|
---|
| 21 | newPath = basePath + ".new.sit"
|
---|
| 22 | oldPath = basePath + ".old.sit"
|
---|
| 23 |
|
---|
| 24 | xplane = XPlane()
|
---|
| 25 |
|
---|
[97] | 26 | print("Connecting to X-Plane...")
|
---|
[84] | 27 |
|
---|
[88] | 28 | while not xplane.isConnected:
|
---|
| 29 | try:
|
---|
| 30 | xplane.connect()
|
---|
| 31 | except:
|
---|
[97] | 32 | print("Connection failed, sleeping...")
|
---|
[88] | 33 | time.sleep(0.5)
|
---|
| 34 |
|
---|
[97] | 35 | print("Connected to X-Plane")
|
---|
[88] | 36 |
|
---|
| 37 | try:
|
---|
| 38 | while True:
|
---|
[84] | 39 | try:
|
---|
[88] | 40 | xplane.saveSituation(savePath)
|
---|
[84] | 41 | try:
|
---|
[88] | 42 | if os.path.exists(path):
|
---|
| 43 | os.rename(path, oldPath)
|
---|
| 44 | os.rename(newPath, path)
|
---|
[84] | 45 |
|
---|
[97] | 46 | print("Situation saved at " + time.strftime("%H:%M:%S"))
|
---|
| 47 | except OSError as e:
|
---|
| 48 | print("I/O error occured: " + str(e))
|
---|
| 49 | except ProtocolException as e:
|
---|
| 50 | print("Protocol error occured: " + str(e))
|
---|
[88] | 51 | time.sleep(interval)
|
---|
[97] | 52 | except Exception as e:
|
---|
| 53 | print("Connection failed: " + str(e))
|
---|
[88] | 54 | try:
|
---|
[84] | 55 | xplane.disconnect()
|
---|
[88] | 56 | except:
|
---|
| 57 | pass
|
---|
Note:
See
TracBrowser
for help on using the repository browser.