Skip to content

Commit 8a692e3

Browse files
committed
IdealOscillator: Added more documentation to implementation.
1 parent db6eb9c commit 8a692e3

2 files changed

Lines changed: 47 additions & 4 deletions

File tree

src/inet/clock/oscillator/IdealOscillator.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,34 @@
1313

1414
namespace inet {
1515

16+
/**
17+
* @brief Ideal (uniform) oscillator.
18+
*
19+
* Provides a strictly periodic tick sequence with constant tick length and no
20+
* drift. The computation origin is a simulation time (o ≤ now).
21+
*
22+
* Mathematical semantics
23+
* ----------------------
24+
* - Let L := tickLength > 0 be the nominal tick interval (constant).
25+
* - Tick instants (relative to origin) are τ_i := i·L, i = 1,2,… (the origin
26+
* itself is not counted as a tick).
27+
* - Tick count from origin for interval Δt ≥ 0: N(Δt) = |{ i : 0 < τ_i ≤ Δt }|
28+
* = floor(Δt / L) (tick exactly at Δt is included; a tick at the origin is
29+
* excluded).
30+
* - Minimal interval for n ≥ 0 ticks: I(n) = inf{ Δt ≥ 0 : N(Δt) ≥ n } = n · L
31+
* with I(0) = 0.
32+
*
33+
* This class implements the ~IOscillator mapping without generating per-tick
34+
* events. It is suitable as a reference oscillator for clocks that require a
35+
* simple, drift-free timebase.
36+
*/
1637
class INET_API IdealOscillator : public OscillatorBase
1738
{
1839
protected:
40+
/// Computation origin (o ≤ now); tick counting is measured from here.
1941
simtime_t origin;
42+
43+
/// Constant tick length L > 0 used for both N(Δt) and I(n).
2044
simtime_t tickLength;
2145

2246
protected:
@@ -25,15 +49,20 @@ class INET_API IdealOscillator : public OscillatorBase
2549
virtual void scheduleTickTimer() override;
2650

2751
public:
52+
/** @name IOscillator contract */
53+
///@{
2854
virtual simtime_t getComputationOrigin() const override { return origin; }
55+
2956
virtual simtime_t getNominalTickLength() const override { return tickLength; }
57+
3058
virtual int64_t getNumTicksAtOrigin() const override { return 0; }
3159

3260
virtual int64_t computeTicksForInterval(simtime_t timeInterval) const override;
61+
3362
virtual simtime_t computeIntervalForTicks(int64_t numTicks) const override;
63+
///@}
3464
};
3565

3666
} // namespace inet
3767

3868
#endif
39-

src/inet/clock/oscillator/IdealOscillator.ned

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,26 @@ import inet.clock.base.OscillatorBase;
1111
import inet.clock.contract.IOscillator;
1212

1313
//
14-
// Generates ticks periodically with a constant tick length.
14+
// Ideal strictly periodic oscillator (no drift).
15+
//
16+
// Summary
17+
// -------
18+
// Provides a constant tick length L and implements the ~IOscillator mappings
19+
// without generating per-tick events.
20+
//
21+
// Semantics
22+
// ---------
23+
// - Let o be the computation origin (o ≤ now), and L = tickLength (> 0 unless 0s is used; see below).
24+
// - Tick instants (relative to origin): τ_k = k·L for k = 1,2,… (tick at origin is not counted).
25+
// - Mapping functions:
26+
// N(Δt) = floor(Δt / L) // ticks in (0, Δt], Δt ≥ 0
27+
// I(n) = n · L, with I(0) = 0 // minimal Δt for n ticks, n ≥ 0
28+
//
29+
// @see ~IOscillator
1530
//
1631
simple IdealOscillator extends OscillatorBase like IOscillator
1732
{
1833
parameters:
19-
double tickLength @unit(s) = default(0s);
34+
double tickLength @unit(s) = default(0s); // Constant tick length L. If 0s, the simulation time precision is used; otherwise must be > 0.
2035
@class(IdealOscillator);
2136
}
22-

0 commit comments

Comments
 (0)