Changeset 893:147633a04fda for src


Ignore:
Timestamp:
03/11/18 09:02:42 (7 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Children:
894:995dccbca6ab, 901:960acab7a319
Phase:
public
Message:

The timestamps from X-Plane are increasing monotonically (re #333)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/xplane.py

    r881 r893  
    657657
    658658    @staticmethod
    659     def _getTimestamp(data):
    660         """Convert the given data into a timestamp."""
    661         year = datetime.date.today().year
    662         timestamp = calendar.timegm(time.struct_time([year,
    663                                                       1, 1, 0, 0, 0, -1, 1, 0]))
    664         timestamp += data[0] * 24 * 3600
    665         timestamp += data[1]
    666 
    667         return timestamp
    668 
    669     @staticmethod
    670659    def _getHotkeyCode(hotkey):
    671660        """Get the hotkey code for the given hot key."""
     
    709698        self._nextSyncTime = -1
    710699
     700        self._timestampBase = None
     701        self._timestampDaysOffset = 0
     702        self._lastZuluSeconds = None
     703
    711704        self._normalRequestID = None
    712705
     
    931924        self._connectionListener.disconnected()
    932925
     926    def _getTimestamp(self, data):
     927        """Convert the given data into a timestamp."""
     928        if self._timestampBase is None:
     929            year = datetime.date.today().year
     930            self._timestampBase  = \
     931              calendar.timegm(time.struct_time([year, 1, 1, 0, 0, 0, -1, 1, 0]))
     932            self._timestampBase += data[0] * 24 * 3600
     933            self._timestampDaysOffset = 0
     934            self._lastZuluSeconds = None
     935
     936        zuluSeconds = data[1]
     937        if self._lastZuluSeconds is not None and \
     938           zuluSeconds<self._lastZuluSeconds:
     939            print "xplane.Simulator._getTimestamp: Zulu seconds have gone backwards (%f -> %f), increasing day offset" % \
     940              (self._lastZuluSeconds, zuluSeconds)
     941            self._timestampDaysOffset += 1
     942
     943        self._lastZuluSeconds = zuluSeconds
     944
     945        timestamp = self._timestampBase
     946        timestamp += self._timestampDaysOffset * 24 * 3600
     947        timestamp += zuluSeconds
     948
     949        return timestamp
     950
    933951    def _startDefaultNormal(self):
    934952        """Start the default normal periodic request."""
    935953        assert self._normalRequestID is None
     954        self._timestampBase = None
    936955        self._normalRequestID = \
    937956             self._handler.requestPeriodicRead(1.0,
     
    953972        aircraft-specific values.
    954973        """
    955         timestamp = Simulator._getTimestamp(data)
     974        timestamp = self._getTimestamp(data)
    956975
    957976        createdNewModel = self._setAircraftName(timestamp,
     
    11041123    def _handleTime(self, data, callback):
    11051124        """Callback for a time retrieval request."""
    1106         callback(Simulator._getTimestamp(data))
     1125        callback(self._getTimestamp(data))
    11071126
    11081127    def _handleWeights(self, data, callback):
Note: See TracChangeset for help on using the changeset viewer.