View | Details | Raw Unified | Return to bug 1774
Collapse All | Expand All

(-)a/src/lr-wpan/bindings/modulegen__gcc_ILP32.py (-2 / +8 lines)
 Lines 1702-1711    Link Here 
1702
    cls.add_method('CreateTxPowerSpectralDensity', 
1702
    cls.add_method('CreateTxPowerSpectralDensity', 
1703
                   'ns3::Ptr< ns3::SpectrumValue >', 
1703
                   'ns3::Ptr< ns3::SpectrumValue >', 
1704
                   [param('double', 'txPower'), param('uint32_t', 'channel')])
1704
                   [param('double', 'txPower'), param('uint32_t', 'channel')])
1705
    ## lr-wpan-spectrum-value-helper.h (module 'lr-wpan'): static double ns3::LrWpanSpectrumValueHelper::TotalAvgPower(ns3::Ptr<ns3::SpectrumValue const> psd) [member function]
1705
    ## lr-wpan-spectrum-value-helper.h (module 'lr-wpan'): static double ns3::LrWpanSpectrumValueHelper::TotalAvgPower(ns3::Ptr<ns3::SpectrumValue const> psd, uint32_t channel) [member function]
1706
    cls.add_method('TotalAvgPower', 
1706
    cls.add_method('TotalAvgPower', 
1707
                   'double', 
1707
                   'double', 
1708
                   [param('ns3::Ptr< ns3::SpectrumValue const >', 'psd')], 
1708
                   [param('ns3::Ptr< ns3::SpectrumValue const >', 'psd'), param('uint32_t', 'channel')], 
1709
                   is_static=True)
1709
                   is_static=True)
1710
    return
1710
    return
1711
1711
 Lines 2929-2934    Link Here 
2929
def register_Ns3LrWpanHelper_methods(root_module, cls):
2929
def register_Ns3LrWpanHelper_methods(root_module, cls):
2930
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::LrWpanHelper::LrWpanHelper() [constructor]
2930
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::LrWpanHelper::LrWpanHelper() [constructor]
2931
    cls.add_constructor([])
2931
    cls.add_constructor([])
2932
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::LrWpanHelper::LrWpanHelper(bool useMultiModelSpectrumChannel) [constructor]
2933
    cls.add_constructor([param('bool', 'useMultiModelSpectrumChannel')])
2934
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::Ptr<ns3::SpectrumChannel> ns3::LrWpanHelper::GetChannel() [member function]
2935
    cls.add_method('GetChannel', 
2936
                   'ns3::Ptr< ns3::SpectrumChannel >', 
2937
                   [])
2932
    ## lr-wpan-helper.h (module 'lr-wpan'): void ns3::LrWpanHelper::AddMobility(ns3::Ptr<ns3::LrWpanPhy> phy, ns3::Ptr<ns3::MobilityModel> m) [member function]
2938
    ## lr-wpan-helper.h (module 'lr-wpan'): void ns3::LrWpanHelper::AddMobility(ns3::Ptr<ns3::LrWpanPhy> phy, ns3::Ptr<ns3::MobilityModel> m) [member function]
