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

Implemented ACARS sending

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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."""
Note: See TracChangeset for help on using the changeset viewer.