Skip to content

Commit f5d38aa

Browse files
committed
DriftingOscillatorBase: Refactored setDriftRate to use SimTimeScale arithmetic.
1 parent 9060533 commit f5d38aa

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

src/inet/clock/base/DriftingOscillatorBase.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,12 @@ void DriftingOscillatorBase::setDriftRate(ppm newDriftRate)
7575
emit(preOscillatorStateChangedSignal, this);
7676
simtime_t currentSimTime = simTime();
7777
EV_INFO << "Setting oscillator drift rate from " << driftRate << " to " << newDriftRate << " at simtime " << currentSimTime << ".\n";
78-
if (elapsedTickTime == SIMTIME_ZERO)
79-
nextTickFromOrigin = 0;
80-
else {
81-
int64_t v = increaseWithDriftRate(currentTickLength.raw() - elapsedTickTime.raw());
82-
nextTickFromOrigin = SimTime::fromRaw(decreaseWithDriftRate(v, newInverseDriftRate));
83-
}
8478
simtime_t oldCurrentTickLength = getCurrentTickLength();
8579
simtime_t baseTickTime = origin + nextTickFromOrigin - oldCurrentTickLength;
8680
simtime_t elapsedTickTime = fmod(currentSimTime - baseTickTime, oldCurrentTickLength);
8781
SimTimeScale newDriftFactor = SimTimeScale::fromPpm(newDriftRate.get<ppm>());
82+
simtime_t remainingTickTime = oldCurrentTickLength - elapsedTickTime;
83+
nextTickFromOrigin = SimTime::fromRaw(remainingTickTime.raw() * driftFactor / newDriftFactor);
8884
driftRate = newDriftRate;
8985
setDriftFactor(newDriftFactor);
9086
setOrigin(currentSimTime);

0 commit comments

Comments
 (0)