2 Ревизии 2303e1e205 ... 0a6d467f60

Автор SHA1 Съобщение Дата
  Andreas T. Meyer-Berg 0a6d467f60 Adds Temperature Sensor & Producer, which use room temperature преди 3 години
  Andreas T. Meyer-Berg 863e8f2b7c Adds basic room for sharing values between devices преди 3 години

+ 47 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/RoomStatus.java

@@ -0,0 +1,47 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.scheduler.Schedulable;
+
+/**
+ * Class for storing attributes of a room, and sharing it between different devices
+ *
+ */
+public class RoomStatus implements Schedulable {
+
+	/**
+	 * True if light is on
+	 */
+	private boolean lightOn = false;
+	
+	/**
+	 * Average temperature of the room
+	 */
+	private float temperature = 21f;
+	
+	@Override
+	public long getEventTime() {
+		return Long.MAX_VALUE;
+	}
+
+	@Override
+	public void simulateEvent(long time) {
+		// TODO: Maybe simulation? e.g. sharing temperature with other rooms, outside etc.
+	}
+
+	public boolean isLightOn() {
+		return lightOn;
+	}
+
+	public void setLightOn(boolean lightOn) {
+		this.lightOn = lightOn;
+	}
+
+	public float getTemperature() {
+		return temperature;
+	}
+
+	public void setTemperature(float temperature) {
+		this.temperature = temperature;
+	}
+
+}

+ 17 - 2
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/devices/FloatSensorDevice.java

@@ -36,6 +36,10 @@ public class FloatSensorDevice extends SmartDevice implements FloatSensor, Sched
 	 */
 	long nextSimulationTime = 0;
 	
+	/**
+	 * Update interval
+	 */
+	int updateInterval = 10000;
 	/**
 	 * Name of the sensor reading
 	 */
@@ -57,6 +61,17 @@ public class FloatSensorDevice extends SmartDevice implements FloatSensor, Sched
 		init();
 	}
 	
+	/**
+	 * Create a new Sensor with the given name and update interval
+	 * @param name
+	 * @param updateInterval
+	 */
+	public FloatSensorDevice(String name, int updateInterval) {
+		super(name);
+		this.updateInterval = updateInterval;
+		init();
+	}
+	
 	public void init(){
 		min = 10;
 		max = 35;
@@ -120,11 +135,11 @@ public class FloatSensorDevice extends SmartDevice implements FloatSensor, Sched
 	public void simulateEvent(long time) {
 		updateData();
 		//Update again in 10 seconds
-		nextSimulationTime=time + 10000;
+		nextSimulationTime=time + updateInterval;
 		SimulationManager.scheduleEvent(this);
 	}
 	
-	private void updateData() {
+	protected void updateData() {
 		float newVal = val + (val-oldVal)+new Random().nextFloat()/2.0f-0.25f;
 		newVal = Math.max(Math.min(newVal, max),min);
 		this.oldVal = val;

+ 46 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/devices/SmartTemperatureProducer.java

@@ -0,0 +1,46 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.RoomStatus;
+
+public class SmartTemperatureProducer extends FloatSensorDevice {
+	
+	
+	private RoomStatus roomStatus;
+	private float tempChangePerHour = 0;
+	private float trueTemperature = 10f;
+	
+	public SmartTemperatureProducer(String name, RoomStatus room, int updateInterval) {
+		super(name, updateInterval);
+		roomStatus = room;
+	}
+	
+	@Override
+	protected void updateData() {
+		/**
+		 * Slowly move room temperature to producer temperature
+		 */
+		float cTemp = roomStatus.getTemperature();
+		if(tempChangePerHour > 0) {
+			roomStatus.setTemperature(Math.min(cTemp, cTemp + tempChangePerHour * (float)super.updateInterval/3600000f));
+		} else if(tempChangePerHour < 0) {
+			roomStatus.setTemperature(Math.max(cTemp, cTemp + tempChangePerHour * (float)super.updateInterval/3600000f));
+		}
+		if(roomStatus.getTemperature() == getFSval()) {
+			tempChangePerHour = 0;
+		}
+	}
+
+	public float getTrueTemperature() {
+		return trueTemperature;
+		
+	}
+
+	public void setTrueTemperature(float trueTemperature) {
+		this.trueTemperature = trueTemperature;
+		/*
+		 * Change temperature in 1 hour to target temperature 
+		 */
+		tempChangePerHour = trueTemperature-roomStatus.getTemperature();
+	}
+	
+}

+ 24 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/devices/SmartTemperatureSensor.java

@@ -0,0 +1,24 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.RoomStatus;
+
+public class SmartTemperatureSensor extends FloatSensorDevice {
+	
+	
+	private RoomStatus roomStatus;
+
+	
+	public SmartTemperatureSensor(String name, RoomStatus room) {
+		super(name);
+		roomStatus = room;
+	}
+	
+	@Override
+	protected void updateData() {
+		/**
+		 * Update Temperature to Room Temperature
+		 */
+		super.setFSval(roomStatus.getTemperature());
+	}
+	
+}