FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
prototype_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 prototype_timing.h
10 * @brief Header file for the PrototypeTiming class.
11 */
12
13#pragma once
14
15#include <optional>
16#include <string>
17#include <utility>
18#include <vector>
19
20#include "core/config.h"
21#include "core/sim_id.h"
22
23namespace timing
24{
25 /**
26 * @class PrototypeTiming
27 * @brief Manages timing properties such as frequency, offsets, and synchronization.
28 */
30 {
31 public:
32 /**
33 * @brief Constructor for PrototypeTiming.
34 *
35 * @param name The name of the timing source.
36 */
37 explicit PrototypeTiming(std::string name, const SimId id = 0) noexcept :
38 _id(id == 0 ? SimIdGenerator::instance().generateId(ObjectType::Timing) : id), _name(std::move(name))
39 {
40 }
41
42 ~PrototypeTiming() = default;
43
45
47
49
51
52 /**
53 * @brief Copies the alphas and weights vectors.
54 *
55 * @param alphas Reference to the vector where alpha values will be copied.
56 * @param weights Reference to the vector where weight values will be copied.
57 */
58 void copyAlphas(std::vector<RealType>& alphas, std::vector<RealType>& weights) const noexcept;
59
60 /**
61 * @brief Gets the current frequency.
62 *
63 * @return The current frequency value.
64 */
65 [[nodiscard]] RealType getFrequency() const noexcept { return _frequency; }
66
67 /**
68 * @brief Gets the name of the timing source.
69 *
70 * @return The name of the timing source.
71 */
72 [[nodiscard]] std::string getName() const { return _name; }
73
74 /**
75 * @brief Gets the unique ID of the timing source.
76 *
77 * @return The timing source SimId.
78 */
79 [[nodiscard]] SimId getId() const noexcept { return _id; }
80
81 /**
82 * @brief Checks if synchronization on pulse is enabled.
83 *
84 * @return True if synchronization on pulse is enabled, false otherwise.
85 */
86 [[nodiscard]] bool getSyncOnPulse() const noexcept { return _sync_on_pulse; }
87
88 /**
89 * @brief Gets the phase offset.
90 *
91 * @return The phase offset value.
92 */
93 [[nodiscard]] std::optional<RealType> getPhaseOffset() const noexcept { return _phase_offset; }
94
95 /**
96 * @brief Gets the frequency offset.
97 *
98 * @return The frequency offset value.
99 */
100 [[nodiscard]] std::optional<RealType> getFreqOffset() const noexcept { return _freq_offset; }
101
102 [[nodiscard]] std::optional<RealType> getRandomFreqOffsetStdev() const noexcept { return _random_freq_stdev; }
103
104 [[nodiscard]] std::optional<RealType> getRandomPhaseOffsetStdev() const noexcept { return _random_phase_stdev; }
105
106 /**
107 * @brief Sets the frequency value.
108 *
109 * @param freq The frequency value to be set.
110 */
111 void setFrequency(const RealType freq) noexcept { _frequency = freq; }
112
113 /**
114 * @brief Enables synchronization on pulse.
115 */
116 void setSyncOnPulse() noexcept { _sync_on_pulse = true; }
117
118 /**
119 * @brief Disables synchronization on pulse.
120 */
121 void clearSyncOnPulse() noexcept { _sync_on_pulse = false; }
122
123 /**
124 * @brief Sets an alpha and weight value.
125 *
126 * @param alpha The alpha value to be added.
127 * @param weight The weight value to be added.
128 */
129 void setAlpha(RealType alpha, RealType weight) noexcept;
130
131 /**
132 * @brief Clears all noise entries.
133 */
134 void clearNoiseEntries() noexcept;
135
136 /**
137 * @brief Sets the frequency offset.
138 *
139 * @param offset The frequency offset to be set.
140 */
141 void setFreqOffset(RealType offset) noexcept { _freq_offset = offset; }
142
143 /**
144 * @brief Clears the frequency offset.
145 */
146 void clearFreqOffset() noexcept { _freq_offset = std::nullopt; }
147
148 /**
149 * @brief Sets the phase offset.
150 *
151 * @param offset The phase offset to be set.
152 */
153 void setPhaseOffset(RealType offset) noexcept { _phase_offset = offset; }
154
155 /**
156 * @brief Clears the phase offset.
157 */
158 void clearPhaseOffset() noexcept { _phase_offset = std::nullopt; }
159
160 /**
161 * @brief Sets a random frequency offset standard deviation.
162 *
163 * @param stdev The standard deviation for generating the random frequency offset.
164 */
165 void setRandomFreqOffsetStdev(RealType stdev) noexcept { _random_freq_stdev = stdev; }
166
167 /**
168 * @brief Sets a random phase offset standard deviation.
169 *
170 * @param stdev The standard deviation for generating the random phase offset.
171 */
172 void setRandomPhaseOffsetStdev(RealType stdev) noexcept { _random_phase_stdev = stdev; }
173
174 /**
175 * @brief Clears the random frequency offset standard deviation.
176 */
177 void clearRandomFreqOffsetStdev() noexcept { _random_freq_stdev = std::nullopt; }
178
179 /**
180 * @brief Clears the random phase offset standard deviation.
181 */
182 void clearRandomPhaseOffsetStdev() noexcept { _random_phase_stdev = std::nullopt; }
183
184 /**
185 * @brief Sets the name of the timing source.
186 *
187 * @param name The new name.
188 */
189 void setName(std::string name) noexcept { _name = std::move(name); }
190
191 private:
192 SimId _id; ///< Unique ID for this timing source.
193 std::string _name; ///< The name of the timing source.
194 std::vector<RealType> _alphas; ///< Vector of alpha values.
195 std::vector<RealType> _weights; ///< Vector of weight values.
196 std::optional<RealType> _freq_offset; ///< Constant frequency offset.
197 std::optional<RealType> _phase_offset; ///< Constant phase offset.
198 std::optional<RealType> _random_phase_stdev; ///< Random phase offset standard deviation.
199 std::optional<RealType> _random_freq_stdev; ///< Random frequency offset standard deviation.
200 RealType _frequency{0}; ///< The frequency value.
201 bool _sync_on_pulse{false}; ///< Flag indicating synchronization on pulse.
202 };
203}
Thread-safe Meyers singleton for generating unique object IDs.
Definition sim_id.h:42
Manages timing properties such as frequency, offsets, and synchronization.
PrototypeTiming & operator=(PrototypeTiming &&)=default
void clearNoiseEntries() noexcept
Clears all noise entries.
void setSyncOnPulse() noexcept
Enables synchronization on pulse.
void clearPhaseOffset() noexcept
Clears the phase offset.
void setName(std::string name) noexcept
Sets the name of the timing source.
PrototypeTiming(std::string name, const SimId id=0) noexcept
Constructor for PrototypeTiming.
void setAlpha(RealType alpha, RealType weight) noexcept
Sets an alpha and weight value.
void setRandomPhaseOffsetStdev(RealType stdev) noexcept
Sets a random phase offset standard deviation.
std::optional< RealType > getRandomPhaseOffsetStdev() const noexcept
bool getSyncOnPulse() const noexcept
Checks if synchronization on pulse is enabled.
PrototypeTiming & operator=(const PrototypeTiming &)=default
void clearSyncOnPulse() noexcept
Disables synchronization on pulse.
std::string getName() const
Gets the name of the timing source.
void setFreqOffset(RealType offset) noexcept
Sets the frequency offset.
std::optional< RealType > getRandomFreqOffsetStdev() const noexcept
PrototypeTiming(const PrototypeTiming &)=default
void setPhaseOffset(RealType offset) noexcept
Sets the phase offset.
void setRandomFreqOffsetStdev(RealType stdev) noexcept
Sets a random frequency offset standard deviation.
RealType getFrequency() const noexcept
Gets the current frequency.
void setFrequency(const RealType freq) noexcept
Sets the frequency value.
void clearRandomPhaseOffsetStdev() noexcept
Clears the random phase offset standard deviation.
PrototypeTiming(PrototypeTiming &&)=default
std::optional< RealType > getPhaseOffset() const noexcept
Gets the phase offset.
void clearFreqOffset() noexcept
Clears the frequency offset.
void copyAlphas(std::vector< RealType > &alphas, std::vector< RealType > &weights) const noexcept
Copies the alphas and weights vectors.
SimId getId() const noexcept
Gets the unique ID of the timing source.
void clearRandomFreqOffsetStdev() noexcept
Clears the random frequency offset standard deviation.
std::optional< RealType > getFreqOffset() const noexcept
Gets the frequency offset.
Represents a timing source for simulation.
Definition timing.h:36
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
uint64_t SimId
64-bit Unique Simulation ID.
Definition sim_id.h:18
ObjectType
Categorizes objects for ID generation.
Definition sim_id.h:25