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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Romagnolo Stefano <romagnolostefano93@gmail.com>
7 */
8
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
15namespace ns3
16{
17namespace lorawan
18{
19
21{
22 m_radioEnergy.SetTypeId("ns3::LoraRadioEnergyModel");
23}
24
28
29void
31{
32 m_radioEnergy.Set(name, v);
33}
34
35void
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
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();
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
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 {
100 model->SetTxCurrentModel(txcurrent);
101 }
102 return model;
103}
104
105} // namespace lorawan
106} // namespace ns3
Hold a value for an Attribute.
Definition attribute.h:59
Instantiate subclasses of ns3::Object.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:66
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:55
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< T1 > DynamicCast(const Ptr< T2 > &p)
Cast a Ptr.
Definition ptr.h:580