Changeset 139:839016dcd0d1 for src
- Timestamp:
- 05/01/12 08:29:24 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- src/mlx
- Files:
-
- 1 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/acft.py
r136 r139 8 8 import util 9 9 10 import sys 10 11 import time 12 import traceback 11 13 12 14 #--------------------------------------------------------------------------------------- … … 59 61 self._checkers.append(checks.VisibilityChecker()) 60 62 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 61 71 # Fault checkers 62 72 … … 105 115 return self._flight.logger 106 116 117 @property 118 def state(self): 119 """Get the current aircraft state.""" 120 return self._aircraftState 121 107 122 def getFlapsSpeedLimit(self, flaps): 108 123 """Get the speed limit for the given flaps setting.""" … … 119 134 """Called when the state of the aircraft changes.""" 120 135 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() 123 142 124 143 self._flight.handleState(self._aircraftState, aircraftState) -
src/mlx/checks.py
r134 r139 6 6 import const 7 7 import util 8 from acars import ACARS 9 10 import time 8 11 9 12 #--------------------------------------------------------------------------------------- … … 85 88 #--------------------------------------------------------------------------------------- 86 89 90 class 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 87 125 class TakeOffLogger(StateChecker): 88 126 """Logger for the cruise speed.""" -
src/mlx/config.py
r136 r139 38 38 self._language = "" 39 39 self._onlineGateSystem = True 40 self._onlineACARS = True 40 41 self._flareTimeFromFS = False 41 42 … … 105 106 if onlineGateSystem!=self._onlineGateSystem: 106 107 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 107 120 self._modified = True 108 121 … … 179 192 "onlineGateSystem", 180 193 True) 194 self._onlineACARS = self._getBoolean(config, "general", 195 "onlineACARS", True) 181 196 self._flareTimeFromFS = self._getBoolean(config, "general", 182 197 "flareTimeFromFS", … … 212 227 config.set("general", "onlineGateSystem", 213 228 "yes" if self._onlineGateSystem else "no") 229 config.set("general", "onlineACARS", 230 "yes" if self._onlineACARS else "no") 214 231 config.set("general", "flareTimeFromFS", 215 232 "yes" if self._flareTimeFromFS else "no") -
src/mlx/gui/flight.py
r138 r139 212 212 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.5, 213 213 xscale = 0.0, yscale = 0.0) 214 214 215 215 table = gtk.Table(2, 3) 216 216 table.set_row_spacings(4) -
src/mlx/gui/gui.py
r135 r139 165 165 """Get the flight being performed.""" 166 166 return self._flight 167 168 @property 169 def loginResult(self): 170 """Get the result of the login.""" 171 return self._wizard.loginResult 167 172 168 173 @property -
src/mlx/gui/prefs.py
r136 r139 68 68 self._setLanguage(config.language) 69 69 self._onlineGateSystem.set_active(config.onlineGateSystem) 70 self._onlineACARS.set_active(config.onlineACARS) 70 71 self._flareTimeFromFS.set_active(config.flareTimeFromFS) 71 72 … … 91 92 config.language = self._getLanguage() 92 93 config.onlineGateSystem = self._onlineGateSystem.get_active() 94 config.onlineACARS = self._onlineACARS.get_active() 93 95 config.flareTimeFromFS = self._flareTimeFromFS.get_active() 94 96 … … 148 150 self._onlineGateSystem.set_tooltip_text(xstr("prefs_onlineGateSystem_tooltip")) 149 151 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) 150 157 151 158 self._flareTimeFromFS = gtk.CheckButton(xstr("prefs_flaretimeFromFS")) -
src/mlx/i18n.py
r136 r139 565 565 "If this is checked, the logger will query and update the " 566 566 "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.") 567 572 self.add("prefs_flaretimeFromFS", 568 573 "Take flare _time from the simulator") … … 1065 1070 "Ha ezt bejelölöd, a logger lekérdezi és frissíti az " 1066 1071 "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.") 1067 1077 self.add("prefs_flaretimeFromFS", 1068 1078 "A ki_lebegtetés idejét vedd a szimulátorból") -
src/mlx/web.py
r130 r139 50 50 "YK4" : const.AIRCRAFT_YK40 } 51 51 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 52 68 def __init__(self, id, f): 53 69 """Construct a booked flight with the given ID. … … 581 597 #------------------------------------------------------------------------------ 582 598 599 class 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 682 class 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 583 727 class Handler(threading.Thread): 584 728 """The handler for the web services. … … 618 762 """Send the given PIREP.""" 619 763 self._addRequest(SendPIREP(callback, pirep)) 764 765 def sendACARS(self, callback, acars): 766 """Send the given ACARS""" 767 self._addRequest(SendACARS(callback, acars)) 620 768 621 769 def run(self):
Note:
See TracChangeset
for help on using the changeset viewer.