Changeset 16:eb7e301a7d8b


Ignore:
Timestamp:
02/11/12 19:54:41 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added a model handler for the Dreamwings Dash-8 and some other minor fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/fsuipc.py

    r9 r16  
    276276        while self._connectionRequested:
    277277            try:
    278                 pyuipc.open(pyuipc.SIM_FS2K4)
     278                pyuipc.open(pyuipc.SIM_ANY)
    279279                description = "(FSUIPC version: 0x%04x, library version: 0x%04x, FS version: %d)" % \
    280280                    (pyuipc.fsuipc_version, pyuipc.lib_version,
     
    326326       
    327327        Returns what the request's process() function returned or None if
    328         reconnection failed."""
    329        
     328        reconnection failed."""       
    330329        self._requestCondition.release()
    331330
     
    393392                   (0x0580, "d") ]           # Heading
    394393
    395     def __init__(self, connectionListener, aircraft):
     394    def __init__(self, connectionListener):
    396395        """Construct the simulator.
    397396       
     
    414413         from the simulator or was calculated by the adapter. The other data
    415414         are self-explanatory and expressed in their 'natural' units."""
    416         self._aircraft = aircraft
     415        self._aircraft = None
    417416
    418417        self._handler = Handler(connectionListener)
     
    432431        self._flareStartFS = None
    433432       
    434     def connect(self):
     433    def connect(self, aircraft):
    435434        """Initiate a connection to the simulator."""
     435        self._aircraft = aircraft
     436        self._aircraftName = None
     437        self._aircraftModel = None
    436438        self._handler.connect()
    437439        self._startDefaultNormal()
     
    488490        self._handler.clearPeriodic(self._normalRequestID)
    489491        self._normalRequestID = None
     492        self._monitoring = False
    490493
    491494    def _handleNormal(self, data, extra):
     
    506509       
    507510        if self._monitoringRequested and not self._monitoring:
    508             self._monitoring = True
    509511            self._stopNormal()
    510512            self._startMonitoring()
    511513        elif self._monitoring and not self._monitoringRequested:
    512             self._monitoring = False
    513514            self._stopNormal()
    514515            self._startDefaultNormal()
     
    559560    def _startMonitoring(self):
    560561        """Start monitoring with the current aircraft model."""
    561         assert self._monitoring
    562 
    563562        data = Simulator.normalData[:]
    564563        self._aircraftModel.addMonitoringData(data)
     
    567566            self._handler.requestPeriodicRead(1.0, data,
    568567                                              self._handleNormal)
     568        self._monitoring = True
    569569
    570570    def _addFlareRate(self, data):
     
    802802       
    803803        flapsLeft = data[self._monidx_flapsLeft]
    804         flapsIndex = flapsLeft / flapsIncrement
    805         state.flaps = self._flapsNotches[flapsIndex]
    806         if flapsIndex != numNotchesM1:
    807             thisNotch = flapsIndex * flapsIncrement
    808             nextNotch = thisNotch + flapsIncrement
    809            
    810             state.flaps += (self._flapsNotches[flapsIndex+1] - state.flaps) * \
    811                 (flapsLeft - thisNotch) / (nextNotch - thisNotch)
     804        state.flaps = self._flapsNotches[-1]*flapsLeft/16383.0
    812805       
    813806        lights = data[self._monidx_lights]
     
    891884            self._engineStartIndex = len(data)
    892885            for i in range(0, self._numEngines):
    893                 self._addOffsetWithIndexMember(data, 0x0898 + i * 0x98, "u")  # N1
    894                 self._addOffsetWithIndexMember(data, 0x088c + i * 0x98, "d")  # throttle lever
     886                self._addOffsetWithIndexMember(data, 0x0898 + i * 0x98, "H")  # N1
     887                self._addOffsetWithIndexMember(data, 0x088c + i * 0x98, "h")  # throttle lever
    895888       
    896889    def getAircraftState(self, aircraft, timestamp, data):
     
    10111004
    10121005class DH8DModel(GenericAircraftModel):
    1013     """Generic model for the Boeing 737 NG aircraft."""
     1006    """Generic model for the Bombardier  Dash 8-Q400 aircraft."""
    10141007    def __init__(self):
    10151008        """Construct the model."""
     
    10221015    def name(self):
    10231016        """Get the name for this aircraft model."""
    1024         return "FSUIPC/Generic Bombardier Dash-8 Q400"
    1025 
     1017        return "FSUIPC/Generic Bombardier Dash 8-Q400"
     1018
     1019#------------------------------------------------------------------------------
     1020
     1021class DreamwingsDH8DModel(DH8DModel):
     1022    """Model handler for the Dreamwings Dash 8-Q400."""
     1023    @staticmethod
     1024    def doesHandle(aircraft, (name, airPath)):
     1025        """Determine if this model handler handles the aircraft with the given
     1026        name."""
     1027        return aircraft.type==const.AIRCRAFT_DH8D and \
     1028            (name.find("Dreamwings")!=-1 or airPath.find("Dreamwings")!=-1) and \
     1029            (name.find("Dash")!=-1 or airPath.find("Dash")!=-1) and \
     1030            (name.find("Q400")!=-1 or airPath.find("Q400")!=-1) and \
     1031            airPath.find("Dash8Q400")!=-1
     1032
     1033    @property
     1034    def name(self):
     1035        """Get the name for this aircraft model."""
     1036        return "FSUIPC/Dreamwings Bombardier Dash 8-Q400"
     1037
     1038    def getAircraftState(self, aircraft, timestamp, data):
     1039        """Get the aircraft state.
     1040
     1041        Get it from the parent, and then invert the pitot heat state."""
     1042        state = super(DreamwingsDH8DModel, self).getAircraftState(aircraft,
     1043                                                                  timestamp,
     1044                                                                  data)
     1045        state.pitotHeatOn = not state.pitotHeatOn
     1046
     1047        return state
    10261048#------------------------------------------------------------------------------
    10271049
     
    11531175
    11541176AircraftModel.registerSpecial(PMDGBoeing737NGModel)
    1155 
    1156 #------------------------------------------------------------------------------
    1157 
     1177AircraftModel.registerSpecial(DreamwingsDH8DModel)
     1178
     1179#------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.