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

Implemented FS time synchronization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/fsuipc.py

    r141 r148  
    471471                   (0x0580, "d") ]           # Heading
    472472
     473    TIME_SYNC_INTERVAL = 3.0
     474
    473475    @staticmethod
    474476    def _getTimestamp(data):
     
    514516        self._scroll = False
    515517
     518        self._syncTime = False
     519        self._nextSyncTime = -1
     520       
    516521        self._normalRequestID = None
    517522
     
    536541        self._handler.connect()
    537542        if self._normalRequestID is None:
     543            self._nextSyncTime = -1
    538544            self._startDefaultNormal()
    539545
     
    638644            data.append( (offset, "u", long(level * 128.8 * 65536.0)) )
    639645        self._handler.requestWrite(data, self._handleFuelWritten)
     646
     647    def enableTimeSync(self):
     648        """Enable the time synchronization."""
     649        self._nextSyncTime = -1
     650        self._syncTime = True
     651           
     652    def disableTimeSync(self):
     653        """Enable the time synchronization."""
     654        self._syncTime = False
     655        self._nextSyncTime = -1
    640656           
    641657    def disconnect(self):
     
    678694
    679695        self._scroll = data[7]!=0
     696
     697        self._checkTimeSync()
    680698       
    681699        if self._monitoringRequested and not self._monitoring:
     
    691709            self._aircraft.handleState(aircraftState)
    692710
     711    def _checkTimeSync(self):
     712        """Check if we need to synchronize the FS time."""
     713        if not self._syncTime: return
     714
     715        now = time.time()
     716        seconds = time.gmtime(now).tm_sec
     717
     718        if seconds>30 and seconds<59:
     719            if self._nextSyncTime > (now - 0.49):
     720                return
     721           
     722            self._handler.requestWrite([(0x023a, "b", int(seconds))],
     723                                       self._handleTimeSynced)
     724           
     725            #print "Set the seconds to ", seconds
     726
     727            if self._nextSyncTime<0:
     728                self._nextSyncTime = now
     729               
     730            self._nextSyncTime += Simulator.TIME_SYNC_INTERVAL
     731        else:
     732            self._nextSyncTime = -1
     733
     734    def _handleTimeSynced(self, success, extra):
     735        """Callback for the time sync result."""
     736        pass
     737       
    693738    def _setAircraftName(self, timestamp, name, airPath):
    694739        """Set the name of the aicraft and if it is different from the
Note: See TracChangeset for help on using the changeset viewer.