Changeset 133:dcbe33497899 for src
- Timestamp:
- 04/30/12 13:15:14 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/config.py
r132 r133 232 232 value = config.get(Config._messageTypesSection, option) 233 233 return const.string2messageLevel(value) 234 elif messageType in [const.MESSAGETYPE_LOGGER_ERROR, 235 const.MESSAGETYPE_FAULT, 236 const.MESSAGETYPE_NOGO, 237 const.MESSAGETYPE_GATE_SYSTEM, 238 const.MESSAGETYPE_HELP]: 239 return const.MESSAGELEVEL_BOTH 234 240 else: 235 return const.MESSAGELEVEL_ NONE241 return const.MESSAGELEVEL_FS 236 242 237 243 def _getMessageTypeLevelOptionName(self, messageType): -
src/mlx/const.py
r132 r133 198 198 199 199 # Message type: logger error 200 # FIXME: cannot set the hotkey 200 201 MESSAGETYPE_LOGGER_ERROR = 1 201 202 202 203 # Message type: information 204 # FIXME: flare time begin (3 sec) 203 205 MESSAGETYPE_INFORMATION = 2 204 206 … … 210 212 211 213 # Message type: gate system messages 214 # FIXME: the available gates when arriving to LHBP (10 sec) 212 215 MESSAGETYPE_GATE_SYSTEM = 5 213 216 214 217 # Message type: environment messages 218 # FIXME: flight plan closed (5 sec) 215 219 MESSAGETYPE_ENVIRONMENT = 6 216 220 217 221 # Message type: help messages 222 # FIXME: don't forget V speeds when stage is PUSHANDTAXI (5 sec) 218 223 MESSAGETYPE_HELP = 7 219 224 220 225 # Message type: visibility messages 226 # FIXME: the visibility, once when below 2000 RA, then when below 1000 RA (5 sec) 221 227 MESSAGETYPE_VISIBILITY = 8 222 228 … … 290 296 #------------------------------------------------------------------------------- 291 297 298 # Sound: ding 299 SOUND_DING = "ding.wav" 300 301 #------------------------------------------------------------------------------- 302 292 303 # The available gates at LHBP 293 304 lhbpGateNumbers = [] … … 316 327 languages = ["$system", "en_GB", "hu_HU"] 317 328 329 #------------------------------------------------------------------------------- 330 -
src/mlx/fs.py
r89 r133 4 4 5 5 import const 6 from sound import startSound 6 7 7 8 import fsuipc 9 import threading 10 import time 8 11 9 12 #------------------------------------------------------------------------------- … … 41 44 "Only MS Flight Simulator 2004 and X are supported" 42 45 return fsuipc.Simulator(connectionListener, connectAttempts = 3) 46 47 #------------------------------------------------------------------------------- 48 49 class MessageThread(threading.Thread): 50 """Thread to handle messages.""" 51 def __init__(self, config, simulator): 52 """Initialize the message thread with the given configuration and 53 simulator.""" 54 super(MessageThread, self).__init__() 55 56 self._config = config 57 self._simulator = simulator 58 59 self._requestCondition = threading.Condition() 60 self._messages = [] 61 self._nextMessageTime = None 62 self._toQuit = False 63 64 self.daemon = True 65 66 def add(self, messageType, text, duration): 67 """Add the given message to the requested messages.""" 68 with self._requestCondition: 69 self._messages.append((messageType, text, duration)) 70 self._requestCondition.notify() 71 72 def quit(self): 73 """Quit the thread.""" 74 with self._requestCondition: 75 self._toQuit = True 76 self._requestCondition.notifty() 77 self.join() 78 79 def run(self): 80 """Perform the thread's operation.""" 81 while True: 82 (messageType, text, duration) = (None, None, None) 83 with self._requestCondition: 84 now = time.time() 85 while not self._toQuit and \ 86 ((self._nextMessageTime is not None and \ 87 self._nextMessageTime>now) or \ 88 not self._messages): 89 self._requestCondition.wait(1) 90 now = time.time() 91 92 if self._toQuit: return 93 if self._nextMessageTime is None or \ 94 self._nextMessageTime<=now: 95 self._nextMessageTime = None 96 97 if self._messages: 98 (messageType, text, duration) = self._messages[0] 99 del self._messages[0] 100 101 if text is not None: 102 self._sendMessage(messageType, text, duration) 103 104 def _sendMessage(self, messageType, text, duration): 105 """Send the message and setup the next message time.""" 106 messageLevel = self._config.getMessageTypeLevel(messageType) 107 if messageLevel==const.MESSAGELEVEL_SOUND or \ 108 messageLevel==const.MESSAGELEVEL_BOTH: 109 startSound(const.SOUND_DING) 110 if (messageLevel==const.MESSAGELEVEL_FS or \ 111 messageLevel==const.MESSAGELEVEL_BOTH): 112 self._simulator.sendMessage("[MLX] " + text, duration = duration) 113 self._nextMessageTime = time.time() + duration 114 115 #------------------------------------------------------------------------------- 116 117 _messageThread = None 118 119 #------------------------------------------------------------------------------- 120 121 def setupMessageSending(config, simulator): 122 """Setup message sending with the given config and simulator.""" 123 global _messageThread 124 if _messageThread is not None: 125 _messageThread.quit() 126 _messageThread = MessageThread(config, simulator) 127 _messageThread.start() 128 129 #------------------------------------------------------------------------------- 130 131 def sendMessage(messageType, text, duration = 3): 132 """Send the given message of the given type into the simulator and/or play 133 a corresponding sound.""" 134 global _messageThread 135 if _messageThread is not None: 136 _messageThread.add(messageType, text, duration) 43 137 44 138 #------------------------------------------------------------------------------- -
src/mlx/fsuipc.py
r117 r133 436 436 normalData = timeData + \ 437 437 [ (0x3d00, -256), # The name of the current aircraft 438 (0x3c00, -256) ] # The path of the current AIR file 438 (0x3c00, -256), # The path of the current AIR file 439 (0x1274, "h") ] # Text display mode 439 440 440 441 flareData1 = [ (0x023a, "b"), # Seconds of time … … 496 497 self._handler.start() 497 498 499 self._scroll = False 500 498 501 self._normalRequestID = None 499 502 … … 576 579 self._flareRequestID = None 577 580 581 def sendMessage(self, message, duration = 3): 582 """Send a message to the pilot via the simulator. 583 584 duration is the number of seconds to keep the message displayed.""" 585 586 if self._scroll: 587 if duration==0: duration = -1 588 elif duration == 1: duration = -2 589 else: duration = -duration 590 591 data = [(0x3380, -1 - len(message), message), 592 (0x32fa, 'h', duration)] 593 594 self._handler.requestWrite(data, self._handleMessageSent) 595 578 596 def disconnect(self): 579 597 """Disconnect from the simulator.""" … … 613 631 614 632 createdNewModel = self._setAircraftName(timestamp, data[5], data[6]) 633 634 self._scroll = data[7]!=0 615 635 616 636 if self._monitoringRequested and not self._monitoring: … … 763 783 dow = zfw - payload 764 784 callback(dow, payload, zfw, grossWeight) 785 786 def _handleMessageSent(self, success, extra): 787 """Callback for a message sending request.""" 788 pass 765 789 766 790 #------------------------------------------------------------------------------ -
src/mlx/gui/gui.py
r131 r133 298 298 self._connected = True 299 299 self._logger.untimedMessage("Connected to the simulator %s" % (descriptor,)) 300 fs.sendMessage(const.MESSAGETYPE_INFORMATION, 301 "Welcome to MAVA Logger X " + const.VERSION) 300 302 gobject.idle_add(self._handleConnected, fsType, descriptor) 301 303 … … 680 682 if self._simulator is None: 681 683 self._simulator = fs.createSimulator(const.SIM_MSFS9, self) 684 fs.setupMessageSending(self.config, self._simulator) 682 685 683 686 self._flight.simulator = self._simulator -
src/mlx/logger.py
r97 r133 3 3 #-------------------------------------------------------------------------------------- 4 4 5 from fs import sendMessage 5 6 import const 6 7 import util … … 74 75 if stage==const.STAGE_END: 75 76 self.untimedMessage("Rating: %.0f" % (self.getRating(),)) 77 sendMessage(const.MESSAGETYPE_INFORMATION, "Flight stage: " + s, 3) 76 78 77 79 def fault(self, faultID, timestamp, what, score): … … 87 89 self._faults[faultID] = score 88 90 if score==Logger.NO_GO_SCORE: 89 lineIndex = self.message(timestamp, "%s (NO GO)" % (what))91 text = "%s (NO GO)" % (what) 90 92 else: 91 lineIndex = self.message(timestamp, "%s (%.1f)" % (what, score)) 93 text = "%s (%.1f)" % (what, score) 94 lineIndex = self.message(timestamp, "%s (NO GO)" % (what)) 92 95 self._faultLineIndexes.append(lineIndex) 96 (messageType, duration) = (const.MESSAGETYPE_NOGO, 10) \ 97 if score==Logger.NO_GO_SCORE \ 98 else (const.MESSAGETYPE_FAULT, 5) 99 sendMessage(messageType, text, duration) 93 100 94 101 def noGo(self, faultID, timestamp, what): -
src/mlx/mlx.py
r123 r133 3 3 from config import Config 4 4 from i18n import setLanguage 5 from sound import initializeSound 5 6 6 7 import os … … 39 40 sys.stderr = StdIOHandler(gui) 40 41 42 initializeSound(os.path.join(programDirectory, "sounds")) 43 41 44 try: 42 45 gui.build(programDirectory) -
src/mlx/pyuipc_sim.py
r117 r133 247 247 self.payload = [] 248 248 for i in range(0, 61): self.payload.append(0.0) 249 250 self.textScrolling = False 251 self.message = "" 252 self.messageDuration = 0 249 253 250 254 def read(self, offset): … … 406 410 elif offset==0x1260: # External 2 tank capacity 407 411 return self._getFuelCapacity(self.FUEL_EXTERNAL_2) 412 elif offset==0x1274: # Text display mode 413 return 1 if self.textScrolling else 0 408 414 elif offset==0x13fc: # The number of the payload stations 409 415 return self.payloadCount … … 426 432 if self.radioAltitude is None else self.radioAltitude 427 433 return (radioAltitude * const.FEETTOMETRES * 65536.0) 434 elif offset==0x32fa: # Message duration 435 return self.messageDuration 436 elif offset==0x3380: # Message 437 return self.message 428 438 elif offset==0x3364: # Frozen 429 439 return 1 if self.frozen else 0 … … 590 600 elif offset==0x1260: # External 2 tank capacity 591 601 self._setFuelCapacity(self.FUEL_EXTERNAL_2, value) 602 elif offset==0x1274: # Text display mode 603 textScrolling = value!=0 592 604 elif offset==0x13fc: # The number of the payload stations 593 605 self.payloadCount = int(value) … … 605 617 elif offset==0x31e4: # Radio altitude 606 618 raise FSUIPCException(ERR_DATA) 619 elif offset==0x32fa: # Message duration 620 self.messageDuration = value 621 elif offset==0x3380: # Message 622 self.message = value 607 623 elif offset==0x3364: # Frozen 608 624 self.frozen = value!=0 … … 1137 1153 lambda word: 1138 1154 float(word)*const.KGSTOLB) 1155 self._valueHandlers["textScrolling"] = (0x1274, "h", 1156 CLI.bool2str, CLI.str2bool) 1139 1157 1158 self._valueHandlers["messageDuration"] = (0x32fa, "h", 1159 lambda value: value, 1160 lambda word: int(word)) 1161 self._valueHandlers["message"] = (0x3380, -128, 1162 lambda value: value, 1163 lambda word: word) 1140 1164 def default(self, line): 1141 1165 """Handle unhandle commands."""
Note:
See TracChangeset
for help on using the changeset viewer.