Ignore:
Timestamp:
02/14/13 18:21:47 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Implemented the client support for the new commands and updated the basic test programs with tests showing messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/client/python/xplra.py

    r37 r40  
    3030COMMAND_GET_VERSIONS = 0x31
    3131
     32COMMAND_RELOAD_PLUGINS = 0x32
     33
     34COMMAND_SHOW_MESSAGE = 0x41
     35
    3236TYPE_INT = 0x01
    3337
     
    5761
    5862RESULT_INVALID_ID = 0x07
     63
     64RESULT_INVALID_DURATION = 0x08
    5965
    6066RESULT_OTHER_ERROR = 0xff
     
    7177                 RESULT_INVALID_COUNT : "invalid count",
    7278                 RESULT_INVALID_ID : "invalid ID",
     79                 RESULT_INVALID_DURATION : "invalid duration",
    7380                 RESULT_OTHER_ERROR : "other error" }
    7481
     
    8188            return "unknown error code " + `resultCode`
    8289
    83     def __init__(self, resultCode):
    84         super(ProtocolException, self).__init__("xplra.ProtocolException: " +
    85                                                 self.getMessage(resultCode))
     90    def __init__(self, resultCode, parameter = None):
     91        message = "xplra.ProtocolException: " + self.getMessage(resultCode)
     92        if parameter is not None:
     93            if resultCode==RESULT_UNKNOWN_DATAREF:
     94                message += " (# %d)" % (parameter,)
     95
     96        super(ProtocolException, self).__init__(message)
    8697        self.resultCode = resultCode
     98        self.parameter = parameter
    8799
    88100#-------------------------------------------------------------------------------
     
    145157        return (self._readS32(), self._readS32(), self._readS32())
    146158
     159    def reloadPlugins(self):
     160        """Reload the plugins in X-Plane.
     161
     162        After this, this connection becomes invalid."""
     163        self._writeU8(COMMAND_RELOAD_PLUGINS)
     164        self._flush()
     165        self._checkResult();
     166
    147167    def getInt(self, name):
    148168        """Get the value of the integer dataref with the given name."""
     
    212232        self.setByteArray(name, value, offset)
    213233
     234    def showMessage(self, message, duration):
     235        """Show a message in the simulator window for the given duration.
     236
     237        The duration is a floating-point number denoting seconds."""
     238        self._writeU8(COMMAND_SHOW_MESSAGE)
     239        self._writeString(message)
     240        self._writeFloat(duration)
     241        self._flush()
     242        self._checkResult()
     243
    214244    def disconnect(self):
    215245        """Disconnect from X-Plane."""
     
    218248            self._stream = None
    219249
    220     def _checkResult(self, resultCode = None):
     250    def _checkResult(self, resultCode = None, parameter = None, multi = False):
    221251        """Check the given result code.
    222252
     
    227257        if resultCode is None:
    228258            resultCode = self._readU8()
     259            if multi and resultCode==RESULT_UNKNOWN_DATAREF:
     260                parameter = self._readU32()
     261
    229262        if resultCode!=RESULT_OK:
    230             raise ProtocolException(resultCode)
     263            raise ProtocolException(resultCode, parameter)
    231264
    232265    def _getSingle(self, name, type, length = None, offset = None):
     
    525558
    526559        self._xplane._flush()
    527         self._xplane._checkResult()
     560        self._xplane._checkResult(multi = True)
    528561
    529562    def __len__(self):
     
    591624        self._xplane._flush()
    592625
    593         self._xplane._checkResult()
     626        self._xplane._checkResult(multi = True)
    594627
    595628        self._readValues()
     
    623656        self._xplane._flush()
    624657
    625         self._xplane._checkResult()
     658        self._xplane._checkResult(multi = True)
    626659
    627660    def _executeUnregistered(self):
     
    644677
    645678        self._xplane._flush()
    646         self._xplane._checkResult()
    647 
    648 #-------------------------------------------------------------------------------
     679        self._xplane._checkResult(multi = True)
     680
     681#-------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.