Changeset 334:7978a2496c31


Ignore:
Timestamp:
11/13/12 16:52:27 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

#139: the transponder state is now queried and made available

Location:
src/mlx
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/fs.py

    r321 r334  
    3636    def connectionFailed(self):
    3737        """Called when the connection could not be established."""
    38         print "fs.ConnectionListener.connectionFailed"       
     38        print "fs.ConnectionListener.connectionFailed"
    3939
    4040    def disconnected(self):
     
    116116                        del self._messages[0]
    117117
    118             if text is not None:       
     118            if text is not None:
    119119                self._sendMessage(messageType, text, duration, disconnect)
    120120
    121121    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."""
    123123        messageLevel = self._config.getMessageTypeLevel(messageType)
    124124        if messageLevel==const.MESSAGELEVEL_SOUND or \
     
    180180    - overspeed: a boolean indicating if the aircraft is in overspeed
    181181    - 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
    183183    - zfw: the zero-fuel weight in kilograms (float)
    184184    - grossWeight: the gross weight in kilograms (float)
     
    190190    - ias: the indicated airspeed in knots (float)
    191191    - smoothedIAS: the smoothed IAS in knots (float)
    192     - mach: the airspeed in mach (float)   
     192    - mach: the airspeed in mach (float)
    193193    - groundSpeed: the ground speed (float)
    194194    - vs: the vertical speed in feet/minutes (float)
     
    225225    automatic deployment
    226226    - spoilersExtension: the percentage of how much the spoiler is extended
    227     (float) 
     227    (float)
    228228    - altimeter: the altimeter setting in hPa (float)
    229229    - nav1: the frequency of the NAV1 radio in MHz (string). Can be None, if
     
    245245    - windDirection: the direction of the wind at the aircraft in degrees (float)
    246246    - 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
    248250
    249251    FIXME: needed when taxiing only:
     
    253255    - latitude, longitude
    254256    - transporter
    255     - visibility 
     257    - visibility
    256258    """
    257    
  • src/mlx/fsuipc.py

    r330 r334  
    11881188                      ("windDirection", 0x0e92, "H"),
    11891189                      ("visibility", 0x0e8a, "H"),
    1190                       ("cog", 0x2ef8, "f")]
     1190                      ("cog", 0x2ef8, "f"),
     1191                      ("xpdrC", 0x7b91, "b")]
    11911192
    11921193    specialModels = []
     
    13841385
    13851386        state.cog = data[self._monidx_cog]
     1387
     1388        state.xpdrC = data[self._monidx_xpdrC]==0
    13861389
    13871390        return state
  • src/mlx/gui/monitor.py

    r314 r334  
    2323        """Construct the monitor window."""
    2424        super(MonitorWindow, self).__init__()
    25        
     25
    2626        self._gui = gui
    2727
     
    4848        self._paused = gtk.Label("PAUSED")
    4949        table.attach(self._paused, 2, 4, 0, 1)
    50        
     50
    5151        self._trickMode = gtk.Label("TRICKMODE")
    5252        table.attach(self._trickMode, 4, 6, 0, 1, xoptions = 0)
    53        
     53
    5454        self._overspeed = gtk.Label("OVERSPEED")
    5555        table.attach(self._overspeed, 6, 8, 0, 1)
    56        
     56
    5757        self._stalled = gtk.Label("STALLED")
    5858        table.attach(self._stalled, 8, 10, 0, 1)
    59        
     59
    6060        self._onTheGround = gtk.Label("ONTHEGROUND")
    6161        table.attach(self._onTheGround, 10, 12, 0, 1)
    62        
     62
    6363        (label, self._zfw) = self._createLabeledEntry("ZFW:", 6)
    6464        table.attach(label, 0, 1, 1, 2)
     
    188188        table.attach(self._position, 7, 10, 6, 7)
    189189
     190        self._xpdrC = gtk.Label("XPDR CHARLIE")
     191        table.attach(self._xpdrC, 10, 12, 6, 7)
     192
    190193        alignment.add(table)
    191194
     
    202205        - the box
    203206        - the entry."""
    204        
     207
    205208        alignment = gtk.Alignment(xalign = 1.0, yalign = 0.5, xscale = 1.0)
    206209        alignment.set_padding(padding_top = 0, padding_bottom = 0,
     
    262265            self._windDirection.set_text("-")
    263266            self._position.set_text("-")
     267            self._xpdrC.set_sensitive(False)
    264268        else:
    265269            self._timestamp.set_text(time.strftime("%H:%M:%S",
     
    294298            for (_tank, fuel) in aircraftState.fuel:
    295299                if fuelStr: fuelStr += ", "
    296                 fuelStr += "%.0f" % (fuel,)               
     300                fuelStr += "%.0f" % (fuel,)
    297301            self._fuel.set_text(fuelStr)
    298302
     
    329333                    self._landingLightsOn.set_text("LANDING")
    330334            self._landingLightsOn.set_sensitive(aircraftState.landingLightsOn is True)
    331            
     335
    332336            self._pitotHeatOn.set_sensitive(aircraftState.pitotHeatOn)
    333337            self._parking.set_sensitive(aircraftState.parking)
     
    340344            self._position.set_text(util.getCoordinateString((aircraftState.latitude,
    341345                                                              aircraftState.longitude)))
     346            self._xpdrC.set_sensitive(aircraftState.xpdrC)
    342347
    343348#------------------------------------------------------------------------------
  • src/mlx/pyuipc_sim.py

    r321 r334  
    186186        bcd |= value % 10
    187187        return bcd
    188        
     188
    189189    @staticmethod
    190190    def _writeFrequency(value):
     
    207207        if isMain: mainFrequency = value
    208208        else: extFrequency = value
    209        
     209
    210210        return Values._toADFFrequency(mainFrequency, extFrequency)
    211211
     
    222222
    223223        return bcd
    224        
     224
    225225    def __init__(self):
    226226        """Construct the values with defaults."""
     
    235235        self.latitude = 47.5
    236236        self.longitude = 19.05
    237        
     237
    238238        self.paused = False
    239239        self.frozen = False
     
    243243        self.stalled = False
    244244        self.onTheGround = True
    245        
     245
    246246        self.zfw = 50000.0
    247        
     247
    248248        self.fuelWeights = [0.0, 3000.0, 3000.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
    249249        # Wikipedia: "Jet fuel", Jet A-1 density at 15*C .804kg/l -> 6.7 pounds/gallon
     
    293293        self.windDirection = 300.0
    294294        self.visibility = 10000
    295        
     295
    296296        self.n1 = [0.0, 0.0, 0.0]
    297297        self.throttles = [0.0, 0.0, 0.0]
     
    313313        self.pmdg_737ng_switches = 0
    314314        self.pmdg_737ngx_lts_positionsw = 0
     315
     316        self.xpdrC = False
    315317
    316318    def read(self, offset, type):
     
    447449                           (self.flapsNotches[index+1] - self.flapsNotches[index]))
    448450        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]
    450452        elif offset==0x0be8:       # Gear control
    451453            return int(self.gearControl * 16383.0)
     
    504506            return (self.zfw + sum(self.fuelWeights)) * const.KGSTOLB
    505507        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
    507509            # altitude with some, perhaps random, ground altitude
    508510            # value
     
    551553        elif offset==0x6500:       # PMDG 737NGX lights position SW
    552554            return self.pmdg_737ngx_lts_positionsw
     555        elif offset==0x7b91:       # Transponder standby
     556            return 0 if self.xpdrC else 1
    553557        else:
    554558            print "Unhandled offset: %04x" % (offset,)
     
    697701            self.navLightsOn = (value&0x01)!=0
    698702            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
    701705        elif offset==0x0e8a:       # Visibility
    702706            self.visibility = value * 1609.344 / 100.0
     
    781785        elif offset==0x6500:       # PMDG 737NGX lights position SW
    782786            self.pmdg_737ngx_lts_positionsw = value
     787        elif offset==0x7b91:       # Transponder standby
     788            self.xpdrC = value==0
    783789        else:
    784790            print "Unhandled offset: %04x" % (offset,)
    785791            raise FSUIPCException(ERR_DATA)
    786        
     792
    787793    def _readUTC(self):
    788794        """Read the UTC time.
    789        
     795
    790796        The current offset is added to it."""
    791797        return time.gmtime(time.time() + self._timeOffset)
    792        
     798
    793799    def _getFuelLevel(self, index):
    794800        """Get the fuel level for the fuel tank with the given
     
    796802        return 0 if self.fuelCapacities[index]==0.0 else \
    797803            int(self.fuelWeights[index] * 65536.0 * 128.0 / self.fuelCapacities[index])
    798    
     804
    799805    def _getFuelCapacity(self, index):
    800806        """Get the capacity of the fuel tank with the given index."""
     
    811817        tm1 = tm[:index] + (value,) + tm[(index+1):]
    812818        self._timeOffset += calendar.timegm(tm1) - calendar.timegm(tm)
    813    
     819
    814820    def _setThrottle(self, index, value):
    815821        """Set the throttle value for the given index."""
     
    820826        self.fuelWeights[index] = self.fuelCapacities[index] * float(value) / \
    821827                                  65536.0 / 128.0
    822    
     828
    823829    def _setFuelCapacity(self, index, value):
    824830        """Set the capacity of the fuel tank with the given index."""
     
    830836                                      const.FEETTOMETRES,
    831837                                      5.25588)
    832         temperature = 15 - self.altitude * 6.5 * const.FEETTOMETRES / 1000.0 
     838        temperature = 15 - self.altitude * 6.5 * const.FEETTOMETRES / 1000.0
    833839        temperature += 273.15  # Celsius -> Kelvin
    834840        airDensity = pressure / (temperature * 287.05)
     
    868874    else:
    869875        raise FSUIPCException(ERR_NOTOPEN)
    870        
     876
    871877#------------------------------------------------------------------------------
    872878
     
    877883    else:
    878884        raise FSUIPCException(ERR_NOTOPEN)
    879            
     885
    880886#------------------------------------------------------------------------------
    881887
     
    887893    else:
    888894        raise FSUIPCException(ERR_NOTOPEN)
    889            
     895
    890896#------------------------------------------------------------------------------
    891897
     
    924930        serverSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    925931        serverSocket.bind(("", PORT))
    926    
     932
    927933        serverSocket.listen(5)
    928    
     934
    929935        while True:
    930936            (clientSocket, clientAddress) = serverSocket.accept()
     
    936942        socketFile = clientSocket.makefile()
    937943        try:
    938             while True:               
     944            while True:
    939945                (length,) = struct.unpack("I", clientSocket.recv(4))
    940946                data = clientSocket.recv(length)
    941947                (call, args) = cPickle.loads(data)
    942948                exception = None
    943                
     949
    944950                try:
    945951                    if call==CALL_READ:
     
    977983                pass
    978984            clientSocket.close()
    979                    
     985
    980986#------------------------------------------------------------------------------
    981987
     
    10131019        """Quit from the simulator."""
    10141020        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)
    10161022
    10171023    def _call(self, command, data):
     
    10371043        """Convert the given string to a PyUIPC boolean value (i.e. 0 or 1)."""
    10381044        return 1 if s in ["yes", "true", "on"] else 0
    1039    
     1045
    10401046    @staticmethod
    10411047    def bool2str(value):
     
    10471053        """Convert the given degree (as a string) into a PyUIPC value."""
    10481054        return int(float(degree) * 65536.0 * 65536.0 / 360.0)
    1049        
     1055
    10501056    @staticmethod
    10511057    def pyuipc2degree(value):
     
    10571063        """Convert the given percentage value (as a string) into a PyUIPC value."""
    10581064        return int(float(level) * 128.0 * 65536.0 / 100.0)
    1059        
     1065
    10601066    @staticmethod
    10611067    def pyuipc2fuelLevel(value):
    10621068        """Convert the PyUIPC value into a percentage value."""
    10631069        return value * 100.0 / 128.0 / 65536.0
    1064        
     1070
    10651071    @staticmethod
    10661072    def fuelCapacity2pyuipc(capacity):
    10671073        """Convert the given capacity value (as a string) into a PyUIPC value."""
    10681074        return int(capacity)
    1069        
     1075
    10701076    @staticmethod
    10711077    def pyuipc2fuelCapacity(value):
    10721078        """Convert the given capacity value into a PyUIPC value."""
    10731079        return value
    1074        
     1080
    10751081    @staticmethod
    10761082    def throttle2pyuipc(throttle):
    10771083        """Convert the given throttle value (as a string) into a PyUIPC value."""
    10781084        return int(float(throttle) * 16384.0 / 100.0)
    1079        
     1085
    10801086    @staticmethod
    10811087    def pyuipc2throttle(value):
     
    10861092        """Construct the CLI."""
    10871093        cmd.Cmd.__init__(self)
    1088        
     1094
    10891095        self.use_rawinput = True
    10901096        self.intro = "\nPyUIPC simulator command prompt\n"
     
    11581164                                     lambda word: None)
    11591165        self._valueHandlers["vs"] = ([(0x02c8, "d")],
    1160                                      lambda value: value * 60 /                                     
     1166                                     lambda value: value * 60 /
    11611167                                     const.FEETTOMETRES / 256.0,
    11621168                                     lambda word: int(float(word) *
     
    11641170                                                      256.0 / 60.0))
    11651171        self._valueHandlers["tdRate"] = ([(0x030c, "d")],
    1166                                          lambda value: value * 60 /                                     
     1172                                         lambda value: value * 60 /
    11671173                                         const.FEETTOMETRES / 256.0,
    11681174                                         lambda word: int(float(word) *
     
    13311337                                             CLI.pyuipc2throttle,
    13321338                                             CLI.throttle2pyuipc)
    1333                                                            
     1339
    13341340        self._valueHandlers["visibility"] = ([(0x0e8a, "H")],
    13351341                                             lambda value: value*1609.344/100.0,
    13361342                                             lambda word: int(float(word)*
    13371343                                                              100.0/1609.344))
    1338                                                            
     1344
    13391345        self._valueHandlers["payloadCount"] = ([(0x13fc, "d")],
    13401346                                               lambda value: value,
     
    13481354        self._valueHandlers["textScrolling"] = ([(0x1274, "h")],
    13491355                                                CLI.bool2str, CLI.str2bool)
    1350                                                            
     1356
    13511357        self._valueHandlers["messageDuration"] = ([(0x32fa, "h")],
    13521358                                                  lambda value: value,
     
    13711377                                                             lambda value: value,
    13721378                                                             lambda word: int(word))
     1379        self._valueHandlers["xpdrC"] = ([(0x7b91, "b")],
     1380                                        lambda value: value,
     1381                                        lambda word: int(word))
    13731382
    13741383    def default(self, line):
     
    13831392        """Handle the get command."""
    13841393        names = args.split()
    1385         data = []       
     1394        data = []
    13861395        for name in names:
    13871396            if name not in self._valueHandlers:
     
    14081417                i+=1
    14091418        except Exception, e:
    1410             print >> sys.stderr, "Failed to read data: " + str(e)                       
     1419            print >> sys.stderr, "Failed to read data: " + str(e)
    14111420
    14121421        return False
     
    14401449        if inWord:
    14411450            arguments.append(word)
    1442            
     1451
    14431452        names = []
    14441453        data = []
     
    14671476                      (value, name, str(e))
    14681477                return False
    1469                
     1478
    14701479        try:
    14711480            self._client.write(data)
     
    15081517        except Exception, e:
    15091518            print >> sys.stderr, "Failed to close the connection: " + str(e)
    1510        
     1519
    15111520    def do_failopen(self, args):
    15121521        """Enable/disable the failing of opens."""
     
    15161525            print "Opening will%s fail" % ("" if value else " not",)
    15171526        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)
    15191528
    15201529    def help_failopen(self, usage = False):
     
    15301539        else:
    15311540            return ["yes", "no"]
    1532        
     1541
    15331542    def do_quit(self, args):
    15341543        """Handle the quit command."""
     
    15421551else:
    15431552    server = Server()
    1544     server.start()   
    1545 
    1546 #------------------------------------------------------------------------------
     1553    server.start()
     1554
     1555#------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.