Changeset 139:839016dcd0d1 for src


Ignore:
Timestamp:
05/01/12 08:29:24 (13 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Implemented ACARS sending

Location:
src/mlx
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/acft.py

    r136 r139  
    88import util
    99
     10import sys
    1011import time
     12import traceback
    1113
    1214#---------------------------------------------------------------------------------------
     
    5961            self._checkers.append(checks.VisibilityChecker())
    6062
     63        # FIXME: we should have a central data model object, and not collect
     64        # the data from the GUI. However, some pieces of data (e.g. V-speeds,
     65        # etc. that is entered into the GUI) *should* be a part of the GUI and
     66        # queried from it, so the model should have a reference to the GUI as
     67        # well and access such data via the GUI!
     68        if flight.config.onlineACARS:
     69            self._checkers.append(checks.ACARSSender(flight._gui))
     70
    6171        # Fault checkers
    6272       
     
    105115        return self._flight.logger
    106116
     117    @property
     118    def state(self):
     119        """Get the current aircraft state."""
     120        return self._aircraftState
     121   
    107122    def getFlapsSpeedLimit(self, flaps):
    108123        """Get the speed limit for the given flaps setting."""
     
    119134        """Called when the state of the aircraft changes."""
    120135        for checker in self._checkers:
    121             checker.check(self._flight, self, self._flight.logger,
    122                           self._aircraftState, aircraftState)
     136            try:
     137                checker.check(self._flight, self, self._flight.logger,
     138                              self._aircraftState, aircraftState)
     139            except:
     140                print >> sys.stderr, "Checker", checker, "failed"
     141                traceback.print_exc()
    123142
    124143        self._flight.handleState(self._aircraftState, aircraftState)
  • src/mlx/checks.py

    r134 r139  
    66import const
    77import util
     8from acars import ACARS
     9
     10import time
    811
    912#---------------------------------------------------------------------------------------
     
    8588#---------------------------------------------------------------------------------------
    8689
     90class ACARSSender(StateChecker):
     91    """Sender of online ACARS.
     92
     93    It sends the ACARS every 3 minutes to the MAVA website."""
     94
     95    # The interval at which ACARS is sent
     96    INTERVAL = 3*60.0
     97   
     98    def __init__(self, gui):
     99        """Construct the ACARS sender."""
     100        self._gui = gui
     101        self._lastSent = None
     102
     103    def check(self, flight, aircraft, logger, oldState, state):
     104        """If the time has come to send the ACARS, send it."""
     105        now = time.time()
     106       
     107        if self._lastSent is not None and \
     108           (self._lastSent + ACARSSender.INTERVAL)>now:
     109            return
     110
     111        acars = ACARS(self._gui, state)
     112        self._gui.webHandler.sendACARS(self._acarsCallback, acars)
     113
     114    def _acarsCallback(self, returned, result):
     115        """Callback for ACARS sending."""
     116        if returned:
     117            print "Sent online ACARS"
     118            self._lastSent = time.time() if self._lastSent is None \
     119                             else self._lastSent + ACARSSender.INTERVAL
     120        else:
     121            print "Failed to send the ACARS"
     122       
     123#---------------------------------------------------------------------------------------
     124
    87125class TakeOffLogger(StateChecker):
    88126    """Logger for the cruise speed."""
  • src/mlx/config.py

    r136 r139  
    3838        self._language = ""
    3939        self._onlineGateSystem = True
     40        self._onlineACARS = True
    4041        self._flareTimeFromFS = False
    4142       
     
    105106        if onlineGateSystem!=self._onlineGateSystem:
    106107            self._onlineGateSystem = onlineGateSystem
     108            self._modified = True
     109
     110    @property
     111    def onlineACARS(self):
     112        """Get whether the online ACARS system should be used."""
     113        return self._onlineACARS
     114
     115    @onlineACARS.setter
     116    def onlineACARS(self, onlineACARS):
     117        """Set whether the online ACARS system should be used."""
     118        if onlineACARS!=self._onlineACARS:
     119            self._onlineACARS = onlineACARS
    107120            self._modified = True
    108121
     
    179192                                                  "onlineGateSystem",
    180193                                                  True)
     194        self._onlineACARS = self._getBoolean(config, "general",
     195                                             "onlineACARS", True)
    181196        self._flareTimeFromFS = self._getBoolean(config, "general",
    182197                                                 "flareTimeFromFS",
     
    212227        config.set("general", "onlineGateSystem",
    213228                   "yes" if self._onlineGateSystem else "no")
     229        config.set("general", "onlineACARS",
     230                   "yes" if self._onlineACARS else "no")
    214231        config.set("general", "flareTimeFromFS",
    215232                   "yes" if self._flareTimeFromFS else "no")
  • src/mlx/gui/flight.py

    r138 r139  
    212212        alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
    213213                                  xscale = 0.0, yscale = 0.0)
    214        
     214
    215215        table = gtk.Table(2, 3)
    216216        table.set_row_spacings(4)
  • src/mlx/gui/gui.py

    r135 r139  
    165165        """Get the flight being performed."""
    166166        return self._flight
     167
     168    @property
     169    def loginResult(self):
     170        """Get the result of the login."""
     171        return self._wizard.loginResult
    167172
    168173    @property
  • src/mlx/gui/prefs.py

    r136 r139  
    6868        self._setLanguage(config.language)
    6969        self._onlineGateSystem.set_active(config.onlineGateSystem)
     70        self._onlineACARS.set_active(config.onlineACARS)
    7071        self._flareTimeFromFS.set_active(config.flareTimeFromFS)
    7172
     
    9192        config.language = self._getLanguage()
    9293        config.onlineGateSystem = self._onlineGateSystem.get_active()
     94        config.onlineACARS = self._onlineACARS.get_active()
    9395        config.flareTimeFromFS = self._flareTimeFromFS.get_active()
    9496
     
    148150        self._onlineGateSystem.set_tooltip_text(xstr("prefs_onlineGateSystem_tooltip"))
    149151        mainBox.pack_start(self._onlineGateSystem, False, False, 4)
     152
     153        self._onlineACARS = gtk.CheckButton(xstr("prefs_onlineACARS"))
     154        self._onlineACARS.set_use_underline(True)
     155        self._onlineACARS.set_tooltip_text(xstr("prefs_onlineACARS_tooltip"))
     156        mainBox.pack_start(self._onlineACARS, False, False, 4)
    150157
    151158        self._flareTimeFromFS = gtk.CheckButton(xstr("prefs_flaretimeFromFS"))
  • src/mlx/i18n.py

    r136 r139  
    565565                 "If this is checked, the logger will query and update the "
    566566                 "LHBP Online Gate System.")
     567        self.add("prefs_onlineACARS",
     568                 "Use the Online ACA_RS System")
     569        self.add("prefs_onlineACARS_tooltip",
     570                 "If this is checked, the logger will continuously update "
     571                 "the MAVA Online ACARS System with your flight's data.")
    567572        self.add("prefs_flaretimeFromFS",
    568573                 "Take flare _time from the simulator")
     
    10651070                 "Ha ezt bejelölöd, a logger lekérdezi és frissíti az "
    10661071                 "LHBP Online Gate System adatait.")
     1072        self.add("prefs_onlineACARS",
     1073                 "Az Online ACA_RS rendszer használata")
     1074        self.add("prefs_onlineACARS_tooltip",
     1075                 "Ha ezt bejölöd, a logger folyamatosan közli a repülésed "
     1076                 "adatait a MAVA Online ACARS rendszerrel.")
    10671077        self.add("prefs_flaretimeFromFS",
    10681078                 "A ki_lebegtetés idejét vedd a szimulátorból")
  • src/mlx/web.py

    r130 r139  
    5050                      "YK4" : const.AIRCRAFT_YK40 }
    5151
     52    TYPE2TYPECODE = { const.AIRCRAFT_B736 : "736",
     53                      const.AIRCRAFT_B737 : "73G",
     54                      const.AIRCRAFT_B738 : "738",
     55                      const.AIRCRAFT_B733 : "733",
     56                      const.AIRCRAFT_B734 : "734",
     57                      const.AIRCRAFT_B735 : "735",
     58                      const.AIRCRAFT_DH8D : "DH4",
     59                      const.AIRCRAFT_B762 : "762",
     60                      const.AIRCRAFT_B763 : "763",
     61                      const.AIRCRAFT_CRJ2 : "CR2",
     62                      const.AIRCRAFT_F70  : "F70",
     63                      const.AIRCRAFT_DC3  : "LI2",
     64                      const.AIRCRAFT_T134 : "TU3",
     65                      const.AIRCRAFT_T154 : "TU5",
     66                      const.AIRCRAFT_YK40 : "YK4" }
     67   
    5268    def __init__(self, id, f):
    5369        """Construct a booked flight with the given ID.
     
    581597#------------------------------------------------------------------------------
    582598
     599class SendPIREP(Request):
     600    """A request to send a PIREP to the MAVA website."""
     601    _flightTypes = { const.FLIGHTTYPE_SCHEDULED : "SCHEDULED",
     602                     const.FLIGHTTYPE_OLDTIMER : "OT",
     603                     const.FLIGHTTYPE_VIP : "VIP",
     604                     const.FLIGHTTYPE_CHARTER : "CHARTER" }
     605
     606    _latin2Encoder = codecs.getencoder("iso-8859-2")
     607
     608    def __init__(self, callback, pirep):
     609        """Construct the request for the given PIREP."""
     610        super(SendPIREP, self).__init__(callback)
     611        self._pirep = pirep
     612
     613    def run(self):
     614        """Perform the sending of the PIREP."""
     615        url = "http://www.virtualairlines.hu/malevacars.php"
     616
     617        pirep = self._pirep
     618
     619        data = {}
     620        data["acarsdata"] = pirep.getACARSText()
     621
     622        bookedFlight = pirep.bookedFlight
     623        data["foglalas_id"] = bookedFlight.id
     624        data["repdate"] = bookedFlight.departureTime.date().strftime("%Y-%m-%d")
     625        data["fltnum"] = bookedFlight.callsign
     626        data["depap"] = bookedFlight.departureICAO
     627        data["arrap"] = bookedFlight.arrivalICAO
     628        data["pass"] = str(bookedFlight.numPassengers)
     629        data["crew"] = str(bookedFlight.numCrew)
     630        data["cargo"] = str(pirep.cargoWeight)
     631        data["bag"] = str(bookedFlight.bagWeight)
     632        data["mail"] = str(bookedFlight.mailWeight)
     633       
     634        data["flttype"] = SendPIREP._flightTypes[pirep.flightType]
     635        data["onoff"] = "1" if pirep.online else "0"
     636        data["bt_dep"] = util.getTimestampString(pirep.blockTimeStart)
     637        data["bt_arr"] = util.getTimestampString(pirep.blockTimeEnd)
     638        data["bt_dur"] = util.getTimeIntervalString(pirep.blockTimeEnd -
     639                                                    pirep.blockTimeStart)
     640        data["ft_dep"] = util.getTimestampString(pirep.flightTimeStart)
     641        data["ft_arr"] = util.getTimestampString(pirep.flightTimeEnd)
     642        data["ft_dur"] = util.getTimeIntervalString(pirep.flightTimeEnd -
     643                                                    pirep.flightTimeStart)
     644        data["timecomm"] = pirep.getTimeComment()
     645        data["fuel"] = "%.0f" % (pirep.fuelUsed,)
     646        data["dep_rwy"] = pirep.departureRunway
     647        data["arr_rwy"] = pirep.arrivalRunway
     648        data["wea_dep"] = pirep.departureMETAR
     649        data["wea_arr"] = pirep.arrivalMETAR
     650        data["alt"] = "FL%.0f" % (pirep.filedCruiseAltitude/100.0,)
     651        if pirep.filedCruiseAltitude!=pirep.cruiseAltitude:
     652            data["mod_alt"] = "FL%.0f" % (pirep.cruiseAltitude/100.0,)
     653        else:
     654            data["mod_alt"] = ""
     655        data["sid"] = pirep.sid
     656        data["navroute"] = pirep.route
     657        data["star"] = pirep.getSTAR()
     658        data["aprtype"] = pirep.approachType
     659        data["diff"] = "2"
     660        data["comment"] = SendPIREP._latin2Encoder(pirep.comments)[0]
     661        data["flightdefect"] = SendPIREP._latin2Encoder(pirep.flightDefects)[0]
     662        data["kritika"] = pirep.getRatingText()
     663        data["flightrating"] = "%.1f" % (max(0.0, pirep.rating),)
     664        data["distance"] = "%.3f" % (pirep.flownDistance,)
     665        data["insdate"] = datetime.date.today().strftime("%Y-%m-%d")
     666
     667        f = urllib2.urlopen(url, urllib.urlencode(data), timeout = 10.0)
     668        try:
     669            result = Result()
     670            line = f.readline().strip()
     671            print "PIREP result from website:", line
     672            result.success = line=="OK"
     673            result.alreadyFlown = line=="MARVOLT"
     674            result.notAvailable = line=="NOMORE"
     675        finally:
     676            f.close()
     677
     678        return result   
     679
     680#------------------------------------------------------------------------------
     681
     682class SendACARS(Request):
     683    """A request to send an ACARS to the MAVA website."""
     684    _latin2Encoder = codecs.getencoder("iso-8859-2")
     685
     686    def __init__(self, callback, acars):
     687        """Construct the request for the given PIREP."""
     688        super(SendACARS, self).__init__(callback)
     689        self._acars = acars
     690
     691    def run(self):
     692        """Perform the sending of the ACARS."""
     693        url = "http://www.virtualairlines.hu/acars2/acarsonline.php"
     694
     695        acars = self._acars
     696        bookedFlight = acars.bookedFlight
     697
     698        data = {}
     699        data["pid"] = acars.pid
     700        data["pilot"] = SendACARS._latin2Encoder(acars.pilotName)[0]
     701   
     702        data["pass"] = str(bookedFlight.numPassengers)
     703        data["callsign"] = bookedFlight.callsign
     704        data["airplane"] = BookedFlight.TYPE2TYPECODE[bookedFlight.aircraftType]
     705        data["from"] = bookedFlight.departureICAO
     706        data["to"] = bookedFlight.arrivalICAO       
     707        data["lajstrom"] = bookedFlight.tailNumber
     708
     709        data["block_time"] = acars.getBlockTimeText()
     710        data["longitude"] = str(acars.state.longitude)
     711        data["latitude"] = str(acars.state.latitude)
     712        data["altitude"] = str(acars.state.altitude)
     713        data["speed"] = str(acars.state.groundSpeed)
     714       
     715        data["event"] = acars.getEventText()
     716
     717        f = urllib2.urlopen(url, urllib.urlencode(data), timeout = 10.0)
     718        try:
     719            result = Result()
     720        finally:
     721            f.close()
     722
     723        return result   
     724
     725#------------------------------------------------------------------------------
     726
    583727class Handler(threading.Thread):
    584728    """The handler for the web services.
     
    618762        """Send the given PIREP."""
    619763        self._addRequest(SendPIREP(callback, pirep))
     764
     765    def sendACARS(self, callback, acars):
     766        """Send the given ACARS"""
     767        self._addRequest(SendACARS(callback, acars))
    620768       
    621769    def run(self):
Note: See TracChangeset for help on using the changeset viewer.