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) 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.
 
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 (long long 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 33 of file timing.h.

Constructor & Destructor Documentation

◆ Timing() [1/3]

timing::Timing::Timing ( std::string  name,
unsigned  seed 
)
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: _name(std::move(name)), _rng(seed), _seed(seed) {}

◆ ~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 78 of file timing.cpp.

79 {
80 if (!_prototype)
81 {
82 LOG(Level::FATAL, "Cannot clone a Timing object that has not been initialized from a prototype.");
83 throw std::logic_error("Cannot clone a Timing object that has not been initialized from a prototype.");
84 }
85 auto new_timing = std::make_unique<Timing>(_name, _seed);
86 new_timing->initializeModel(_prototype);
87 return new_timing;
88 }
#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 86 of file timing.h.

86{ 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 80 of file timing.h.

80{ return _frequency; }

◆ 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 66 of file timing.h.

66{ return _name; }

◆ getNextSample()

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

Gets the next sample from the timing source.

Returns
The next sample value or 0.0f if not enabled.

Definition at line 59 of file timing.h.

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

◆ getPhaseOffset()

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

Gets the phase offset of the timing source.

Returns
The phase offset.

Definition at line 92 of file timing.h.

92{ return _phase_offset; }

◆ 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 73 of file timing.h.

73{ return _sync_on_pulse; }

◆ initializeModel()

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

Initializes the timing model.

Parameters
timingThe prototype timing configuration used for initialization.

Definition at line 35 of file timing.cpp.

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

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 99 of file timing.h.

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

◆ 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 119 of file timing.h.

120 {
121 if (_model)
122 {
123 _model->reset();
124 }
125 }

◆ skipSamples()

void timing::Timing::skipSamples ( long long  samples)
noexcept

Skips a number of samples in the timing model.

Parameters
samplesThe number of samples to skip.

Definition at line 27 of file timing.cpp.

28 {
29 if (_enabled && _model)
30 {
31 _model->skipSamples(samples);
32 }
33 }

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