FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
timing::Timing Class Referencefinal

Represents a timing source for simulation. More...

#include "timing.h"

Public Member Functions

 Timing (std::string name, unsigned seed, const SimId id=0) noexcept
 Constructs a Timing object.
 
 ~Timing ()=default
 
 Timing (const Timing &)=delete
 
Timingoperator= (const Timing &)=delete
 
 Timing (Timing &&)=delete
 
Timingoperator= (Timing &&)=delete
 
RealType getNextSample () const noexcept
 Gets the next sample from the timing source.
 
std::string getName () const noexcept
 Gets the name of the timing source.
 
SimId getId () const noexcept
 Gets the unique ID of the timing source.
 
unsigned getSeed () const noexcept
 Gets the initial seed used for the timing source's RNG.
 
bool getSyncOnPulse () const noexcept
 Checks if the timing source synchronizes on pulse.
 
RealType getFrequency () const noexcept
 Gets the frequency of the timing source.
 
RealType getFreqOffset () const noexcept
 Gets the frequency offset of the timing source.
 
RealType getPhaseOffset () const noexcept
 Gets the phase offset of the timing source.
 
bool isEnabled () const noexcept
 Checks if the timing source is enabled.
 
void skipSamples (std::size_t samples) noexcept
 Skips a number of samples in the timing model.
 
void initializeModel (const PrototypeTiming *timing) noexcept
 Initializes the timing model.
 
void reset () noexcept
 Resets the timing model.
 
std::unique_ptr< Timingclone () const
 Creates a new Timing instance based on the same prototype.
 

Detailed Description

Represents a timing source for simulation.

Definition at line 35 of file timing.h.

Constructor & Destructor Documentation

◆ Timing() [1/3]

timing::Timing::Timing ( std::string  name,
unsigned  seed,
const SimId  id = 0 
)
explicitnoexcept

Constructs a Timing object.

Parameters
nameThe name of the timing source.
seedThe seed for the timing source's internal random number generator.

Definition at line 24 of file timing.cpp.

24 :
25 _name(std::move(name)), _id(id == 0 ? SimIdGenerator::instance().generateId(ObjectType::Timing) : id),
26 _rng(seed), _seed(seed)
27 {
28 }
static SimIdGenerator & instance()
Get the singleton instance of SimIdGenerator.
Definition sim_id.h:48

◆ ~Timing()

timing::Timing::~Timing ( )
default

◆ Timing() [2/3]

timing::Timing::Timing ( const Timing )
delete

◆ Timing() [3/3]

timing::Timing::Timing ( Timing &&  )
delete

Member Function Documentation

◆ clone()

std::unique_ptr< Timing > timing::Timing::clone ( ) const

Creates a new Timing instance based on the same prototype.

Returns
A unique_ptr to the new Timing object.
Exceptions
std::logic_errorif the timing object was not initialized from a prototype.

Definition at line 82 of file timing.cpp.

83 {
84 if (_prototype == nullptr)
85 {
86 LOG(Level::FATAL, "Cannot clone a Timing object that has not been initialized from a prototype.");
87 throw std::logic_error("Cannot clone a Timing object that has not been initialized from a prototype.");
88 }
89 auto new_timing = std::make_unique<Timing>(_name, _seed, _id);
90 new_timing->initializeModel(_prototype);
91 return new_timing;
92 }
#define LOG(level,...)
Definition logging.h:19

References LOG.

◆ getFreqOffset()

RealType timing::Timing::getFreqOffset ( ) const
noexcept

Gets the frequency offset of the timing source.

Returns
The frequency offset.

Definition at line 103 of file timing.h.

103{ return _freq_offset; }

◆ getFrequency()

RealType timing::Timing::getFrequency ( ) const
noexcept

Gets the frequency of the timing source.

Returns
The frequency of the timing source.

Definition at line 97 of file timing.h.

97{ return _frequency; }

◆ getId()

SimId timing::Timing::getId ( ) const
noexcept

Gets the unique ID of the timing source.

Returns
The timing source SimId.

Definition at line 76 of file timing.h.

76{ return _id; }

◆ getName()

std::string timing::Timing::getName ( ) const
noexcept

Gets the name of the timing source.

Returns
The name of the timing source.

Definition at line 68 of file timing.h.

68{ return _name; }

◆ getNextSample()

