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/lora-net-device.h"
12#include "ns3/lora-radio-energy-model.h"
13
14namespace ns3
15{
16namespace lorawan
17{
18
20{
21 m_radioEnergy.SetTypeId("ns3::LoraRadioEnergyModel");
22}
23
27
28void
30{
31 m_radioEnergy.Set(name, v);
32}
33
34void
36 std::string n0,
37 const AttributeValue& v0,
38 std::string n1,
39 const AttributeValue& v1,
40 std::string n2,
41 const AttributeValue& v2,
42 std::string n3,
43 const AttributeValue& v3,
44 std::string n4,
45 const AttributeValue& v4,
46 std::string n5,
47 const AttributeValue& v5,
48 std::string n6,
49 const AttributeValue& v6,
50 std::string n7,
51 const AttributeValue& v7)
52{
53 ObjectFactory factory;
54 factory.SetTypeId(name);
55 factory.Set(n0, v0);
56 factory.Set(n1, v1);
57 factory.Set(n2, v2);
58 factory.Set(n3, v3);
59 factory.Set(n4, v4);
60 factory.Set(n5, v5);
61 factory.Set(n6, v6);
62 factory.Set(n7, v7);
63 m_txCurrentModel = factory;
64}
65
66/*
67 * Private function starts here.
68 */
69
72{
73 NS_ASSERT(device);
74 NS_ASSERT(source);
75 // check if device is LoraNetDevice
76 std::string deviceName = device->GetInstanceTypeId().GetName();
77 if (deviceName != "ns3::LoraNetDevice")
78 {
79 NS_FATAL_ERROR("NetDevice type is not LoraNetDevice!");
80 }
81 Ptr<Node> node = device->GetNode();
83 NS_ASSERT(model);
84 // set energy source pointer
85 model->SetEnergySource(source);
86
87 // set energy depletion callback
88 // if none is specified, make a callback to EndDeviceLoraPhy::SetSleepMode
90 Ptr<EndDeviceLoraPhy> loraPhy = DynamicCast<EndDeviceLoraPhy>(loraDevice->GetPhy());
91 // add model to device model list in energy source
92 source->AppendDeviceEnergyModel(model);
93 // create and register energy model phy listener
94 loraPhy->RegisterListener(model->GetPhyListener());
95
96 if (m_txCurrentModel.GetTypeId().GetUid())
97 {
99 model->SetTxCurrentModel(txcurrent);
100 }
101 return model;
102}
103
104} // namespace lorawan
105} // namespace ns3
uint32_t v
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:70
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())
Ptr< energy::DeviceEnergyModel > DoInstall(Ptr< NetDevice > device, Ptr< energy::EnergySource > source) const override
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:605