Ignore:
Timestamp:
05/01/12 12:57:18 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

Fuel loading works

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/fsuipc.py

    r140 r141  
    528528   
    529529        self._latin1decoder = codecs.getdecoder("iso-8859-1")
    530    
     530
    531531    def connect(self, aircraft):
    532532        """Initiate a connection to the simulator."""
     
    608608
    609609        self._handler.requestWrite(data, self._handleMessageSent)
     610
     611    def getFuel(self, tanks, callback):
     612        """Get the fuel from the given tanks.
     613
     614        The callback will be called with a list of two-tuples, where the tuples
     615        have the following items:
     616        - the current weight of the fuel in the tank (in kgs)
     617        - the current total capacity of the tank (in kgs)."""
     618        data = [(0x0af4, "H")]     # Fuel weight
     619        for tank in tanks:
     620            offset = _tank2offset[tank]
     621            data.append( (offset, "u") )     # tank level
     622            data.append( (offset+4, "u") )   # tank capacity
     623
     624        self._handler.requestRead(data, self._handleFuelRetrieved,
     625                                  extra = callback)
     626
     627    def setFuelLevel(self, levels):
     628        """Set the fuel level to the given ones.
     629
     630        levels is an array of two-tuples, where each tuple consists of the
     631        following:
     632        - the const.FUELTANK_XXX constant denoting the tank that must be set,
     633        - the requested level of the fuel as a floating-point value between 0.0
     634        and 1.0."""
     635        data = []
     636        for (tank, level) in levels:
     637            offset = _tank2offset[tank]
     638            data.append( (offset, "u", long(level * 128.8 * 65536.0)) )
     639        self._handler.requestWrite(data, self._handleFuelWritten)
    610640           
    611641    def disconnect(self):
     
    801831    def _handleMessageSent(self, success, extra):
    802832        """Callback for a message sending request."""
     833        pass
     834
     835    def _handleFuelRetrieved(self, data, callback):
     836        """Callback for a fuel retrieval request."""
     837        fuelWeight = data[0] / 256.0
     838        result = []
     839        for i in range(1, len(data), 2):
     840            capacity = data[i+1] * fuelWeight * const.LBSTOKG
     841            amount = data[i] * capacity / 128.0 / 65536.0
     842            result.append( (amount, capacity) )
     843
     844        callback(result)
     845                                                 
     846    def _handleFuelWritten(self, success, extra):
     847        """Callback for a fuel setting request."""
    803848        pass
    804849                                                 
Note: See TracChangeset for help on using the changeset viewer.