source: src/mlx/acars.py@ 1143:dbe6c974f227

python3
Last change on this file since 1143:dbe6c974f227 was 1127:b9c7af542746, checked in by István Váradi <ivaradi@…>, 9 months ago

The number of people on board for the ACARS message is taken from the GUI (re #381)

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 self._gui = gui
23 flight = gui.flight
24 aircraft = flight.aircraft
25
26 self.state = state
27 self.bookedFlight = gui.bookedFlight
28
29 self.blockTime = 0 if flight.blockTimeStart is None \
30 else aircraft.state.timestamp - flight.blockTimeStart
31 self.stage = flight.stage
32
33 def getBlockTimeText(self):
34 """Get the block time in HH:MM format"""
35 hours = int(self.blockTime / 3600)
36 minutes = int((self.blockTime / 60)) % 60
37 return "%02d:%02d" % (hours, minutes)
38
39 def getEventText(self):
40 """Get the 'event', i.e. the stage."""
41 if self.stage==const.STAGE_BOARDING: return "Boarding"
42 elif self.stage==const.STAGE_PUSHANDTAXI: return "Taxiing"
43 elif self.stage==const.STAGE_TAKEOFF: return "Departing"
44 elif self.stage==const.STAGE_CLIMB: return "Climbing"
45 elif self.stage==const.STAGE_CRUISE: return "Cruising"
46 elif self.stage==const.STAGE_DESCENT:
47 return "Descending" if self.state.altitude>=10000 \
48 else "Approaching"
49 else:
50 return "Landed"
51
52 def _serialize(self):
53 """Serialize the ACARS object for JSON-RPC."""
54 bookedFlight = self.bookedFlight
55 state = self.state
56
57 attrs = {}
58 attrs["longitude"] = state.longitude
59 attrs["latitude"] = state.latitude
60 attrs["pilotName"] = self.pilotName
61 attrs["numPassengers"] = \
62 self._gui.numPassengers + \
63 self._gui.numChildren + \
64 self._gui.numInfants
65 attrs["blockTime"] = self.getBlockTimeText()
66 attrs["callsign"] = bookedFlight.callsign
67 attrs["aircraftTypeName"] = bookedFlight.aircraftTypeName
68 attrs["departureICAO"] = bookedFlight.departureICAO
69 attrs["arrivalICAO"] = bookedFlight.arrivalICAO
70 attrs["altitude"] = state.altitude
71 attrs["groundSpeed"] = state.groundSpeed
72 attrs["event"] = self.getEventText()
73 attrs["tailNumber"] = bookedFlight.tailNumber
74
75 return ([], attrs)
76
77#------------------------------------------------------------------------------
Note: See TracBrowser for help on using the repository browser.