Changeset 8:85698811c70e
- Timestamp:
- 02/04/12 15:10:19 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/acft.py
r7 r8 3 3 #--------------------------------------------------------------------------------------- 4 4 5 import const 6 import checks 7 5 8 import time 6 7 import const8 9 9 10 #--------------------------------------------------------------------------------------- … … 11 12 class Aircraft(object): 12 13 """Base class for aircraft.""" 13 def __init__(self, type): 14 @staticmethod 15 def create(flight): 16 """Create an aircraft instance for the type in the given flight.""" 17 return _classes[flight.aircraftType](flight) 18 19 def __init__(self, flight): 14 20 """Construct the aircraft for the given type.""" 15 self._ type = type21 self._flight = flight 16 22 self._aircraftState = None 23 24 self._checkers = [] 25 26 self._checkers.append(checks.StageChecker()) 27 28 self._checkers.append(checks.AltimeterLogger()) 29 30 self._checkers.append(checks.NAV1Logger()) 31 self._checkers.append(checks.NAV2Logger()) 32 self._checkers.append(checks.SquawkLogger()) 33 34 self._checkers.append(checks.AnticollisionLightsLogger()) 35 self._checkers.append(checks.LandingLightsLogger()) 36 self._checkers.append(checks.StrobeLightsLogger()) 37 self._checkers.append(checks.NavLightsLogger()) 38 39 self._checkers.append(checks.FlapsLogger()) 40 41 self._checkers.append(checks.GearsLogger()) 17 42 18 43 @property 19 44 def type(self): 20 45 """Get the type of the aircraft.""" 21 return self._type 22 23 def modelChanged(self, aircraftName, modelName): 46 return self._flight.aircraftType 47 48 @property 49 def flight(self): 50 """Get the flight the aircraft belongs to.""" 51 return self._flight 52 53 @property 54 def logger(self): 55 """Get the logger to use for the aircraft.""" 56 return self._flight.logger 57 58 def modelChanged(self, timestamp, aircraftName, modelName): 24 59 """Called when the simulator's aircraft changes.""" 25 print "Aircraft.modelChanged: aircraftName='%s', modelName='%s'" % \ 26 (aircraftName, modelName) 60 self._flight.logger.message(timestamp, 61 "Aircraft: name='%s', model='%s'" % \ 62 (aircraftName, modelName)) 27 63 28 64 def handleState(self, aircraftState): 29 65 """Called when the state of the aircraft changes.""" 30 timeStr = time.ctime(aircraftState.timestamp) 31 32 if self._aircraftState is None or \ 33 self._aircraftState.paused != aircraftState.paused: 34 print "Aircraft.handleState: %s: paused=%d" % \ 35 (timeStr, aircraftState.paused) 36 37 if self._aircraftState is None or \ 38 self._aircraftState.trickMode != aircraftState.trickMode: 39 print "Aircraft.handleState: %s: trickMode=%d" % \ 40 (timeStr, aircraftState.trickMode) 41 42 if self._aircraftState is None or \ 43 self._aircraftState.overspeed != aircraftState.overspeed: 44 print "Aircraft.handleState: %s: overspeed=%d" % \ 45 (timeStr, aircraftState.overspeed) 46 47 if self._aircraftState is None or \ 48 self._aircraftState.stalled != aircraftState.stalled: 49 print "Aircraft.handleState: %s: stalled=%d" % \ 50 (timeStr, aircraftState.stalled) 51 52 if self._aircraftState is None or \ 53 self._aircraftState.onTheGround != aircraftState.onTheGround: 54 print "Aircraft.handleState: %s: onTheGround=%d" % \ 55 (timeStr, aircraftState.onTheGround) 56 57 if self._aircraftState is None or \ 58 self._aircraftState.grossWeight != aircraftState.grossWeight: 59 print "Aircraft.handleState: %s: grossWeight=%f" % \ 60 (timeStr, aircraftState.grossWeight) 61 62 if self._aircraftState is None or \ 63 self._aircraftState.heading != aircraftState.heading: 64 print "Aircraft.handleState: %s: heading=%f" % \ 65 (timeStr, aircraftState.heading) 66 67 if self._aircraftState is None or \ 68 self._aircraftState.pitch != aircraftState.pitch: 69 print "Aircraft.handleState: %s: pitch=%f" % \ 70 (timeStr, aircraftState.pitch) 71 72 if self._aircraftState is None or \ 73 self._aircraftState.bank != aircraftState.bank: 74 print "Aircraft.handleState: %s: bank=%f" % \ 75 (timeStr, aircraftState.bank) 76 77 if self._aircraftState is None or \ 78 self._aircraftState.ias != aircraftState.ias: 79 print "Aircraft.handleState: %s: ias=%f" % \ 80 (timeStr, aircraftState.ias) 81 82 if self._aircraftState is None or \ 83 self._aircraftState.groundSpeed != aircraftState.groundSpeed: 84 print "Aircraft.handleState: %s: groundSpeed=%f" % \ 85 (timeStr, aircraftState.groundSpeed) 86 87 if self._aircraftState is None or \ 88 self._aircraftState.vs != aircraftState.vs: 89 print "Aircraft.handleState: %s: vs=%f" % \ 90 (timeStr, aircraftState.vs) 91 92 if self._aircraftState is None or \ 93 self._aircraftState.altitude != aircraftState.altitude: 94 print "Aircraft.handleState: %s: altitude=%f" % \ 95 (timeStr, aircraftState.altitude) 96 97 if self._aircraftState is None or \ 98 self._aircraftState.gLoad != aircraftState.gLoad: 99 print "Aircraft.handleState: %s: gLoad=%f" % \ 100 (timeStr, aircraftState.gLoad) 101 102 if self._aircraftState is None or \ 103 self._aircraftState.flapsSet != aircraftState.flapsSet: 104 print "Aircraft.handleState: %s: flapsSet=%f" % \ 105 (timeStr, aircraftState.flapsSet) 106 107 if self._aircraftState is None or \ 108 self._aircraftState.flaps != aircraftState.flaps: 109 print "Aircraft.handleState: %s: flaps=%f" % \ 110 (timeStr, aircraftState.flaps) 111 112 if self._aircraftState is None or \ 113 self._aircraftState.navLightsOn != aircraftState.navLightsOn: 114 print "Aircraft.handleState: %s: navLightsOn=%d" % \ 115 (timeStr, aircraftState.navLightsOn) 116 117 if self._aircraftState is None or \ 118 self._aircraftState.antiCollisionLightsOn != aircraftState.antiCollisionLightsOn: 119 print "Aircraft.handleState: %s: antiCollisionLightsOn=%d" % \ 120 (timeStr, aircraftState.antiCollisionLightsOn) 121 122 if self._aircraftState is None or \ 123 self._aircraftState.strobeLightsOn != aircraftState.strobeLightsOn: 124 print "Aircraft.handleState: %s: strobeLightsOn=%d" % \ 125 (timeStr, aircraftState.strobeLightsOn) 126 127 if self._aircraftState is None or \ 128 self._aircraftState.landingLightsOn != aircraftState.landingLightsOn: 129 print "Aircraft.handleState: %s: landingLightsOn=%d" % \ 130 (timeStr, aircraftState.landingLightsOn) 131 132 if self._aircraftState is None or \ 133 self._aircraftState.pitotHeatOn != aircraftState.pitotHeatOn: 134 print "Aircraft.handleState: %s: pitotHeatOn=%d" % \ 135 (timeStr, aircraftState.pitotHeatOn) 136 137 if self._aircraftState is None or \ 138 self._aircraftState.gearsDown != aircraftState.gearsDown: 139 print "Aircraft.handleState: %s: gearsDown=%f" % \ 140 (timeStr, aircraftState.gearsDown) 141 142 if self._aircraftState is None or \ 143 self._aircraftState.spoilersArmed != aircraftState.spoilersArmed: 144 print "Aircraft.handleState: %s: spoilersArmed=%f" % \ 145 (timeStr, aircraftState.spoilersArmed) 146 147 if self._aircraftState is None or \ 148 self._aircraftState.spoilersExtension != aircraftState.spoilersExtension: 149 print "Aircraft.handleState: %s: spoilersExtension=%f" % \ 150 (timeStr, aircraftState.spoilersExtension) 151 152 if self._aircraftState is None or \ 153 self._aircraftState.altimeter != aircraftState.altimeter: 154 print "Aircraft.handleState: %s: altimeter=%f" % \ 155 (timeStr, aircraftState.altimeter) 156 157 if self._aircraftState is None or \ 158 self._aircraftState.nav1 != aircraftState.nav1: 159 print "Aircraft.handleState: %s: nav1=%s" % \ 160 (timeStr, aircraftState.nav1) 161 162 if self._aircraftState is None or \ 163 self._aircraftState.nav2 != aircraftState.nav2: 164 print "Aircraft.handleState: %s: nav2=%s" % \ 165 (timeStr, aircraftState.nav2) 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) 66 for checker in self._checkers: 67 checker.check(self._flight, self, self._flight.logger, 68 self._aircraftState, aircraftState) 181 69 182 70 self._aircraftState = aircraftState 183 71 72 def setStage(self, aircraftState, newStage): 73 """Set the given stage as the new one and do whatever should be 74 done.""" 75 self._flight.setStage(aircraftState.timestamp, newStage) 76 77 def flare(self): 78 """Called when it is detected that we are during flare. 79 80 On the first call, it should start monitoring some parameters more 81 closely to determine flare time.""" 82 pass 83 84 def cancelFlare(self): 85 """Cancel flare, if it has started.""" 86 pass 87 88 def checkFlightEnd(self, aircraftState): 89 """Check if the end of the flight has arrived. 90 91 This default implementation checks the N1 values, but for 92 piston-powered aircraft you need to check the RPMs.""" 93 for n1 in aircraftState.n1: 94 if n1>=0.5: return False 95 return True 96 184 97 #--------------------------------------------------------------------------------------- 185 98 … … 198 111 class B736(Boeing737): 199 112 """Boeing 737-600 aircraft.""" 200 def __init__(self ):201 super(B736, self).__init__( const.AIRCRAFT_B736)113 def __init__(self, flight): 114 super(B736, self).__init__(flight) 202 115 203 116 #--------------------------------------------------------------------------------------- … … 205 118 class B737(Boeing737): 206 119 """Boeing 737-700 aircraft.""" 207 def __init__(self ):208 super(B737, self).__init__( const.AIRCRAFT_B737)120 def __init__(self, flight): 121 super(B737, self).__init__(flight) 209 122 210 123 #--------------------------------------------------------------------------------------- … … 212 125 class B738(Boeing737): 213 126 """Boeing 737-800 aircraft.""" 214 def __init__(self ):215 super(B738, self).__init__( const.AIRCRAFT_B738)127 def __init__(self, flight): 128 super(B738, self).__init__(flight) 216 129 217 130 #--------------------------------------------------------------------------------------- … … 219 132 class B733(Boeing737): 220 133 """Boeing 737-300 aircraft.""" 221 def __init__(self ):222 super(B733, self).__init__( const.AIRCRAFT_B733)134 def __init__(self, flight): 135 super(B733, self).__init__(flight) 223 136 224 137 #--------------------------------------------------------------------------------------- … … 226 139 class B734(Boeing737): 227 140 """Boeing 737-400 aircraft.""" 228 def __init__(self ):229 super(B734, self).__init__( const.AIRCRAFT_B734)141 def __init__(self, flight): 142 super(B734, self).__init__(flight) 230 143 231 144 #--------------------------------------------------------------------------------------- … … 233 146 class B735(Boeing737): 234 147 """Boeing 737-500 aircraft.""" 235 def __init__(self ):236 super(B735, self).__init__( const.AIRCRAFT_B735)148 def __init__(self, flight): 149 super(B735, self).__init__(flight) 237 150 238 151 #--------------------------------------------------------------------------------------- … … 246 159 - n1: left, right 247 160 - reverser: left, right.""" 248 def __init__(self ):249 super(DH8D, self).__init__( const.AIRCRAFT_DH8D)161 def __init__(self, flight): 162 super(DH8D, self).__init__(flight) 250 163 251 164 #--------------------------------------------------------------------------------------- … … 264 177 class B762(Boeing767): 265 178 """Boeing 767-200 aircraft.""" 266 def __init__(self ):267 super(B762, self).__init__( const.AIRCRAFT_B762)179 def __init__(self, flight): 180 super(B762, self).__init__(flight) 268 181 269 182 #--------------------------------------------------------------------------------------- … … 271 184 class B763(Boeing767): 272 185 """Boeing 767-300 aircraft.""" 273 def __init__(self ):274 super(B763, self).__init__(c onst.AIRCRAFT_B763)186 def __init__(self, flight): 187 super(B763, self).__init__(cflight) 275 188 276 189 #--------------------------------------------------------------------------------------- … … 284 197 - n1: left, right 285 198 - reverser: left, right.""" 286 def __init__(self ):287 super(CRJ2, self).__init__( const.AIRCRAFT_CRJ2)199 def __init__(self, flight): 200 super(CRJ2, self).__init__(flight) 288 201 289 202 #--------------------------------------------------------------------------------------- … … 297 210 - n1: left, right 298 211 - reverser: left, right.""" 299 def __init__(self ):300 super(F70, self).__init__( const.AIRCRAFT_F70)212 def __init__(self, flight): 213 super(F70, self).__init__(flight) 301 214 302 215 #--------------------------------------------------------------------------------------- … … 310 223 - rpm: left, right 311 224 - reverser: left, right.""" 312 def __init__(self): 313 super(DC3, self).__init__(const.AIRCRAFT_DC3) 225 def __init__(self, flight): 226 super(DC3, self).__init__(flight) 227 228 def _checkFlightEnd(self, aircraftState): 229 """Check if the end of the flight has arrived. 230 231 This implementation checks the RPM values to be 0.""" 232 for rpm in aircraftState.rpm: 233 if rpm>0: return 234 self._setStage(aircraftState, const.STAGE_END) 314 235 315 236 #--------------------------------------------------------------------------------------- … … 324 245 - n1: left, right 325 246 - reverser: left, right.""" 326 def __init__(self ):327 super(T134, self).__init__( const.AIRCRAFT_T134)247 def __init__(self, flight): 248 super(T134, self).__init__(flight) 328 249 329 250 #--------------------------------------------------------------------------------------- … … 337 258 - n1: left, centre, right 338 259 - reverser: left, right""" 339 def __init__(self ):340 super(T154, self).__init__( const.AIRCRAFT_T154)260 def __init__(self, flight): 261 super(T154, self).__init__(flight) 341 262 342 263 #--------------------------------------------------------------------------------------- … … 350 271 - n1: left, right 351 272 - reverser: left, right""" 352 def __init__(self): 353 super(YK40, self).__init__(const.AIRCRAFT_YK40) 354 355 #--------------------------------------------------------------------------------------- 356 273 def __init__(self, flight): 274 super(YK40, self).__init__(flight) 275 276 #--------------------------------------------------------------------------------------- 277 278 _classes = { const.AIRCRAFT_B736 : B736, 279 const.AIRCRAFT_B737 : B737, 280 const.AIRCRAFT_B738 : B738, 281 const.AIRCRAFT_B733 : B733, 282 const.AIRCRAFT_B734 : B734, 283 const.AIRCRAFT_B735 : B735, 284 const.AIRCRAFT_DH8D : DH8D, 285 const.AIRCRAFT_B762 : B762, 286 const.AIRCRAFT_B763 : B763, 287 const.AIRCRAFT_CRJ2 : CRJ2, 288 const.AIRCRAFT_F70 : F70, 289 const.AIRCRAFT_DC3 : DC3, 290 const.AIRCRAFT_T134 : T134, 291 const.AIRCRAFT_T154 : T154, 292 const.AIRCRAFT_YK40 : YK40 } 293 294 #--------------------------------------------------------------------------------------- -
src/const.py
r7 r8 70 70 AIRCRAFT_YK40 = 15 71 71 72 #------------------------------------------------------------------------------- 73 74 # Flight stage: boarding 75 STAGE_BOARDING = 1 76 77 # Flight stage: pushback, startup and taxi 78 STAGE_PUSHANDTAXI = 2 79 80 # Flight stage: takeoff 81 STAGE_TAKEOFF = 3 82 83 # Flight stage: RTO 84 STAGE_RTO = 4 85 86 # Flight stage: climb 87 STAGE_CLIMB = 5 88 89 # Flight stage: cruise 90 STAGE_CRUISE = 6 91 92 # Flight stage: descent 93 STAGE_DESCENT = 7 94 95 # Flight stage: landing 96 STAGE_LANDING = 8 97 98 # Flight stage: taxi after landing 99 STAGE_TAXIAFTERLAND = 9 100 101 # Flight stage: parking 102 STAGE_PARKING = 10 103 104 # Flight stage: go-around 105 STAGE_GOAROUND = 11 106 107 # Flight stage: end 108 STAGE_END = 12 -
src/fs.py
r6 r8 62 62 - groundSpeed: the ground speed (float) 63 63 - vs: the vertical speed in feet/minutes (float) 64 - radioAltitude: the radio altitude of the aircraft in feet (float) 64 65 - altitude: the altitude of the aircraft in feet (float) 65 66 - gLoad: G-load (float) … … 82 83 - langingLightsOn: a boolean indicating if the landing lights are on 83 84 - pitotHeatOn: a boolean indicating if the pitot heat is on 85 - parking: a boolean indicating if the parking brake is set 84 86 - gearsDown: a boolean indicating if the gears are down 85 87 - spoilersArmed: a boolean indicating if the spoilers have been armed for … … 90 92 - nav1: the frequency of the NAV1 radio in MHz (string) 91 93 - nav2: the frequency of the NAV1 radio in MHz (string) 94 - squawk: the transponder code 92 95 93 96 FIXME: needed when taxiing only: -
src/fsuipc.py
r7 r8 341 341 via FSUIPC.""" 342 342 # The basic data that should be queried all the time once we are connected 343 normalData = [ (0x3d00, -256) ] 344 343 normalData = [ (0x0240, "H"), 344 (0x023e, "H"), 345 (0x023b, "b"), 346 (0x023c, "b"), 347 (0x023a, "b"), 348 (0x3d00, -256), 349 (0x3c00, -256) ] 350 345 351 def __init__(self, connectionListener, aircraft): 346 352 """Construct the simulator. … … 407 413 aircraft-specific values. 408 414 """ 409 self._setAircraftName(data[0]) 415 timestamp = calendar.timegm(time.struct_time([data[0], 416 1, 1, 0, 0, 0, -1, 1, 0])) 417 timestamp += data[1] * 24 * 3600 418 timestamp += data[2] * 3600 419 timestamp += data[3] * 60 420 timestamp += data[4] 421 422 createdNewModel = self._setAircraftName(timestamp, data[5], data[6]) 423 410 424 if self._monitoringRequested and not self._monitoring: 411 425 self._monitoring = True … … 416 430 self._stopNormal() 417 431 self._startDefaultNormal() 418 elif self._monitoring and self._aircraftModel is not None: 419 aircraftState = self._aircraftModel.getAircraftState(self._aircraft, data) 432 elif self._monitoring and self._aircraftModel is not None and \ 433 not createdNewModel: 434 aircraftState = self._aircraftModel.getAircraftState(self._aircraft, 435 timestamp, data) 420 436 self._aircraft.handleState(aircraftState) 421 437 422 def _setAircraftName(self, name):438 def _setAircraftName(self, timestamp, name, airPath): 423 439 """Set the name of the aicraft and if it is different from the 424 440 previous, create a new model for it. 425 441 426 If so, also notifty the aircraft about the change.""" 427 if name==self._aircraftName: 428 return 429 430 self._aircraftName = name 431 if self._aircraftModel is None or \ 432 not self._aircraftModel.doesHandle(name): 433 self._setAircraftModel(AircraftModel.create(self._aircraft, name)) 434 435 self._aircraft.modelChanged(self._aircraftName, 436 self._aircraftModel.name) 442 If so, also notifty the aircraft about the change. 443 444 Return if a new model was created.""" 445 aircraftName = (name, airPath) 446 if aircraftName==self._aircraftName: 447 return False 448 449 self._aircraftName = aircraftName 450 needNew = self._aircraftModel is None 451 needNew = needNew or\ 452 not self._aircraftModel.doesHandle(self._aircraft, aircraftName) 453 if not needNew: 454 specialModel = AircraftModel.findSpecial(self._aircraft, aircraftName) 455 needNew = specialModel is not None and \ 456 specialModel is not self._aircraftModel.__class__ 457 458 if needNew: 459 self._setAircraftModel(AircraftModel.create(self._aircraft, aircraftName)) 460 461 self._aircraft.modelChanged(timestamp, name, self._aircraftModel.name) 462 463 return needNew 437 464 438 465 def _setAircraftModel(self, model): … … 444 471 445 472 if self._monitoring: 446 self._ handler.clearPeriodic(self._normalRequestID)473 self._stopNormal() 447 474 self._startMonitoring() 448 475 … … 465 492 Aircraft models handle the data arriving from FSUIPC and turn it into an 466 493 object describing the aircraft's state.""" 467 monitoringData = [("year", 0x0240, "H"), 468 ("dayOfYear", 0x023e, "H"), 469 ("zuluHour", 0x023b, "b"), 470 ("zuluMinute", 0x023c, "b"), 471 ("seconds", 0x023a, "b"), 472 ("paused", 0x0264, "H"), 494 monitoringData = [("paused", 0x0264, "H"), 473 495 ("frozen", 0x3364, "H"), 474 496 ("replay", 0x0628, "d"), … … 484 506 ("groundSpeed", 0x02b4, "d"), 485 507 ("vs", 0x02c8, "d"), 508 ("radioAltitude", 0x31e4, "d"), 486 509 ("altitude", 0x0570, "l"), 487 510 ("gLoad", 0x11ba, "H"), … … 491 514 ("lights", 0x0d0c, "H"), 492 515 ("pitot", 0x029c, "b"), 516 ("parking", 0x0bc8, "H"), 493 517 ("noseGear", 0x0bec, "d"), 494 518 ("spoilersArmed", 0x0bcc, "d"), … … 496 520 ("altimeter", 0x0330, "H"), 497 521 ("nav1", 0x0350, "H"), 498 ("nav2", 0x0352, "H")] 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 } 522 ("nav2", 0x0352, "H"), 523 ("squawk", 0x0354, "H")] 515 524 516 525 specialModels = [] … … 522 531 523 532 @staticmethod 533 def findSpecial(aircraft, aircraftName): 534 for specialModel in AircraftModel.specialModels: 535 if specialModel.doesHandle(aircraft, aircraftName): 536 return specialModel 537 return None 538 539 @staticmethod 524 540 def create(aircraft, aircraftName): 525 541 """Create the model for the given aircraft name, and notify the 526 542 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]() 543 specialModel = AircraftModel.findSpecial(aircraft, aircraftName) 544 if specialModel is not None: 545 return specialModel() 546 if aircraft.type in _genericModels: 547 return _genericModels[aircraft.type]() 533 548 else: 534 549 return GenericModel() 550 551 @staticmethod 552 def convertBCD(data, length): 553 """Convert a data item encoded as BCD into a string of the given number 554 of digits.""" 555 bcd = "" 556 for i in range(0, length): 557 digit = chr(ord('0') + (data&0x0f)) 558 data >>= 4 559 bcd = digit + bcd 560 return bcd 535 561 536 562 @staticmethod 537 563 def convertFrequency(data): 538 564 """Convert the given frequency data to a string.""" 539 frequency = "" 540 for i in range(0, 4): 541 digit = chr(ord('0') + (data&0x0f)) 542 data >>= 4 543 frequency = digit + frequency 544 if i==1: 545 frequency = "." + frequency 546 return "1" + frequency 565 bcd = AircraftModel.convertBCD(data, 4) 566 return "1" + bcd[0:2] + "." + bcd[2:4] 547 567 548 568 def __init__(self, flapsNotches): … … 557 577 return "FSUIPC/Generic" 558 578 559 def doesHandle(self, aircraft Name):579 def doesHandle(self, aircraft, aircraftName): 560 580 """Determine if the model handles the given aircraft name. 561 581 … … 568 588 dest.append((offset, type)) 569 589 if attrName is not None: 570 setattr(self, attrName, len(dest) )590 setattr(self, attrName, len(dest)-1) 571 591 572 592 def _addDataWithIndexMembers(self, dest, prefix, data): … … 586 606 def addMonitoringData(self, data): 587 607 """Add the model-specific monitoring data to the given array.""" 588 self. addDataWithIndexMembers(data, "_monidx_",589 AircraftModel.monitoringData)608 self._addDataWithIndexMembers(data, "_monidx_", 609 AircraftModel.monitoringData) 590 610 591 def getAircraftState(self, aircraft, data):611 def getAircraftState(self, aircraft, timestamp, data): 592 612 """Get an aircraft state object for the given monitoring data.""" 593 613 state = fs.AircraftState() 594 614 595 timestamp = calendar.timegm(time.struct_time([data[self._monidx_year],596 1, 1, 0, 0, 0, -1, 1, 0]))597 timestamp += data[self._monidx_dayOfYear] * 24 * 3600598 timestamp += data[self._monidx_zuluHour] * 3600599 timestamp += data[self._monidx_zuluMinute] * 60600 timestamp += data[self._monidx_seconds]601 615 state.timestamp = timestamp 602 616 … … 622 636 state.vs = data[self._monidx_vs]*60.0/const.FEETTOMETRES/256.0 623 637 638 state.radioAltitude = data[self._monidx_radioAltitude]/const.FEETTOMETRES/65536.0 624 639 state.altitude = data[self._monidx_altitude]/const.FEETTOMETRES/65536.0/65536.0 625 640 … … 655 670 state.pitotHeatOn = data[self._monidx_pitot]!=0 656 671 672 state.parking = data[self._monidx_parking]!=0 673 657 674 state.gearsDown = data[self._monidx_noseGear]==16383 658 675 … … 669 686 state.nav1 = AircraftModel.convertFrequency(data[self._monidx_nav1]) 670 687 state.nav2 = AircraftModel.convertFrequency(data[self._monidx_nav2]) 688 state.squawk = AircraftModel.convertBCD(data[self._monidx_squawk], 4) 671 689 672 690 return state … … 699 717 self._isN1 = isN1 700 718 719 def doesHandle(self, aircraft, aircraftName): 720 """Determine if the model handles the given aircraft name. 721 722 This implementation returns True.""" 723 return True 724 701 725 def addMonitoringData(self, data): 702 726 """Add the model-specific monitoring data to the given array.""" … … 716 740 self._addOffsetWithIndexMember(data, 0x088c + i * 0x98, "d") # throttle lever 717 741 718 def getAircraftState(self, aircraft, data):742 def getAircraftState(self, aircraft, timestamp, data): 719 743 """Get the aircraft state. 720 744 … … 722 746 the engine parameters.""" 723 747 state = super(GenericAircraftModel, self).getAircraftState(aircraft, 748 timestamp, 724 749 data) 725 750 … … 746 771 def __init__(self): 747 772 """Construct the model.""" 748 super(Generic AircraftModel, self).773 super(GenericModel, self). \ 749 774 __init__(flapsNotches = [0, 10, 20, 30], 750 775 fuelInfo = [0x0b74, 0x0b7c, 0xb94], … … 762 787 def __init__(self): 763 788 """Construct the model.""" 764 super( GenericAircraftModel, self).789 super(B737Model, self). \ 765 790 __init__(flapsNotches = [0, 1, 2, 5, 10, 15, 25, 30, 40], 766 791 fuelInfo = [0x0b74, 0x0b7c, 0xb94], … … 771 796 """Get the name for this aircraft model.""" 772 797 return "FSUIPC/Generic Boeing 737" 798 799 #------------------------------------------------------------------------------ 800 801 class PMDGBoeing737NGModel(B737Model): 802 """A model handler for the PMDG Boeing 737NG model.""" 803 @staticmethod 804 def doesHandle(aircraft, (name, airPath)): 805 """Determine if this model handler handles the aircraft with the given 806 name.""" 807 return aircraft.type in [const.AIRCRAFT_B736, 808 const.AIRCRAFT_B737, 809 const.AIRCRAFT_B738] and \ 810 (name.find("PMDG")!=-1 or airPath.find("PMDG")!=-1) and \ 811 (name.find("737")!=-1 or airPath.find("737")!=-1) and \ 812 (name.find("600")!=-1 or airPath.find("600")!=-1 or \ 813 name.find("700")!=-1 or airPath.find("700")!=-1 or \ 814 name.find("800")!=-1 or airPath.find("800")!=-1 or \ 815 name.find("900")!=-1 or airPath.find("900")!=-1) 816 817 @property 818 def name(self): 819 """Get the name for this aircraft model.""" 820 return "FSUIPC/PMDG Boeing 737NG" 821 822 def addMonitoringData(self, data): 823 """Add the model-specific monitoring data to the given array.""" 824 super(PMDGBoeing737NGModel, self).addMonitoringData(data) 825 826 self._addOffsetWithIndexMember(data, 0x6202, "b", "_pmdgidx_switches") 827 828 def getAircraftState(self, aircraft, timestamp, data): 829 """Get the aircraft state. 830 831 Get it from the parent, and then check some PMDG-specific stuff.""" 832 state = super(PMDGBoeing737NGModel, self).getAircraftState(aircraft, 833 timestamp, 834 data) 835 if data[self._pmdgidx_switches]&0x01==0x01: 836 state.altimeter = 1013.25 837 838 return state 773 839 774 840 #------------------------------------------------------------------------------ … … 778 844 def __init__(self): 779 845 """Construct the model.""" 780 super( GenericAircraftModel, self).846 super(B767Model, self). \ 781 847 __init__(flapsNotches = [0, 1, 5, 15, 20, 25, 30], 782 848 fuelInfo = [0x0b74, 0x0b7c, 0xb94], … … 794 860 def __init__(self): 795 861 """Construct the model.""" 796 super( GenericAircraftModel, self).862 super(DH8DModel, self). \ 797 863 __init__(flapsNotches = [0, 5, 10, 15, 35], 798 864 fuelInfo = [0x0b74, 0x0b7c, 0xb94], … … 810 876 def __init__(self): 811 877 """Construct the model.""" 812 super( GenericAircraftModel, self).878 super(CRJ2Model, self). \ 813 879 __init__(flapsNotches = [0, 8, 20, 30, 45], 814 880 fuelInfo = [0x0b74, 0x0b7c, 0xb94], … … 826 892 def __init__(self): 827 893 """Construct the model.""" 828 super( GenericAircraftModel, self).894 super(F70Model, self). \ 829 895 __init__(flapsNotches = [0, 8, 15, 25, 42], 830 896 fuelInfo = [0x0b74, 0x0b7c, 0xb94], … … 842 908 def __init__(self): 843 909 """Construct the model.""" 844 super( GenericAircraftModel, self).910 super(DC3Model, self). \ 845 911 __init__(flapsNotches = [0, 15, 30, 45], 846 912 fuelInfo = [0x0b7c, 0x0b84, 0x0b94, 0x0b9c], … … 858 924 def __init__(self): 859 925 """Construct the model.""" 860 super( GenericAircraftModel, self).926 super(T134Model, self). \ 861 927 __init__(flapsNotches = [0, 10, 20, 30], 862 928 fuelInfo = [0x0b74, … … 877 943 def __init__(self): 878 944 """Construct the model.""" 879 super( GenericAircraftModel, self).945 super(T154Model, self). \ 880 946 __init__(flapsNotches = [0, 15, 28, 45], 881 947 fuelInfo = [0x0b74, 0x0b7c, 0x0b94, 882 0x1244, 0x0b84, 0x0b9c] 948 0x1244, 0x0b84, 0x0b9c], 883 949 numEngines = 3) 884 950 … … 888 954 return "FSUIPC/Generic Tupolev Tu-154" 889 955 890 def getAircraftState(self, aircraft, data):956 def getAircraftState(self, aircraft, timestamp, data): 891 957 """Get an aircraft state object for the given monitoring data. 892 958 893 959 This removes the reverser value for the middle engine.""" 894 state = super(T154Model, self).getAircraftState(aircraft, data)960 state = super(T154Model, self).getAircraftState(aircraft, timestamp, data) 895 961 del state.reverser[1] 896 962 return state … … 902 968 def __init__(self): 903 969 """Construct the model.""" 904 super( GenericAircraftModel, self).970 super(YK40Model, self). \ 905 971 __init__(flapsNotches = [0, 20, 35], 906 fuelInfo = [0x0b7c, 0x0b94] 972 fuelInfo = [0x0b7c, 0x0b94], 907 973 numEngines = 2) 908 974 … … 914 980 #------------------------------------------------------------------------------ 915 981 982 _genericModels = { const.AIRCRAFT_B736 : B737Model, 983 const.AIRCRAFT_B737 : B737Model, 984 const.AIRCRAFT_B738 : B737Model, 985 const.AIRCRAFT_B733 : B737Model, 986 const.AIRCRAFT_B734 : B737Model, 987 const.AIRCRAFT_B735 : B737Model, 988 const.AIRCRAFT_DH8D : DH8DModel, 989 const.AIRCRAFT_B762 : B767Model, 990 const.AIRCRAFT_B763 : B767Model, 991 const.AIRCRAFT_CRJ2 : B767Model, 992 const.AIRCRAFT_F70 : F70Model, 993 const.AIRCRAFT_DC3 : DC3Model, 994 const.AIRCRAFT_T134 : T134Model, 995 const.AIRCRAFT_T154 : T154Model, 996 const.AIRCRAFT_YK40 : YK40Model } 997 998 #------------------------------------------------------------------------------ 999 1000 AircraftModel.registerSpecial(PMDGBoeing737NGModel) 1001 1002 #------------------------------------------------------------------------------ 1003 -
src/test.py
r6 r8 2 2 3 3 import fs 4 import flight 5 import logger 4 6 import acft 5 7 import const 8 6 9 import time 10 import sys 7 11 8 12 def callback(data, extra): … … 10 14 11 15 def main(): 12 simulator = fs.createSimulator(const.SIM_MSFS9, fs.ConnectionListener(), 13 acft.Aircraft(const.AIRCRAFT_B737)) 14 simulator.connect() 16 with open(sys.argv[1], "wt") as output: 17 fl = flight.Flight(logger.Logger(output = output)) 18 fl.cruiseAltitude = 18000 19 fl.aircraftType = const.AIRCRAFT_B736 20 fl.aircraft = acft.Aircraft.create(fl) 21 simulator = fs.createSimulator(const.SIM_MSFS9, fs.ConnectionListener(), 22 fl.aircraft) 23 fl.simulator = simulator 15 24 16 time.sleep(10) 17 simulator.startMonitoring() 25 simulator.connect() 26 simulator.startMonitoring() 27 28 fl.wait() 18 29 19 while True: 20 time.sleep(1000) 21 simulator.stopMonitoring() 22 simulator.disconnect() 23 24 time.sleep(5) 30 simulator.stopMonitoring() 31 simulator.disconnect() 25 32 26 33 if __name__ == "__main__":
Note:
See TracChangeset
for help on using the changeset viewer.