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