Changeset 134:9ce031d5d4a9


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

Most of the remaining messages are implemented

Location:
src/mlx
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/acft.py

    r117 r134  
    55import const
    66import checks
     7import fs
    78import util
    89
     
    5455        self._checkers.append(checks.CruiseSpeedLogger())
    5556        self._checkers.append(checks.SpoilerLogger())
     57
     58        if flight.config.isMessageTypeFS(const.MESSAGETYPE_VISIBILITY):
     59            self._checkers.append(checks.VisibilityChecker())
    5660
    5761        # Fault checkers
     
    134138                self.logger.message(aircraftState.timestamp,
    135139                                    "Zero-fuel weight: %.0f kg" % (aircraftState.zfw))
     140                flight = self._flight
     141                if flight.v1 is None or flight.vr is None or flight.v2 is None:
     142                    fs.sendMessage(const.MESSAGETYPE_HELP,
     143                                   "Don't forget to set the takeoff V-speeds!",
     144                                   5)
    136145            elif newStage==const.STAGE_TAKEOFF:
    137146                self.logger.message(aircraftState.timestamp, "Flight time start")
     
    145154                self._logV1R2()
    146155            elif newStage==const.STAGE_TAXIAFTERLAND:
     156                bookedFlight = self._flight.bookedFlight
     157                if bookedFlight.arrivalICAO=="LHBP" and \
     158                   self._flight.config.isMessageTypeFS(const.MESSAGETYPE_GATE_SYSTEM):
     159                    self._flight.getFleet(callback = self._fleetRetrieved,
     160                                          force = True)
    147161                self.logger.message(aircraftState.timestamp, "Flight time end")
    148162                self.logFuel(aircraftState)
     
    167181                                    "Block time: " +
    168182                                    util.getTimeIntervalString(blockLength))
     183                bookedFlight = self._flight.bookedFlight
     184                # FIXME: translate the ICAO into an airport name
     185                fs.sendMessage(const.MESSAGETYPE_ENVIRONMENT,
     186                               "Flight plan closed. Welcome to %s" % \
     187                               (bookedFlight.arrivalICAO,),
     188                               5)
    169189
    170190    def prepareFlare(self):
     
    189209        self._logVRef()
    190210        self.flight.flareStarted(flareStart, flareStartFS)
     211        fs.sendMessage(const.MESSAGETYPE_INFORMATION, "Flare-time", 3)
    191212         
    192213    def flareFinished(self, flareEnd, flareEndFS, tdRate, tdRateCalculatedByFS,
     
    265286        else:
    266287            self.logger.updateLine(self._vrefLineIndex, message)
     288
     289    def _fleetRetrieved(self, fleet):
     290        """Callback for the fleet retrieval result."""
     291        if fleet is not None:
     292            gateList = ""
     293            occupiedGateNumbers = fleet.getOccupiedGateNumbers()
     294            for gateNumber in const.lhbpGateNumbers:
     295                if gateNumber not in occupiedGateNumbers:
     296                    if gateList: gateList += ", "
     297                    gateList += gateNumber
     298            fs.sendMessage(const.MESSAGETYPE_GATE_SYSTEM,
     299                           "Free gates: " + gateList, 20)
     300       
    267301
    268302#---------------------------------------------------------------------------------------
  • src/mlx/checks.py

    r60 r134  
    33#---------------------------------------------------------------------------------------
    44
     5import fs
    56import const
     7import util
    68
    79#---------------------------------------------------------------------------------------
     
    143145#---------------------------------------------------------------------------------------
    144146
     147class VisibilityChecker(StateChecker):
     148    """Inform the pilot of the visibility once when descending below 2000 ft,
     149    then when descending below 1000 ft."""
     150    def __init__(self):
     151        """Construct the visibility checker."""
     152        self._informedBelow2000 = False
     153        self._informedBelow1000 = False
     154
     155    def check(self, flight, aircraft, logger, oldState, state):
     156        """Check if we need to inform the pilot of the visibility."""
     157        if flight.stage==const.STAGE_DESCENT or \
     158           flight.stage==const.STAGE_LANDING:
     159            if (state.radioAltitude<2000 and not self._informedBelow2000) or \
     160               (state.radioAltitude<1000 and not self._informedBelow1000):
     161                visibilityString = util.visibility2String(state.visibility)
     162                fs.sendMessage(const.MESSAGETYPE_VISIBILITY,
     163                               "Current visibility: " + visibilityString,
     164                               5)
     165                logger.message(state.timestamp,
     166                               "Pilot was informed about the visibility: " +
     167                               visibilityString)
     168                self._informedBelow2000 = True
     169                self._informedBelow1000 = state.radioAltitude<1000
     170
     171#---------------------------------------------------------------------------------------
     172
    145173class StateChangeLogger(StateChecker):
    146174    """Base class for classes the instances of which check if a specific change has
  • src/mlx/config.py

    r133 r134  
    114114               else const.MESSAGELEVEL_NONE
    115115
     116    def isMessageTypeFS(self, messageType):
     117        """Determine if the given message type is displayed in the
     118        simulator."""
     119        level = self.getMessageTypeLevel(messageType)
     120        return level==const.MESSAGELEVEL_FS or \
     121               level==const.MESSAGELEVEL_BOTH
     122       
    116123    def setMessageTypeLevel(self, messageType, level):
    117124        """Set the level of the given message type."""
  • src/mlx/const.py

    r133 r134  
    202202
    203203# Message type: information
    204 # FIXME: flare time begin (3 sec)
    205204MESSAGETYPE_INFORMATION = 2
    206205
     
    212211
    213212# Message type: gate system messages
    214 # FIXME: the available gates when arriving to LHBP (10 sec)
    215213MESSAGETYPE_GATE_SYSTEM = 5
    216214
     
    220218
    221219# Message type: help messages
    222 # FIXME: don't forget V speeds when stage is PUSHANDTAXI (5 sec)
    223220MESSAGETYPE_HELP = 7
    224221
    225222# Message type: visibility messages
    226 # FIXME: the visibility, once when below 2000 RA, then when below 1000 RA (5 sec)
    227223MESSAGETYPE_VISIBILITY = 8
    228224
  • src/mlx/flight.py

    r89 r134  
    6060
    6161    @property
     62    def config(self):
     63        """Get the configuration."""
     64        return self._gui.config
     65
     66    @property
    6267    def stage(self):
    6368        """Get the flight stage."""
    6469        return self._stage
     70
     71    @property
     72    def bookedFlight(self):
     73        """Get the booked flight."""
     74        return self._gui.bookedFlight
    6575
    6676    @property
     
    163173                self._endCondition.wait(1)
    164174
     175    def getFleet(self, callback, force = False):
     176        """Get the fleet and call the given callback."""
     177        self._gui.getFleetAsync(callback = callback, force = force)
     178
    165179    def _updateFlownDistance(self, currentState):
    166180        """Update the flown distance."""
  • src/mlx/fs.py

    r133 r134  
    199199    - windSpeed: the speed of the wind at the aircraft in knots (float)
    200200    - windDirection: the direction of the wind at the aircraft in degrees (float)
     201    - visibility: the visibility in metres (float)
    201202
    202203    FIXME: needed when taxiing only:
  • src/mlx/fsuipc.py

    r133 r134  
    830830                      ("squawk", 0x0354, "H"),
    831831                      ("windSpeed", 0x0e90, "H"),
    832                       ("windDirection", 0x0e92, "H")]
     832                      ("windDirection", 0x0e92, "H"),
     833                      ("visibility", 0x0e8a, "H")]
    833834
    834835
     
    10031004        state.windDirection = data[self._monidx_windDirection]*360.0/65536.0
    10041005        if state.windDirection<0.0: state.windDirection += 360.0
     1006
     1007        state.visibility = data[self._monidx_visibility]*1609.344/100.0
    10051008       
    10061009        return state
  • src/mlx/gui/gui.py

    r133 r134  
    400400        self._statusbar.updateConnection(False, False)
    401401        self._weightHelp.disable()
     402
     403        return True
    402404           
    403405    def addFlightLogLine(self, timeStr, line):
     
    442444        self._wizard.setStage(stage)
    443445        if stage==const.STAGE_END:
    444             self._disconnect()
     446            # FIXME: perhaps a more elegant method, e.g.
     447            # the simulator should provide a function disconnect
     448            # with a final message
     449            gobject.timeout_add(1.0, self._disconnect)
    445450
    446451    def setRating(self, rating):
     
    564569        self._weightHelp.reset()
    565570        self._weightHelp.enable()
     571
     572    def getFleetAsync(self, callback = None, force = None):
     573        """Get the fleet asynchronously."""
     574        gobject.idle_add(self.getFleet, callback, force)
    566575
    567576    def getFleet(self, callback = None, force = False):
  • src/mlx/logger.py

    r133 r134  
    7575        if stage==const.STAGE_END:
    7676            self.untimedMessage("Rating: %.0f" % (self.getRating(),))
    77         sendMessage(const.MESSAGETYPE_INFORMATION, "Flight stage: " + s, 3)
     77        else:
     78            sendMessage(const.MESSAGETYPE_INFORMATION, "Flight stage: " + s, 3)
    7879       
    7980    def fault(self, faultID, timestamp, what, score):
  • src/mlx/util.py

    r97 r134  
    149149    return (radians2nm(d), math.degrees(tc))
    150150
     151#------------------------------------------------------------------------------
     152
     153def visibility2String(visibility):
     154    """Convert the given visibility expressed in metres into a string."""
     155    return "%.0f metres" % (visibility,) if visibility<10000 \
     156           else "%.1f kilometres" % (visibility/1000.0,)
Note: See TracChangeset for help on using the changeset viewer.