A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
waveform-generator.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2009 CTTC
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Nicola Baldo <nbaldo@cttc.es>
19
*/
20
21
22
#include <ns3/object-factory.h>
23
#include <ns3/log.h>
24
#include <ns3/simulator.h>
25
#include <ns3/double.h>
26
#include <ns3/packet-burst.h>
27
#include <ns3/antenna-model.h>
28
29
#include "
waveform-generator.h
"
30
31
NS_LOG_COMPONENT_DEFINE
(
"WaveformGenerator"
);
32
33
namespace
ns3 {
34
35
NS_OBJECT_ENSURE_REGISTERED
(WaveformGenerator);
36
37
WaveformGenerator::WaveformGenerator
()
38
: m_mobility (0),
39
m_netDevice (0),
40
m_channel (0),
41
m_txPowerSpectralDensity (0),
42
m_startTime (
Seconds
(0)),
43
m_active (false)
44
{
45
46
}
47
48
49
WaveformGenerator::~WaveformGenerator
()
50
{
51
52
}
53
54
55
void
56
WaveformGenerator::DoDispose
(
void
)
57
{
58
NS_LOG_FUNCTION
(
this
);
59
m_channel
= 0;
60
m_netDevice
= 0;
61
m_mobility
= 0;
62
}
63
64
TypeId
65
WaveformGenerator::GetTypeId
(
void
)
66
{
67
static
TypeId
tid =
TypeId
(
"ns3::WaveformGenerator"
)
68
.
SetParent
<
SpectrumPhy
> ()
69
.AddConstructor<WaveformGenerator> ()
70
.AddAttribute (
"Period"
,
71
"the period (=1/frequency)"
,
72
TimeValue
(
Seconds
(1.0)),
73
MakeTimeAccessor (&
WaveformGenerator::SetPeriod
,
74
&
WaveformGenerator::GetPeriod
),
75
MakeTimeChecker ())
76
.AddAttribute (
"DutyCycle"
,
77
"the duty cycle of the generator, i.e., the fraction of the period that is occupied by a signal"
,
78
DoubleValue
(0.5),
79
MakeDoubleAccessor (&
WaveformGenerator::SetDutyCycle
,
80
&
WaveformGenerator::GetDutyCycle
),
81
MakeDoubleChecker<double> ())
82
.AddTraceSource (
"TxStart"
,
83
"Trace fired when a new transmission is started"
,
84
MakeTraceSourceAccessor
(&
WaveformGenerator::m_phyTxStartTrace
))
85
.AddTraceSource (
"TxEnd"
,
86
"Trace fired when a previosuly started transmission is finished"
,
87
MakeTraceSourceAccessor
(&
WaveformGenerator::m_phyTxEndTrace
))
88
;
89
return
tid;
90
}
91
92
93
94
Ptr<NetDevice>
95
WaveformGenerator::GetDevice
()
96
{
97
return
m_netDevice
;
98
}
99
100
101
Ptr<MobilityModel>
102
WaveformGenerator::GetMobility
()
103
{
104
return
m_mobility
;
105
}
106
107
108
Ptr<const SpectrumModel>
109
WaveformGenerator::GetRxSpectrumModel
()
const
110
{
111
// this device is not interested in RX
112
return
0;
113
}
114
115
void
116
WaveformGenerator::SetDevice
(
Ptr<NetDevice>
d)
117
{
118
m_netDevice
= d;
119
}
120
121
122
void
123
WaveformGenerator::SetMobility
(
Ptr<MobilityModel>
m)
124
{
125
m_mobility
= m;
126
}
127
128
129
void
130
WaveformGenerator::SetChannel
(
Ptr<SpectrumChannel>
c)
131
{
132
NS_LOG_FUNCTION_NOARGS
();
133
m_channel
= c;
134
}
135
136
137
138
void
139
WaveformGenerator::StartRx
(
Ptr<SpectrumSignalParameters>
params)
140
{
141
NS_LOG_FUNCTION
(
this
<< params);
142
}
143
144
void
145
WaveformGenerator::SetTxPowerSpectralDensity
(
Ptr<SpectrumValue>
txPsd)
146
{
147
NS_LOG_FUNCTION
(
this
<< *txPsd);
148
m_txPowerSpectralDensity
= txPsd;
149
}
150
151
Ptr<AntennaModel>
152
WaveformGenerator::GetRxAntenna
()
153
{
154
return
m_antenna
;
155
}
156
157
void
158
WaveformGenerator::SetAntenna
(
Ptr<AntennaModel>
a)
159
{
160
NS_LOG_FUNCTION
(
this
<< a);
161
m_antenna
= a;
162
}
163
164
void
165
WaveformGenerator::SetPeriod
(
Time
period)
166
{
167
m_period
= period;
168
}
169
170
Time
171
WaveformGenerator::GetPeriod
()
const
172
{
173
return
m_period
;
174
}
175
176
177
178
void
179
WaveformGenerator::SetDutyCycle
(
double
dutyCycle)
180
{
181
m_dutyCycle
= dutyCycle;
182
}
183
184
double
WaveformGenerator::GetDutyCycle
()
const
185
{
186
return
m_dutyCycle
;
187
}
188
189
190
191
void
192
WaveformGenerator::GenerateWaveform
()
193
{
194
NS_LOG_FUNCTION
(
this
);
195
196
Ptr<SpectrumSignalParameters>
txParams = Create<SpectrumSignalParameters> ();
197
txParams->duration =
Time
(
m_period
*
m_dutyCycle
);
198
txParams->psd =
m_txPowerSpectralDensity
;
199
txParams->txPhy = GetObject<SpectrumPhy> ();
200
txParams->txAntenna =
m_antenna
;
201
202
NS_LOG_LOGIC
(
"generating waveform : "
<< *
m_txPowerSpectralDensity
);
203
m_phyTxStartTrace
(0);
204
m_channel
->
StartTx
(txParams);
205
206
if
(
m_active
)
207
{
208
NS_LOG_LOGIC
(
"scheduling next waveform"
);
209
Simulator::Schedule
(
m_period
, &
WaveformGenerator::GenerateWaveform
,
this
);
210
}
211
}
212
213
214
void
215
WaveformGenerator::Start
()
216
{
217
NS_LOG_FUNCTION
(
this
);
218
if
(!
m_active
)
219
{
220
NS_LOG_LOGIC
(
"generator was not active, now starting"
);
221
m_active
=
true
;
222
m_startTime
=
Now
();
223
Simulator::ScheduleNow
(&
WaveformGenerator::GenerateWaveform
,
this
);
224
}
225
}
226
227
228
void
229
WaveformGenerator::Stop
()
230
{
231
NS_LOG_FUNCTION
(
this
);
232
m_active
=
false
;
233
}
234
235
236
}
// namespace ns3
src
spectrum
model
waveform-generator.cc
Generated on Tue Oct 9 2012 16:45:46 for ns-3 by
1.8.1.2