瀏覽代碼

Adds Temperature Sensor & Producer, which use room temperature

* Producer has a True value, the FS Value, to enable creation of
anomalies
Andreas T. Meyer-Berg 3 年之前
父節點
當前提交
0a6d467f60

+ 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());
+	}
+	
+}