A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
basic-energy-source.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
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 * Authors: Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
18 */
19
20#ifndef BASIC_ENERGY_SOURCE_H
21#define BASIC_ENERGY_SOURCE_H
22
23#include "energy-source.h"
24
25#include "ns3/event-id.h"
26#include "ns3/nstime.h"
27#include "ns3/traced-value.h"
28
29namespace ns3
30{
31
32/**
33 * \ingroup energy
34 * BasicEnergySource decreases/increases remaining energy stored in itself in
35 * linearly.
36 *
37 */
39{
40 public:
41 /**
42 * \brief Get the type ID.
43 * \return The object TypeId.
44 */
45 static TypeId GetTypeId();
47 ~BasicEnergySource() override;
48
49 /**
50 * \return Initial energy stored in energy source, in Joules.
51 *
52 * Implements GetInitialEnergy.
53 */
54 double GetInitialEnergy() const override;
55
56 /**
57 * \returns Supply voltage at the energy source.
58 *
59 * Implements GetSupplyVoltage.
60 */
61 double GetSupplyVoltage() const override;
62
63 /**
64 * \return Remaining energy in energy source, in Joules
65 *
66 * Implements GetRemainingEnergy.
67 */
68 double GetRemainingEnergy() override;
69
70 /**
71 * \returns Energy fraction.
72 *
73 * Implements GetEnergyFraction.
74 */
75 double GetEnergyFraction() override;
76
77 /**
78 * Implements UpdateEnergySource.
79 */
80 void UpdateEnergySource() override;
81
82 /**
83 * \param initialEnergyJ Initial energy, in Joules
84 *
85 * Sets initial energy stored in the energy source. Note that initial energy
86 * is assumed to be set before simulation starts and is set only once per
87 * simulation.
88 */
89 void SetInitialEnergy(double initialEnergyJ);
90
91 /**
92 * \param supplyVoltageV Supply voltage at the energy source, in Volts.
93 *
94 * Sets supply voltage of the energy source.
95 */
96 void SetSupplyVoltage(double supplyVoltageV);
97
98 /**
99 * \param interval Energy update interval.
100 *
101 * This function sets the interval between each energy update.
102 */
103 void SetEnergyUpdateInterval(Time interval);
104
105 /**
106 * \returns The interval between each energy update.
107 */
109
110 private:
111 /// Defined in ns3::Object
112 void DoInitialize() override;
113
114 /// Defined in ns3::Object
115 void DoDispose() override;
116
117 /**
118 * Handles the remaining energy going to zero event. This function notifies
119 * all the energy models aggregated to the node about the energy being
120 * depleted. Each energy model is then responsible for its own handler.
121 */
123
124 /**
125 * Handles the remaining energy exceeding the high threshold after it went
126 * below the low threshold. This function notifies all the energy models
127 * aggregated to the node about the energy being recharged. Each energy model
128 * is then responsible for its own handler.
129 */
131
132 /**
133 * Calculates remaining energy. This function uses the total current from all
134 * device models to calculate the amount of energy to decrease. The energy to
135 * decrease is given by:
136 * energy to decrease = total current * supply voltage * time duration
137 * This function subtracts the calculated energy to decrease from remaining
138 * energy.
139 */
141
142 private:
143 double m_initialEnergyJ; //!< initial energy, in Joules
144 double m_supplyVoltageV; //!< supply voltage, in Volts
145 double m_lowBatteryTh; //!< low battery threshold, as a fraction of the initial energy
146 double m_highBatteryTh; //!< high battery threshold, as a fraction of the initial energy
147 /**
148 * set to true when the remaining energy goes below the low threshold,
149 * set to false again when the remaining energy exceeds the high threshold
150 */
152 TracedValue<double> m_remainingEnergyJ; //!< remaining energy, in Joules
153 EventId m_energyUpdateEvent; //!< energy update event
154 Time m_lastUpdateTime; //!< last update time
155 Time m_energyUpdateInterval; //!< energy update interval
156};
157
158} // namespace ns3
159
160#endif /* BASIC_ENERGY_SOURCE_H */
BasicEnergySource decreases/increases remaining energy stored in itself in linearly.
void HandleEnergyRechargedEvent()
Handles the remaining energy exceeding the high threshold after it went below the low threshold.
void SetEnergyUpdateInterval(Time interval)
double GetSupplyVoltage() const override
static TypeId GetTypeId()
Get the type ID.
Time m_energyUpdateInterval
energy update interval
double m_initialEnergyJ
initial energy, in Joules
double m_lowBatteryTh
low battery threshold, as a fraction of the initial energy
double GetRemainingEnergy() override
double GetEnergyFraction() override
void HandleEnergyDrainedEvent()
Handles the remaining energy going to zero event.
Time m_lastUpdateTime
last update time
double GetInitialEnergy() const override
void SetSupplyVoltage(double supplyVoltageV)
void DoDispose() override
Defined in ns3::Object.
EventId m_energyUpdateEvent
energy update event
void DoInitialize() override
Defined in ns3::Object.
TracedValue< double > m_remainingEnergyJ
remaining energy, in Joules
bool m_depleted
set to true when the remaining energy goes below the low threshold, set to false again when the remai...
double m_highBatteryTh
high battery threshold, as a fraction of the initial energy
void UpdateEnergySource() override
Implements UpdateEnergySource.
void SetInitialEnergy(double initialEnergyJ)
double m_supplyVoltageV
supply voltage, in Volts
void CalculateRemainingEnergy()
Calculates remaining energy.
Introspection did not find any typical Config paths.
Definition: energy-source.h:87
An identifier for simulation events.
Definition: event-id.h:55
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Trace classes with value semantics.
Definition: traced-value.h:116
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.