A Discrete-Event Network Simulator
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 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Romagnolo Stefano <romagnolostefano93@gmail.com>
18 */
19
21
22#include "ns3/end-device-lora-phy.h"
23#include "ns3/lora-net-device.h"
24#include "ns3/lora-tx-current-model.h"
25
26namespace ns3
27{
28namespace lorawan
29{
30
32{
33 m_radioEnergy.SetTypeId("ns3::LoraRadioEnergyModel");
34}
35
37{
38}
39
40void
42{
43 m_radioEnergy.Set(name, v);
44}
45
46void
48 std::string n0,
49 const AttributeValue& v0,
50 std::string n1,
51 const AttributeValue& v1,
52 std::string n2,
53 const AttributeValue& v2,
54 std::string n3,
55 const AttributeValue& v3,
56 std::string n4,
57 const AttributeValue& v4,
58 std::string n5,
59 const AttributeValue& v5,
60 std::string n6,
61 const AttributeValue& v6,
62 std::string n7,
63 const AttributeValue& v7)
64{
65 ObjectFactory factory;
66 factory.SetTypeId(name);
67 factory.Set(n0, v0);
68 factory.Set(n1, v1);
69 factory.Set(n2, v2);
70 factory.Set(n3, v3);
71 factory.Set(n4, v4);
72 factory.Set(n5, v5);
73 factory.Set(n6, v6);
74 factory.Set(n7, v7);
75 m_txCurrentModel = factory;
76}
77
78/*
79 * Private function starts here.
80 */
81
84{
85 NS_ASSERT(device);
86 NS_ASSERT(source);
87 // check if device is LoraNetDevice
88 std::string deviceName = device->GetInstanceTypeId().GetName();
89 if (deviceName != "ns3::LoraNetDevice")
90 {
91 NS_FATAL_ERROR("NetDevice type is not LoraNetDevice!");
92 }
93 Ptr<Node> node = device->GetNode();
95 NS_ASSERT(model);
96 // set energy source pointer
97 model->SetEnergySource(source);
98
99 // set energy depletion callback
100 // if none is specified, make a callback to EndDeviceLoraPhy::SetSleepMode
101 Ptr<LoraNetDevice> loraDevice = device->GetObject<LoraNetDevice>();
102 Ptr<EndDeviceLoraPhy> loraPhy = loraDevice->GetPhy()->GetObject<EndDeviceLoraPhy>();
103 // add model to device model list in energy source
104 source->AppendDeviceEnergyModel(model);
105 // create and register energy model phy listener
106 loraPhy->RegisterListener(model->GetPhyListener());
107
109 {
111 model->SetTxCurrentModel(txcurrent);
112 }
113 return model;
114}
115
116} // namespace lorawan
117} // namespace ns3
Hold a value for an Attribute.
Definition: attribute.h:70
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
TypeId GetTypeId() const
Get the TypeId which will be created by this ObjectFactory.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition: object.h:522
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
uint16_t GetUid() const
Get the internal id of this TypeId.
Definition: type-id.cc:1206
Class representing a LoRa transceiver.
Hold together all LoRa related objects.
Ptr< DeviceEnergyModel > DoInstall(Ptr< NetDevice > device, Ptr< EnergySource > source) const override
void Set(std::string name, const AttributeValue &v) override
ObjectFactory m_txCurrentModel
transmit current model
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())
Model the transmit current as a function of the transmit power and mode.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:179
Every class exported by the ns3 library is enclosed in the ns3 namespace.