RealType timing::Timing::getNextSample ( ) const
noexcept

Gets the next sample from the timing source.

Returns
The next sample value or 0.0 if not enabled.

Definition at line 61 of file timing.h.

61{ return _enabled ? _model->getSample() : 0.0; }

◆ getPhaseOffset()

RealType timing::Timing::getPhaseOffset ( ) const
noexcept

Gets the phase offset of the timing source.

Returns
The phase offset.

Definition at line 109 of file timing.h.

109{ return _phase_offset; }

◆ getSeed()

unsigned timing::Timing::getSeed ( ) const
noexcept

Gets the initial seed used for the timing source's RNG.

Returns
The initial seed value.

Definition at line 83 of file timing.h.

83{ return _seed; }

◆ getSyncOnPulse()

bool timing::Timing::getSyncOnPulse ( ) const
noexcept

Checks if the timing source synchronizes on pulse.

Returns
True if synchronized on pulse, otherwise false.

Definition at line 90 of file timing.h.

90{ return _sync_on_pulse; }

Referenced by processing::pipeline::advanceTimingModel().

+ Here is the caller graph for this function:

◆ initializeModel()

void timing::Timing::initializeModel ( const PrototypeTiming timing)
noexcept

Initializes the timing model.

Parameters
timingThe prototype timing configuration used for initialization.

Definition at line 39 of file timing.cpp.

40 {
41 if (_model)
42 {
43 LOG(Level::WARNING, "Timing source '{}' already initialized. Skipping re-initialization.", _name);
44 return;
45 }
46
47 _prototype = timing;
48 _frequency = timing->getFrequency();
49
50 std::normal_distribution normal_dist{0.0, 1.0};
51
52 _freq_offset = timing->getFreqOffset().value_or(0);
53 if (const std::optional<RealType> random_freq_stdev = timing->getRandomFreqOffsetStdev(); random_freq_stdev)
54 {
55 LOG(Level::INFO, "Timing source '{}': applying random frequency offset with stdev {} Hz.", _name,
56 random_freq_stdev.value());
57 _freq_offset += normal_dist(_rng) * random_freq_stdev.value();
58 }
59
60 _phase_offset = timing->getPhaseOffset().value_or(0);
61 if (const std::optional<RealType> random_phase_stdev = timing->getRandomPhaseOffsetStdev(); random_phase_stdev)
62 {
63 LOG(Level::INFO, "Timing source '{}': applying random phase offset with stdev {} radians.", _name,
64 random_phase_stdev.value());
65 _phase_offset += normal_dist(_rng) * random_phase_stdev.value();
66 }
67
68 timing->copyAlphas(_alphas, _weights);
69
70 _model = std::make_unique<noise::ClockModelGenerator>(_rng, _alphas, _weights, _frequency, _phase_offset,
71 _freq_offset, 15);
72
73 if (timing->getFrequency() == 0.0)
74 {
75 LOG(Level::INFO, "Timing source frequency not set, results could be incorrect.");
76 }
77
78 _sync_on_pulse = timing->getSyncOnPulse();
79 _enabled = true;
80 }

References LOG.

◆ isEnabled()

bool timing::Timing::isEnabled ( ) const
noexcept

Checks if the timing source is enabled.

Returns
True if enabled, otherwise false.

Definition at line 116 of file timing.h.

116{ return _enabled && _model && _model->enabled(); }

Referenced by processing::pipeline::advanceTimingModel().

+ Here is the caller graph for this function:

◆ operator=() [1/2]

Timing & timing::Timing::operator= ( const Timing )
delete

◆ operator=() [2/2]

Timing & timing::Timing::operator= ( Timing &&  )
delete

◆ reset()

void timing::Timing::reset ( )
noexcept

Resets the timing model.

Definition at line 136 of file timing.h.

137 {
138 if (_model)
139 {
140 _model->reset();
141 }
142 }

Referenced by processing::pipeline::advanceTimingModel().

+ Here is the caller graph for this function:

◆ skipSamples()

void timing::Timing::skipSamples ( std::size_t  samples)
noexcept

Skips a number of samples in the timing model.

Parameters
samplesThe number of samples to skip.

Definition at line 31 of file timing.cpp.

32 {
33 if (_enabled && _model)
34 {
35 _model->skipSamples(samples);
36 }
37 }

Referenced by processing::pipeline::advanceTimingModel().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: