Browse Source

Adds first Sensor Devices

Andreas T. Meyer-Berg 5 years ago
parent
commit
a944f51a8b

+ 9 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/SmartDevice.java

@@ -37,6 +37,15 @@ public class SmartDevice {
 		links = new LinkedList<Link>();
 		links = new LinkedList<Link>();
 		ports = new LinkedList<Port>();
 		ports = new LinkedList<Port>();
 	}
 	}
+	
+	/**
+	 * Creates a new SmartDevice without links
+	 */
+	public SmartDevice() {
+		this.name = "Unnamed";
+		links = new LinkedList<Link>();
+		ports = new LinkedList<Port>();
+	}
 
 
 	/**
 	/**
 	 * Position on the x-Axis
 	 * Position on the x-Axis

+ 68 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/devices/BoolSensorDevice.java

@@ -0,0 +1,68 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
+
+
+/**
+ * A simple boolean sensor, which will generate float reading within the given bounds.
+ *
+ * @author Andreas T. Meyer-Berg
+ */
+public class BoolSensorDevice extends SmartDevice implements BoolSensor {
+
+	/**
+	 * Current value
+	 */
+	private boolean val;
+
+	
+	/**
+	 * Name of the sensor reading
+	 */
+	private String infoName;
+	
+	/**
+	 * Initialize the Sensor
+	 */
+	public BoolSensorDevice() {
+		super();
+		init();
+	}
+	/**
+	 * Create a new Sensor with the given name
+	 * @param name
+	 */
+	public BoolSensorDevice(String name) {
+		super(name);
+		init();
+	}
+	
+	private void init(){
+		val = false;
+		infoName = "";
+	}
+	
+	@Override
+	public void simulateTimeStep(long startTime, long duration) {
+		boolean newVal = !val;
+		val = newVal;
+	}
+	@Override
+	public void setBSinfoName(String name) {
+		this.infoName = name;
+		
+	}
+	@Override
+	public String getBSinfoName() {
+		return infoName;
+	}
+	@Override
+	public boolean getBSval() {
+		return val;
+	}
+	@Override
+	public void setBSval(boolean val) {
+		this.val = val;
+	}
+
+}

+ 110 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/core/devices/FloatSensorDevice.java

@@ -0,0 +1,110 @@
+package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.devices;
+
+import java.util.Random;
+
+import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
+
+
+/**
+ * A simple float sensor, which will generate float reading within the given bounds.
+ *
+ * @author Andreas T. Meyer-Berg
+ */
+public class FloatSensorDevice extends SmartDevice implements FloatSensor {
+
+	/**
+	 * Minimum value
+	 */
+	private float min;
+	/**
+	 * Maximum value
+	 */
+	private float max;
+	/**
+	 * Current value
+	 */
+	private float val;
+	/**
+	 * Previous value
+	 */
+	private float oldVal;
+	
+	/**
+	 * Name of the sensor reading
+	 */
+	private String infoName;
+	
+	/**
+	 * Initialize the Sensor
+	 */
+	public FloatSensorDevice() {
+		super();
+		init();
+	}
+	/**
+	 * Create a new Sensor with the given name
+	 * @param name
+	 */
+	public FloatSensorDevice(String name) {
+		super(name);
+		init();
+	}
+	
+	public void init(){
+		min = 10;
+		max = 35;
+		val = 22;
+		oldVal = 22;
+		infoName = "temperature";
+	}
+	
+	@Override
+	public void setFSinfoName(String name) {
+		this.infoName = name;
+	}
+
+	@Override
+	public String getFSinfoName() {
+		return infoName;
+	}
+
+	@Override
+	public float getFSmax() {
+		return max;
+	}
+
+	@Override
+	public void setFSmax(long max) {
+		this.max = max;
+	}
+
+	@Override
+	public float getFSmin() {
+		return min;
+	}
+
+	@Override
+	public void setFSmin(long min) {
+		this.min = min;
+	}
+
+	@Override
+	public float getFSval() {
+		return val;
+	}
+
+	@Override
+	public void setFSval(long val) {
+		this.oldVal = this.val;
+		this.val = val;
+	}
+	
+	@Override
+	public void simulateTimeStep(long startTime, long duration) {
+		float newVal = val + (val-oldVal)+new Random().nextFloat()/2.0f-0.25f;
+		newVal = Math.max(Math.min(newVal, max),min);
+		this.oldVal = val;
+		val = newVal;
+	}
+
+}