Ignore:
Timestamp:
02/01/12 16:48:49 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Added the different type-specific aircraft classes and the type-specific generic FSUIPC-based models

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/fsuipc.py

    r6 r7  
    498498                      ("nav2", 0x0352, "H")]
    499499
     500    genericModels = { const.AIRCRAFT.B736 : B737Model,
     501                      const.AIRCRAFT_B737 : B737Model,
     502                      const.AIRCRAFT_B738 : B737Model,
     503                      const.AIRCRAFT_B733 : B737Model,
     504                      const.AIRCRAFT_B734 : B737Model,
     505                      const.AIRCRAFT_B735 : B737Model,
     506                      const.AIRCRAFT_DH8D : DH8DModel,
     507                      const.AIRCRAFT_B762 : B767Model,
     508                      const.AIRCRAFT_B763 : B767Model,
     509                      const.AIRCRAFT_CRJ2 : B767Model,
     510                      const.AIRCRAFT_F79  : F70Model,
     511                      const.AIRCRAFT_DC3  : DC3Model,
     512                      const.AIRCRAFT_T134 : T134Model,
     513                      const.AIRCRAFT_T154 : T154Model,
     514                      const.AIRCRAFT_YK40 : YK40Model }
     515
     516    specialModels = []
     517
     518    @staticmethod
     519    def registerSpecial(clazz):
     520        """Register the given class as a special model."""
     521        AircraftModel.specialModels.append(clazz)
     522
    500523    @staticmethod
    501524    def create(aircraft, aircraftName):
    502525        """Create the model for the given aircraft name, and notify the
    503         aircraft about it."""       
    504         return AircraftModel([0, 10, 20, 30])
     526        aircraft about it."""
     527        for specialModel in AircraftModel.specialModels:
     528            if specialModel.doesHandle(aircraft, aircraftName):
     529                return specialModel(aircraft, aircraftName)
     530       
     531        if aircraft.type in AircraftModel.genericModels:
     532            return AircraftModel.genericModels[aircraft.type]()
     533        else:
     534            return GenericModel()
    505535
    506536    @staticmethod
     
    530560        """Determine if the model handles the given aircraft name.
    531561       
    532         This default implementation returns True."""
    533         return True
    534 
    535     def addDataWithIndexMembers(self, dest, prefix, data):
     562        This default implementation returns False."""
     563        return False
     564
     565    def _addOffsetWithIndexMember(self, dest, offset, type, attrName = None):
     566        """Add the given FSUIPC offset and type to the given array and a member
     567        attribute with the given name."""       
     568        dest.append((offset, type))
     569        if attrName is not None:
     570            setattr(self, attrName, len(dest))
     571
     572    def _addDataWithIndexMembers(self, dest, prefix, data):
    536573        """Add FSUIPC data to the given array and also corresponding index
    537574        member variables with the given prefix.
     
    544581       
    545582        The latter two items will be appended to dest."""
    546         index = len(dest)
    547583        for (name, offset, type) in data:
    548             setattr(self, prefix + name, index)
    549             dest.append((offset, type))
    550             index += 1
     584            self._addOffsetWithIndexMember(dest, offset, type, prefix + name)
    551585           
    552586    def addMonitoringData(self, data):
    553         """Get the data specification for monitoring.
    554        
    555         Add the model-specific monitoring data to the given array."""
     587        """Add the model-specific monitoring data to the given array."""
    556588        self.addDataWithIndexMembers(data, "_monidx_",
    557589                                     AircraftModel.monitoringData)
     
    642674#------------------------------------------------------------------------------
    643675
     676class GenericAircraftModel(AircraftModel):
     677    """A generic aircraft model that can handle the fuel levels, the N1 or RPM
     678    values and some other common parameters in a generic way."""
     679    def __init__(self, flapsNotches, fuelInfo, numEngines, isN1 = True):
     680        """Construct the generic aircraft model with the given data.
     681
     682        flapsNotches is an array of how much degrees the individual flaps
     683        notches mean.
     684
     685        fuelInfo is an array of FSUIPC offsets for the levels of the fuel
     686        tanks. It is assumed to be a 4-byte value, followed by another 4-byte
     687        value, which is the fuel tank capacity.
     688
     689        numEngines is the number of engines the aircraft has.
     690
     691        isN1 determines if the engines have an N1 value or an RPM value
     692        (e.g. pistons)."""
     693        super(GenericAircraftModel, self).__init__(flapsNotches = flapsNotches)
     694
     695        self._fuelInfo = fuelInfo
     696        self._fuelStartIndex = None
     697        self._numEngines = numEngines
     698        self._engineStartIndex = None
     699        self._isN1 = isN1
     700
     701    def addMonitoringData(self, data):
     702        """Add the model-specific monitoring data to the given array."""
     703        super(GenericAircraftModel, self).addMonitoringData(data)
     704       
     705        self._addOffsetWithIndexMember(data, 0x0af4, "H", "_monidx_fuelWeight")
     706
     707        self._fuelStartIndex = len(data)
     708        for offset in self._fuelInfo:
     709            self._addOffsetWithIndexMember(data, offset, "u")    # tank level
     710            self._addOffsetWithIndexMember(data, offset+4, "u")  # tank capacity
     711
     712        if self._isN1:
     713            self._engineStartIndex = len(data)
     714            for i in range(0, self._numEngines):
     715                self._addOffsetWithIndexMember(data, 0x0898 + i * 0x98, "u")  # N1
     716                self._addOffsetWithIndexMember(data, 0x088c + i * 0x98, "d")  # throttle lever
     717       
     718    def getAircraftState(self, aircraft, data):
     719        """Get the aircraft state.
     720
     721        Get it from the parent, and then add the data about the fuel levels and
     722        the engine parameters."""
     723        state = super(GenericAircraftModel, self).getAircraftState(aircraft,
     724                                                                   data)
     725
     726        fuelWeight = data[self._monidx_fuelWeight]/256.0
     727        state.fuel = []
     728        for i in range(self._fuelStartIndex,
     729                       self._fuelStartIndex + 2*len(self._fuelInfo), 2):
     730            fuel = data[i+1]*data[i]*fuelWeight*const.LBSTOKG/128.0/65536.0
     731            state.fuel.append(fuel)
     732
     733        state.n1 = []
     734        state.reverser = []
     735        for i in range(self._engineStartIndex,
     736                       self._engineStartIndex + 2*self._numEngines, 2):
     737            state.n1.append(data[i]*100.0/16384.0)
     738            state.reverser.append(data[i+1]<0)
     739
     740        return state
     741
     742#------------------------------------------------------------------------------
     743
     744class GenericModel(GenericAircraftModel):
     745    """Generic aircraft model for an unknown type."""
     746    def __init__(self):
     747        """Construct the model."""
     748        super(GenericAircraftModel, self).
     749            __init__(flapsNotches = [0, 10, 20, 30],
     750                     fuelInfo = [0x0b74, 0x0b7c, 0xb94],
     751                     numEngines = 2)
     752
     753    @property
     754    def name(self):
     755        """Get the name for this aircraft model."""
     756        return "FSUIPC/Generic"   
     757
     758#------------------------------------------------------------------------------
     759
     760class B737Model(GenericAircraftModel):
     761    """Generic model for the Boeing 737 Classing and NG aircraft."""
     762    def __init__(self):
     763        """Construct the model."""
     764        super(GenericAircraftModel, self).
     765            __init__(flapsNotches = [0, 1, 2, 5, 10, 15, 25, 30, 40],
     766                     fuelInfo = [0x0b74, 0x0b7c, 0xb94],
     767                     numEngines = 2)
     768
     769    @property
     770    def name(self):
     771        """Get the name for this aircraft model."""
     772        return "FSUIPC/Generic Boeing 737"
     773
     774#------------------------------------------------------------------------------
     775
     776class B767Model(GenericAircraftModel):
     777    """Generic model for the Boeing 767 aircraft."""
     778    def __init__(self):
     779        """Construct the model."""
     780        super(GenericAircraftModel, self).
     781            __init__(flapsNotches = [0, 1, 5, 15, 20, 25, 30],
     782                     fuelInfo = [0x0b74, 0x0b7c, 0xb94],
     783                     numEngines = 2)
     784
     785    @property
     786    def name(self):
     787        """Get the name for this aircraft model."""
     788        return "FSUIPC/Generic Boeing 767"
     789
     790#------------------------------------------------------------------------------
     791
     792class DH8DModel(GenericAircraftModel):
     793    """Generic model for the Boeing 737 NG aircraft."""
     794    def __init__(self):
     795        """Construct the model."""
     796        super(GenericAircraftModel, self).
     797            __init__(flapsNotches = [0, 5, 10, 15, 35],
     798                     fuelInfo = [0x0b74, 0x0b7c, 0xb94],
     799                     numEngines = 2)
     800
     801    @property
     802    def name(self):
     803        """Get the name for this aircraft model."""
     804        return "FSUIPC/Generic Bombardier Dash-8 Q400"
     805
     806#------------------------------------------------------------------------------
     807
     808class CRJ2Model(GenericAircraftModel):
     809    """Generic model for the Bombardier CRJ-200 aircraft."""
     810    def __init__(self):
     811        """Construct the model."""
     812        super(GenericAircraftModel, self).
     813            __init__(flapsNotches = [0, 8, 20, 30, 45],
     814                     fuelInfo = [0x0b74, 0x0b7c, 0xb94],
     815                     numEngines = 2)
     816
     817    @property
     818    def name(self):
     819        """Get the name for this aircraft model."""
     820        return "FSUIPC/Generic Bombardier CRJ-200"
     821
     822#------------------------------------------------------------------------------
     823
     824class F70Model(GenericAircraftModel):
     825    """Generic model for the Fokker F70 aircraft."""
     826    def __init__(self):
     827        """Construct the model."""
     828        super(GenericAircraftModel, self).
     829            __init__(flapsNotches = [0, 8, 15, 25, 42],
     830                     fuelInfo = [0x0b74, 0x0b7c, 0xb94],
     831                     numEngines = 2)
     832
     833    @property
     834    def name(self):
     835        """Get the name for this aircraft model."""
     836        return "FSUIPC/Generic Fokker 70"
     837
     838#------------------------------------------------------------------------------
     839
     840class DC3Model(GenericAircraftModel):
     841    """Generic model for the Lisunov Li-2 (DC-3) aircraft."""
     842    def __init__(self):
     843        """Construct the model."""
     844        super(GenericAircraftModel, self).
     845            __init__(flapsNotches = [0, 15, 30, 45],
     846                     fuelInfo = [0x0b7c, 0x0b84, 0x0b94, 0x0b9c],
     847                     numEngines = 2)
     848
     849    @property
     850    def name(self):
     851        """Get the name for this aircraft model."""
     852        return "FSUIPC/Generic Lisunov Li-2"
     853
     854#------------------------------------------------------------------------------
     855
     856class T134Model(GenericAircraftModel):
     857    """Generic model for the Tupolev Tu-134 aircraft."""
     858    def __init__(self):
     859        """Construct the model."""
     860        super(GenericAircraftModel, self).
     861            __init__(flapsNotches = [0, 10, 20, 30],
     862                     fuelInfo = [0x0b74,
     863                                 0x0b8c, 0x0b84,
     864                                 0x0ba4, 0x0b9c,
     865                                 0x1254, 0x125c],
     866                     numEngines = 2)
     867
     868    @property
     869    def name(self):
     870        """Get the name for this aircraft model."""
     871        return "FSUIPC/Generic Tupolev Tu-134"
     872
     873#------------------------------------------------------------------------------
     874
     875class T154Model(GenericAircraftModel):
     876    """Generic model for the Tupolev Tu-134 aircraft."""
     877    def __init__(self):
     878        """Construct the model."""
     879        super(GenericAircraftModel, self).
     880            __init__(flapsNotches = [0, 15, 28, 45],
     881                     fuelInfo = [0x0b74, 0x0b7c, 0x0b94,
     882                                 0x1244, 0x0b84, 0x0b9c]
     883                     numEngines = 3)
     884
     885    @property
     886    def name(self):
     887        """Get the name for this aircraft model."""
     888        return "FSUIPC/Generic Tupolev Tu-154"
     889
     890    def getAircraftState(self, aircraft, data):
     891        """Get an aircraft state object for the given monitoring data.
     892
     893        This removes the reverser value for the middle engine."""
     894        state = super(T154Model, self).getAircraftState(aircraft, data)
     895        del state.reverser[1]
     896        return state
     897
     898#------------------------------------------------------------------------------
     899
     900class YK40Model(GenericAircraftModel):
     901    """Generic model for the Yakovlev Yak-40 aircraft."""
     902    def __init__(self):
     903        """Construct the model."""
     904        super(GenericAircraftModel, self).
     905            __init__(flapsNotches = [0, 20, 35],
     906                     fuelInfo = [0x0b7c, 0x0b94]
     907                     numEngines = 2)
     908
     909    @property
     910    def name(self):
     911        """Get the name for this aircraft model."""
     912        return "FSUIPC/Generic Yakovlev Yak-40"
     913
     914#------------------------------------------------------------------------------
     915
Note: See TracChangeset for help on using the changeset viewer.