Skip to content

Commit 3a4e8d4

Browse files
committed
DriftingOscillatorBase: Implemented getNumTicksAtOrigin().
1 parent 5ee68cf commit 3a4e8d4

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/inet/clock/base/DriftingOscillatorBase.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void DriftingOscillatorBase::initialize(int stage)
2323
throw cRuntimeError("The nominalTickLength parameter value %lg cannot be accurately represented with the current simulation time precision, conversion result: %s", nominalTickLengthAsDouble, nominalTickLength.ustr().c_str());
2424
inverseDriftRate = invertDriftRate(driftRate);
2525
setOrigin(simTime());
26+
numTicksAtOrigin = 0;
2627
simtime_t currentTickLength = getCurrentTickLength();
2728
simtime_t tickOffset = par("tickOffset");
2829
if (tickOffset < 0 || tickOffset >= currentTickLength)
@@ -43,6 +44,7 @@ void DriftingOscillatorBase::setOrigin(simtime_t origin)
4344
EV_DEBUG << "Setting oscillator origin" << EV_FIELD(origin) << EV_ENDL;
4445
DEBUG_CMP(origin, <=, simTime());
4546
DEBUG_CMP(this->origin, <=, origin);
47+
numTicksAtOrigin += computeTicksForInterval(origin - this->origin);
4648
this->origin = origin;
4749
}
4850

src/inet/clock/base/DriftingOscillatorBase.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class INET_API DriftingOscillatorBase : public OscillatorBase, public IScriptabl
2828
simtime_t origin; // simulation time from which the computeClockTicksForInterval and computeIntervalForClockTicks is measured
2929
simtime_t nextTickFromOrigin; // simulation time interval from the computation origin to the next tick
3030

31+
/** Total number of ticks strictly before the origin (absolute tick index at o). */
32+
int64_t numTicksAtOrigin;
33+
3134
protected:
3235
virtual void initialize(int stage) override;
3336

@@ -49,6 +52,9 @@ class INET_API DriftingOscillatorBase : public OscillatorBase, public IScriptabl
4952
virtual simtime_t getNominalTickLength() const override { return nominalTickLength; }
5053
virtual double getCurrentTickLength() const { return nominalTickLength.dbl() + nominalTickLength.dbl() * inverseDriftRate.get<unit>(); }
5154

55+
56+
/** Returns the absolute tick count at the origin (ticks strictly before o). */
57+
virtual int64_t getNumTicksAtOrigin() const override { return numTicksAtOrigin; }
5258
virtual ppm getDriftRate() const { return driftRate; }
5359
virtual void setDriftRate(ppm driftRate);
5460
virtual void setTickOffset(simtime_t tickOffset);
@@ -62,4 +68,3 @@ class INET_API DriftingOscillatorBase : public OscillatorBase, public IScriptabl
6268
} // namespace inet
6369

6470
#endif
65-

0 commit comments

Comments
 (0)