Commit 1de811e3 authored by Julian Zobel's avatar Julian Zobel
Browse files

Moved energy models and components into their own packages, this is more...

Moved energy models and components into their own packages, this is more convenient w/ a better overview
parent c3ef5c28
......@@ -52,6 +52,10 @@ public enum ComponentType {
/**
* Other components which consume energy
*/
BASIC
BASIC,
/**
* Actuators, Motors, Rotors
*/
ACTUATOR
}
......@@ -55,7 +55,7 @@ public interface EnergyModel extends SimHostComponent {
*
* @return
*/
public EnergyInfo getInfo();
public EnergyInfo getEnergyInfo();
/**
* Save some casting and use this method to return all components of the
......
......@@ -28,6 +28,7 @@ import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.EnergyConfiguration;
import de.tud.kom.p2psim.api.energy.EnergyModel;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.impl.energy.models.ModularEnergyModel;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
......
/*
* Copyright (c) 2005-2010 KOM � Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.energy.components;
import de.tud.kom.p2psim.api.energy.ComponentType;
import de.tud.kom.p2psim.api.energy.EnergyComponent;
import de.tud.kom.p2psim.api.energy.EnergyEventListener;
import de.tud.kom.p2psim.api.energy.EnergyState;
import de.tud.kom.p2psim.impl.energy.DefaultEnergyState;
import de.tudarmstadt.maki.simonstrator.api.Time;
public class ActuatorEnergyComponent implements EnergyComponent {
/**
* States supported by this energy component
*
* TODO More states reflecting a more accurate energy consumption?
*/
public final EnergyState OFF, HOVER, FLY;
private EnergyState currentState;
private EnergyEventListener energyModel;
private long lastStateChange;
public ActuatorEnergyComponent(int numberOfActuators, double volt, double hoverAmp, double flyAmp) {
OFF = new DefaultEnergyState("OFF", 0);
HOVER = new DefaultEnergyState("HOVER", numberOfActuators * (hoverAmp * volt) * 1000000);
FLY = new DefaultEnergyState("FLY", numberOfActuators * (flyAmp * volt) * 1000000);
this.currentState = OFF;
this.lastStateChange = Time.getCurrentTime();
}
public void doStateChange(EnergyState newState) {
// FIXME TODO
long timeSpentInState = Time.getCurrentTime() - lastStateChange;
energyModel.switchedState(this, currentState, newState,
timeSpentInState);
currentState = newState;
lastStateChange = Time.getCurrentTime();
}
@Override
public void eventOccurred(Object content, int type) {
// TODO Auto-generated method stub
}
@Override
public ComponentType getType() {
return ComponentType.ACTUATOR;
}
@Override
public void turnOff() {
if(!currentState.equals(OFF)) {
doStateChange(OFF);
}
}
@Override
public boolean turnOn() {
// TODO
return false;
}
public boolean isAvailable() {
// TODO
return false;
}
@Override
public boolean isOn() {
// TODO
return false;
}
@Override
public void setEnergyEventListener(EnergyEventListener listener) {
energyModel = listener;
}
public EnergyState getCurrentState() {
return currentState;
}
}
......@@ -18,11 +18,12 @@
*
*/
package de.tud.kom.p2psim.impl.energy;
package de.tud.kom.p2psim.impl.energy.components;
import de.tud.kom.p2psim.api.energy.ComponentType;
import de.tud.kom.p2psim.api.energy.EnergyComponent;
import de.tud.kom.p2psim.api.energy.EnergyEventListener;
import de.tud.kom.p2psim.impl.energy.DefaultEnergyState;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.Time;
......
......@@ -18,7 +18,7 @@
*
*/
package de.tud.kom.p2psim.impl.energy;
package de.tud.kom.p2psim.impl.energy.components;
import de.tud.kom.p2psim.api.energy.ComponentType;
import de.tud.kom.p2psim.api.energy.EnergyCommunicationComponent;
......@@ -26,6 +26,7 @@ import de.tud.kom.p2psim.api.energy.EnergyEventListener;
import de.tud.kom.p2psim.api.energy.EnergyModel;
import de.tud.kom.p2psim.api.energy.EnergyState;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.impl.energy.DefaultEnergyState;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tudarmstadt.maki.simonstrator.api.Message;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
......
......@@ -18,7 +18,7 @@
*
*/
package de.tud.kom.p2psim.impl.energy;
package de.tud.kom.p2psim.impl.energy.components;
import de.tud.kom.p2psim.api.energy.ComponentType;
import de.tud.kom.p2psim.api.energy.EnergyCommunicationComponent;
......@@ -26,6 +26,7 @@ import de.tud.kom.p2psim.api.energy.EnergyEventListener;
import de.tud.kom.p2psim.api.energy.EnergyModel;
import de.tud.kom.p2psim.api.energy.EnergyState;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.impl.energy.DefaultEnergyState;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tudarmstadt.maki.simonstrator.api.Message;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
......
......@@ -18,13 +18,14 @@
*
*/
package de.tud.kom.p2psim.impl.energy;
package de.tud.kom.p2psim.impl.energy.components;
import de.tud.kom.p2psim.api.energy.ComponentType;
import de.tud.kom.p2psim.api.energy.EnergyCommunicationComponent;
import de.tud.kom.p2psim.api.energy.EnergyEventListener;
import de.tud.kom.p2psim.api.energy.EnergyState;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.impl.energy.DefaultEnergyState;
import de.tudarmstadt.maki.simonstrator.api.Message;
import de.tudarmstadt.maki.simonstrator.api.Time;
......
......@@ -18,13 +18,15 @@
*
*/
package de.tud.kom.p2psim.impl.energy;
package de.tud.kom.p2psim.impl.energy.components;
import de.tud.kom.p2psim.api.energy.ComponentType;
import de.tud.kom.p2psim.api.energy.EnergyCommunicationComponent;
import de.tud.kom.p2psim.api.energy.EnergyEventListener;
import de.tud.kom.p2psim.api.energy.EnergyState;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.impl.energy.DefaultEnergyState;
import de.tud.kom.p2psim.impl.energy.models.ModularEnergyModel;
import de.tudarmstadt.maki.simonstrator.api.Message;
import de.tudarmstadt.maki.simonstrator.api.Time;
......
......@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.energy.configs;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.ComponentType;
import de.tud.kom.p2psim.api.energy.EnergyConfiguration;
import de.tud.kom.p2psim.impl.energy.OneStateEnergyComponent;
import de.tud.kom.p2psim.impl.energy.components.OneStateEnergyComponent;
/**
* This class creates an Energy Component for basic Energy Consumption. It
......
......@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.energy.configs;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.EnergyConfiguration;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.impl.energy.SmartphoneCellularCommunicationEnergyComponent;
import de.tud.kom.p2psim.impl.energy.components.SmartphoneCellularCommunicationEnergyComponent;
public class CellularTimeBased implements
EnergyConfiguration<SmartphoneCellularCommunicationEnergyComponent> {
......
......@@ -24,7 +24,7 @@ import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.EnergyCommunicationComponent;
import de.tud.kom.p2psim.api.energy.EnergyConfiguration;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.impl.energy.StatelessCommunicationComponent;
import de.tud.kom.p2psim.impl.energy.components.StatelessCommunicationComponent;
/**
* This is a Message-Based {@link EnergyCommunicationComponent}-creating
......
......@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.energy.configs;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.EnergyConfiguration;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.impl.energy.StateEnergyCommunicationComponent;
import de.tud.kom.p2psim.impl.energy.components.StateEnergyCommunicationComponent;
/**
* This class contains the measured values from the Nexus One in the AdHoc Mode.
......
......@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.energy.configs;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.EnergyConfiguration;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.impl.energy.SmartphoneCommunicationEnergyComponent;
import de.tud.kom.p2psim.impl.energy.components.SmartphoneCommunicationEnergyComponent;
public class TimeBased implements
EnergyConfiguration<SmartphoneCommunicationEnergyComponent> {
......
......@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.energy.configs;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.EnergyConfiguration;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.impl.energy.StateEnergyCommunicationComponent;
import de.tud.kom.p2psim.impl.energy.components.StateEnergyCommunicationComponent;
/**
* This class is a configuration for the
......
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.energy.models;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.ComponentType;
import de.tud.kom.p2psim.api.energy.EnergyComponent;
import de.tud.kom.p2psim.api.energy.EnergyInfo;
import de.tud.kom.p2psim.api.energy.EnergyModel;
import de.tud.kom.p2psim.impl.energy.Battery;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.battery.BatterySensor;
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.SiSInformationProvider.SiSProviderHandle;
import de.tudarmstadt.maki.simonstrator.api.component.sis.exception.InformationNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
public abstract class AbstractEnergyModel implements EnergyModel, BatterySensor, EnergyInfo {
protected SimHost host;
protected List<EnergyComponent> energyComponents;
protected Battery bat;
public AbstractEnergyModel(SimHost host, Battery bat) {
energyComponents = new Vector<EnergyComponent>();
this.bat = bat;
this.host = host;
}
@Override
public void initialize() {
//
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();
}
}
@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
}
}
@Override
public <T extends EnergyComponent> List<T> getComponents(
ComponentType type, Class<T> componentClass) {
List<T> componentsOfType = new Vector<T>();
for (EnergyComponent energyComponent : energyComponents) {
if (energyComponent.getType().equals(type)
&& componentClass.isInstance(energyComponent)) {
componentsOfType.add(componentClass.cast(energyComponent));
}
}
return componentsOfType;
}
@Override
public <T extends EnergyComponent> T getComponent(ComponentType type,
Class<T> componentClass) {
for (EnergyComponent energyComponent : energyComponents) {
if (energyComponent.getType().equals(type)
&& componentClass.isInstance(energyComponent)) {
return componentClass.cast(energyComponent);
}
}
return null;
}
@Override
public EnergyInfo getEnergyInfo() {
/*
* We export our status to interested applications via this interface
*/
return this;
}
@Override
public Battery getBattery() {
return bat;
}
@Override
public double getCurrentPercentage() {
return bat.getCurrentPercentage();
}
@Override
public double getCurrentEnergyLevel() {
return bat.getCurrentEnergyLevel();
}
@Override
public SimHost getHost() {
return host;
}
@Override
public void shutdown() {
throw new AssertionError(
"You are not supposed to shutdown this component.");
}
@Override
public void reset() {
throw new AssertionError(
"You are not supposed to reset this component.");
}
}
......@@ -18,12 +18,14 @@
*
*/
package de.tud.kom.p2psim.impl.energy;
package de.tud.kom.p2psim.impl.energy.models;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import org.joda.time.chrono.JulianChronology;
import de.tud.kom.p2psim.api.analyzer.EnergyAnalyzer;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.energy.ComponentType;
......@@ -33,6 +35,7 @@ import de.tud.kom.p2psim.api.energy.EnergyInfo;
import de.tud.kom.p2psim.api.energy.EnergyModel;
import de.tud.kom.p2psim.api.energy.EnergyState;
import de.tud.kom.p2psim.api.network.SimNetInterface;
import de.tud.kom.p2psim.impl.energy.Battery;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
......@@ -52,25 +55,14 @@ import de.tudarmstadt.maki.simonstrator.api.component.sis.type.SiSTypes;
* <i>old</i> EnergyModels these are Host components, ie. there is one instance
* for each host.
*
* @author Bjoern Richerzhagen
* @version 1.0, 27.02.2012
* @author Bjoern Richerzhagen, Julian Zobel
* @version 2.0, 07.09.2018
*/
public class ModularEnergyModel implements EnergyModel, EnergyEventListener,
EnergyInfo, BatterySensor {
// private static Logger log =
// SimLogger.getLogger(ModularEnergyModel.class);
private SimHost host;
public class ModularEnergyModel extends AbstractEnergyModel implements EnergyEventListener {
private List<EnergyComponent> energyComponents;
private Battery bat;
public ModularEnergyModel(SimHost host, Battery bat) {
energyComponents = new Vector<EnergyComponent>();
this.bat = bat;
this.host = host;
super(host, bat);
}
@Override
......@@ -138,60 +130,6 @@ public class ModularEnergyModel implements EnergyModel, EnergyEventListener,
}
}
@Override
public void shutdown() {
throw new AssertionError(
"You are not supposed to shutdown this component.");
}
@Override
public <T extends EnergyComponent> List<T> getComponents(
ComponentType type, Class<T> componentClass) {
List<T> componentsOfType = new Vector<T>();
for (EnergyComponent energyComponent : energyComponents) {
if (energyComponent.getType().equals(type)
&& componentClass.isInstance(energyComponent)) {
componentsOfType.add(componentClass.cast(energyComponent));
}
}
return componentsOfType;
}
@Override
public <T extends EnergyComponent> T getComponent(ComponentType type,
Class<T> componentClass) {
for (EnergyComponent energyComponent : energyComponents) {
if (energyComponent.getType().equals(type)
&& componentClass.isInstance(energyComponent)) {
return componentClass.cast(energyComponent);
}
}
return null;
}
@Override
public EnergyInfo getInfo() {
/*
* We export our status to interested applications via this interface
*/
return this;
}
@Override
public Battery getBattery() {
return bat;
}
@Override
public double getCurrentPercentage() {
return bat.getCurrentPercentage();
}
@Override
public double getCurrentEnergyLevel() {
return bat.getCurrentEnergyLevel();
}
@Override
public void registerComponent(EnergyComponent comp) {
comp.setEnergyEventListener(this);
......@@ -242,12 +180,7 @@ public class ModularEnergyModel implements EnergyModel, EnergyEventListener,
public boolean turnOn(EnergyComponent component) {
return !bat.isEmpty();
}
@Override
public SimHost getHost() {
return host;
}
@Override
public void reset() {
bat.reset();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment