A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
uan-tx-mode.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Leonard Tracy <lentracy@gmail.com>
7 */
8#include "uan-tx-mode.h"
9
10#include "ns3/log.h"
11
12#include <map>
13#include <utility>
14
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("UanTxMode");
19
23
27
33
39
45
51
57
63
64std::string
69
72{
73 return m_uid;
74}
75
76std::ostream&
77operator<<(std::ostream& os, const UanTxMode& mode)
78{
79 os << mode.m_uid;
80 return os;
81}
82
83std::istream&
84operator>>(std::istream& is, UanTxMode& mode)
85{
86 std::string name;
87 uint32_t duh;
88
89 is >> duh;
90
91 mode.m_uid = duh;
92 return is;
93}
94
96 : m_nextUid(0)
97{
98}
99
104
105bool
107{
108 auto it = m_modes.begin();
109
110 for (; it != m_modes.end(); it++)
111 {
112 if ((*it).second.m_name == name)
113 {
114 return true;
115 }
116 }
117 return false;
118}
119
122 uint32_t dataRateBps,
123 uint32_t phyRateSps,
124 uint32_t cfHz,
125 uint32_t bwHz,
126 uint32_t constSize,
127 std::string name)
128{
130
131 UanTxModeItem* item;
132
133 if (factory.NameUsed(name))
134 {
135 NS_LOG_WARN("Redefining UanTxMode with name \"" << name << "\"");
136 item = &factory.GetModeItem(name);
137 }
138 else
139 {
140 item = &factory.m_modes[factory.m_nextUid];
141 item->m_uid = factory.m_nextUid++;
142 }
143
144 item->m_type = type;
145 item->m_dataRateBps = dataRateBps;
146 item->m_phyRateSps = phyRateSps;
147 item->m_cfHz = cfHz;
148 item->m_bwHz = bwHz;
149 item->m_constSize = constSize;
150 item->m_name = name;
151 return factory.MakeModeFromItem(*item);
152}
153
156{
157 if (uid >= m_nextUid)
158 {
159 NS_FATAL_ERROR("Attempting to retrieve UanTxMode with uid, " << uid << ", >= m_nextUid");
160 }
161
162 return m_modes[uid];
163}
164
167{
168 auto it = m_modes.begin();
169 for (; it != m_modes.end(); it++)
170 {
171 if ((*it).second.m_name == name)
172 {
173 return (*it).second;
174 }
175 }
176 NS_FATAL_ERROR("Unknown mode, \"" << name << "\", requested from mode factory");
177 return (*it).second; // dummy to get rid of warning
178}
179
182{
184 return factory.MakeModeFromItem(factory.GetModeItem(name));
185}
186
189{
191 return factory.MakeModeFromItem(factory.GetModeItem(uid));
192}
193
196{
197 UanTxMode mode;
198 mode.m_uid = item.m_uid;
199 return mode;
200}
201
204{
205 static UanTxModeFactory factory;
206 return factory;
207}
208
212
214{
215 m_modes.clear();
216}
217
218void
220{
221 m_modes.push_back(newMode);
222}
223
224void
226{
227 NS_ASSERT(modeNum < m_modes.size());
228
229 auto it = m_modes.begin();
230 for (uint32_t i = 0; i < modeNum; i++)
231 {
232 it++;
233 }
234 it = m_modes.erase(it);
235}
236
239{
240 NS_ASSERT(i < m_modes.size());
241 return m_modes[i];
242}
243
246{
247 return static_cast<uint32_t>(m_modes.size());
248}
249
250std::ostream&
251operator<<(std::ostream& os, const UanModesList& ml)
252{
253 os << ml.GetNModes() << "|";
254
255 for (uint32_t i = 0; i < ml.m_modes.size(); i++)
256 {
257 os << ml[i] << "|";
258 }
259 return os;
260}
261
262std::istream&
263operator>>(std::istream& is, UanModesList& ml)
264{
265 char c = '\0';
266
267 int numModes;
268
269 is >> numModes >> c;
270 if (c != '|')
271 {
272 is.setstate(std::ios_base::failbit);
273 return is;
274 }
275 ml.m_modes.clear();
276 ml.m_modes.resize(numModes);
277
278 if (numModes == 0 && is.peek() == std::istream::traits_type::eof())
279 {
280 return is;
281 }
282
283 int i;
284 for (i = 0; is.peek() != std::istream::traits_type::eof() && i < numModes; i++)
285 {
286 is >> ml.m_modes[i] >> c;
287 if (c != '|')
288 {
289 is.setstate(std::ios_base::failbit);
290 return is;
291 }
292 }
293 if (i < numModes)
294 {
295 is.setstate(std::ios_base::failbit);
296 }
297
298 return is;
299}
300
302
303} // namespace ns3
Container for UanTxModes.
void DeleteMode(uint32_t num)
Delete the mode at given index.
UanModesList()
Constructor.
uint32_t GetNModes() const
Get the number of modes in this list.
void AppendMode(UanTxMode mode)
Add mode to this list.
UanTxMode operator[](uint32_t index) const
Retrieve a mode by index.
virtual ~UanModesList()
Destructor.
std::vector< UanTxMode > m_modes
The vector of modes in this list.
Global database of UanTxMode objects, retrievable by id or name.
static UanTxMode CreateMode(UanTxMode::ModulationType type, uint32_t dataRateBps, uint32_t phyRateSps, uint32_t cfHz, uint32_t bwHz, uint32_t constSize, std::string name)
UanTxMode MakeModeFromItem(const UanTxModeItem &item)
Create a public UanTxMode from an internal UanTxModeItem.
UanTxModeFactory()
Constructor.
static UanTxModeFactory & GetFactory()
Construct and get the static global factory instance.
static UanTxMode GetMode(std::string name)
Get a mode by name.
std::map< uint32_t, UanTxModeItem > m_modes
Container for modes.
~UanTxModeFactory()
Destructor.
bool NameUsed(std::string name)
Check if the mode name already exists.
uint32_t m_nextUid
next id number
UanTxModeItem & GetModeItem(uint32_t uid)
Get a mode by id.
Abstraction of packet modulation information.
Definition uan-tx-mode.h:32
uint32_t GetUid() const
Get a unique id for the mode.
ModulationType
Modulation type.
Definition uan-tx-mode.h:41
uint32_t GetConstellationSize() const
Get the number of constellation points in the modulation scheme.
uint32_t GetPhyRateSps() const
Get the physical signaling rate.
uint32_t GetDataRateBps() const
Get the data rate of the transmit mode.
~UanTxMode()
Destructor.
uint32_t GetBandwidthHz() const
Get the transmission signal bandwidth.
std::string GetName() const
Get the mode name.
UanTxMode()
Constructor.
uint32_t m_uid
Mode id.
ModulationType GetModType() const
Get the modulation type of the mode.
uint32_t GetCenterFreqHz() const
Get the transmission center frequency.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition log.h:250
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition angles.cc:148
std::istream & operator>>(std::istream &is, Angles &a)
Definition angles.cc:172
Container for the UanTxMode properties.
uint32_t m_constSize
Modulation constellation size (2 for BPSK, 4 for QPSK).
uint32_t m_phyRateSps
Symbol rate in symbols per second.
std::string m_name
Unique string name for this transmission mode.
UanTxMode::ModulationType m_type
Modulation type.
uint32_t m_bwHz
Bandwidth in Hz.
uint32_t m_dataRateBps
Data rate in BPS.
uint32_t m_cfHz
Center frequency in Hz.