Changeset 7:f8d6fda3c66d for src
- Timestamp:
- 02/01/12 16:48:49 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/acft.py
r5 r7 4 4 5 5 import time 6 7 import const 6 8 7 9 #--------------------------------------------------------------------------------------- … … 163 165 (timeStr, aircraftState.nav2) 164 166 167 if self._aircraftState is None or \ 168 self._aircraftState.fuel != aircraftState.fuel: 169 print "Aircraft.handleState: %s: fuel=%s" % \ 170 (timeStr, aircraftState.fuel) 171 172 if self._aircraftState is None or \ 173 self._aircraftState.n1 != aircraftState.n1: 174 print "Aircraft.handleState: %s: n1=%s" % \ 175 (timeStr, aircraftState.n1) 176 177 if self._aircraftState is None or \ 178 self._aircraftState.reverser != aircraftState.reverser: 179 print "Aircraft.handleState: %s: reverser=%s" % \ 180 (timeStr, aircraftState.reverser) 181 165 182 self._aircraftState = aircraftState 166 183 167 184 #--------------------------------------------------------------------------------------- 168 185 186 class Boeing737(Aircraft): 187 """Base class for the various aircraft in the Boeing 737 family. 188 189 The aircraft type-specific values in the aircraft state have the following 190 structure: 191 - fuel: centre, left, right 192 - n1: left, right 193 - reverser: left, right""" 194 pass 195 196 #--------------------------------------------------------------------------------------- 197 198 class B736(Boeing737): 199 """Boeing 737-600 aircraft.""" 200 def __init__(self): 201 super(B736, self).__init__(const.AIRCRAFT_B736) 202 203 #--------------------------------------------------------------------------------------- 204 205 class B737(Boeing737): 206 """Boeing 737-700 aircraft.""" 207 def __init__(self): 208 super(B737, self).__init__(const.AIRCRAFT_B737) 209 210 #--------------------------------------------------------------------------------------- 211 212 class B738(Boeing737): 213 """Boeing 737-800 aircraft.""" 214 def __init__(self): 215 super(B738, self).__init__(const.AIRCRAFT_B738) 216 217 #--------------------------------------------------------------------------------------- 218 219 class B733(Boeing737): 220 """Boeing 737-300 aircraft.""" 221 def __init__(self): 222 super(B733, self).__init__(const.AIRCRAFT_B733) 223 224 #--------------------------------------------------------------------------------------- 225 226 class B734(Boeing737): 227 """Boeing 737-400 aircraft.""" 228 def __init__(self): 229 super(B734, self).__init__(const.AIRCRAFT_B734) 230 231 #--------------------------------------------------------------------------------------- 232 233 class B735(Boeing737): 234 """Boeing 737-500 aircraft.""" 235 def __init__(self): 236 super(B735, self).__init__(const.AIRCRAFT_B735) 237 238 #--------------------------------------------------------------------------------------- 239 240 class DH8D(Aircraft): 241 """Bombardier Dash-8 Q400 aircraft. 242 243 The aircraft type-specific values in the aircraft state have the following 244 structure: 245 - fuel: centre, left, right 246 - n1: left, right 247 - reverser: left, right.""" 248 def __init__(self): 249 super(DH8D, self).__init__(const.AIRCRAFT_DH8D) 250 251 #--------------------------------------------------------------------------------------- 252 253 class Boeing767(Aircraft): 254 """Base class for the various aircraft in the Boeing 767 family. 255 256 The aircraft type-specific values in the aircraft state have the following 257 structure: 258 - fuel: centre, left, right 259 - n1: left, right 260 - reverser: left, right""" 261 262 #--------------------------------------------------------------------------------------- 263 264 class B762(Boeing767): 265 """Boeing 767-200 aircraft.""" 266 def __init__(self): 267 super(B762, self).__init__(const.AIRCRAFT_B762) 268 269 #--------------------------------------------------------------------------------------- 270 271 class B763(Boeing767): 272 """Boeing 767-300 aircraft.""" 273 def __init__(self): 274 super(B763, self).__init__(const.AIRCRAFT_B763) 275 276 #--------------------------------------------------------------------------------------- 277 278 class CRJ2(Aircraft): 279 """Bombardier CRJ-200 aircraft. 280 281 The aircraft type-specific values in the aircraft state have the following 282 structure: 283 - fuel: centre, left, right 284 - n1: left, right 285 - reverser: left, right.""" 286 def __init__(self): 287 super(CRJ2, self).__init__(const.AIRCRAFT_CRJ2) 288 289 #--------------------------------------------------------------------------------------- 290 291 class F70(Aircraft): 292 """Fokker 70 aircraft. 293 294 The aircraft type-specific values in the aircraft state have the following 295 structure: 296 - fuel: centre, left, right 297 - n1: left, right 298 - reverser: left, right.""" 299 def __init__(self): 300 super(F70, self).__init__(const.AIRCRAFT_F70) 301 302 #--------------------------------------------------------------------------------------- 303 304 class DC3(Aircraft): 305 """Lisunov Li-2 (DC-3) aircraft. 306 307 The aircraft type-specific values in the aircraft state have the following 308 structure: 309 - fuel: left, right, left aux, right aix 310 - rpm: left, right 311 - reverser: left, right.""" 312 def __init__(self): 313 super(DC3, self).__init__(const.AIRCRAFT_DC3) 314 315 #--------------------------------------------------------------------------------------- 316 317 class T134(Aircraft): 318 """Tupolev Tu-134 aircraft. 319 320 The aircraft type-specific values in the aircraft state have the following 321 structure: 322 - fuel: centre, left tip, left aux, right tip, right aux, external 1, 323 external 2 324 - n1: left, right 325 - reverser: left, right.""" 326 def __init__(self): 327 super(T134, self).__init__(const.AIRCRAFT_T134) 328 329 #--------------------------------------------------------------------------------------- 330 331 class T154(Aircraft): 332 """Tupolev Tu-154 aircraft. 333 334 The aircraft type-specific values in the aircraft state have the following 335 structure: 336 - fuel: centre, left, right, centre 2, left aux, right aux 337 - n1: left, centre, right 338 - reverser: left, right""" 339 def __init__(self): 340 super(T154, self).__init__(const.AIRCRAFT_T154) 341 342 #--------------------------------------------------------------------------------------- 343 344 class YK40(Aircraft): 345 """Yakovlev Yak-40 aircraft. 346 347 The aircraft type-specific values in the aircraft state have the following 348 structure: 349 - fuel: left, right 350 - n1: left, right 351 - reverser: left, right""" 352 def __init__(self): 353 super(YK40, self).__init__(const.AIRCRAFT_YK40) 354 355 #--------------------------------------------------------------------------------------- 356 -
src/const.py
r6 r7 34 34 AIRCRAFT_B738 = 3 35 35 36 # Aircraft type: Dash-8 Q40037 AIRCRAFT_DH8D = 438 39 36 # Aircraft type: Boeing 737-300 40 AIRCRAFT_B733 = 537 AIRCRAFT_B733 = 4 41 38 42 39 # Aircraft type: Boeing 737-400 43 AIRCRAFT_B734 = 640 AIRCRAFT_B734 = 5 44 41 45 42 # Aircraft type: Boeing 737-500 46 AIRCRAFT_B735 = 7 43 AIRCRAFT_B735 = 6 44 45 # Aircraft type: Dash-8 Q400 46 AIRCRAFT_DH8D = 7 47 47 48 48 # Aircraft type: Boeing 767-200 … … 50 50 51 51 # Aircraft type: Boeing 767-300 52 AIRCRAFT_B76 2= 952 AIRCRAFT_B763 = 9 53 53 54 54 # Aircraft type: Canadair CRJ-200 … … 58 58 AIRCRAFT_F70 = 11 59 59 60 # Aircraft type: Lisunov Li- 360 # Aircraft type: Lisunov Li-2 61 61 AIRCRAFT_DC3 = 12 62 62 -
src/fsuipc.py
r6 r7 498 498 ("nav2", 0x0352, "H")] 499 499 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 500 523 @staticmethod 501 524 def create(aircraft, aircraftName): 502 525 """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() 505 535 506 536 @staticmethod … … 530 560 """Determine if the model handles the given aircraft name. 531 561 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): 536 573 """Add FSUIPC data to the given array and also corresponding index 537 574 member variables with the given prefix. … … 544 581 545 582 The latter two items will be appended to dest.""" 546 index = len(dest)547 583 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) 551 585 552 586 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.""" 556 588 self.addDataWithIndexMembers(data, "_monidx_", 557 589 AircraftModel.monitoringData) … … 642 674 #------------------------------------------------------------------------------ 643 675 676 class 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 744 class 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 760 class 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 776 class 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 792 class 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 808 class 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 824 class 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 840 class 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 856 class 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 875 class 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 900 class 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.