source: src/mlx/acars.py@ 1112:8138afeb88c2

python3
Last change on this file since 1112:8138afeb88c2 was 1049:6455f47f42a0, checked in by István Váradi <ivaradi@…>, 3 years ago

The total number of passengers is passed to the online ACARS (re #357)

File size: 2.7 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"] = \
61 bookedFlight.numPassengers + \
62 bookedFlight.numChildren + \
63 bookedFlight.numInfants
64 attrs["blockTime"] = self.getBlockTimeText()
65 attrs["callsign"] = bookedFlight.callsign
66 attrs["aircraftTypeName"] = bookedFlight.aircraftTypeName
67 attrs["departureICAO"] = bookedFlight.departureICAO
68 attrs["arrivalICAO"] = bookedFlight.arrivalICAO
69 attrs["altitude"] = state.altitude
70 attrs["groundSpeed"] = state.groundSpeed
71 attrs["event"] = self.getEventText()
72 attrs["tailNumber"] = bookedFlight.tailNumber
73
74 return ([], attrs)
75
76#------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.