Index: src/mlx/fsuipc.py
===================================================================
--- src/mlx/fsuipc.py	(revision 321)
+++ src/mlx/fsuipc.py	(revision 330)
@@ -146,5 +146,5 @@
             self._extra = extra
             self._validator = validator
-            
+
         def process(self, time):
             """Process the request.
@@ -152,5 +152,5 @@
             Return True if the request has succeeded, False if data validation
             has failed for a reading request. An exception may also be thrown
-            if there is some lower-level communication problem."""            
+            if there is some lower-level communication problem."""
             if self._forWrite:
                 pyuipc.write(self._data)
@@ -180,5 +180,5 @@
             self._extra = extra
             self._validator = validator
-            
+
         @property
         def id(self):
@@ -203,5 +203,5 @@
             if time<self._nextFire:
                 return True
-            
+
             if self._preparedData is None:
                 self._preparedData = pyuipc.prepare_data(self._data)
@@ -214,5 +214,5 @@
                 while self._nextFire <= time:
                     self._nextFire += self._period
-            
+
             return isOK
 
@@ -237,5 +237,5 @@
         self._requestCondition = threading.Condition()
         self._connectionRequested = False
-        self._connected = False        
+        self._connected = False
 
         self._requests = []
@@ -321,5 +321,5 @@
                 self._connectionRequested = True
                 self._requestCondition.notify()
-        
+
     def disconnect(self):
         """Disconnect from the flight simulator."""
@@ -327,5 +327,5 @@
             self._requests = []
             if self._connectionRequested:
-                self._connectionRequested = False                
+                self._connectionRequested = False
                 self._requestCondition.notify()
 
@@ -339,10 +339,10 @@
         while True:
             self._waitConnectionRequest()
-            
+
             if self._connect()>0:
                 self._handleConnection()
 
             self._disconnect()
-            
+
     def _waitConnectionRequest(self):
         """Wait for a connection request to arrive."""
@@ -350,5 +350,5 @@
             while not self._connectionRequested:
                 self._requestCondition.wait()
-            
+
     def _connect(self, autoReconnection = False, attempts = 0):
         """Try to connect to the flight simulator via FSUIPC
@@ -361,16 +361,16 @@
                 self._connectionRequested = False
                 if autoReconnection:
