Ignore:
Timestamp:
04/07/12 11:03:47 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

The time page is implemented too.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/fsuipc.py

    r59 r61  
    428428    via FSUIPC."""
    429429    # The basic data that should be queried all the time once we are connected
    430     normalData = [ (0x0240, "H"),            # Year
    431                    (0x023e, "H"),            # Number of day in year
    432                    (0x023b, "b"),            # UTC hour
    433                    (0x023c, "b"),            # UTC minute
    434                    (0x023a, "b"),            # seconds
    435                    (0x3d00, -256),           # The name of the current aircraft
     430    timeData = [ (0x0240, "H"),            # Year
     431                 (0x023e, "H"),            # Number of day in year
     432                 (0x023b, "b"),            # UTC hour
     433                 (0x023c, "b"),            # UTC minute
     434                 (0x023a, "b") ]           # seconds
     435   
     436    normalData = timeData + \
     437                 [ (0x3d00, -256),           # The name of the current aircraft
    436438                   (0x3c00, -256) ]          # The path of the current AIR file
    437439
     
    452454                   (0x057c, "d"),            # Bank
    453455                   (0x0580, "d") ]           # Heading
     456
     457    @staticmethod
     458    def _getTimestamp(data):
     459        """Convert the given data into a timestamp."""
     460        timestamp = calendar.timegm(time.struct_time([data[0],
     461                                                      1, 1, 0, 0, 0, -1, 1, 0]))
     462        timestamp += data[1] * 24 * 3600
     463        timestamp += data[2] * 3600
     464        timestamp += data[3] * 60
     465        timestamp += data[4]       
     466
     467        return timestamp
    454468
    455469    def __init__(self, connectionListener, connectAttempts = -1,
     
    516530        """Send a request for the ZFW."""
    517531        self._handler.requestRead([(0x3bfc, "d")], self._handleZFW, extra = callback)
     532
     533    def requestTime(self, callback):
     534        """Request the time from the simulator."""
     535        self._handler.requestRead(Simulator.timeData, self._handleTime,
     536                                  extra = callback)
    518537                                                           
    519538    def startMonitoring(self):
     
    583602        aircraft-specific values.
    584603        """
    585         timestamp = calendar.timegm(time.struct_time([data[0],
    586                                                       1, 1, 0, 0, 0, -1, 1, 0]))
    587         timestamp += data[1] * 24 * 3600
    588         timestamp += data[2] * 3600
    589         timestamp += data[3] * 60
    590         timestamp += data[4]       
     604        timestamp = Simulator._getTimestamp(data)
    591605
    592606        createdNewModel = self._setAircraftName(timestamp, data[5], data[6])
     
    719733        zfw = data[0] * const.LBSTOKG / 256.0
    720734        callback(zfw)
     735                                                 
     736    def _handleTime(self, data, callback):
     737        """Callback for a time retrieval request."""
     738        callback(Simulator._getTimestamp(data))
    721739                                                 
    722740#------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.