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 1705-1714    Link Here 
1705
    cls.add_method('CreateTxPowerSpectralDensity', 
1705
    cls.add_method('CreateTxPowerSpectralDensity', 
1706
                   'ns3::Ptr< ns3::SpectrumValue >', 
1706
                   'ns3::Ptr< ns3::SpectrumValue >', 
1707
                   [param('double', 'txPower'), param('uint32_t', 'channel')])
1707
                   [param('double', 'txPower'), param('uint32_t', 'channel')])
1708
    ## lr-wpan-spectrum-value-helper.h (module 'lr-wpan'): static double ns3::LrWpanSpectrumValueHelper::TotalAvgPower(ns3::Ptr<ns3::SpectrumValue const> psd) [member function]
1708
    ## 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]
1709
    cls.add_method('TotalAvgPower', 
1709
    cls.add_method('TotalAvgPower', 
1710
                   'double', 
1710
                   'double', 
1711
                   [param('ns3::Ptr< ns3::SpectrumValue const >', 'psd')], 
1711
                   [param('ns3::Ptr< ns3::SpectrumValue const >', 'psd'), param('uint32_t', 'channel')], 
1712
                   is_static=True)
1712
                   is_static=True)
1713
    return
1713
    return
1714
1714
 Lines 2948-2953    Link Here 
2948
def register_Ns3LrWpanHelper_methods(root_module, cls):
2948
def register_Ns3LrWpanHelper_methods(root_module, cls):
2949
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::LrWpanHelper::LrWpanHelper() [constructor]
2949
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::LrWpanHelper::LrWpanHelper() [constructor]
2950
    cls.add_constructor([])
2950
    cls.add_constructor([])
2951
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::LrWpanHelper::LrWpanHelper(bool useMultiModelSpectrumChannel) [constructor]
2952
    cls.add_constructor([param('bool', 'useMultiModelSpectrumChannel')])
2953
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::Ptr<ns3::SpectrumChannel> ns3::LrWpanHelper::GetChannel() [member function]
2954
    cls.add_method('GetChannel', 
2955
                   'ns3::Ptr< ns3::SpectrumChannel >', 
2956
                   [])
2951
    ## lr-wpan-helper.h (module 'lr-wpan'): void ns3::LrWpanHelper::AddMobility(ns3::Ptr<ns3::LrWpanPhy> phy, ns3::Ptr<ns3::MobilityModel> m) [member function]
2957
    ## lr-wpan-helper.h (module 'lr-wpan'): void ns3::LrWpanHelper::AddMobility(ns3::Ptr<ns3::LrWpanPhy> phy, ns3::Ptr<ns3::MobilityModel> m) [member function]
