Changeset 431:207f92566e4f for src/mlx


Ignore:
Timestamp:
02/17/13 12:41:47 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
xplane
Phase:
public
Message:

Added check for the existence of X-FMC and its status and disabling NAV2 and AP heading when it is in LNAV mode

Location:
src/mlx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/monitor.py

    r428 r431  
    409409            self._adf1.set_text("-" if aircraftState.adf1 is None else aircraftState.adf1)
    410410            self._adf2.set_text("-" if aircraftState.adf2 is None else aircraftState.adf2)
    411             self._cog.set_text("%.2f%%" % (aircraftState.cog,))
     411            self._cog.set_text("%.2f%%" % (aircraftState.cog*100.0,))
    412412
    413413#------------------------------------------------------------------------------
  • src/mlx/xplane.py

    r429 r431  
    1212import math
    1313
    14 from xplra import XPlane, MultiGetter, MultiSetter
     14from xplra import XPlane, MultiGetter, MultiSetter, ProtocolException
    1515from xplra import TYPE_INT, TYPE_FLOAT, TYPE_DOUBLE
    1616from xplra import TYPE_FLOAT_ARRAY, TYPE_INT_ARRAY, TYPE_BYTE_ARRAY
     
    9797            self._result = True
    9898            return True
    99         elif Handler._performRead(self._multiBuffer,
    100                                   self._extra, self._validator):
    101             self._result = self._multiBuffer
     99
     100        try:
     101            if Handler._performRead(self._multiBuffer,
     102                                    self._extra, self._validator):
     103                self._result = self._multiBuffer
     104                return True
     105            else:
     106                return False
     107        except ProtocolException, e:
     108            self._result = None
    102109            return True
    103         else:
    104             return False
    105110
    106111class ShowMessageRequest(Request):
     
    304309        attemptsLeft = Handler.NUM_READATTEMPTS
    305310        while attemptsLeft>0:
    306             multiGetter.execute()
     311            try:
     312                multiGetter.execute()
     313            except ProtocolException, e:
     314                print "xplane.Handler._performRead: " + str(e)
     315                raise
     316
    307317            if validator is None or \
    308318               Handler._callSafe(lambda: validator(multiGetter, extra)):
     
    718728        self._fuelCallback = None
    719729
     730        self._hasXFMC = None
     731
     732    @property
     733    def hasXFMC(self):
     734        """Indicate if the simulator has the X-FMC plugin."""
     735        return self._hasXFMC
     736
    720737    def connect(self, aircraft):
    721738        """Initiate a connection to the simulator."""
     
    892909        simulator of the given type."""
    893910        self._fsType = fsType
     911
     912        self._handler.requestRead([("xfmc/Status", TYPE_INT)],
     913                                  self._xfmcStatusRead)
     914
    894915        with self._hotkeyLock:
    895916            if self._hotkeyCodes is not None:
     
    911932    def disconnected(self):
    912933        """Called when a connection to the flight simulator has been broken."""
     934        self._hasXFMC = None
    913935        with self._hotkeyLock:
    914936            self._clearHotkeyRequest()
     
    929951        self._normalRequestID = None
    930952        self._monitoring = False
     953
     954    def _xfmcStatusRead(self, data, extra):
     955        """Called when the xfmc/Status dataref is read or not."""
     956        self._hasXFMC = data is not None
     957        print "xplane.Simulator: XFMC is %savailable" % \
     958          ("" if self._hasXFMC else "not ")
    931959
    932960    def _handleNormal(self, data, extra):
     
    10081036        will be replaced by a new one."""
    10091037        self._aircraftModel = model
     1038        model.simulator = self
    10101039
    10111040        if self._monitoring:
     
    13021331        flapsNotches is a list of degrees of flaps that are available on the aircraft."""
    13031332        self._flapsNotches = flapsNotches
     1333        self._simulator = None
    13041334
    13051335    @property
     
    13071337        """Get the name for this aircraft model."""
    13081338        return "X-Plane/Generic"
     1339
     1340    @property
     1341    def simulator(self):
     1342        """Get the simulator this aircraft model works for."""
     1343        return self._simulator
     1344
     1345    @simulator.setter
     1346    def simulator(self, simulator):
     1347        """Get the simulator this aircraft model works for."""
     1348        self._simulator = simulator
    13091349
    13101350    def doesHandle(self, aircraft, aircraftInfo):
     
    13401380        self._addDataWithIndexMembers(data, "_monidx_",
    13411381                                      AircraftModel.monitoringData)
     1382        if self.simulator.hasXFMC:
     1383            print "xplane.AircraftModel.addMonitoringData: adding XFMC status dataref"""
     1384            self._addDatarefWithIndexMember(data, "xfmc/Status", TYPE_INT,
     1385                                            attrName = "_monidx_xfmcStatus")
    13421386
    13431387    def getAircraftState(self, aircraft, timestamp, data):
    13441388        """Get an aircraft state object for the given monitoring data."""
    13451389        state = fs.AircraftState()
     1390
     1391        xfmcLNAVOn = self.simulator.hasXFMC and \
     1392                     (data[self._monidx_xfmcStatus]&0x03==0x03)
    13461393
    13471394        state.timestamp = timestamp
     
    14121459        state.nav2 = self._convertFrequency(data[self._monidx_nav2])
    14131460        state.nav2_obs = self._convertOBS(data[self._monidx_nav2_obs])
    1414         state.nav2_manual = True
     1461        state.nav2_manual = not xfmcLNAVOn
    14151462        state.adf1 = str(data[self._monidx_adf1])
    14161463        state.adf2 = str(data[self._monidx_adf2])
     
    14311478        state.apMaster = data[self._monidx_apMaster]==2
    14321479        apState = data[self._monidx_apState]
    1433         state.apHeadingHold = (apState&0x00002)!=0
    1434         state.apHeading = data[self._monidx_apHeading]
     1480        if xfmcLNAVOn:
     1481           state.apHeadingHold = None
     1482           state.apHeading = None
     1483        else:
     1484            state.apHeadingHold = (apState&0x00002)!=0
     1485            state.apHeading = data[self._monidx_apHeading]
     1486
    14351487        state.apAltitudeHold = (apState&0x04000)!=0
    14361488        state.apAltitude = data[self._monidx_apAltitude]
     
    16921744        name."""
    16931745        return aircraft.type==const.AIRCRAFT_DH8D and \
    1694             description.find("Dash 8 Q400")!=-1 and \
    1695             liveryPath.startswith("Aircraft/Heavy Metal/Dash 8 Q400")
     1746          description.find("Dash 8 Q400")!=-1 and \
     1747          ((author=="2012" and tailnum=="N62890") or \
     1748           author.find("Jack Skieczius")!=-1)
    16961749
    16971750    @property
Note: See TracChangeset for help on using the changeset viewer.