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{
31namespace energy
32{
33
34/**
35 * \ingroup energy
36 * BasicEnergySource decreases/increases remaining energy stored in itself in
37 * linearly.
38 *
39 */
41{
42 public:
43 /**
44 * \brief Get the type ID.
45 * \return The object TypeId.
46 */
47 static TypeId GetTypeId();
49 ~BasicEnergySource() override;
50
51 /**
52 * \return Initial energy stored in energy source, in Joules.
53 *
54 * Implements GetInitialEnergy.
55 */
56 double GetInitialEnergy() const override;
57
58 /**
59 * \returns Supply voltage at the energy source.
60 *
61 * Implements GetSupplyVoltage.
62 */
63 double GetSupplyVoltage() const override;
64
65 /**
66 * \return Remaining energy in energy source, in Joules
67 *
68 * Implements GetRemainingEnergy.
69 */
70 double GetRemainingEnergy() override;
71
72 /**
73 * \returns Energy fraction.
74 *
75 * Implements GetEnergyFraction.
76 */
77 double GetEnergyFraction() override;
78
79 /**
80 * Implements UpdateEnergySource.
81 */
82 void UpdateEnergySource() override;
83
84 /**
85 * \param initialEnergyJ Initial energy, in Joules
86 *
87 * Sets initial energy stored in the energy source. Note that initial energy
88 * is assumed to be set before simulation starts and is set only once per
89 * simulation.
90 */
91 void SetInitialEnergy(double initialEnergyJ);
92
93 /**
94 * \param supplyVoltageV Supply voltage at the energy source, in Volts.
95 *
96 * Sets supply voltage of the energy source.
97 */
98 void SetSupplyVoltage(double supplyVoltageV);
99
100 /**
101 * \param interval Energy update interval.
102 *
103 * This function sets the interval between each energy update.
104 */
105 void SetEnergyUpdateInterval(Time interval);
106
107 /**
108 * \returns The interval between each energy update.
109 */
111
112 private:
113 /// Defined in ns3::Object
114 void DoInitialize() override;
115
116 /// Defined in ns3::Object
117 void DoDispose() override;
118
119 /**
120 * Handles the remaining energy going to zero event. This function notifies
121 * all the energy models aggregated to the node about the energy being
122 * depleted. Each energy model is then responsible for its own handler.
123 */
125
126 /**
127 * Handles the remaining energy exceeding the high threshold after it went
128 * below the low threshold. This function notifies all the energy models
129 * aggregated to the node about the energy being recharged. Each energy model
130 * is then responsible for its own handler.
131 */
133
134 /**
135 * Calculates remaining energy. This function uses the total current from all
136 * device models to calculate the amount of energy to decrease. The energy to
137 * decrease is given by:
138 * energy to decrease = total current * supply voltage * time duration
139 * This function subtracts the calculated energy to decrease from remaining
140 * energy.
141 */
143
144 private:
145 double m_initialEnergyJ; //!< initial energy, in Joules
146 double m_supplyVoltageV; //!< supply voltage, in Volts
147 double m_lowBatteryTh; //!< low battery threshold, as a fraction of the initial energy
148 double m_highBatteryTh; //!< high battery threshold, as a fraction of the initial energy
149 /**
150 * set to true when the remaining energy goes below the low threshold,
151 * set to false again when the remaining energy exceeds the high threshold
152 */
154 TracedValue<double> m_remainingEnergyJ; //!< remaining energy, in Joules
155 EventId m_energyUpdateEvent; //!< energy update event
156 Time m_lastUpdateTime; //!< last update time
157 Time m_energyUpdateInterval; //!< energy update interval
158};
159
160} // namespace energy
161} // namespace ns3
162
163#endif /* BASIC_ENERGY_SOURCE_H */
An identifier for simulation events.
Definition: event-id.h:56
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
BasicEnergySource decreases/increases remaining energy stored in itself in linearly.
double m_lowBatteryTh
low battery threshold, as a fraction of the initial energy
double m_initialEnergyJ
initial energy, in Joules
Time m_lastUpdateTime
last update time
static TypeId GetTypeId()
Get the type ID.
double GetSupplyVoltage() const override
Time m_energyUpdateInterval
energy update interval
EventId m_energyUpdateEvent
energy update event
void SetInitialEnergy(double initialEnergyJ)
bool m_depleted
set to true when the remaining energy goes below the low threshold, set to false again when the remai...
TracedValue< double > m_remainingEnergyJ
remaining energy, in Joules
void DoDispose() override
Defined in ns3::Object.
void SetSupplyVoltage(double supplyVoltageV)
void SetEnergyUpdateInterval(Time interval)
double GetInitialEnergy() const override
void HandleEnergyDrainedEvent()
Handles the remaining energy going to zero event.
void UpdateEnergySource() override
Implements UpdateEnergySource.
void CalculateRemainingEnergy()
Calculates remaining energy.
double m_highBatteryTh
high battery threshold, as a fraction of the initial energy
void HandleEnergyRechargedEvent()
Handles the remaining energy exceeding the high threshold after it went below the low threshold.
void DoInitialize() override
Defined in ns3::Object.
double m_supplyVoltageV
supply voltage, in Volts
Energy source base class.
Definition: energy-source.h:88
Every class exported by the ns3 library is enclosed in the ns3 namespace.