FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
timing.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2006-2008 Marc Brooker and Michael Inggs
4// Copyright (c) 2008-present FERS Contributors (see AUTHORS.md).
5//
6// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
7
8/**
9 * @file timing.h
10 * @brief Timing source for simulation objects.
11 *
12 * All objects must adhere to a common timing source, which is modeled and adjusted by the methods in this class.
13 */
14
15#pragma once
16
17#include <memory>
18#include <random>
19#include <string>
20#include <vector>
21
22#include "core/config.h"
24
25namespace timing
26{
27 class PrototypeTiming;
28
29 /**
30 * @class Timing
31 * @brief Represents a timing source for simulation.
32 */
33 class Timing final
34 {
35 public:
36 /**
37 * @brief Constructs a Timing object.
38 *
39 * @param name The name of the timing source.
40 * @param seed The seed for the timing source's internal random number generator.
41 */
42 explicit Timing(std::string name, unsigned seed) noexcept;
43
44 ~Timing() = default;
45
46 Timing(const Timing&) = delete;
47
48 Timing& operator=(const Timing&) = delete;
49
50 Timing(Timing&&) = delete;
51
52 Timing& operator=(Timing&&) = delete;
53
54 /**
55 * @brief Gets the next sample from the timing source.
56 *
57 * @return The next sample value or 0.0f if not enabled.
58 */
59 [[nodiscard]] RealType getNextSample() const noexcept { return _enabled ? _model->getSample() : 0.0f; }
60
61 /**
62 * @brief Gets the name of the timing source.
63 *
64 * @return The name of the timing source.
65 */
66 [[nodiscard]] std::string getName() const noexcept { return _name; }
67
68 /**
69 * @brief Checks if the timing source synchronizes on pulse.
70 *
71 * @return True if synchronized on pulse, otherwise false.
72 */
73 [[nodiscard]] bool getSyncOnPulse() const noexcept { return _sync_on_pulse; }
74
75 /**
76 * @brief Gets the frequency of the timing source.
77 *
78 * @return The frequency of the timing source.
79 */
80 [[nodiscard]] RealType getFrequency() const noexcept { return _frequency; }
81
82 /**
83 * @brief Gets the frequency offset of the timing source.
84 * @return The frequency offset.
85 */
86 [[nodiscard]] RealType getFreqOffset() const noexcept { return _freq_offset; }
87
88 /**
89 * @brief Gets the phase offset of the timing source.
90 * @return The phase offset.
91 */
92 [[nodiscard]] RealType getPhaseOffset() const noexcept { return _phase_offset; }
93
94 /**
95 * @brief Checks if the timing source is enabled.
96 *
97 * @return True if enabled, otherwise false.
98 */
99 [[nodiscard]] bool isEnabled() const noexcept { return _enabled && _model && _model->enabled(); }
100
101 /**
102 * @brief Skips a number of samples in the timing model.
103 *
104 * @param samples The number of samples to skip.
105 */
106 void skipSamples(long long samples) noexcept;
107
108 /**
109 * @brief Initializes the timing model.
110 *
111 * @param timing The prototype timing configuration used for initialization.
112 */
113 void initializeModel(const PrototypeTiming* timing) noexcept;
114
115 /**
116 * @brief Resets the timing model.
117 */
118 // NOLINTNEXTLINE(readability-make-member-function-const)
119 void reset() noexcept
120 {
121 if (_model)
122 {
123 _model->reset();
124 }
125 }
126
127 /**
128 * @brief Creates a new Timing instance based on the same prototype.
129 * @return A unique_ptr to the new Timing object.
130 * @throws std::logic_error if the timing object was not initialized from a prototype.
131 */
132 [[nodiscard]] std::unique_ptr<Timing> clone() const;
133
134 private:
135 std::string _name; ///< The name of the timing source.
136 bool _enabled{false}; ///< Flag indicating if the timing source is enabled.
137 std::unique_ptr<noise::ClockModelGenerator> _model{nullptr}; ///< Noise generator model for the timing source.
138 std::vector<RealType> _alphas; ///< The alpha values for the noise generator model.
139 std::vector<RealType> _weights; ///< The weights for the noise generator model.
140 RealType _frequency{}; ///< The frequency of the timing source.
141 RealType _freq_offset{}; ///< The frequency offset of the timing source.
142 RealType _phase_offset{}; ///< The phase offset of the timing source.
143 bool _sync_on_pulse{false}; ///< Flag indicating if the timing source synchronizes on pulse.
144 std::mt19937 _rng; ///< Per-object random number generator for statistical independence.
145 const PrototypeTiming* _prototype{nullptr}; ///< Pointer to the prototype used for initialization.
146 unsigned _seed; ///< The initial seed for the RNG.
147 };
148}
Manages timing properties such as frequency, offsets, and synchronization.
Represents a timing source for simulation.
Definition timing.h:34
Timing & operator=(Timing &&)=delete
std::string getName() const noexcept
Gets the name of the timing source.
Definition timing.h:66
void reset() noexcept
Resets the timing model.
Definition timing.h:119
Timing & operator=(const Timing &)=delete
Timing(Timing &&)=delete
~Timing()=default
void initializeModel(const PrototypeTiming *timing) noexcept
Initializes the timing model.
Definition timing.cpp:35
RealType getNextSample() const noexcept
Gets the next sample from the timing source.
Definition timing.h:59
void skipSamples(long long samples) noexcept
Skips a number of samples in the timing model.
Definition timing.cpp:27
RealType getFreqOffset() const noexcept
Gets the frequency offset of the timing source.
Definition timing.h:86
bool getSyncOnPulse() const noexcept
Checks if the timing source synchronizes on pulse.
Definition timing.h:73
bool isEnabled() const noexcept
Checks if the timing source is enabled.
Definition timing.h:99
RealType getFrequency() const noexcept
Gets the frequency of the timing source.
Definition timing.h:80
Timing(const Timing &)=delete
RealType getPhaseOffset() const noexcept
Gets the phase offset of the timing source.
Definition timing.h:92
std::unique_ptr< Timing > clone() const
Creates a new Timing instance based on the same prototype.
Definition timing.cpp:78
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
Header file for noise generator classes.