2 Achegas 0a6d467f60 ... 05a24c937a

Autor SHA1 Mensaxe Data
  Andreas T. Meyer-Berg 05a24c937a Adds updated Devices to Scenario %!s(int64=3) %!d(string=hai) anos
  Andreas T. Meyer-Berg 389dbdf47c Adds SmartLight & Sensor Devices %!s(int64=3) %!d(string=hai) anos

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

@@ -16,7 +16,7 @@ public class RoomStatus implements Schedulable {
 	/**
 	 * Average temperature of the room
 	 */
-	private float temperature = 21f;
+	private float temperature = 19;
 	
 	@Override
 	public long getEventTime() {

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

+ 28 - 16
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/menuBar/MenuBarNetworkExamples.java

@@ -26,11 +26,16 @@ import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PacketSniffer;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Port;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.PrecisionLink;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Protocol;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.RoomStatus;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.BoolCollectorDevice;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.BoolSensorDevice;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatCollectorDevice;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.FloatSensorDevice;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.SmartLight;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.SmartLightSensor;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.SmartTemperatureProducer;
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices.SmartTemperatureSensor;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.distributionHandler.NormalDistributionHandler;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.protocols.MQTT_protocol;
 import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.simpleImplementation.CountingMetric;
@@ -796,7 +801,7 @@ public class MenuBarNetworkExamples extends JMenu{
 		/*
 		 * Main networking devices 
 		 */
-		SmartDevice smartHub = networkController.createSmartDevice("SmartHub", 500, 500, 50);
+		SmartDevice smartHub = networkController.createSmartDevice("SmartHub", 400, 400, 50);
 		
 		/*
 		 * Links/Networks
@@ -823,20 +828,26 @@ public class MenuBarNetworkExamples extends JMenu{
 		networkController.addDeviceToConnectionAndProtocol(pBroker, mqtt, 0);
 		networkController.addConnection(mqtt);
 		
+		/**
+		 * Room
+		 */
+		String roomName = "Bedroom";
+		RoomStatus room = new RoomStatus();
+		room.setTemperature(19f);
 		/*
 		 * Add some MQTT Devices
 		 */
 		
-		String roomName = "Bedroom";
 		/**
 		 * Room Thermostat
 		 */
-		FloatSensorDevice floatSensor = new FloatSensorDevice(roomName + " Thermostat");
+		SmartTemperatureSensor floatSensor = new SmartTemperatureSensor(roomName + " Thermostat", room);
 		floatSensor.setFSinfoName("home/" + roomName + "/sensorTemp");
 		networkController.addLinkToDevice(zigbee, floatSensor);
-		networkController.moveSmartDevice(floatSensor, 300, 500, 50);
-		floatSensor.setFSmin(15.0f);
-		floatSensor.setFSmax(32.0f);
+		networkController.moveSmartDevice(floatSensor, 300, 300, 50);
+		floatSensor.setFSmin(19.0f);
+		floatSensor.setFSmax(21.0f);
+		floatSensor.setFSval(19.0f);
 		networkController.addSmartDevice(floatSensor);
 		Port pFloatSensor = new Port(floatSensor, (short)1883, 15000);
 		pFloatSensor.setTriggerHandler(new NormalDistributionHandler(15000, 500));
@@ -845,14 +856,15 @@ public class MenuBarNetworkExamples extends JMenu{
 		networkController.addDeviceToConnectionAndProtocol(pFloatSensor, mqtt,1);
 		
 		/*
-		 * Add Heater
+		 * Add Heater (every second update)
 		 */
-		FloatSensorDevice heaterDevice = new FloatSensorDevice(roomName + "Heater");
+		SmartTemperatureProducer heaterDevice = new SmartTemperatureProducer(roomName + " Heater", room, 1000);
 		heaterDevice.setFSinfoName("home/" + roomName + "/heaterTemp");
 		networkController.addLinkToDevice(zigbee, heaterDevice);
-		networkController.moveSmartDevice(heaterDevice, 100, 600, 50);
-		heaterDevice.setFSmin(-6.0f);
-		heaterDevice.setFSmax(-4.0f);
+		networkController.moveSmartDevice(heaterDevice, 300, 500, 50);
+		heaterDevice.setFSmin(19.0f);
+		heaterDevice.setFSmax(21.0f);
+		heaterDevice.setFSval(19.0f);
 		networkController.addSmartDevice(heaterDevice);
 		Port pHeaterDevice = new Port(heaterDevice, (short)1883, 15000);
 		pHeaterDevice.setStatus(Port.SENDING);
@@ -862,12 +874,12 @@ public class MenuBarNetworkExamples extends JMenu{
 		
 		
 		/*
-		 * Add some kitchen lights
+		 * Add a light
 		 */
-		BoolSensorDevice smartLight = new BoolSensorDevice(roomName + "Light");
+		SmartLight smartLight = new SmartLight(roomName + " Light", room);
 		smartLight.setBSinfoName("home/" + roomName + "/light");
 		networkController.addLinkToDevice(zigbee, smartLight);
-		networkController.moveSmartDevice(smartLight, 250, 400, 50);
+		networkController.moveSmartDevice(smartLight, 500, 500, 50);
 		networkController.addSmartDevice(smartLight);
 		Port pSmartLight = new Port(smartLight, (short)1883, 15000);
 		pSmartLight.setTriggerHandler(new NormalDistributionHandler(15000, 500));
@@ -878,10 +890,10 @@ public class MenuBarNetworkExamples extends JMenu{
 		/*
 		 * Add light Sensor
 		 */
-		BoolSensorDevice lightSensor = new BoolSensorDevice(roomName + "Light");
+		SmartLightSensor lightSensor = new SmartLightSensor(roomName + " LightSensor", room, 10000);
 		lightSensor.setBSinfoName("home/" + roomName + "/light");
 		networkController.addLinkToDevice(zigbee, lightSensor);
-		networkController.moveSmartDevice(lightSensor, 750, 400, 50);
+		networkController.moveSmartDevice(lightSensor, 500, 300, 50);
 		networkController.addSmartDevice(lightSensor);
 		Port pLightSensor = new Port(lightSensor, (short)1883, 15000);
 		pLightSensor.setTriggerHandler(new NormalDistributionHandler(15000, 500));