Changeset 919:2ce8ca39525b for src/mlx/fsuipc.py
- Timestamp:
- 03/24/19 08:15:59 (5 years ago)
- Branch:
- python3
- hg-Phase:
- (<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/fsuipc.py
r877 r919 1 1 2 import fs3 import const4 import util5 import acft6 from watchdog import Watchdog2 from . import fs 3 from . import const 4 from . import util 5 from . import acft 6 from .watchdog import Watchdog 7 7 8 8 import threading … … 17 17 import pyuipc 18 18 else: 19 import pyuipc_sim as pyuipc19 from . import pyuipc_sim as pyuipc 20 20 21 21 #------------------------------------------------------------------------------ … … 104 104 try: 105 105 return fun() 106 except Exception ,e:107 print >> sys.stderr, util.utf2unicode(str(e))106 except Exception as e: 107 print(util.utf2unicode(str(e)), file=sys.stderr) 108 108 return None 109 109 … … 133 133 try: 134 134 values = pyuipc.read(data) 135 except TypeError ,e:135 except TypeError as e: 136 136 exception = e 137 137 … … 174 174 try: 175 175 pyuipc.write(self._data) 176 except TypeError ,e:176 except TypeError as e: 177 177 exception = e 178 178 … … 420 420 self._connected = True 421 421 return attempts 422 except Exception ,e:423 print 422 except Exception as e: 423 print("fsuipc.Handler._connect: connection failed: " + \ 424 424 util.utf2unicode(str(e)) + \ 425 " (attempts: %d)" % (attempts,) 425 " (attempts: %d)" % (attempts,)) 426 426 if attempts<self.NUM_CONNECTATTEMPTS: 427 427 time.sleep(self.CONNECT_INTERVAL) … … 454 454 def _disconnect(self): 455 455 """Disconnect from the flight simulator.""" 456 print "fsuipc.Handler._disconnect"456 print("fsuipc.Handler._disconnect") 457 457 if self._connected: 458 458 pyuipc.close() … … 479 479 try: 480 480 if not request.process(time): 481 print "fsuipc.Handler._processRequest: FSUIPC returned invalid data too many times, reconnecting"481 print("fsuipc.Handler._processRequest: FSUIPC returned invalid data too many times, reconnecting") 482 482 needReconnect = True 483 483 except TypeError as e: 484 print 484 print("fsuipc.Handler._processRequest: type error: " + \ 485 485 util.utf2unicode(str(e)) + \ 486 486 ("." if request.unimportant else 487 (", reconnecting (attempts=%d)." % (attempts,))) 487 (", reconnecting (attempts=%d)." % (attempts,)))) 488 488 needReconnect = not request.unimportant 489 489 except Exception as e: 490 print 490 print("fsuipc.Handler._processRequest: FSUIPC connection failed (" + \ 491 491 util.utf2unicode(str(e)) + \ 492 "), reconnecting (attempts=%d)." % (attempts,) 492 "), reconnecting (attempts=%d)." % (attempts,)) 493 493 needReconnect = True 494 494 … … 723 723 duration is the number of seconds to keep the message displayed.""" 724 724 725 print "fsuipc.Simulator.sendMessage:", message725 print("fsuipc.Simulator.sendMessage:", message) 726 726 727 727 if self._scroll: … … 732 732 try: 733 733 message = str(message) 734 except Exception ,e:735 print "fsuipc.Simulator.sendMessage: failed to convert the message to a string:", e734 except Exception as e: 735 print("fsuipc.Simulator.sendMessage: failed to convert the message to a string:", e) 736 736 737 737 data = [(0x3380, -1 - len(message), message), … … 822 822 assert not self._monitoringRequested 823 823 824 print "fsuipc.Simulator.disconnect", closingMessage, duration824 print("fsuipc.Simulator.disconnect", closingMessage, duration) 825 825 826 826 self._stopNormal() … … 953 953 return False 954 954 955 print 956 (name, airPath) 955 print("fsuipc.Simulator: new aircraft name and air file path: %s, %s" % \ 956 (name, airPath)) 957 957 958 958 self._aircraftName = aircraftName … … 1088 1088 self._handler.disconnect() 1089 1089 1090 def _handleNumHotkeys(self, data, (id, generation)):1090 def _handleNumHotkeys(self, data, xxx_todo_changeme5): 1091 1091 """Handle the result of the query of the number of hotkeys""" 1092 (id, generation) = xxx_todo_changeme5 1092 1093 with self._hotkeyLock: 1093 1094 if id==self._hotkeySetID and generation==self._hotkeySetGeneration: 1094 1095 numHotkeys = data[0] 1095 print "fsuipc.Simulator._handleNumHotkeys: numHotkeys:", numHotkeys1096 print("fsuipc.Simulator._handleNumHotkeys: numHotkeys:", numHotkeys) 1096 1097 data = [(0x3210 + i*4, "d") for i in range(0, numHotkeys)] 1097 1098 self._handler.requestRead(data, self._handleHotkeyTable, … … 1135 1136 1136 1137 for offset in oldHotkeyOffsets: 1137 writeData.append((offset, "u", long(0)))1138 writeData.append((offset, "u", int(0))) 1138 1139 1139 1140 return writeData 1140 1141 1141 def _handleHotkeyTable(self, data, (id, generation)):1142 def _handleHotkeyTable(self, data, xxx_todo_changeme6): 1142 1143 """Handle the result of the query of the hotkey table.""" 1144 (id, generation) = xxx_todo_changeme6 1143 1145 with self._hotkeyLock: 1144 1146 if id==self._hotkeySetID and generation==self._hotkeySetGeneration: … … 1148 1150 (id, generation)) 1149 1151 1150 def _handleHotkeysWritten(self, success, (id, generation)):1152 def _handleHotkeysWritten(self, success, xxx_todo_changeme7): 1151 1153 """Handle the result of the hotkeys having been written.""" 1154 (id, generation) = xxx_todo_changeme7 1152 1155 with self._hotkeyLock: 1153 1156 if success and id==self._hotkeySetID and \ … … 1160 1163 (id, generation)) 1161 1164 1162 def _handleHotkeys(self, data, (id, generation)):1165 def _handleHotkeys(self, data, xxx_todo_changeme8): 1163 1166 """Handle the hotkeys.""" 1167 (id, generation) = xxx_todo_changeme8 1164 1168 with self._hotkeyLock: 1165 1169 if id!=self._hotkeySetID or generation!=self._hotkeySetGeneration: … … 1406 1410 state.flapsSet = self._flapsNotches[flapsIndex] 1407 1411 if state.flapsSet != self._flapsSet: 1408 print 1412 print("flapsControl: %d, flapsLeft: %d, flapsRight: %d, flapsAxis: %d, flapsIncrement: %d, flapsSet: %d, numNotchesM1: %d" % \ 1409 1413 (flapsControl, data[self._monidx_flapsLeft], 1410 1414 data[self._monidx_flapsRight], data[self._monidx_flapsAxis], 1411 data[self._monidx_flapsIncrement], state.flapsSet, numNotchesM1) 1415 data[self._monidx_flapsIncrement], state.flapsSet, numNotchesM1)) 1412 1416 self._flapsSet = state.flapsSet 1413 1417 … … 1588 1592 for (tank, level) in levels: 1589 1593 offset = _tank2offset[tank] 1590 value = long(level * 128.0 * 65536.0)1594 value = int(level * 128.0 * 65536.0) 1591 1595 data.append( (offset, "u", value) ) 1592 1596 … … 1698 1702 """A model handler for the PMDG Boeing 737NG model.""" 1699 1703 @staticmethod 1700 def doesHandle(aircraft, (name, airPath)):1704 def doesHandle(aircraft, xxx_todo_changeme): 1701 1705 """Determine if this model handler handles the aircraft with the given 1702 1706 name.""" 1707 (name, airPath) = xxx_todo_changeme 1703 1708 return aircraft.type in [const.AIRCRAFT_B736, 1704 1709 const.AIRCRAFT_B737, … … 1730 1735 1731 1736 if fsType==const.SIM_MSFSX or fsType==const.SIM_P3D: 1732 print 1733 ("FSX" if fsType==const.SIM_MSFSX else "P3D",) 1737 print("%s detected, adding PMDG 737 NGX-specific offsets" % \ 1738 ("FSX" if fsType==const.SIM_MSFSX else "P3D",)) 1734 1739 self._addOffsetWithIndexMember(data, 0x6500, "b", 1735 1740 "_pmdgidx_lts_positionsw") … … 1741 1746 self._addOffsetWithIndexMember(data, 0x65cd, "b", "_pmdgidx_xpdr") 1742 1747 else: 1743 print "FS9 detected, adding PMDG 737 NG-specific offsets"1748 print("FS9 detected, adding PMDG 737 NG-specific offsets") 1744 1749 self._addOffsetWithIndexMember(data, 0x6202, "b", "_pmdgidx_switches") 1745 1750 self._addOffsetWithIndexMember(data, 0x6216, "b", "_pmdgidx_xpdr") … … 1786 1791 1787 1792 if gearControl!=self._lastGearControl or noseGear!=self._lastNoseGear: 1788 print "gearControl:", gearControl, " noseGear:", noseGear1793 print("gearControl:", gearControl, " noseGear:", noseGear) 1789 1794 self._lastGearControl = gearControl 1790 1795 self._lastNoseGear = noseGear … … 1833 1838 """Model handler for the Dreamwings Dash 8-Q400.""" 1834 1839 @staticmethod 1835 def doesHandle(aircraft, (name, airPath)):1840 def doesHandle(aircraft, xxx_todo_changeme1): 1836 1841 """Determine if this model handler handles the aircraft with the given 1837 1842 name.""" 1843 (name, airPath) = xxx_todo_changeme1 1838 1844 return aircraft.type==const.AIRCRAFT_DH8D and \ 1839 1845 (name.find("Dreamwings")!=-1 or airPath.find("Dreamwings")!=-1) and \ … … 1870 1876 """Model handler for the Majestic Dash 8-Q400.""" 1871 1877 @staticmethod 1872 def doesHandle(aircraft, (name, airPath)):1878 def doesHandle(aircraft, xxx_todo_changeme2): 1873 1879 """Determine if this model handler handles the aircraft with the given 1874 1880 name.""" 1881 (name, airPath) = xxx_todo_changeme2 1875 1882 return aircraft.type==const.AIRCRAFT_DH8D and \ 1876 1883 (name.find("MJC8Q400")!=-1 or \ … … 1948 1955 """Model for the Digital Aviation F70 implementation on FS9.""" 1949 1956 @staticmethod 1950 def doesHandle(aircraft, (name, airPath)):1957 def doesHandle(aircraft, xxx_todo_changeme3): 1951 1958 """Determine if this model handler handles the aircraft with the given 1952 1959 name.""" 1960 (name, airPath) = xxx_todo_changeme3 1953 1961 return aircraft.type == const.AIRCRAFT_F70 and \ 1954 1962 (airPath.endswith("fokker70_2k4_v4.1.air") or … … 2137 2145 """Project Tupolev Tu-154.""" 2138 2146 @staticmethod 2139 def doesHandle(aircraft, (name, airPath)):2147 def doesHandle(aircraft, xxx_todo_changeme4): 2140 2148 """Determine if this model handler handles the aircraft with the given 2141 2149 name.""" 2142 print "PTT154Model.doesHandle", aircraft.type, name, airPath 2150 (name, airPath) = xxx_todo_changeme4 2151 print("PTT154Model.doesHandle", aircraft.type, name, airPath) 2143 2152 return aircraft.type==const.AIRCRAFT_T154 and \ 2144 2153 (name.find("Tu-154")!=-1 or name.find("Tu154B")!=-1) and \
Note:
See TracChangeset
for help on using the changeset viewer.