2933
    cls.add_method('AddMobility', 
2939
    cls.add_method('AddMobility', 
2934
                   'void', 
2940
                   'void', 
(-)a/src/lr-wpan/bindings/modulegen__gcc_LP64.py (-2 / +8 lines)
 Lines 1702-1711    Link Here 
1702
    cls.add_method('CreateTxPowerSpectralDensity', 
1702
    cls.add_method('CreateTxPowerSpectralDensity', 
1703
                   'ns3::Ptr< ns3::SpectrumValue >', 
1703
                   'ns3::Ptr< ns3::SpectrumValue >', 
1704
                   [param('double', 'txPower'), param('uint32_t', 'channel')])
1704
                   [param('double', 'txPower'), param('uint32_t', 'channel')])
1705
    ## lr-wpan-spectrum-value-helper.h (module 'lr-wpan'): static double ns3::LrWpanSpectrumValueHelper::TotalAvgPower(ns3::Ptr<ns3::SpectrumValue const> psd) [member function]
1705
    ## lr-wpan-spectrum-value-helper.h (module 'lr-wpan'): static double ns3::LrWpanSpectrumValueHelper::TotalAvgPower(ns3::Ptr<ns3::SpectrumValue const> psd, uint32_t channel) [member function]
1706
    cls.add_method('TotalAvgPower', 
1706
    cls.add_method('TotalAvgPower', 
1707
                   'double', 
1707
                   'double', 
1708
                   [param('ns3::Ptr< ns3::SpectrumValue const >', 'psd')], 
1708
                   [param('ns3::Ptr< ns3::SpectrumValue const >', 'psd'), param('uint32_t', 'channel')], 
1709
                   is_static=True)
1709
                   is_static=True)
1710
    return
1710
    return
1711
1711
 Lines 2929-2934    Link Here 
2929
def register_Ns3LrWpanHelper_methods(root_module, cls):
2929
def register_Ns3LrWpanHelper_methods(root_module, cls):
2930
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::LrWpanHelper::LrWpanHelper() [constructor]
2930
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::LrWpanHelper::LrWpanHelper() [constructor]
2931
    cls.add_constructor([])
2931
    cls.add_constructor([])
2932
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::LrWpanHelper::LrWpanHelper(bool useMultiModelSpectrumChannel) [constructor]
2933
    cls.add_constructor([param('bool', 'useMultiModelSpectrumChannel')])
2934
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::Ptr<ns3::SpectrumChannel> ns3::LrWpanHelper::GetChannel() [member function]
2935
    cls.add_method('GetChannel', 
2936
                   'ns3::Ptr< ns3::SpectrumChannel >', 
2937
                   [])
2932
    ## lr-wpan-helper.h (module 'lr-wpan'): void ns3::LrWpanHelper::AddMobility(ns3::Ptr<ns3::LrWpanPhy> phy, ns3::Ptr<ns3::MobilityModel> m) [member function]
2938
    ## lr-wpan-helper.h (module 'lr-wpan'): void ns3::LrWpanHelper::AddMobility(ns3::Ptr<ns3::LrWpanPhy> phy, ns3::Ptr<ns3::MobilityModel> m) [member function]
2933
    cls.add_method('AddMobility', 
2939
    cls.add_method('AddMobility', 
2934
                   'void', 
2940
                   'void', 
(-)a/src/lr-wpan/examples/lr-wpan-error-distance-plot.cc (-1 / +2 lines)
 Lines 37-42    Link Here 
37
#include <ns3/node.h>
37
#include <ns3/node.h>
38
#include <ns3/net-device.h>
38
#include <ns3/net-device.h>
39
#include <ns3/single-model-spectrum-channel.h>
39
#include <ns3/single-model-spectrum-channel.h>
40
#include <ns3/multi-model-spectrum-channel.h>
40
#include <ns3/mac16-address.h>
41
#include <ns3/mac16-address.h>
41
#include <ns3/constant-position-mobility-model.h>
42
#include <ns3/constant-position-mobility-model.h>
42
#include <ns3/uinteger.h>
43
#include <ns3/uinteger.h>
 Lines 95-101    Link Here 
95
  Ptr<LrWpanNetDevice> dev1 = CreateObject<LrWpanNetDevice> ();
96
  Ptr<LrWpanNetDevice> dev1 = CreateObject<LrWpanNetDevice> ();
96
  dev0->SetAddress (Mac16Address ("00:01"));
97
  dev0->SetAddress (Mac16Address ("00:01"));
97
  dev1->SetAddress (Mac16Address ("00:02"));
98
  dev1->SetAddress (Mac16Address ("00:02"));
98
  Ptr<SingleModelSpectrumChannel> channel = CreateObject<SingleModelSpectrumChannel> ();
99
  Ptr<MultiModelSpectrumChannel> channel = CreateObject<MultiModelSpectrumChannel> ();
99
  Ptr<LogDistancePropagationLossModel> model = CreateObject<LogDistancePropagationLossModel> ();
100
  Ptr<LogDistancePropagationLossModel> model = CreateObject<LogDistancePropagationLossModel> ();
100
  channel->AddPropagationLossModel (model);
101
  channel->AddPropagationLossModel (model);
101
  dev0->SetChannel (channel);
102
  dev0->SetChannel (channel);
(-)a/src/lr-wpan/helper/lr-wpan-helper.cc (-2 / +47 lines)
 Lines 25-32    Link Here 
25
#include <ns3/lr-wpan-net-device.h>
25
#include <ns3/lr-wpan-net-device.h>
26
#include <ns3/mobility-model.h>
26
#include <ns3/mobility-model.h>
27
#include <ns3/single-model-spectrum-channel.h>
27
#include <ns3/single-model-spectrum-channel.h>
28
#include <ns3/multi-model-spectrum-channel.h>
28
#include <ns3/propagation-loss-model.h>
29
#include <ns3/propagation-loss-model.h>
30
#include <ns3/propagation-delay-model.h>
29
#include <ns3/log.h>
31
#include <ns3/log.h>
32
#include "ns3/names.h"
30
33
31
namespace ns3 {
34
namespace ns3 {
32
35
 Lines 63-70    Link Here 
63
LrWpanHelper::LrWpanHelper (void)
66
LrWpanHelper::LrWpanHelper (void)
64
{
67
{
65
  m_channel = CreateObject<SingleModelSpectrumChannel> ();
68
  m_channel = CreateObject<SingleModelSpectrumChannel> ();
66
  Ptr<LogDistancePropagationLossModel> model = CreateObject<LogDistancePropagationLossModel> ();
69
67
  m_channel->AddPropagationLossModel (model);
70
  Ptr<LogDistancePropagationLossModel> lossModel = CreateObject<LogDistancePropagationLossModel> ();
71
  m_channel->AddPropagationLossModel (lossModel);
72
73
  Ptr<ConstantSpeedPropagationDelayModel> delayModel = CreateObject<ConstantSpeedPropagationDelayModel> ();
74
  m_channel->SetPropagationDelayModel (delayModel);
75
}
76
77
LrWpanHelper::LrWpanHelper (bool useMultiModelSpectrumChannel)
78
{
79
  if (useMultiModelSpectrumChannel)
80
    {
81
      m_channel = CreateObject<MultiModelSpectrumChannel> ();
82
    }
83
  else
84
    {
85
      m_channel = CreateObject<SingleModelSpectrumChannel> ();
86
    }
87
  Ptr<LogDistancePropagationLossModel> lossModel = CreateObject<LogDistancePropagationLossModel> ();
88
  m_channel->AddPropagationLossModel (lossModel);
89
90
  Ptr<ConstantSpeedPropagationDelayModel> delayModel = CreateObject<ConstantSpeedPropagationDelayModel> ();
91
  m_channel->SetPropagationDelayModel (delayModel);
68
}
92
}
69
93
70
LrWpanHelper::~LrWpanHelper (void)
94
LrWpanHelper::~LrWpanHelper (void)
 Lines 167-172    Link Here 
167
  return devices;
191
  return devices;
168
}
192
}
169
193
194
195
Ptr<SpectrumChannel>
196
LrWpanHelper::GetChannel (void)
197
{
198
  return m_channel;
199
}
200
201
void
202
LrWpanHelper::SetChannel (Ptr<SpectrumChannel> channel)
203
{
204
  m_channel = channel;
205
}
206
207
void
208
LrWpanHelper::SetChannel (std::string channelName)
209
{
210
  Ptr<SpectrumChannel> channel = Names::Find<SpectrumChannel> (channelName);
211
  m_channel = channel;
212
}
213
214
170
int64_t
215
int64_t
171
LrWpanHelper::AssignStreams (NetDeviceContainer c, int64_t stream)
216
LrWpanHelper::AssignStreams (NetDeviceContainer c, int64_t stream)
172
{
217
{
(-)a/src/lr-wpan/helper/lr-wpan-helper.h (-6 / +32 lines)
 Lines 29-35    Link Here 
29
29
30
namespace ns3 {
30
namespace ns3 {
31
31
32
class SingleModelSpectrumChannel;
32
class SpectrumChannel;
33
class MobilityModel;
33
class MobilityModel;
34
34
35
/**
35
/**
 Lines 50-62    Link Here 
50
   * \brief Create a LrWpan helper in an empty state.
50
   * \brief Create a LrWpan helper in an empty state.
51
   */
51
   */
52
  LrWpanHelper (void);
52
  LrWpanHelper (void);
53
54
  /**
55
   * \brief Create a LrWpan helper in an empty state with either a
56
   * SingleModelSpectrumChannel or a MultiModelSpectrumChannel.
57
   * \param useMultiModelSpectrumChannel use a MultiModelSpectrumChannel if true, a SingleModelSpectrumChannel otherwise
58
   */
59
  LrWpanHelper (bool useMultiModelSpectrumChannel);
60
53
  virtual ~LrWpanHelper (void);
61
  virtual ~LrWpanHelper (void);
54
62
55
  /**
63
  /**
56
  * \brief Add mobility model to a physical device
64
   * \brief Get the channel associated to this helper
57
  * \param phy the physical device
65
   * \returns the channel
58
  * \param m the mobility model
66
   */
59
  */
67
  Ptr<SpectrumChannel> GetChannel (void);
68
69
  /**
70
   * \brief Set the channel associated to this helper
71
   * \param channel the channel
72
   */
73
  void SetChannel (Ptr<SpectrumChannel> channel);
74
75
  /**
76
   * \brief Set the channel associated to this helper
77
   * \param channelName the channel name
78
   */
79
  void SetChannel (std::string channelName);
80
81
  /**
82
   * \brief Add mobility model to a physical device
83
   * \param phy the physical device
84
   * \param m the mobility model
85
   */
60
  void AddMobility (Ptr<LrWpanPhy> phy, Ptr<MobilityModel> m);
86
  void AddMobility (Ptr<LrWpanPhy> phy, Ptr<MobilityModel> m);
61
87
62
  /**
88
  /**
 Lines 151-157    Link Here 
151
                                    bool explicitFilename);
177
                                    bool explicitFilename);
152
178
153
private:
179
private:
154
  Ptr<SingleModelSpectrumChannel> m_channel; //!< channel to be used for the devices
180
  Ptr<SpectrumChannel> m_channel; //!< channel to be used for the devices
155
181
156
};
182
};
157
183
(-)a/src/lr-wpan/model/lr-wpan-phy.cc (-19 / +46 lines)
 Lines 260-279    Link Here 
260
  NS_LOG_FUNCTION (this << spectrumRxParams);
260
  NS_LOG_FUNCTION (this << spectrumRxParams);
261
  LrWpanSpectrumValueHelper psdHelper;
261
  LrWpanSpectrumValueHelper psdHelper;
262
262
263
264
  Ptr<LrWpanSpectrumSignalParameters> lrWpanRxParams = DynamicCast<LrWpanSpectrumSignalParameters> (spectrumRxParams);
265
  NS_ASSERT (lrWpanRxParams != 0);
266
  Ptr<Packet> p = (lrWpanRxParams->packetBurst->GetPackets ()).front ();
267
  NS_ASSERT (p != 0);
268
269
  if (!m_edRequest.IsExpired ())
263
  if (!m_edRequest.IsExpired ())
270
    {
264
    {
271
      // Update the average receive power during ED.
265
      // Update the average receive power during ED.
272
      Time now = Simulator::Now ();
266
      Time now = Simulator::Now ();
273
      m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd ()) * (now - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementLength.GetTimeStep ();
267
      m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel) * (now - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementLength.GetTimeStep ();
274
      m_edPower.lastUpdate = now;
268
      m_edPower.lastUpdate = now;
275
    }
269
    }
276
270
271
  Ptr<LrWpanSpectrumSignalParameters> lrWpanRxParams = DynamicCast<LrWpanSpectrumSignalParameters> (spectrumRxParams);
272
273
  if ( lrWpanRxParams == 0)
274
    {
275
      CheckInterference ();
276
      m_signal->AddSignal (spectrumRxParams->psd);
277
278
      // Update peak power if CCA is in progress.
279
      if (!m_ccaRequest.IsExpired ())
280
        {
281
          double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel);
282
          if (m_ccaPeakPower < power)
283
            {
284
              m_ccaPeakPower = power;
285
            }
286
        }
287
288
      Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
289
      return;
290
    }
291
292
  Ptr<Packet> p = (lrWpanRxParams->packetBurst->GetPackets ()).front ();
293
  NS_ASSERT (p != 0);
294
277
  // Prevent PHY from receiving another packet while switching the transceiver state.
295
  // Prevent PHY from receiving another packet while switching the transceiver state.
278
  if (m_trxState == IEEE_802_15_4_PHY_RX_ON && !m_setTRXState.IsRunning ())
296
  if (m_trxState == IEEE_802_15_4_PHY_RX_ON && !m_setTRXState.IsRunning ())
279
    {
297
    {
 Lines 293-304    Link Here 
293
311
294
      // Add any incoming packet to the current interference before checking the
312
      // Add any incoming packet to the current interference before checking the
295
      // SINR.
313
      // SINR.
296
      NS_LOG_DEBUG (this << " receiving packet with power: " << 10 * log10(LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->psd)) + 30 << "dBm");
314
      NS_LOG_DEBUG (this << " receiving packet with power: " << 10 * log10(LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->psd, m_phyPIBAttributes.phyCurrentChannel)) + 30 << "dBm");
297
      m_signal->AddSignal (lrWpanRxParams->psd);
315
      m_signal->AddSignal (lrWpanRxParams->psd);
298
      Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
316
      Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
299
      *interferenceAndNoise -= *lrWpanRxParams->psd;
317
      *interferenceAndNoise -= *lrWpanRxParams->psd;
300
      *interferenceAndNoise += *m_noise;
318
      *interferenceAndNoise += *m_noise;
301
      double sinr = LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->psd) / LrWpanSpectrumValueHelper::TotalAvgPower (interferenceAndNoise);
319
      double sinr = LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->psd, m_phyPIBAttributes.phyCurrentChannel) / LrWpanSpectrumValueHelper::TotalAvgPower (interferenceAndNoise, m_phyPIBAttributes.phyCurrentChannel);
302
320
303
      // Std. 802.15.4-2006, appendix E, Figure E.2
321
      // Std. 802.15.4-2006, appendix E, Figure E.2
304
      // At SNR < -5 the BER is less than 10e-1.
322
      // At SNR < -5 the BER is less than 10e-1.
 Lines 343-349    Link Here 
343
  // Update peak power if CCA is in progress.
361
  // Update peak power if CCA is in progress.
344
  if (!m_ccaRequest.IsExpired ())
362
  if (!m_ccaRequest.IsExpired ())
345
    {
363
    {
346
      double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd ());
364
      double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel);
347
      if (m_ccaPeakPower < power)
365
      if (m_ccaPeakPower < power)
348
        {
366
        {
349
          m_ccaPeakPower = power;
367
          m_ccaPeakPower = power;
 Lines 352-358    Link Here 
352
370
353
  // Always call EndRx to update the interference.
371
  // Always call EndRx to update the interference.
354
  // \todo: Do we need to keep track of these events to unschedule them when disposing off the PHY?
372
  // \todo: Do we need to keep track of these events to unschedule them when disposing off the PHY?
355
  Simulator::Schedule (lrWpanRxParams->duration, &LrWpanPhy::EndRx, this, lrWpanRxParams);
373
374
  Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
356
}
375
}
357
376
358
void
377
void
 Lines 376-382    Link Here 
376
          Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
395
          Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
377
          *interferenceAndNoise -= *currentRxParams->psd;
396
          *interferenceAndNoise -= *currentRxParams->psd;
378
          *interferenceAndNoise += *m_noise;
397
          *interferenceAndNoise += *m_noise;
379
          double sinr = LrWpanSpectrumValueHelper::TotalAvgPower (currentRxParams->psd) / LrWpanSpectrumValueHelper::TotalAvgPower (interferenceAndNoise);
398
          double sinr = LrWpanSpectrumValueHelper::TotalAvgPower (currentRxParams->psd, m_phyPIBAttributes.phyCurrentChannel) / LrWpanSpectrumValueHelper::TotalAvgPower (interferenceAndNoise, m_phyPIBAttributes.phyCurrentChannel);
380
          double per = 1.0 - m_errorModel->GetChunkSuccessRate (sinr, chunkSize);
399
          double per = 1.0 - m_errorModel->GetChunkSuccessRate (sinr, chunkSize);
381
400
382
          // The LQI is the total packet success rate scaled to 0-255.
401
          // The LQI is the total packet success rate scaled to 0-255.
 Lines 402-426    Link Here 
402
}
421
}
403
422
404
void
423
void
405
LrWpanPhy::EndRx (Ptr<LrWpanSpectrumSignalParameters> params)
424
LrWpanPhy::EndRx (Ptr<SpectrumSignalParameters> par)
406
{
425
{
407
  NS_LOG_FUNCTION (this);
426
  NS_LOG_FUNCTION (this);
408
  NS_ASSERT (params != 0);
427
  //NS_ASSERT (params != 0);
428
429
  Ptr<LrWpanSpectrumSignalParameters> params = DynamicCast<LrWpanSpectrumSignalParameters> (par);
409
430
410
  if (!m_edRequest.IsExpired ())
431
  if (!m_edRequest.IsExpired ())
411
    {
432
    {
412
      // Update the average receive power during ED.
433
      // Update the average receive power during ED.
413
      Time now = Simulator::Now ();
434
      Time now = Simulator::Now ();
414
      m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd ()) * (now - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementLength.GetTimeStep ();
435
      m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel) * (now - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementLength.GetTimeStep ();
415
      m_edPower.lastUpdate = now;
436
      m_edPower.lastUpdate = now;
416
    }
437
    }
417
438
418
  CheckInterference ();
439
  CheckInterference ();
419
440
420
  // Update the interference.
441
  // Update the interference.
421
  m_signal->RemoveSignal (params->psd);
442
  m_signal->RemoveSignal (par->psd);
422
443
423
  // If this is the end of the currently received packet, check if reception was successfull.
444
  if (params == 0)
445
    {
446
      NS_LOG_LOGIC ("Node: " << m_device->GetAddress() << " Removing interferent: " << *(par->psd));
447
      return;
448
    }
449
450
  // If this is the end of the currently received packet, check if reception was successful.
424
  Ptr<LrWpanSpectrumSignalParameters> currentRxParams = m_currentRxPacket.first;
451
  Ptr<LrWpanSpectrumSignalParameters> currentRxParams = m_currentRxPacket.first;
425
  if (currentRxParams == params)
452
  if (currentRxParams == params)
426
    {
453
    {
 Lines 1029-1035    Link Here 
1029
{
1056
{
1030
  NS_LOG_FUNCTION (this);
1057
  NS_LOG_FUNCTION (this);
1031
1058
1032
  m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd ()) * (Simulator::Now () - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementLength.GetTimeStep ();
1059
  m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel) * (Simulator::Now () - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementLength.GetTimeStep ();
1033
1060
1034
  uint8_t energyLevel;
1061
  uint8_t energyLevel;
1035
1062
 Lines 1063-1069    Link Here 
1063
  LrWpanPhyEnumeration sensedChannelState = IEEE_802_15_4_PHY_UNSPECIFIED;
1090
  LrWpanPhyEnumeration sensedChannelState = IEEE_802_15_4_PHY_UNSPECIFIED;
1064
1091
1065
  // Update peak power.
1092
  // Update peak power.
1066
  double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd ());
1093
  double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel);
1067
  if (m_ccaPeakPower < power)
1094
  if (m_ccaPeakPower < power)
1068
    {
1095
    {
1069
      m_ccaPeakPower = power;
1096
      m_ccaPeakPower = power;
(-)a/src/lr-wpan/model/lr-wpan-phy.h (-1 / +1 lines)
 Lines 499-505    Link Here 
499
   *
499
   *
500
   * \param params signal parameters of the packet
500
   * \param params signal parameters of the packet
501
   */
501
   */
502
  void EndRx (Ptr<LrWpanSpectrumSignalParameters> params);
502
  void EndRx (Ptr<SpectrumSignalParameters> params);
503
503
504
  /**
504
  /**
505
   * Cancel an ongoing ED procedure. This is called when the transceiver is
505
   * Cancel an ongoing ED procedure. This is called when the transceiver is
(-)a/src/lr-wpan/model/lr-wpan-spectrum-value-helper.cc (-5 / +12 lines)
 Lines 54-60    Link Here 
54
    g_LrWpanSpectrumModel = Create<SpectrumModel> (bands);
54
    g_LrWpanSpectrumModel = Create<SpectrumModel> (bands);
55
  }
55
  }
56
56
57
} g_LrWpanSpectrumModelInitializerInstance;  //!< Global object used to initialize the LrWpan Spectrum Model
57
} g_LrWpanSpectrumModelInitializerInstance; //!< Global object used to initialize the LrWpan Spectrum Model
58
58
59
LrWpanSpectrumValueHelper::LrWpanSpectrumValueHelper (void)
59
LrWpanSpectrumValueHelper::LrWpanSpectrumValueHelper (void)
60
{
60
{
 Lines 124-138    Link Here 
124
}
124
}
125
125
126
double
126
double
127
LrWpanSpectrumValueHelper::TotalAvgPower (Ptr<const SpectrumValue> psd)
127
LrWpanSpectrumValueHelper::TotalAvgPower (Ptr<const SpectrumValue> psd, uint32_t channel)
128
{
128
{
129
  NS_LOG_FUNCTION (psd);
129
  NS_LOG_FUNCTION (psd);
130
  double totalAvgPower = 0.0;
130
  double totalAvgPower = 0.0;
131
131
132
  // numerically integrate to get area under psd using
132
  NS_ASSERT (psd->GetSpectrumModel () == g_LrWpanSpectrumModel);
133
  // 1 MHz resolution from 2400 to 2483 MHz (center freq)
134
133
135
  totalAvgPower = Sum (*psd * 1.0e6);
134
  // numerically integrate to get area under psd using 1 MHz resolution
135
136
  totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 - 2];
137
  totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 - 1];
138
  totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400];
139
  totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 + 1];
140
  totalAvgPower += (*psd)[2405 + 5 * (channel - 11) - 2400 + 2];
141
  totalAvgPower *= 1.0e6;
142
136
  return totalAvgPower;
143
  return totalAvgPower;
137
}
144
}
138
145
(-)a/src/lr-wpan/model/lr-wpan-spectrum-value-helper.h (-3 / +5 lines)
 Lines 53-63    Link Here 
53
  Ptr<SpectrumValue> CreateNoisePowerSpectralDensity (uint32_t channel);
53
  Ptr<SpectrumValue> CreateNoisePowerSpectralDensity (uint32_t channel);
54
54
55
  /**
55
  /**
56
   * \brief total average power of the signal is the integral of the PSD
56
   * \brief total average power of the signal is the integral of the PSD using
57
   * the limits of the given channel
57
   * \param psd spectral density
58
   * \param psd spectral density
58
   * \return total power (using composite trap. rule to numerally integrate
59
   * \param channel the channel number per IEEE802.15.4
60
   * \return total power (using composite trap. rule to numerally integrate)
59
   */
61
   */
60
  static double TotalAvgPower (Ptr<const SpectrumValue> psd);
62
  static double TotalAvgPower (Ptr<const SpectrumValue> psd, uint32_t channel);
61
63
62
private:
64
private:
63
  /**
65
  /**
(-)a/src/lr-wpan/test/lr-wpan-spectrum-value-helper-test.cc (-1 / +1 lines)
 Lines 59-65    Link Here 
59
          value = helper.CreateTxPowerSpectralDensity (pwrdBm, chan);
59
          value = helper.CreateTxPowerSpectralDensity (pwrdBm, chan);
60
          pwrWatts = pow (10.0, pwrdBm / 10.0) / 1000;
60
          pwrWatts = pow (10.0, pwrdBm / 10.0) / 1000;
61
          // Test that average power calculation is within +/- 25% of expected
61
          // Test that average power calculation is within +/- 25% of expected
62
          NS_TEST_ASSERT_MSG_EQ_TOL (helper.TotalAvgPower (value), pwrWatts, pwrWatts / 4.0, "Not equal for channel " << chan << " pwrdBm " << pwrdBm);
62
          NS_TEST_ASSERT_MSG_EQ_TOL (helper.TotalAvgPower (value, chan), pwrWatts, pwrWatts / 4.0, "Not equal for channel " << chan << " pwrdBm " << pwrdBm);
63
        }
63
        }
64
    }
64
    }
65
}
65
}

Return to bug 1774