bbc / pydvbcss

Python library that implements DVB protocols for companion synchronisation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wc dispersion calc

lwba21190 opened this issue · comments

commented

Hello Matt Hammond,
I am testing your dvbcss project. I have some problems. In code as followed,the currentDispersion will be always bigger than candidateDispersion, because currentDispersion uses time_now() to calc. Is it right? Thank you!

currentDispersion = self.getCurrentDispersion()

        if candidate is not None:
            cn=candidate['nanos']
            ct=candidate['ticks']
            candidateDispersion=self.dispCalc.calc(cn)

            if currentDispersion >= candidateDispersion:
                self.bestCandidate = candidate
                update=True
                self.clock.adjustTicks(ct.offset)
                if cumulativeOffset is None:
                    cumulativeOffset=0
                else:
                    cumulativeOffset+=ct.offset

                # notify of the change
                growthRate = self.dispCalc.getGrowthRate(cn)
                self.onClockAdjusted(self.clock.ticks, ct.offset, currentDispersion, candidateDispersion, growthRate)

            else:
                pass

Hello,

Both use the current time to make the calculation of dispersion. The dispCalc.calc() function is used to calculate the dispersion of the new candidate, and it uses self.clock.nanos:

def calc(self, candidate):
        return 1000000000*(candidate.precision + self.precision) \
             + ( candidate.maxFreqError*(candidate.t3-candidate.t2)    \
               + self.maxFreqError*(candidate.t4-candidate.t1)
               + (candidate.maxFreqError+self.maxFreqError)*(self.clock.nanos - candidate.t4) \
               ) / 1000000 + \
               candidate.rtt/2

This function is also used by getCurrentDispersion() to calculate the dispersion of the candidate currently being used (considered the "best" candidate).

You may find it makes more sense if you look at the new version of this code in the new-clock-model branch:

            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:
                    ...
                    self.clock.correlation = candidateClock.correlation

Here, the CorrelatedClocks model the dispersion internally. The Correlation object carried not only the two values making up the correlation (see new-clock-model Correlation class ), but also carries two additional parameters that are needed to calculate the dispersion.

A 2nd clock is used to represent the new candidate. The dispersion is calculated for both the existing clock and the 2nd clock and they are compared. If the 2nd clock has lower dispersion then its correlation (which includes the dispersion calculation parameters) are transferred across.

Please can you confirm if my previous response has answered your question adequately? If so, then please close this issue.

Many thanks

commented

Thank you!