Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
1353b71e
Commit
1353b71e
authored
Oct 22, 2015
by
Nils Richerzhagen
Browse files
Added SiS support for EnergyLevel of Battery.
parent
94bed953
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/api/energy/EnergyInfo.java
View file @
1353b71e
...
...
@@ -34,12 +34,19 @@ import de.tud.kom.p2psim.impl.energy.Battery;
public
interface
EnergyInfo
{
/**
* Gets the current status of the Battery as a Percentage-Value
* Gets the current status of the
{@link
Battery
}
as a Percentage-Value
*
* @return double between 0 and 100
*/
public
double
getCurrentPercentage
();
/**
* Gets the current energy level of the {@link Battery} in uJ.
*
* @return double - the current capacity of the battery in uJ
*/
public
double
getCurrentEnergyLevel
();
/**
* Access the Battery - do not use this for functional parts, it is mainly
* needed for analyzing
...
...
src/de/tud/kom/p2psim/impl/energy/Battery.java
View file @
1353b71e
...
...
@@ -20,10 +20,9 @@
package
de.tud.kom.p2psim.impl.energy
;
/**
* This interface implements basic methods used by the EnergyModel
*
to simulate a
battery.
* This interface implements basic methods used by the EnergyModel
to simulate a
* battery.
*
* @author Fabio Zöllner
* @version 1.0, 20.04.2012
...
...
@@ -37,6 +36,13 @@ public interface Battery extends Cloneable {
*/
public
double
getCurrentPercentage
();
/**
* Returns the current energy level in uJ.
*
* @return the current capacity of the battery in uJ
*/
public
double
getCurrentEnergyLevel
();
/**
* Returns the consumed energy in uJoule
*
...
...
@@ -48,7 +54,7 @@ public interface Battery extends Cloneable {
* Resets the Battery to the initial Energy-Level
*/
public
void
reset
();
/**
* Sets the battery to a given percentage.
*
...
...
src/de/tud/kom/p2psim/impl/energy/ModularEnergyModel.java
View file @
1353b71e
...
...
@@ -42,7 +42,6 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.battery.BatterySens
import
de.tudarmstadt.maki.simonstrator.api.component.sis.SiSComponent
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.SiSDataCallback
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInfoProperties.SiSScope
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.SiSInformationProvider.SiSProviderHandle
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException
;
import
de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes
;
...
...
@@ -59,7 +58,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
public
class
ModularEnergyModel
implements
EnergyModel
,
EnergyEventListener
,
EnergyInfo
,
BatterySensor
{
// private static Logger log = SimLogger.getLogger(ModularEnergyModel.class);
// private static Logger log =
// SimLogger.getLogger(ModularEnergyModel.class);
private
SimHost
host
;
...
...
@@ -78,31 +78,61 @@ public class ModularEnergyModel implements EnergyModel, EnergyEventListener,
//
try
{
SiSComponent
sis
=
host
.
getComponent
(
SiSComponent
.
class
);
sis
.
provide
().
nodeState
(
SiSTypes
.
ENERGY_BATTERY_LEVEL
,
new
SiSDataCallback
<
Double
>()
{
Set
<
INodeID
>
localID
=
INodeID
.
getSingleIDSet
(
getHost
().
getId
());
@Override
public
Double
getValue
(
INodeID
nodeID
,
SiSProviderHandle
providerHandle
)
throws
InformationNotAvailableException
{
if
(
nodeID
.
equals
(
getHost
().
getId
()))
{
return
getCurrentPercentage
();
}
else
{
throw
new
InformationNotAvailableException
();
}
}
sis
.
provide
().
nodeState
(
SiSTypes
.
ENERGY_BATTERY_LEVEL
,
new
SiSDataCallback
<
Double
>()
{
@Override
public
Set
<
INodeID
>
getObservedNodes
()
{
return
localID
;
}
Set
<
INodeID
>
localID
=
INodeID
.
getSingleIDSet
(
getHost
()
.
getId
());
@Override
public
SiSInfoProperties
getInfoProperties
()
{
return
new
SiSInfoProperties
();
}
});
@Override
public
Double
getValue
(
INodeID
nodeID
,
SiSProviderHandle
providerHandle
)
throws
InformationNotAvailableException
{
if
(
nodeID
.
equals
(
getHost
().
getId
()))
{
return
getCurrentPercentage
();
}
else
{
throw
new
InformationNotAvailableException
();
}
}
@Override
public
Set
<
INodeID
>
getObservedNodes
()
{
return
localID
;
}
@Override
public
SiSInfoProperties
getInfoProperties
()
{
return
new
SiSInfoProperties
();
}
});
sis
.
provide
().
nodeState
(
SiSTypes
.
ENERGY_BATTERY_CAPACITY
,
new
SiSDataCallback
<
Double
>()
{
Set
<
INodeID
>
localID
=
INodeID
.
getSingleIDSet
(
getHost
()
.
getId
());
@Override
public
Double
getValue
(
INodeID
nodeID
,
SiSProviderHandle
providerHandle
)
throws
InformationNotAvailableException
{
if
(
nodeID
.
equals
(
getHost
().
getId
()))
{
return
getCurrentEnergyLevel
();
}
else
{
throw
new
InformationNotAvailableException
();
}
}
@Override
public
Set
<
INodeID
>
getObservedNodes
()
{
return
localID
;
}
@Override
public
SiSInfoProperties
getInfoProperties
()
{
return
new
SiSInfoProperties
();
}
});
}
catch
(
ComponentNotAvailableException
e
)
{
// OK
}
...
...
@@ -157,6 +187,11 @@ public class ModularEnergyModel implements EnergyModel, EnergyEventListener,
return
bat
.
getCurrentPercentage
();
}
@Override
public
double
getCurrentEnergyLevel
()
{
return
bat
.
getCurrentEnergyLevel
();
}
@Override
public
void
registerComponent
(
EnergyComponent
comp
)
{
comp
.
setEnergyEventListener
(
this
);
...
...
@@ -182,9 +217,9 @@ public class ModularEnergyModel implements EnergyModel, EnergyEventListener,
//
}
//
log.debug(component.toString() + " consumed " + consumedEnergy
//
+ " uJ in State " + oldState.getName() + " after spending "
//
+ (timeSpentInOldState/Simulator.SECOND_UNIT) + " sec there.");
//
log.debug(component.toString() + " consumed " + consumedEnergy
//
+ " uJ in State " + oldState.getName() + " after spending "
//
+ (timeSpentInOldState/Simulator.SECOND_UNIT) + " sec there.");
if
(
bat
.
isEmpty
())
{
/*
...
...
src/de/tud/kom/p2psim/impl/energy/SimpleBattery.java
View file @
1353b71e
...
...
@@ -63,6 +63,14 @@ public class SimpleBattery implements Battery {
return
percent
;
}
@Override
public
double
getCurrentEnergyLevel
()
{
if
(
isEmpty
)
{
return
0.0
;
}
return
currentEnergy
;
}
@Override
public
double
getConsumedEnergy
()
{
return
capacity
-
currentEnergy
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment