Changeset 334:7978a2496c31
- Timestamp:
- 11/13/12 16:52:27 (12 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/fs.py
r321 r334 36 36 def connectionFailed(self): 37 37 """Called when the connection could not be established.""" 38 print "fs.ConnectionListener.connectionFailed" 38 print "fs.ConnectionListener.connectionFailed" 39 39 40 40 def disconnected(self): … … 116 116 del self._messages[0] 117 117 118 if text is not None: 118 if text is not None: 119 119 self._sendMessage(messageType, text, duration, disconnect) 120 120 121 121 def _sendMessage(self, messageType, text, duration, disconnect): 122 """Send the message and setup the next message time.""" 122 """Send the message and setup the next message time.""" 123 123 messageLevel = self._config.getMessageTypeLevel(messageType) 124 124 if messageLevel==const.MESSAGELEVEL_SOUND or \ … … 180 180 - overspeed: a boolean indicating if the aircraft is in overspeed 181 181 - stalled: a boolean indicating if the aircraft is stalled 182 - onTheGround: a boolean indicating if the aircraft is on the ground 182 - onTheGround: a boolean indicating if the aircraft is on the ground 183 183 - zfw: the zero-fuel weight in kilograms (float) 184 184 - grossWeight: the gross weight in kilograms (float) … … 190 190 - ias: the indicated airspeed in knots (float) 191 191 - smoothedIAS: the smoothed IAS in knots (float) 192 - mach: the airspeed in mach (float) 192 - mach: the airspeed in mach (float) 193 193 - groundSpeed: the ground speed (float) 194 194 - vs: the vertical speed in feet/minutes (float) … … 225 225 automatic deployment 226 226 - spoilersExtension: the percentage of how much the spoiler is extended 227 (float) 227 (float) 228 228 - altimeter: the altimeter setting in hPa (float) 229 229 - nav1: the frequency of the NAV1 radio in MHz (string). Can be None, if … … 245 245 - windDirection: the direction of the wind at the aircraft in degrees (float) 246 246 - visibility: the visibility in metres (float) 247 - cog: the centre of gravity 247 - cog: the centre of gravity 248 - xpdrC: a boolean indicating whether the transponder is in C mode, or 249 None, if the state cannot be read properly 248 250 249 251 FIXME: needed when taxiing only: … … 253 255 - latitude, longitude 254 256 - transporter 255 - visibility 257 - visibility 256 258 """ 257 -
src/mlx/fsuipc.py
r330 r334 1188 1188 ("windDirection", 0x0e92, "H"), 1189 1189 ("visibility", 0x0e8a, "H"), 1190 ("cog", 0x2ef8, "f")] 1190 ("cog", 0x2ef8, "f"), 1191 ("xpdrC", 0x7b91, "b")] 1191 1192 1192 1193 specialModels = [] … … 1384 1385 1385 1386 state.cog = data[self._monidx_cog] 1387 1388 state.xpdrC = data[self._monidx_xpdrC]==0 1386 1389 1387 1390 return state -
src/mlx/gui/monitor.py
r314 r334 23 23 """Construct the monitor window.""" 24 24 super(MonitorWindow, self).__init__() 25 25 26 26 self._gui = gui 27 27 … … 48 48 self._paused = gtk.Label("PAUSED") 49 49 table.attach(self._paused, 2, 4, 0, 1) 50 50 51 51 self._trickMode = gtk.Label("TRICKMODE") 52 52 table.attach(self._trickMode, 4, 6, 0, 1, xoptions = 0) 53 53 54 54 self._overspeed = gtk.Label("OVERSPEED") 55 55 table.attach(self._overspeed, 6, 8, 0, 1) 56 56 57 57 self._stalled = gtk.Label("STALLED") 58 58 table.attach(self._stalled, 8, 10, 0, 1) 59 59 60 60 self._onTheGround = gtk.Label("ONTHEGROUND") 61 61 table.attach(self._onTheGround, 10, 12, 0, 1) 62 62 63 63 (label, self._zfw) = self._createLabeledEntry("ZFW:", 6) 64 64 table.attach(label, 0, 1, 1, 2) … … 188 188 table.attach(self._position, 7, 10, 6, 7) 189 189 190 self._xpdrC = gtk.Label("XPDR CHARLIE") 191 table.attach(self._xpdrC, 10, 12, 6, 7) 192 190 193 alignment.add(table) 191 194 … … 202 205 - the box 203 206 - the entry.""" 204 207 205 208 alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5, xscale = 1.0) 206 209 alignment.set_padding(padding_top = 0, padding_bottom = 0, … … 262 265 self._windDirection.set_text("-") 263 266 self._position.set_text("-") 267 self._xpdrC.set_sensitive(False) 264 268 else: 265 269 self._timestamp.set_text(time.strftime("%H:%M:%S", … … 294 298 for (_tank, fuel) in aircraftState.fuel: 295 299 if fuelStr: fuelStr += ", " 296 fuelStr += "%.0f" % (fuel,) 300 fuelStr += "%.0f" % (fuel,) 297 301 self._fuel.set_text(fuelStr) 298 302 … … 329 333 self._landingLightsOn.set_text("LANDING") 330 334 self._landingLightsOn.set_sensitive(aircraftState.landingLightsOn is True) 331 335 332 336 self._pitotHeatOn.set_sensitive(aircraftState.pitotHeatOn) 333 337 self._parking.set_sensitive(aircraftState.parking) … … 340 344 self._position.set_text(util.getCoordinateString((aircraftState.latitude, 341 345 aircraftState.longitude))) 346 self._xpdrC.set_sensitive(aircraftState.xpdrC) 342 347 343 348 #------------------------------------------------------------------------------ -
src/mlx/pyuipc_sim.py
r321 r334 186 186 bcd |= value % 10 187 187 return bcd 188 188 189 189 @staticmethod 190 190 def _writeFrequency(value): … … 207 207 if isMain: mainFrequency = value 208 208 else: extFrequency = value 209 209 210 210 return Values._toADFFrequency(mainFrequency, extFrequency) 211 211 … … 222 222 223 223 return bcd 224 224 225 225 def __init__(self): 226 226 """Construct the values with defaults.""" … … 235 235 self.latitude = 47.5 236 236 self.longitude = 19.05 237 237 238 238 self.paused = False 239 239 self.frozen = False … … 243 243 self.stalled = False 244 244 self.onTheGround = True 245 245 246 246 self.zfw = 50000.0 247 247 248 248 self.fuelWeights = [0.0, 3000.0, 3000.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] 249 249 # Wikipedia: "Jet fuel", Jet A-1 density at 15*C .804kg/l -> 6.7 pounds/gallon … … 293 293 self.windDirection = 300.0 294 294 self.visibility = 10000 295 295 296 296 self.n1 = [0.0, 0.0, 0.0] 297 297 self.throttles = [0.0, 0.0, 0.0] … … 313 313 self.pmdg_737ng_switches = 0 314 314 self.pmdg_737ngx_lts_positionsw = 0 315 316 self.xpdrC = False 315 317 316 318 def read(self, offset, type): … … 447 449 (self.flapsNotches[index+1] - self.flapsNotches[index])) 448 450 elif offset==0x0be0 or offset==0x0be4: # Flaps left and right 449 return self.flaps * 16383.0 / self.flapsNotches[-1] 451 return self.flaps * 16383.0 / self.flapsNotches[-1] 450 452 elif offset==0x0be8: # Gear control 451 453 return int(self.gearControl * 16383.0) … … 504 506 return (self.zfw + sum(self.fuelWeights)) * const.KGSTOLB 505 507 elif offset==0x31e4: # Radio altitude 506 # FIXME: if self.radioAltitude is None, calculate from the 508 # FIXME: if self.radioAltitude is None, calculate from the 507 509 # altitude with some, perhaps random, ground altitude 508 510 # value … … 551 553 elif offset==0x6500: # PMDG 737NGX lights position SW 552 554 return self.pmdg_737ngx_lts_positionsw 555 elif offset==0x7b91: # Transponder standby 556 return 0 if self.xpdrC else 1 553 557 else: 554 558 print "Unhandled offset: %04x" % (offset,) … … 697 701 self.navLightsOn = (value&0x01)!=0 698 702 self.antiCollisionLightsOn = (value&0x02)!=0 699 self.landingLightsOn = (value&0x04)!=0 700 self.strobeLightsOn = (value&0x10)!=0 703 self.landingLightsOn = (value&0x04)!=0 704 self.strobeLightsOn = (value&0x10)!=0 701 705 elif offset==0x0e8a: # Visibility 702 706 self.visibility = value * 1609.344 / 100.0 … … 781 785 elif offset==0x6500: # PMDG 737NGX lights position SW 782 786 self.pmdg_737ngx_lts_positionsw = value 787 elif offset==0x7b91: # Transponder standby 788 self.xpdrC = value==0 783 789 else: 784 790 print "Unhandled offset: %04x" % (offset,) 785 791 raise FSUIPCException(ERR_DATA) 786 792 787 793 def _readUTC(self): 788 794 """Read the UTC time. 789 795 790 796 The current offset is added to it.""" 791 797 return time.gmtime(time.time() + self._timeOffset) 792 798 793 799 def _getFuelLevel(self, index): 794 800 """Get the fuel level for the fuel tank with the given … … 796 802 return 0 if self.fuelCapacities[index]==0.0 else \ 797 803 int(self.fuelWeights[index] * 65536.0 * 128.0 / self.fuelCapacities[index]) 798 804 799 805 def _getFuelCapacity(self, index): 800 806 """Get the capacity of the fuel tank with the given index.""" … … 811 817 tm1 = tm[:index] + (value,) + tm[(index+1):] 812 818 self._timeOffset += calendar.timegm(tm1) - calendar.timegm(tm) 813 819 814 820 def _setThrottle(self, index, value): 815 821 """Set the throttle value for the given index.""" … … 820 826 self.fuelWeights[index] = self.fuelCapacities[index] * float(value) / \ 821 827 65536.0 / 128.0 822 828 823 829 def _setFuelCapacity(self, index, value): 824 830 """Set the capacity of the fuel tank with the given index.""" … … 830 836 const.FEETTOMETRES, 831 837 5.25588) 832 temperature = 15 - self.altitude * 6.5 * const.FEETTOMETRES / 1000.0 838 temperature = 15 - self.altitude * 6.5 * const.FEETTOMETRES / 1000.0 833 839 temperature += 273.15 # Celsius -> Kelvin 834 840 airDensity = pressure / (temperature * 287.05) … … 868 874 else: 869 875 raise FSUIPCException(ERR_NOTOPEN) 870 876 871 877 #------------------------------------------------------------------------------ 872 878 … … 877 883 else: 878 884 raise FSUIPCException(ERR_NOTOPEN) 879 885 880 886 #------------------------------------------------------------------------------ 881 887 … … 887 893 else: 888 894 raise FSUIPCException(ERR_NOTOPEN) 889 895 890 896 #------------------------------------------------------------------------------ 891 897 … … 924 930 serverSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 925 931 serverSocket.bind(("", PORT)) 926 932 927 933 serverSocket.listen(5) 928 934 929 935 while True: 930 936 (clientSocket, clientAddress) = serverSocket.accept() … … 936 942 socketFile = clientSocket.makefile() 937 943 try: 938 while True: 944 while True: 939 945 (length,) = struct.unpack("I", clientSocket.recv(4)) 940 946 data = clientSocket.recv(length) 941 947 (call, args) = cPickle.loads(data) 942 948 exception = None 943 949 944 950 try: 945 951 if call==CALL_READ: … … 977 983 pass 978 984 clientSocket.close() 979 985 980 986 #------------------------------------------------------------------------------ 981 987 … … 1013 1019 """Quit from the simulator.""" 1014 1020 data = cPickle.dumps((CALL_QUIT, None)) 1015 self._socket.send(struct.pack("I", len(data)) + data) 1021 self._socket.send(struct.pack("I", len(data)) + data) 1016 1022 1017 1023 def _call(self, command, data): … … 1037 1043 """Convert the given string to a PyUIPC boolean value (i.e. 0 or 1).""" 1038 1044 return 1 if s in ["yes", "true", "on"] else 0 1039 1045 1040 1046 @staticmethod 1041 1047 def bool2str(value): … … 1047 1053 """Convert the given degree (as a string) into a PyUIPC value.""" 1048 1054 return int(float(degree) * 65536.0 * 65536.0 / 360.0) 1049 1055 1050 1056 @staticmethod 1051 1057 def pyuipc2degree(value): … … 1057 1063 """Convert the given percentage value (as a string) into a PyUIPC value.""" 1058 1064 return int(float(level) * 128.0 * 65536.0 / 100.0) 1059 1065 1060 1066 @staticmethod 1061 1067 def pyuipc2fuelLevel(value): 1062 1068 """Convert the PyUIPC value into a percentage value.""" 1063 1069 return value * 100.0 / 128.0 / 65536.0 1064 1070 1065 1071 @staticmethod 1066 1072 def fuelCapacity2pyuipc(capacity): 1067 1073 """Convert the given capacity value (as a string) into a PyUIPC value.""" 1068 1074 return int(capacity) 1069 1075 1070 1076 @staticmethod 1071 1077 def pyuipc2fuelCapacity(value): 1072 1078 """Convert the given capacity value into a PyUIPC value.""" 1073 1079 return value 1074 1080 1075 1081 @staticmethod 1076 1082 def throttle2pyuipc(throttle): 1077 1083 """Convert the given throttle value (as a string) into a PyUIPC value.""" 1078 1084 return int(float(throttle) * 16384.0 / 100.0) 1079 1085 1080 1086 @staticmethod 1081 1087 def pyuipc2throttle(value): … … 1086 1092 """Construct the CLI.""" 1087 1093 cmd.Cmd.__init__(self) 1088 1094 1089 1095 self.use_rawinput = True 1090 1096 self.intro = "\nPyUIPC simulator command prompt\n" … … 1158 1164 lambda word: None) 1159 1165 self._valueHandlers["vs"] = ([(0x02c8, "d")], 1160 lambda value: value * 60 / 1166 lambda value: value * 60 / 1161 1167 const.FEETTOMETRES / 256.0, 1162 1168 lambda word: int(float(word) * … … 1164 1170 256.0 / 60.0)) 1165 1171 self._valueHandlers["tdRate"] = ([(0x030c, "d")], 1166 lambda value: value * 60 / 1172 lambda value: value * 60 / 1167 1173 const.FEETTOMETRES / 256.0, 1168 1174 lambda word: int(float(word) * … … 1331 1337 CLI.pyuipc2throttle, 1332 1338 CLI.throttle2pyuipc) 1333 1339 1334 1340 self._valueHandlers["visibility"] = ([(0x0e8a, "H")], 1335 1341 lambda value: value*1609.344/100.0, 1336 1342 lambda word: int(float(word)* 1337 1343 100.0/1609.344)) 1338 1344 1339 1345 self._valueHandlers["payloadCount"] = ([(0x13fc, "d")], 1340 1346 lambda value: value, … … 1348 1354 self._valueHandlers["textScrolling"] = ([(0x1274, "h")], 1349 1355 CLI.bool2str, CLI.str2bool) 1350 1356 1351 1357 self._valueHandlers["messageDuration"] = ([(0x32fa, "h")], 1352 1358 lambda value: value, … … 1371 1377 lambda value: value, 1372 1378 lambda word: int(word)) 1379 self._valueHandlers["xpdrC"] = ([(0x7b91, "b")], 1380 lambda value: value, 1381 lambda word: int(word)) 1373 1382 1374 1383 def default(self, line): … … 1383 1392 """Handle the get command.""" 1384 1393 names = args.split() 1385 data = [] 1394 data = [] 1386 1395 for name in names: 1387 1396 if name not in self._valueHandlers: … … 1408 1417 i+=1 1409 1418 except Exception, e: 1410 print >> sys.stderr, "Failed to read data: " + str(e) 1419 print >> sys.stderr, "Failed to read data: " + str(e) 1411 1420 1412 1421 return False … … 1440 1449 if inWord: 1441 1450 arguments.append(word) 1442 1451 1443 1452 names = [] 1444 1453 data = [] … … 1467 1476 (value, name, str(e)) 1468 1477 return False 1469 1478 1470 1479 try: 1471 1480 self._client.write(data) … … 1508 1517 except Exception, e: 1509 1518 print >> sys.stderr, "Failed to close the connection: " + str(e) 1510 1519 1511 1520 def do_failopen(self, args): 1512 1521 """Enable/disable the failing of opens.""" … … 1516 1525 print "Opening will%s fail" % ("" if value else " not",) 1517 1526 except Exception, e: 1518 print >> sys.stderr, "Failed to set open failure: " + str(e) 1527 print >> sys.stderr, "Failed to set open failure: " + str(e) 1519 1528 1520 1529 def help_failopen(self, usage = False): … … 1530 1539 else: 1531 1540 return ["yes", "no"] 1532 1541 1533 1542 def do_quit(self, args): 1534 1543 """Handle the quit command.""" … … 1542 1551 else: 1543 1552 server = Server() 1544 server.start() 1545 1546 #------------------------------------------------------------------------------ 1553 server.start() 1554 1555 #------------------------------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.