2952
    cls.add_method('AddMobility', 
2958
    cls.add_method('AddMobility', 
2953
                   'void', 
2959
                   'void', 
(-)a/src/lr-wpan/bindings/modulegen__gcc_LP64.py (-2 / +8 lines)
 Lines 1705-1714    Link Here 
1705
    cls.add_method('CreateTxPowerSpectralDensity', 
1705
    cls.add_method('CreateTxPowerSpectralDensity', 
1706
                   'ns3::Ptr< ns3::SpectrumValue >', 
1706
                   'ns3::Ptr< ns3::SpectrumValue >', 
1707
                   [param('double', 'txPower'), param('uint32_t', 'channel')])
1707
                   [param('double', 'txPower'), param('uint32_t', 'channel')])
1708
    ## lr-wpan-spectrum-value-helper.h (module 'lr-wpan'): static double ns3::LrWpanSpectrumValueHelper::TotalAvgPower(ns3::Ptr<ns3::SpectrumValue const> psd) [member function]
1708
    ## 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]
1709
    cls.add_method('TotalAvgPower', 
1709
    cls.add_method('TotalAvgPower', 
1710
                   'double', 
1710
                   'double', 
1711
                   [param('ns3::Ptr< ns3::SpectrumValue const >', 'psd')], 
1711
                   [param('ns3::Ptr< ns3::SpectrumValue const >', 'psd'), param('uint32_t', 'channel')], 
1712
                   is_static=True)
1712
                   is_static=True)
1713
    return
1713
    return
1714
1714
 Lines 2948-2953    Link Here 
2948
def register_Ns3LrWpanHelper_methods(root_module, cls):
2948
def register_Ns3LrWpanHelper_methods(root_module, cls):
2949
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::LrWpanHelper::LrWpanHelper() [constructor]
2949
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::LrWpanHelper::LrWpanHelper() [constructor]
2950
    cls.add_constructor([])
2950
    cls.add_constructor([])
2951
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::LrWpanHelper::LrWpanHelper(bool useMultiModelSpectrumChannel) [constructor]
2952
    cls.add_constructor([param('bool', 'useMultiModelSpectrumChannel')])
2953
    ## lr-wpan-helper.h (module 'lr-wpan'): ns3::Ptr<ns3::SpectrumChannel> ns3::LrWpanHelper::GetChannel() [member function]
2954
    cls.add_method('GetChannel', 
2955
                   'ns3::Ptr< ns3::SpectrumChannel >', 
2956
                   [])
2951
    ## lr-wpan-helper.h (module 'lr-wpan'): void ns3::LrWpanHelper::AddMobility(ns3::Ptr<ns3::LrWpanPhy> phy, ns3::Ptr<ns3::MobilityModel> m) [member function]
2957
    ## lr-wpan-helper.h (module 'lr-wpan'): void ns3::LrWpanHelper::AddMobility(ns3::Ptr<ns3::LrWpanPhy> phy, ns3::Ptr<ns3::MobilityModel> m) [member function]
2952
    cls.add_method('AddMobility', 
2958
    cls.add_method('AddMobility', 
2953
                   'void', 
2959
                   '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 (-7 / +51 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 47-62    Link Here 
47
{
47
{
48
public:
48
public:
49
  /**
49
  /**
50
   * \brief Create a LrWpan helper in an empty state.
50
   * \brief Create a LrWpan helper in an empty state with a
51
   * SingleModelSpectrumChannel.
52
   *
53
   * The channel propagation and delay models are
54
   * LogDistancePropagationLossModel and
55
   * ConstantSpeedPropagationDelayModel respectively.
56
   *
57
   * It is possible to set different propagation/delay
58
   * models on a channel and replace the default one though
59
   * LtrWpan::SetChannel (Ptr<SpectrumChannel> channel).
51
   */
60
   */
52
  LrWpanHelper (void);
61
  LrWpanHelper (void);
62
63
  /**
64
   * \brief Create a LrWpan helper in an empty state with either a
65
   * SingleModelSpectrumChannel or a MultiModelSpectrumChannel.
66
   *
67
   * The channel propagation and delay models are
68
   * LogDistancePropagationLossModel and
69
   * ConstantSpeedPropagationDelayModel respectively.
70
   *
71
   * It is possible to set different propagation/delay
72
   * models on a channel and replace the default one though
73
   * LtrWpan::SetChannel (Ptr<SpectrumChannel> channel).
74
   *
75
   * \param useMultiModelSpectrumChannel use a MultiModelSpectrumChannel if true, a SingleModelSpectrumChannel otherwise
76
   */
77
  LrWpanHelper (bool useMultiModelSpectrumChannel);
78
53
  virtual ~LrWpanHelper (void);
79
  virtual ~LrWpanHelper (void);
54
80
55
  /**
81
  /**
56
  * \brief Add mobility model to a physical device
82
   * \brief Get the channel associated to this helper
57
  * \param phy the physical device
83
   * \returns the channel
58
  * \param m the mobility model
84
   */
59
  */
85
  Ptr<SpectrumChannel> GetChannel (void);
86
87
  /**
88
   * \brief Set the channel associated to this helper
89
   * \param channel the channel
90
   */
91
  void SetChannel (Ptr<SpectrumChannel> channel);
92
93
  /**
94
   * \brief Set the channel associated to this helper
95
   * \param channelName the channel name
96
   */
97
  void SetChannel (std::string channelName);
98
99
  /**
100
   * \brief Add mobility model to a physical device
101
   * \param phy the physical device
102
   * \param m the mobility model
103
   */
60
  void AddMobility (Ptr<LrWpanPhy> phy, Ptr<MobilityModel> m);
104
  void AddMobility (Ptr<LrWpanPhy> phy, Ptr<MobilityModel> m);
61
105
62
  /**
106
  /**
 Lines 147-153    Link Here 
147
                                    bool explicitFilename);
191
                                    bool explicitFilename);
148
192
149
private:
193
private:
150
  Ptr<SingleModelSpectrumChannel> m_channel; //!< channel to be used for the devices
194
  Ptr<SpectrumChannel> m_channel; //!< channel to be used for the devices
151
195
152
};
196
};
153
197
(-)a/src/lr-wpan/model/lr-wpan-phy.cc (-19 / +46 lines)
 Lines 274-293    Link Here 
274
  NS_LOG_FUNCTION (this << spectrumRxParams);
274
  NS_LOG_FUNCTION (this << spectrumRxParams);
275
  LrWpanSpectrumValueHelper psdHelper;
275
  LrWpanSpectrumValueHelper psdHelper;
276
276
277
278
  Ptr<LrWpanSpectrumSignalParameters> lrWpanRxParams = DynamicCast<LrWpanSpectrumSignalParameters> (spectrumRxParams);
279
  NS_ASSERT (lrWpanRxParams != 0);
280
  Ptr<Packet> p = (lrWpanRxParams->packetBurst->GetPackets ()).front ();
281
  NS_ASSERT (p != 0);
282
283
  if (!m_edRequest.IsExpired ())
277
  if (!m_edRequest.IsExpired ())
284
    {
278
    {
285
      // Update the average receive power during ED.
279
      // Update the average receive power during ED.
286
      Time now = Simulator::Now ();
280
      Time now = Simulator::Now ();
287
      m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd ()) * (now - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementLength.GetTimeStep ();
281
      m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel) * (now - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementLength.GetTimeStep ();
288
      m_edPower.lastUpdate = now;
282
      m_edPower.lastUpdate = now;
289
    }
283
    }
290
284
285
  Ptr<LrWpanSpectrumSignalParameters> lrWpanRxParams = DynamicCast<LrWpanSpectrumSignalParameters> (spectrumRxParams);
286
287
  if ( lrWpanRxParams == 0)
288
    {
289
      CheckInterference ();
290
      m_signal->AddSignal (spectrumRxParams->psd);
291
292
      // Update peak power if CCA is in progress.
293
      if (!m_ccaRequest.IsExpired ())
294
        {
295
          double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel);
296
          if (m_ccaPeakPower < power)
297
            {
298
              m_ccaPeakPower = power;
299
            }
300
        }
301
302
      Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
303
      return;
304
    }
305
306
  Ptr<Packet> p = (lrWpanRxParams->packetBurst->GetPackets ()).front ();
307
  NS_ASSERT (p != 0);
308
291
  // Prevent PHY from receiving another packet while switching the transceiver state.
309
  // Prevent PHY from receiving another packet while switching the transceiver state.
292
  if (m_trxState == IEEE_802_15_4_PHY_RX_ON && !m_setTRXState.IsRunning ())
310
  if (m_trxState == IEEE_802_15_4_PHY_RX_ON && !m_setTRXState.IsRunning ())
293
    {
311
    {
 Lines 307-318    Link Here 
307
325
308
      // Add any incoming packet to the current interference before checking the
326
      // Add any incoming packet to the current interference before checking the
309
      // SINR.
327
      // SINR.
310
      NS_LOG_DEBUG (this << " receiving packet with power: " << 10 * log10(LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->psd)) + 30 << "dBm");
328
      NS_LOG_DEBUG (this << " receiving packet with power: " << 10 * log10(LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->psd, m_phyPIBAttributes.phyCurrentChannel)) + 30 << "dBm");
311
      m_signal->AddSignal (lrWpanRxParams->psd);
329
      m_signal->AddSignal (lrWpanRxParams->psd);
312
      Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
330
      Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
313
      *interferenceAndNoise -= *lrWpanRxParams->psd;
331
      *interferenceAndNoise -= *lrWpanRxParams->psd;
314
      *interferenceAndNoise += *m_noise;
332
      *interferenceAndNoise += *m_noise;
315
      double sinr = LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->psd) / LrWpanSpectrumValueHelper::TotalAvgPower (interferenceAndNoise);
333
      double sinr = LrWpanSpectrumValueHelper::TotalAvgPower (lrWpanRxParams->psd, m_phyPIBAttributes.phyCurrentChannel) / LrWpanSpectrumValueHelper::TotalAvgPower (interferenceAndNoise, m_phyPIBAttributes.phyCurrentChannel);
316
334
317
      // Std. 802.15.4-2006, appendix E, Figure E.2
335
      // Std. 802.15.4-2006, appendix E, Figure E.2
318
      // At SNR < -5 the BER is less than 10e-1.
336
      // At SNR < -5 the BER is less than 10e-1.
 Lines 357-363    Link Here 
357
  // Update peak power if CCA is in progress.
375
  // Update peak power if CCA is in progress.
358
  if (!m_ccaRequest.IsExpired ())
376
  if (!m_ccaRequest.IsExpired ())
359
    {
377
    {
360
      double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd ());
378
      double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel);
361
      if (m_ccaPeakPower < power)
379
      if (m_ccaPeakPower < power)
362
        {
380
        {
363
          m_ccaPeakPower = power;
381
          m_ccaPeakPower = power;
 Lines 366-372    Link Here 
366
384
367
  // Always call EndRx to update the interference.
385
  // Always call EndRx to update the interference.
368
  // \todo: Do we need to keep track of these events to unschedule them when disposing off the PHY?
386
  // \todo: Do we need to keep track of these events to unschedule them when disposing off the PHY?
369
  Simulator::Schedule (lrWpanRxParams->duration, &LrWpanPhy::EndRx, this, lrWpanRxParams);
387
388
  Simulator::Schedule (spectrumRxParams->duration, &LrWpanPhy::EndRx, this, spectrumRxParams);
370
}
389
}
371
390
372
void
391
void
 Lines 390-396    Link Here 
390
          Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
409
          Ptr<SpectrumValue> interferenceAndNoise = m_signal->GetSignalPsd ();
391
          *interferenceAndNoise -= *currentRxParams->psd;
410
          *interferenceAndNoise -= *currentRxParams->psd;
392
          *interferenceAndNoise += *m_noise;
411
          *interferenceAndNoise += *m_noise;
393
          double sinr = LrWpanSpectrumValueHelper::TotalAvgPower (currentRxParams->psd) / LrWpanSpectrumValueHelper::TotalAvgPower (interferenceAndNoise);
412
          double sinr = LrWpanSpectrumValueHelper::TotalAvgPower (currentRxParams->psd, m_phyPIBAttributes.phyCurrentChannel) / LrWpanSpectrumValueHelper::TotalAvgPower (interferenceAndNoise, m_phyPIBAttributes.phyCurrentChannel);
394
          double per = 1.0 - m_errorModel->GetChunkSuccessRate (sinr, chunkSize);
413
          double per = 1.0 - m_errorModel->GetChunkSuccessRate (sinr, chunkSize);
395
414
396
          // The LQI is the total packet success rate scaled to 0-255.
415
          // The LQI is the total packet success rate scaled to 0-255.
 Lines 416-440    Link Here 
416
}
435
}
417
436
418
void
437
void
419
LrWpanPhy::EndRx (Ptr<LrWpanSpectrumSignalParameters> params)
438
LrWpanPhy::EndRx (Ptr<SpectrumSignalParameters> par)
420
{
439
{
421
  NS_LOG_FUNCTION (this);
440
  NS_LOG_FUNCTION (this);
422
  NS_ASSERT (params != 0);
441
  //NS_ASSERT (params != 0);
442
443
  Ptr<LrWpanSpectrumSignalParameters> params = DynamicCast<LrWpanSpectrumSignalParameters> (par);
423
444
424
  if (!m_edRequest.IsExpired ())
445
  if (!m_edRequest.IsExpired ())
425
    {
446
    {
426
      // Update the average receive power during ED.
447
      // Update the average receive power during ED.
427
      Time now = Simulator::Now ();
448
      Time now = Simulator::Now ();
428
      m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd ()) * (now - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementLength.GetTimeStep ();
449
      m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel) * (now - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementLength.GetTimeStep ();
429
      m_edPower.lastUpdate = now;
450
      m_edPower.lastUpdate = now;
430
    }
451
    }
431
452
432
  CheckInterference ();
453
  CheckInterference ();
433
454
434
  // Update the interference.
455
  // Update the interference.
435
  m_signal->RemoveSignal (params->psd);
456
  m_signal->RemoveSignal (par->psd);
436
457
437
  // If this is the end of the currently received packet, check if reception was successfull.
458
  if (params == 0)
459
    {
460
      NS_LOG_LOGIC ("Node: " << m_device->GetAddress() << " Removing interferent: " << *(par->psd));
461
      return;
462
    }
463
464
  // If this is the end of the currently received packet, check if reception was successful.
438
  Ptr<LrWpanSpectrumSignalParameters> currentRxParams = m_currentRxPacket.first;
465
  Ptr<LrWpanSpectrumSignalParameters> currentRxParams = m_currentRxPacket.first;
439
  if (currentRxParams == params)
466
  if (currentRxParams == params)
440
    {
467
    {
 Lines 1043-1049    Link Here 
1043
{
1070
{
1044
  NS_LOG_FUNCTION (this);
1071
  NS_LOG_FUNCTION (this);
1045
1072
1046
  m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd ()) * (Simulator::Now () - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementLength.GetTimeStep ();
1073
  m_edPower.averagePower += LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel) * (Simulator::Now () - m_edPower.lastUpdate).GetTimeStep () / m_edPower.measurementLength.GetTimeStep ();
1047
1074
1048
  uint8_t energyLevel;
1075
  uint8_t energyLevel;
1049
1076
 Lines 1077-1083    Link Here 
1077
  LrWpanPhyEnumeration sensedChannelState = IEEE_802_15_4_PHY_UNSPECIFIED;
1104
  LrWpanPhyEnumeration sensedChannelState = IEEE_802_15_4_PHY_UNSPECIFIED;
1078
1105
1079
  // Update peak power.
1106
  // Update peak power.
1080
  double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd ());
1107
  double power = LrWpanSpectrumValueHelper::TotalAvgPower (m_signal->GetSignalPsd (), m_phyPIBAttributes.phyCurrentChannel);
1081
  if (m_ccaPeakPower < power)
1108
  if (m_ccaPeakPower < power)
1082
    {
1109
    {
1083
      m_ccaPeakPower = power;
1110
      m_ccaPeakPower = power;
(-)a/src/lr-wpan/model/lr-wpan-phy.h (-1 / +1 lines)
 Lines 547-553    Link Here 
547
   *
547
   *
548
   * \param params signal parameters of the packet
548
   * \param params signal parameters of the packet
549
   */
549
   */
550
  void EndRx (Ptr<LrWpanSpectrumSignalParameters> params);
550
  void EndRx (Ptr<SpectrumSignalParameters> params);
551
551
552
  /**
552
  /**
553
   * Cancel an ongoing ED procedure. This is called when the transceiver is
553
   * 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