Pārlūkot izejas kodu

Adds SmartLight & Sensor Devices

Andreas T. Meyer-Berg 3 gadi atpakaļ
vecāks
revīzija
389dbdf47c

+ 37 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/devices/SmartLight.java

@@ -0,0 +1,37 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.RoomStatus;
+
+public class SmartLight extends BoolSensorDevice {
+
+	RoomStatus roomStatus;
+	private boolean trueStatus = false;
+	
+	public SmartLight(String name, RoomStatus roomStatus) {
+		super(name);
+		this.roomStatus = roomStatus;
+		
+	}
+
+	@Override
+	public void simulateTimeStep(long startTime, long duration) {
+		/**
+		 * Do nothing
+		 */
+	}
+	
+	/**
+	 * @return the trueStatus
+	 */
+	public boolean isTrueStatus() {
+		return trueStatus;
+	}
+	/**
+	 * @param trueStatus the trueStatus to set
+	 */
+	public void setTrueStatus(boolean trueStatus) {
+		this.trueStatus = trueStatus;
+		roomStatus.setLightOn(trueStatus);
+	}
+
+}

+ 42 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/devices/SmartLightSensor.java

@@ -0,0 +1,42 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.RoomStatus;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SimulationManager;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.scheduler.Schedulable;
+
+public class SmartLightSensor extends BoolSensorDevice implements Schedulable {
+
+	long eventTime = -1000;
+	long updateInterval = 10000;
+	RoomStatus roomStatus;
+	
+	public SmartLightSensor(String name, RoomStatus roomStatus, long updateInterval) {
+		super(name);
+		this.roomStatus = roomStatus;
+		this.updateInterval = updateInterval;
+		SimulationManager.scheduleEvent(this);
+		
+	}
+	@Override
+	public long getEventTime() {
+		return eventTime;
+	}
+
+	@Override
+	public void simulateTimeStep(long startTime, long duration) {
+		/**
+		 * Do nothing
+		 */
+	}
+	@Override
+	public void simulateEvent(long time) {
+		/*
+		 * get Light Status
+		 */
+		this.setBSval(roomStatus.isLightOn());
+		eventTime = time + updateInterval;
+		SimulationManager.scheduleEvent(this);
+
+	}
+
+}