-                    Handler._callSafe(lambda:     
+                    Handler._callSafe(lambda:
                                       self._connectionListener.disconnected())
                 else:
-                    Handler._callSafe(lambda:     
+                    Handler._callSafe(lambda:
                                       self._connectionListener.connectionFailed())
                 return 0
-                
+
             try:
                 attempts += 1
                 pyuipc.open(pyuipc.SIM_ANY)
                 description = "(FSUIPC version: 0x%04x, library version: 0x%04x, FS version: %d)" % \
-                    (pyuipc.fsuipc_version, pyuipc.lib_version, 
+                    (pyuipc.fsuipc_version, pyuipc.lib_version,
                      pyuipc.fs_version)
                 if not autoReconnection:
@@ -378,6 +378,6 @@
                              if pyuipc.fs_version == pyuipc.SIM_FSX \
                              else const.SIM_MSFS9
-                
-                    Handler._callSafe(lambda:     
+
+                    Handler._callSafe(lambda:
                                       self._connectionListener.connected(fsType,
                                                                          description))
@@ -389,5 +389,5 @@
                 if attempts<self.NUM_CONNECTATTEMPTS:
                     time.sleep(self.CONNECT_INTERVAL)
-                
+
     def _handleConnection(self):
         """Handle a living connection."""
@@ -412,7 +412,7 @@
                (timeout is not None and timeout <= 0.0):
                 return
-            
+
             self._requestCondition.wait(timeout)
-                
+
     def _disconnect(self):
         """Disconnect from the flight simulator."""
@@ -421,7 +421,7 @@
             pyuipc.close()
             self._connected = False
-            
+
     def _processRequest(self, request, time, attempts):
-        """Process the given request. 
+        """Process the given request.
 
         If an exception occurs or invalid data is read too many times, we try
@@ -457,5 +457,5 @@
         finally:
             self._requestCondition.acquire()
-        
+
     def _processRequests(self):
         """Process any pending requests.
@@ -471,5 +471,5 @@
             if request.nextFire>t:
                 break
-            
+
             attempts = self._processRequest(request, t, attempts)
 
@@ -493,5 +493,5 @@
                  (0x023c, "b"),            # UTC minute
                  (0x023a, "b") ]           # seconds
-    
+
     normalData = timeData + \
                  [ (0x3d00, -256),           # The name of the current aircraft
@@ -502,9 +502,9 @@
                    (0x31e4, "d"),            # Radio altitude
                    (0x02c8, "d") ]           # Vertical speed
-                   
+
     flareStartData = [ (0x0e90, "H"),        # Ambient wind speed
                        (0x0e92, "H"),        # Ambient wind direction
                        (0x0e8a, "H") ]       # Visibility
-                       
+
     flareData2 = [ (0x023a, "b"),            # Seconds of time
                    (0x0366, "H"),            # On the ground
@@ -526,5 +526,5 @@
         timestamp += data[2] * 3600
         timestamp += data[3] * 60
-        timestamp += data[4]        
+        timestamp += data[4]
 
         return timestamp
@@ -542,11 +542,11 @@
 
         data.append((offset + 2, "b", 0))
-        
-        data.append((offset + 3, "b", 0))        
+
+        data.append((offset + 3, "b", 0))
 
     def __init__(self, connectionListener, connectAttempts = -1,
                  connectInterval = 0.2):
         """Construct the simulator.
-        
+
         The aircraft object passed must provide the following members:
         - type: one of the AIRCRAFT_XXX constants from const.py
@@ -559,5 +559,5 @@
           visibility is in metres. flareStart and flareStartFS are two time
           values expressed in seconds that can be used to calculate the flare
-          time. 
+          time.
        - flareFinished(flareEnd, flareEndFS, tdRate, tdRateCalculatedByFS,
                        ias, pitch, bank, heading): called when the flare has
@@ -580,5 +580,5 @@
         self._syncTime = False
         self._nextSyncTime = -1
-        
+
         self._normalRequestID = None
 
@@ -630,5 +630,5 @@
 
         These values will be passed to the callback function in this order, as
-        separate arguments."""        
+        separate arguments."""
         self._handler.requestRead([(0x13fc, "d")], self._handlePayloadCount,
                                   extra = callback)
@@ -638,14 +638,14 @@
         self._handler.requestRead(Simulator.timeData, self._handleTime,
                                   extra = callback)
-                                                            
+
     def startMonitoring(self):
         """Start the periodic monitoring of the aircraft and pass the resulting
         state to the aircraft object periodically."""
-        assert not self._monitoringRequested         
+        assert not self._monitoringRequested
         self._monitoringRequested = True
 
     def stopMonitoring(self):
         """Stop the periodic monitoring of the aircraft."""
-        assert self._monitoringRequested 
+        assert self._monitoringRequested
         self._monitoringRequested = False
 
@@ -721,5 +721,5 @@
         self._nextSyncTime = -1
         self._syncTime = True
-            
+
     def disableTimeSync(self):
         """Enable the time synchronization."""
@@ -740,5 +740,5 @@
             self._hotkeySetGeneration = 0
             self._hotkeyCallback = callback
-            
+
             self._handler.requestRead([(0x320c, "u")],
                                       self._handleNumHotkeys,
@@ -765,11 +765,11 @@
                 self._hotkeyCallback = None
                 self._clearHotkeyRequest()
-            
+
     def disconnect(self, closingMessage = None, duration = 3):
         """Disconnect from the simulator."""
-        assert not self._monitoringRequested 
+        assert not self._monitoringRequested
 
         print "fsuipc.Simulator.disconnect", closingMessage, duration
-        
+
         self._stopNormal()
         self.clearHotkeys()
@@ -787,5 +787,5 @@
             if self._hotkeys is not None:
                 self._hotkeySetGeneration += 1
-            
+
                 self._handler.requestRead([(0x320c, "u")],
                                           self._handleNumHotkeys,
@@ -850,9 +850,9 @@
         elif self._monitoring and self._aircraftModel is not None and \
              not createdNewModel:
-            aircraftState = self._aircraftModel.getAircraftState(self._aircraft, 
+            aircraftState = self._aircraftModel.getAircraftState(self._aircraft,
                                                                  timestamp, data)
 
             self._checkTimeSync(aircraftState)
-        
+
             self._aircraft.handleState(aircraftState)
 
@@ -870,13 +870,13 @@
             if self._nextSyncTime > (now - 0.49):
                 return
-            
+
             self._handler.requestWrite([(0x023a, "b", int(seconds))],
                                        self._handleTimeSynced)
-            
+
             #print "Set the seconds to ", seconds
 
             if self._nextSyncTime<0:
                 self._nextSyncTime = now
-                
+
             self._nextSyncTime += Simulator.TIME_SYNC_INTERVAL
         else:
@@ -886,9 +886,9 @@
         """Callback for the time sync result."""
         pass
-        
+
     def _setAircraftName(self, timestamp, name, airPath):
         """Set the name of the aicraft and if it is different from the
         previous, create a new model for it.
-        
+
         If so, also notifty the aircraft about the change.
 
@@ -912,8 +912,8 @@
         if needNew:
             self._setAircraftModel(AircraftModel.create(self._aircraft, aircraftName))
- 
-        
+
+
         self._aircraft.modelChanged(timestamp, self._latin1decoder(name)[0],
-                                    self._aircraftModel.name)        
+                                    self._aircraftModel.name)
 
         return needNew
@@ -925,16 +925,16 @@
         will be replaced by a new one."""
         self._aircraftModel = model
-        
+
         if self._monitoring:
             self._stopNormal()
             self._startMonitoring()
-            
+
     def _startMonitoring(self):
         """Start monitoring with the current aircraft model."""
         data = Simulator.normalData[:]
         self._aircraftModel.addMonitoringData(data, self._fsType)
-        
+
         self._normalRequestID = \
-            self._handler.requestPeriodicRead(1.0, data, 
+            self._handler.requestPeriodicRead(1.0, data,
                                               self._handleNormal,
                                               validator = self._validateNormal)
@@ -955,10 +955,10 @@
             self._handler.clearPeriodic(self._flareRequestID)
             self._flareRequestID = \
-                self._handler.requestPeriodicRead(0.1, 
+                self._handler.requestPeriodicRead(0.1,
                                                   Simulator.flareData2,
                                                   self._handleFlare2)
             self._handler.requestRead(Simulator.flareStartData,
                                       self._handleFlareStart)
-                
+
         self._addFlareRate(data[2])
 
@@ -1005,5 +1005,5 @@
         zfw = data[0] * const.LBSTOKG / 256.0
         callback(zfw)
-                                                  
+
     def _handleTime(self, data, callback):
         """Callback for a time retrieval request."""
@@ -1016,5 +1016,5 @@
         for i in range(0, payloadCount):
             data.append((0x1400 + i*48, "f"))
-        
+
         self._handler.requestRead(data, self._handleWeights,
                                   extra = callback)
@@ -1040,5 +1040,5 @@
                 numHotkeys = data[0]
                 print "fsuipc.Simulator._handleNumHotkeys: numHotkeys:", numHotkeys
-                data = [(0x3210 + i*4, "d") for i in range(0, numHotkeys)]        
+                data = [(0x3210 + i*4, "d") for i in range(0, numHotkeys)]
                 self._handler.requestRead(data, self._handleHotkeyTable,
                                           (id, generation))
@@ -1093,12 +1093,12 @@
                                            self._handleHotkeysWritten,
                                            (id, generation))
-            
+
     def _handleHotkeysWritten(self, success, (id, generation)):
         """Handle the result of the hotkeys having been written."""
-        with self._hotkeyLock:            
+        with self._hotkeyLock:
             if success and id==self._hotkeySetID and \
             generation==self._hotkeySetGeneration:
                 data = [(offset + 3, "b") for offset in self._hotkeyOffets]
-        
+
                 self._hotkeyRequestID = \
                     self._handler.requestPeriodicRead(0.5, data,
@@ -1107,5 +1107,5 @@
 
     def _handleHotkeys(self, data, (id, generation)):
-        """Handle the hotkeys."""        
+        """Handle the hotkeys."""
         with self._hotkeyLock:
             if id!=self._hotkeySetID or generation!=self._hotkeySetGeneration:
@@ -1129,5 +1129,5 @@
 
     def _handleHotkeysCleared(self, sucess, extra):
-        """Callback for the hotkey-clearing write request."""        
+        """Callback for the hotkey-clearing write request."""
 
     def _clearHotkeyRequest(self):
@@ -1136,5 +1136,5 @@
             self._handler.clearPeriodic(self._hotkeyRequestID)
             self._hotkeyRequestID = None
-                                                  
+
 #------------------------------------------------------------------------------
 
@@ -1241,19 +1241,19 @@
         return (extBCD[1] if extBCD[1]!="0" else "") + \
                mainBCD[1:] + "." + extBCD[3]
-    
+
     def __init__(self, flapsNotches):
         """Construct the aircraft model.
-        
+
         flapsNotches is a list of degrees of flaps that are available on the aircraft."""
         self._flapsNotches = flapsNotches
-    
+
     @property
     def name(self):
         """Get the name for this aircraft model."""
         return "FSUIPC/Generic"
-    
+
     def doesHandle(self, aircraft, aircraftName):
         """Determine if the model handles the given aircraft name.
-        
+
         This default implementation returns False."""
         return False
@@ -1261,5 +1261,5 @@
     def _addOffsetWithIndexMember(self, dest, offset, type, attrName = None):
         """Add the given FSUIPC offset and type to the given array and a member
-        attribute with the given name."""        
+        attribute with the given name."""
         dest.append((offset, type))
         if attrName is not None:
@@ -1275,18 +1275,18 @@
         - the FSUIPC offset
         - the FSUIPC type
-        
+
         The latter two items will be appended to dest."""
         for (name, offset, type) in data:
             self._addOffsetWithIndexMember(dest, offset, type, prefix + name)
-            
+
     def addMonitoringData(self, data, fsType):
         """Add the model-specific monitoring data to the given array."""
         self._addDataWithIndexMembers(data, "_monidx_",
                                       AircraftModel.monitoringData)
-    
+
     def getAircraftState(self, aircraft, timestamp, data):
         """Get an aircraft state object for the given monitoring data."""
         state = fs.AircraftState()
-        
+
         state.timestamp = timestamp
 
@@ -1297,5 +1297,5 @@
                           360.0 / 65536.0 / 65536.0 / 65536.0 / 65536.0
         if state.longitude>180.0: state.longitude = 360.0 - state.longitude
-        
+
         state.paused = data[self._monidx_paused]!=0 or \
             data[self._monidx_frozen]!=0 or \
@@ -1309,5 +1309,5 @@
         state.zfw = data[self._monidx_zfw] * const.LBSTOKG / 256.0
         state.grossWeight = data[self._monidx_grossWeight] * const.LBSTOKG
-        
+
         state.heading = Handler.fsuipc2PositiveDegrees(data[self._monidx_heading])
 
@@ -1325,5 +1325,5 @@
 
         state.gLoad = data[self._monidx_gLoad] / 625.0
-        
+
         numNotchesM1 = len(self._flapsNotches) - 1
         flapsIncrement = 16383 / numNotchesM1
@@ -1335,15 +1335,15 @@
                 flapsIndex += 1
         state.flapsSet = self._flapsNotches[flapsIndex]
-        
+
         flapsLeft = data[self._monidx_flapsLeft]
         state.flaps = self._flapsNotches[-1]*flapsLeft/16383.0
-        
+
         lights = data[self._monidx_lights]
-        
+
         state.navLightsOn = (lights&0x01) != 0
         state.antiCollisionLightsOn = (lights&0x02) != 0
         state.landingLightsOn = (lights&0x04) != 0
         state.strobeLightsOn = (lights&0x10) != 0
-        
+
         state.pitotHeatOn = data[self._monidx_pitot]!=0
 
@@ -1354,5 +1354,5 @@
 
         state.spoilersArmed = data[self._monidx_spoilersArmed]!=0
-        
+
         spoilers = data[self._monidx_spoilers]
         if spoilers<=4800:
@@ -1362,5 +1362,5 @@
 
         state.altimeter = data[self._monidx_altimeter] / 16.0
-           
+
         state.nav1 = AircraftModel.convertFrequency(data[self._monidx_nav1])
         state.nav1_obs = data[self._monidx_nav1_obs]
@@ -1382,7 +1382,7 @@
 
         state.visibility = data[self._monidx_visibility]*1609.344/100.0
-        
+
         state.cog = data[self._monidx_cog]
-        
+
         return state
 
@@ -1392,5 +1392,5 @@
     """A generic aircraft model that can handle the fuel levels, the N1 or RPM
     values and some other common parameters in a generic way."""
-    
+
     def __init__(self, flapsNotches, fuelTanks, numEngines, isN1 = True):
         """Construct the generic aircraft model with the given data.
@@ -1416,5 +1416,5 @@
     def doesHandle(self, aircraft, aircraftName):
         """Determine if the model handles the given aircraft name.
-        
+
         This implementation returns True."""
         return True
@@ -1423,5 +1423,5 @@
         """Add the model-specific monitoring data to the given array."""
         super(GenericAircraftModel, self).addMonitoringData(data, fsType)
-        
+
         self._fuelStartIndex = self._addFuelOffsets(data, "_monidx_fuelWeight")
 
@@ -1434,9 +1434,9 @@
                 self._addOffsetWithIndexMember(data, 0x0898 + i * 0x98, "H")  # RPM
                 self._addOffsetWithIndexMember(data, 0x08c8 + i * 0x98, "H")  # RPM scaler
-        
+
     def getAircraftState(self, aircraft, timestamp, data):
         """Get the aircraft state.
 
-        Get it from the parent, and then add the data about the fuel levels and 
+        Get it from the parent, and then add the data about the fuel levels and
         the engine parameters."""
         state = super(GenericAircraftModel, self).getAircraftState(aircraft,
@@ -1450,5 +1450,5 @@
         state.rpm = None if self._isN1 else []
         itemsPerEngine = 2 if self._isN1 else 3
-        
+
         state.reverser = []
         for i in range(self._engineStartIndex,
@@ -1503,5 +1503,5 @@
             self._addOffsetWithIndexMember(data, offset, "u")    # tank level
             self._addOffsetWithIndexMember(data, offset+4, "u")  # tank capacity
-        
+
         return fuelStartIndex
 
@@ -1523,17 +1523,17 @@
             amount = data[index] * capacity / 128.0 / 65536.0
             index += 2
-            
-            result.append( (fuelTank, amount, capacity) if addCapacities 
+
+            result.append( (fuelTank, amount, capacity) if addCapacities
                            else (fuelTank, amount))
             totalFuel += amount
 
-        return (result, totalFuel)        
+        return (result, totalFuel)
 
     def _handleFuelRetrieved(self, data, callback):
         """Callback for a fuel retrieval request."""
-        (fuelData, _totalFuel) = self._convertFuelData(data, 
+        (fuelData, _totalFuel) = self._convertFuelData(data,
                                                        addCapacities = True)
         callback(fuelData)
-                                                          
+
     def _handleFuelWritten(self, success, extra):
         """Callback for a fuel setting request."""
@@ -1554,5 +1554,5 @@
     def name(self):
         """Get the name for this aircraft model."""
-        return "FSUIPC/Generic"    
+        return "FSUIPC/Generic"
 
 #------------------------------------------------------------------------------
@@ -1560,6 +1560,6 @@
 class B737Model(GenericAircraftModel):
     """Generic model for the Boeing 737 Classing and NG aircraft."""
-    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]    
-    
+    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]
+
     def __init__(self):
         """Construct the model."""
@@ -1601,7 +1601,7 @@
         """Add the model-specific monitoring data to the given array."""
         self._fsType = fsType
-        
+
         super(PMDGBoeing737NGModel, self).addMonitoringData(data, fsType)
-                
+
         self._addOffsetWithIndexMember(data, 0x6202, "b", "_pmdgidx_switches")
 
@@ -1630,5 +1630,5 @@
 class B767Model(GenericAircraftModel):
     """Generic model for the Boeing 767 aircraft."""
-    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]    
+    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]
 
     def __init__(self):
@@ -1648,6 +1648,6 @@
 class DH8DModel(GenericAircraftModel):
     """Generic model for the Bombardier  Dash 8-Q400 aircraft."""
-    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_RIGHT]    
-    
+    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_RIGHT]
+
     def __init__(self):
         """Construct the model."""
@@ -1696,5 +1696,5 @@
 class CRJ2Model(GenericAircraftModel):
     """Generic model for the Bombardier CRJ-200 aircraft."""
-    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]    
+    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]
 
     def __init__(self):
@@ -1714,5 +1714,5 @@
 class F70Model(GenericAircraftModel):
     """Generic model for the Fokker F70 aircraft."""
-    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]    
+    fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE, const.FUELTANK_RIGHT]
 
     def __init__(self):
@@ -1762,5 +1762,5 @@
     """Generic model for the Lisunov Li-2 (DC-3) aircraft."""
     fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_CENTRE,
-                 const.FUELTANK_RIGHT]    
+                 const.FUELTANK_RIGHT]
     # fuelTanks = [const.FUELTANK_LEFT_AUX, const.FUELTANK_LEFT,
     #              const.FUELTANK_RIGHT, const.FUELTANK_RIGHT_AUX]
@@ -1797,5 +1797,5 @@
             self._leftLevel = self._rightLevel = \
                 centreAmount / centreCapacity / 2.0
-            fuelData = [(const.FUELTANK_LEFT_AUX, 
+            fuelData = [(const.FUELTANK_LEFT_AUX,
                          rawFuelData[0][1], rawFuelData[0][2]),
                         (const.FUELTANK_LEFT,
@@ -1822,5 +1822,5 @@
         centreLevel = None
         rightLevel = None
-        
+
         for (tank, level) in levels:
             if tank==const.FUELTANK_LEFT_AUX:
@@ -1905,5 +1905,5 @@
     """Generic model for the Yakovlev Yak-40 aircraft."""
     fuelTanks = [const.FUELTANK_LEFT, const.FUELTANK_RIGHT]
-    
+
     def __init__(self):
         """Construct the model."""
