source: src/mlx/acars.py@ 948:483488585dd8

python3
Last change on this file since 948:483488585dd8 was 919:2ce8ca39525b, checked in by István Váradi <ivaradi@…>, 6 years ago

Ran 2to3

File size: 2.6 KB
Line 
1
2from . import const
3
4#------------------------------------------------------------------------------
5
6## @package mlx.acars
7#
8# The handling of the ACARS.
9#
10# This module defines the \ref ACARS class that is used to extract and contain
11# the data needed to send ACARS information to the MAVA server.
12
13#------------------------------------------------------------------------------
14
15class ACARS(object):
16 """The ACARS object."""
17 def __init__(self, gui, state):
18 """Construct the acars."""
19 self.pid = gui.config.pilotID
20 self.pilotName = gui.loginResult.pilotName
21
22 flight = gui.flight
23 aircraft = flight.aircraft
24
25 self.state = state
26 self.bookedFlight = gui.bookedFlight
27
28 self.blockTime = 0 if flight.blockTimeStart is None \
29 else aircraft.state.timestamp - flight.blockTimeStart
30 self.stage = flight.stage
31
32 def getBlockTimeText(self):
33 """Get the block time in HH:MM format"""
34 hours = int(self.blockTime / 3600)
35 minutes = int((self.blockTime / 60)) % 60
36 return "%02d:%02d" % (hours, minutes)
37
38 def getEventText(self):
39 """Get the 'event', i.e. the stage."""
40 if self.stage==const.STAGE_BOARDING: return "Boarding"
41 elif self.stage==const.STAGE_PUSHANDTAXI: return "Taxiing"
42 elif self.stage==const.STAGE_TAKEOFF: return "Departing"
43 elif self.stage==const.STAGE_CLIMB: return "Climbing"
44 elif self.stage==const.STAGE_CRUISE: return "Cruising"
45 elif self.stage==const.STAGE_DESCENT:
46 return "Descending" if self.state.altitude>=10000 \
47 else "Approaching"
48 else:
49 return "Landed"
50
51 def _serialize(self):
52 """Serialize the ACARS object for JSON-RPC."""
53 bookedFlight = self.bookedFlight
54 state = self.state
55
56 attrs = {}
57 attrs["longitude"] = state.longitude
58 attrs["latitude"] = state.latitude
59 attrs["pilotName"] = self.pilotName
60 attrs["numPassengers"] = bookedFlight.numPassengers
61 attrs["blockTime"] = self.getBlockTimeText()
62 attrs["callsign"] = bookedFlight.callsign
63 attrs["aircraftTypeName"] = bookedFlight.aircraftTypeName
64 attrs["departureICAO"] = bookedFlight.departureICAO
65 attrs["arrivalICAO"] = bookedFlight.arrivalICAO
66 attrs["altitude"] = state.altitude
67 attrs["groundSpeed"] = state.groundSpeed
68 attrs["event"] = self.getEventText()
69 attrs["tailNumber"] = bookedFlight.tailNumber
70
71 return ([], attrs)
72
73#------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.