aircraft: Specified as: --aircraft={aircraft}. This is separate from because we need to know the name of recording files. args: Miscellenous args either space-separated name=value strings or a dict. env: Envi
(self, aircraft, args, env=None, telnet_port=None, telnet_hz=None, out=None, screensaver_suspend=True)
| 101 | communicate with Flightgear. |
| 102 | ''' |
| 103 | def __init__(self, aircraft, args, env=None, telnet_port=None, telnet_hz=None, out=None, screensaver_suspend=True): |
| 104 | ''' |
| 105 | aircraft: |
| 106 | Specified as: --aircraft={aircraft}. This is separate from <args> |
| 107 | because we need to know the name of recording files. |
| 108 | args: |
| 109 | Miscellenous args either space-separated name=value strings or a |
| 110 | dict. |
| 111 | env: |
| 112 | Environment to set. If DISPLAY is not in <env> we add 'DISPLAY=:0'. |
| 113 | telnet_port: |
| 114 | telnet_hz: |
| 115 | . |
| 116 | ''' |
| 117 | self.child = None |
| 118 | self.aircraft = aircraft |
| 119 | if aircraft: |
| 120 | args += f' --aircraft={aircraft}' |
| 121 | |
| 122 | if telnet_port is None: |
| 123 | telnet_port = 5500 |
| 124 | if telnet_hz is None: |
| 125 | args += f' --telnet={telnet_port}' |
| 126 | else: |
| 127 | args += f' --telnet=_,_,{telnet_hz},_,{telnet_port},_' |
| 128 | args += f' --prop:/sim/replay/tape-directory={g_tapedir}' |
| 129 | args += f' --prop:bool:/sim/startup/screensaver-suspend={"true" if screensaver_suspend else "false"}' |
| 130 | |
| 131 | args2 = args.split() |
| 132 | |
| 133 | environ = os.environ.copy() |
| 134 | if isinstance(env, str): |
| 135 | for nv in env.split(): |
| 136 | n, v = nv.split('=', 1) |
| 137 | environ[n] = v |
| 138 | if 'DISPLAY' not in environ: |
| 139 | environ['DISPLAY'] = ':0' |
| 140 | |
| 141 | # Run flightgear in new process, telling it to open telnet server. |
| 142 | # |
| 143 | # We run not in a shell, otherwise self.child.terminate() doesn't |
| 144 | # work - it would kill the shell but leave fgfs running (there are |
| 145 | # workarounds for this, such as prefixing the command with 'exec'). |
| 146 | # |
| 147 | log(f'Command is: {args}') |
| 148 | log(f'Running: {args2}') |
| 149 | if resource: |
| 150 | def preexec(): |
| 151 | try: |
| 152 | resource.setrlimit(resource.RLIMIT_CORE, (resource.RLIM_INFINITY, resource.RLIM_INFINITY)) |
| 153 | except Exception as e: |
| 154 | log(f'*** preexec failed with e={e}') |
| 155 | raise |
| 156 | else: |
| 157 | preexec = None |
| 158 | if out: |
| 159 | out = open(out, 'w') |
| 160 | self.child = subprocess.Popen( |