A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
lora-radio-energy-model-helper.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2017 University of Padova
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Romagnolo Stefano <romagnolostefano93@gmail.com>
7
*/
8
9
#include "
lora-radio-energy-model-helper.h
"
10
11
#include "ns3/end-device-lora-phy.h"
12
#include "ns3/lora-net-device.h"
13
#include "ns3/lora-tx-current-model.h"
14
15
namespace
ns3
16
{
17
namespace
lorawan
18
{
19
20
LoraRadioEnergyModelHelper::LoraRadioEnergyModelHelper
()
21
{
22
m_radioEnergy
.SetTypeId(
"ns3::LoraRadioEnergyModel"
);
23
}
24
25
LoraRadioEnergyModelHelper::~LoraRadioEnergyModelHelper
()
26
{
27
}
28
29
void
30
LoraRadioEnergyModelHelper::Set
(std::string name,
const
AttributeValue
& v)
31
{
32
m_radioEnergy
.Set(name, v);
33
}
34
35
void
36
LoraRadioEnergyModelHelper::SetTxCurrentModel
(std::string name,
37
std::string n0,
38
const
AttributeValue
& v0,
39
std::string n1,
40
const
AttributeValue
& v1,
41
std::string n2,
42
const
AttributeValue
& v2,
43
std::string n3,
44
const
AttributeValue
& v3,
45
std::string n4,
46
const
AttributeValue
& v4,
47
std::string n5,
48
const
AttributeValue
& v5,
49
std::string n6,
50
const
AttributeValue
& v6,
51
std::string n7,
52
const
AttributeValue
& v7)
53
{
54
ObjectFactory
factory;
55
factory.
SetTypeId
(name);
56
factory.
Set
(n0, v0);
57
factory.
Set
(n1, v1);
58
factory.
Set
(n2, v2);
59
factory.
Set
(n3, v3);
60
factory.
Set
(n4, v4);
61
factory.
Set
(n5, v5);
62
factory.
Set
(n6, v6);
63
factory.
Set
(n7, v7);
64
m_txCurrentModel
= factory;
65
}
66
67
/*
68
* Private function starts here.
69
*/
70
71
Ptr<DeviceEnergyModel>
72
LoraRadioEnergyModelHelper::DoInstall
(
Ptr<NetDevice>
device,
Ptr<EnergySource>
source)
const
73
{
74
NS_ASSERT
(device);
75
NS_ASSERT
(source);
76
// check if device is LoraNetDevice
77
std::string deviceName = device->GetInstanceTypeId().GetName();
78
if
(deviceName !=
"ns3::LoraNetDevice"
)
79
{
80
NS_FATAL_ERROR
(
"NetDevice type is not LoraNetDevice!"
);
81
}
82
Ptr<Node>
node = device->GetNode();
83
Ptr<LoraRadioEnergyModel>
model =
m_radioEnergy
.Create<
LoraRadioEnergyModel
>();
84
NS_ASSERT
(model);
85
// set energy source pointer
86
model->SetEnergySource(source);
87
88
// set energy depletion callback
89
// if none is specified, make a callback to EndDeviceLoraPhy::SetSleepMode
90
Ptr<LoraNetDevice>
loraDevice =
DynamicCast<LoraNetDevice>
(device);
91
Ptr<EndDeviceLoraPhy>
loraPhy =
DynamicCast<EndDeviceLoraPhy>
(loraDevice->GetPhy());
92
// add model to device model list in energy source
93
source->AppendDeviceEnergyModel(model);
94
// create and register energy model phy listener
95
loraPhy->RegisterListener(model->GetPhyListener());
96
97
if
(
m_txCurrentModel
.GetTypeId().GetUid())
98
{
99
Ptr<LoraTxCurrentModel>
txcurrent =
m_txCurrentModel
.Create<
LoraTxCurrentModel
>();
100
model->SetTxCurrentModel(txcurrent);
101
}
102
return
model;
103
}
104
105
}
// namespace lorawan
106
}
// namespace ns3
ns3::AttributeValue
Hold a value for an Attribute.
Definition
attribute.h:59
ns3::ObjectFactory
Instantiate subclasses of ns3::Object.
Definition
object-factory.h:37
ns3::ObjectFactory::Set
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
Definition
object-factory.h:213
ns3::ObjectFactory::SetTypeId
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Definition
object-factory.cc:31
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition
ptr.h:66
ns3::lorawan::LoraRadioEnergyModelHelper::m_radioEnergy
ObjectFactory m_radioEnergy
radio energy
Definition
lora-radio-energy-model-helper.h:92
ns3::lorawan::LoraRadioEnergyModelHelper::DoInstall
Ptr< DeviceEnergyModel > DoInstall(Ptr< NetDevice > device, Ptr< EnergySource > source) const override
Definition
lora-radio-energy-model-helper.cc:72
ns3::lorawan::LoraRadioEnergyModelHelper::Set
void Set(std::string name, const AttributeValue &v) override
Definition
lora-radio-energy-model-helper.cc:30
ns3::lorawan::LoraRadioEnergyModelHelper::m_txCurrentModel
ObjectFactory m_txCurrentModel
transmit current model
Definition
lora-radio-energy-model-helper.h:93
ns3::lorawan::LoraRadioEnergyModelHelper::~LoraRadioEnergyModelHelper
~LoraRadioEnergyModelHelper() override
Destructor.
Definition
lora-radio-energy-model-helper.cc:25
ns3::lorawan::LoraRadioEnergyModelHelper::SetTxCurrentModel
void SetTxCurrentModel(std::string name, std::string n0="", const AttributeValue &v0=EmptyAttributeValue(), std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue())
Definition
lora-radio-energy-model-helper.cc:36
ns3::lorawan::LoraRadioEnergyModelHelper::LoraRadioEnergyModelHelper
LoraRadioEnergyModelHelper()
Default constructor.
Definition
lora-radio-energy-model-helper.cc:20
ns3::lorawan::LoraRadioEnergyModel
A LoRa radio energy model.
Definition
lora-radio-energy-model.h:123
ns3::lorawan::LoraTxCurrentModel
Model the transmit current as a function of the transmit power and mode.
Definition
lora-tx-current-model.h:27
NS_ASSERT
#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
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition
fatal-error.h:168
lora-radio-energy-model-helper.h
ns3::lorawan
Definition
forwarder-helper.cc:25
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::DynamicCast
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition
ptr.h:580
src
lorawan
helper
lora-radio-energy-model-helper.cc
Generated on Wed Jun 11 2025 13:15:31 for ns-3 by
1.13.2