Changeset 133:dcbe33497899 for src


Ignore:
Timestamp:
04/30/12 13:15:14 (13 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The general message sending works and the most important messages are sent

Location:
src/mlx
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/config.py

    r132 r133  
    232232            value = config.get(Config._messageTypesSection, option)
    233233            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
    234240        else:
    235             return const.MESSAGELEVEL_NONE
     241            return const.MESSAGELEVEL_FS
    236242
    237243    def _getMessageTypeLevelOptionName(self, messageType):
  • src/mlx/const.py

    r132 r133  
    198198
    199199# Message type: logger error
     200# FIXME: cannot set the hotkey
    200201MESSAGETYPE_LOGGER_ERROR = 1
    201202
    202203# Message type: information
     204# FIXME: flare time begin (3 sec)
    203205MESSAGETYPE_INFORMATION = 2
    204206
     
    210212
    211213# Message type: gate system messages
     214# FIXME: the available gates when arriving to LHBP (10 sec)
    212215MESSAGETYPE_GATE_SYSTEM = 5
    213216
    214217# Message type: environment messages
     218# FIXME: flight plan closed (5 sec)
    215219MESSAGETYPE_ENVIRONMENT = 6
    216220
    217221# Message type: help messages
     222# FIXME: don't forget V speeds when stage is PUSHANDTAXI (5 sec)
    218223MESSAGETYPE_HELP = 7
    219224
    220225# Message type: visibility messages
     226# FIXME: the visibility, once when below 2000 RA, then when below 1000 RA (5 sec)
    221227MESSAGETYPE_VISIBILITY = 8
    222228
     
    290296#-------------------------------------------------------------------------------
    291297
     298# Sound: ding
     299SOUND_DING = "ding.wav"
     300
     301#-------------------------------------------------------------------------------
     302
    292303# The available gates at LHBP
    293304lhbpGateNumbers = []
     
    316327languages = ["$system", "en_GB", "hu_HU"]
    317328
     329#-------------------------------------------------------------------------------
     330
  • src/mlx/fs.py

    r89 r133  
    44
    55import const
     6from sound import startSound
    67
    78import fsuipc
     9import threading
     10import time
    811
    912#-------------------------------------------------------------------------------
     
    4144           "Only MS Flight Simulator 2004 and X are supported"
    4245    return fsuipc.Simulator(connectionListener, connectAttempts = 3)
     46
     47#-------------------------------------------------------------------------------
     48
     49class 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
     121def 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
     131def 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)
    43137
    44138#-------------------------------------------------------------------------------
  • src/mlx/fsuipc.py

    r117 r133  
    436436    normalData = timeData + \
    437437                 [ (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
    439440
    440441    flareData1 = [ (0x023a, "b"),            # Seconds of time
     
    496497        self._handler.start()
    497498
     499        self._scroll = False
     500
    498501        self._normalRequestID = None
    499502
     
    576579            self._flareRequestID = None
    577580
     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           
    578596    def disconnect(self):
    579597        """Disconnect from the simulator."""
     
    613631
    614632        createdNewModel = self._setAircraftName(timestamp, data[5], data[6])
     633
     634        self._scroll = data[7]!=0
    615635       
    616636        if self._monitoringRequested and not self._monitoring:
     
    763783        dow = zfw - payload
    764784        callback(dow, payload, zfw, grossWeight)
     785
     786    def _handleMessageSent(self, success, extra):
     787        """Callback for a message sending request."""
     788        pass
    765789                                                 
    766790#------------------------------------------------------------------------------
  • src/mlx/gui/gui.py

    r131 r133  
    298298        self._connected = True
    299299        self._logger.untimedMessage("Connected to the simulator %s" % (descriptor,))
     300        fs.sendMessage(const.MESSAGETYPE_INFORMATION,
     301                       "Welcome to MAVA Logger X " + const.VERSION)
    300302        gobject.idle_add(self._handleConnected, fsType, descriptor)
    301303
     
    680682        if self._simulator is None:
    681683            self._simulator = fs.createSimulator(const.SIM_MSFS9, self)
     684            fs.setupMessageSending(self.config, self._simulator)
    682685
    683686        self._flight.simulator = self._simulator
  • src/mlx/logger.py

    r97 r133  
    33#--------------------------------------------------------------------------------------
    44
     5from fs import sendMessage
    56import const
    67import util
     
    7475        if stage==const.STAGE_END:
    7576            self.untimedMessage("Rating: %.0f" % (self.getRating(),))
     77        sendMessage(const.MESSAGETYPE_INFORMATION, "Flight stage: " + s, 3)
    7678       
    7779    def fault(self, faultID, timestamp, what, score):
     
    8789        self._faults[faultID] = score
    8890        if score==Logger.NO_GO_SCORE:
    89             lineIndex = self.message(timestamp, "%s (NO GO)" % (what))
     91            text = "%s (NO GO)" % (what)
    9092        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))
    9295        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)           
    93100
    94101    def noGo(self, faultID, timestamp, what):
  • src/mlx/mlx.py

    r123 r133  
    33from config import Config
    44from i18n import setLanguage
     5from sound import initializeSound
    56
    67import os
     
    3940    sys.stderr = StdIOHandler(gui)
    4041
     42    initializeSound(os.path.join(programDirectory, "sounds"))
     43
    4144    try:
    4245        gui.build(programDirectory)
  • src/mlx/pyuipc_sim.py

    r117 r133  
    247247        self.payload = []
    248248        for i in range(0, 61): self.payload.append(0.0)
     249
     250        self.textScrolling = False
     251        self.message = ""
     252        self.messageDuration = 0
    249253
    250254    def read(self, offset):
     
    406410        elif offset==0x1260:       # External 2 tank capacity
    407411            return self._getFuelCapacity(self.FUEL_EXTERNAL_2)
     412        elif offset==0x1274:       # Text display mode
     413            return 1 if self.textScrolling else 0
    408414        elif offset==0x13fc:       # The number of the payload stations
    409415            return self.payloadCount
     
    426432                if self.radioAltitude is None else self.radioAltitude
    427433            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
    428438        elif offset==0x3364:       # Frozen
    429439            return 1 if self.frozen else 0
     
    590600        elif offset==0x1260:       # External 2 tank capacity
    591601            self._setFuelCapacity(self.FUEL_EXTERNAL_2, value)
     602        elif offset==0x1274:       # Text display mode
     603            textScrolling = value!=0
    592604        elif offset==0x13fc:       # The number of the payload stations
    593605            self.payloadCount = int(value)
     
    605617        elif offset==0x31e4:       # Radio altitude
    606618            raise FSUIPCException(ERR_DATA)
     619        elif offset==0x32fa:       # Message duration
     620            self.messageDuration = value
     621        elif offset==0x3380:       # Message
     622            self.message = value
    607623        elif offset==0x3364:       # Frozen
    608624            self.frozen = value!=0
     
    11371153                                                       lambda word:
    11381154                                                       float(word)*const.KGSTOLB)
     1155        self._valueHandlers["textScrolling"] = (0x1274, "h",
     1156                                                CLI.bool2str, CLI.str2bool)
    11391157                                                           
     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)
    11401164    def default(self, line):
    11411165        """Handle unhandle commands."""
Note: See TracChangeset for help on using the changeset viewer.