Beispiel #1
0
    def test_fromParentTicks(self):
        mockTime = self.mockTime

        b = self.newSysClock(tickRate=2000000)

        mockTime.timeNow = 1000.0

        c = CorrelatedClock(b, 1000, correlation=Correlation(50, 300))
        self.assertAlmostEqual(c.fromParentTicks(50 + (400 - 300) * 2000),
                               400,
                               places=5)

        c = CorrelatedClock(b, 1000, correlation=Correlation(50, 300), speed=0)
        self.assertEquals(c.fromParentTicks(50), 300)
        self.assertEquals(c.fromParentTicks(100), 300)
Beispiel #2
0
 def test_differentBranches(self):
     a = SysClock(tickRate=1000000)
     a1 = CorrelatedClock(a, tickRate=100, correlation=(50,0))
     a2 = CorrelatedClock(a1, tickRate=78, correlation=(28,999))
     a3 = CorrelatedClock(a2, tickRate=178, correlation=(5,1003))
     a4 = CorrelatedClock(a3, tickRate=28, correlation=(17,9))
     b3 = CorrelatedClock(a2, tickRate=1000, correlation=(10,20))
     b4 = CorrelatedClock(b3, tickRate=2000, correlation=(15,90))
     
     v = a4.toParentTicks(500)
     v = a3.toParentTicks(v)
     v = b3.fromParentTicks(v)
     v = b4.fromParentTicks(v)
     
     self.assertEquals(a4.toOtherClockTicks(b4, 500), v)
Beispiel #3
0
    def test_fromParentTicks(self):
        mockTime = self.mockTime

        mockTime.timeNow = 1000.0
        
        b = SysClock(tickRate=2000000)
        c = CorrelatedClock(b, 1000, correlation=(50,300))
        self.assertAlmostEqual(c.fromParentTicks(50 + (400-300)*2000), 400, places=5 )
Beispiel #4
0
    def algorithm(self):
        candidateClock = CorrelatedClock(self.clock.getParent(),
                                         tickRate=self.clock.tickRate,
                                         correlation=self.clock.correlation)

        while True:
            update = False
            cumulativeOffset = None
            candidate = (yield self.timeoutSecs)

            t = self.clock.ticks
            currentDispersion = self.clock.dispersionAtTime(t)

            if candidate is not None:

                candidateClock.correlation = candidate.calcCorrelationFor(
                    self.clock, self.localMaxFreqErrorPpm)
                candidateDispersion = candidateClock.dispersionAtTime(t)

                update = candidateDispersion < currentDispersion
                if update:
                    pt = self.clock.toParentTicks(t)
                    adjustment = candidateClock.fromParentTicks(pt) - t
                    if cumulativeOffset is None:
                        cumulativeOffset = 0
                    else:
                        cumulativeOffset += adjustment

                    self.clock.correlation = candidateClock.correlation
                    self.onClockAdjusted(
                        self.clock.ticks, adjustment,
                        1000000000 * currentDispersion,
                        1000000000 * candidateDispersion,
                        self.clock.correlation.errorGrowthRate)

                else:
                    pass

                # update worst dispersion seen so far
                self.worstDispersion = max(self.worstDispersion,
                                           currentDispersion,
                                           candidateDispersion)

                co = cumulativeOffset or 0  # convert None to 0
                self.log.info(
                    "Old / New dispersion (millis) is %.5f / %.5f ... offset=%20d  new best candidate? %s\n"
                    % (1000 * currentDispersion, 1000 * candidateDispersion,
                       co, str(update)))
            else:
                self.log.info("Timeout.  Dispersion (millis) is %.5f\n" %
                              (1000 * currentDispersion, ))
            # retry more quickly if we didn't get an improved candidate
            if update:
                time.sleep(self.repeatSecs)
            else:
                time.sleep(self.timeoutSecs)
Beispiel #5
0
    def test_differentBranches(self):
        a = self.newSysClock(tickRate=1000000)
        a1 = CorrelatedClock(a, tickRate=100, correlation=Correlation(50, 0))
        a2 = CorrelatedClock(a1, tickRate=78, correlation=Correlation(28, 999))
        a3 = CorrelatedClock(a2,
                             tickRate=178,
                             correlation=Correlation(5, 1003))
        a4 = CorrelatedClock(a3, tickRate=28, correlation=Correlation(17, 9))
        b3 = CorrelatedClock(a2,
                             tickRate=1000,
                             correlation=Correlation(10, 20))
        b4 = CorrelatedClock(b3,
                             tickRate=2000,
                             correlation=Correlation(15, 90))

        v = a4.toParentTicks(500)
        v = a3.toParentTicks(v)
        v = b3.fromParentTicks(v)
        v = b4.fromParentTicks(v)

        self.assertEquals(a4.toOtherClockTicks(b4, 500), v)