瀏覽代碼

Adds First Sketch of new Example Network

Andreas T. Meyer-Berg 5 年之前
父節點
當前提交
0847d613e6

+ 2 - 1
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/control/NetworkController.java

@@ -92,12 +92,13 @@ public class NetworkController {
 	 * @param z_pos
 	 *            position on the z-Axis
 	 */
-	public void createSmartDevice(String name, int x_pos, int y_pos, int z_pos) {
+	public SmartDevice createSmartDevice(String name, int x_pos, int y_pos, int z_pos) {
 		SmartDevice sd = new SmartDevice(name);
 		sd.setX(controller.getSettingsController().scalePos(x_pos, 1.0, controller.getSettingsController().getWidth()));
 		sd.setY(controller.getSettingsController().scalePos(y_pos, 1.0, controller.getSettingsController().getHeight()));
 		sd.setZ(controller.getSettingsController().scalePos(z_pos, 1.0, controller.getSettingsController().getDepth()));
 		model.addDevices(sd);
+		return sd;
 	}
 
 	/**

+ 84 - 0
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/popups/MenuBarNetworkExamples.java

@@ -1,5 +1,6 @@
 package de.tu_darmstadt.tk.SmartHomeNetworkSim.view.popups;
 
+import java.awt.print.Paper;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -105,6 +106,13 @@ public class MenuBarNetworkExamples extends JMenu{
 		JMenuItem mnPacketCollectionExmample = new JMenuItem("Packet Collection Example");
 		mnPacketCollectionExmample.addActionListener(a->testPackageCollection());
 		this.add(mnPacketCollectionExmample);
+		
+		/**
+		 * Paper example
+		 */
+		JMenuItem mnPaperExample = new JMenuItem("Paper Example");
+		mnPaperExample.addActionListener(a->createPaperExample());
+		this.add(mnPaperExample);
 	}
 	
 
@@ -405,4 +413,80 @@ public class MenuBarNetworkExamples extends JMenu{
 			controller.notifyObservers();
 		}
 	}
+	
+	public void createPaperExample(){
+		/*
+		 * Main networking devices 
+		 */
+		SmartDevice router = networkController.createSmartDevice("Wifi-Router", 500, 100, 50);
+		SmartDevice zigBeeRouter = networkController.createSmartDevice("ZigBee-Router", 500, 300, 50);
+		SmartDevice broker = networkController.createSmartDevice("Broker", 500, 500, 50);
+		
+		/*
+		 * Links/Networks
+		 */
+		Link wifi = new PrecisionLink("Wifi");
+		networkController.addLink(wifi);
+		Link zigbee = new PrecisionLink("ZigBee");
+		networkController.addLink(zigbee);
+		
+		/*
+		 * Connect Devices to Links
+		 */
+		networkController.addLinkToDevice(wifi, router);
+		networkController.addLinkToDevice(wifi, zigBeeRouter);
+		networkController.addLinkToDevice(zigbee, zigBeeRouter);
+		networkController.addLinkToDevice(zigbee, broker);
+		
+		/*
+		 * Internet Access Connection 
+		 */
+		Connection inetAcces = new ConnectionPrecision();
+		inetAcces.setName("Cloud  Access");
+		networkController.addConnectionToLink(inetAcces, wifi);
+		inetAcces.setProtocol(new SimpleProtocol());
+		Port pRouter = new Port(router, (short)80, 1000L);
+		pRouter.setTriggerInterval(-500L);
+		networkController.addDeviceToConnectionAndProtocol(pRouter, inetAcces, 0);
+		Port pZigBee = new Port(zigBeeRouter, (short)80, 1000L);
+		networkController.addDeviceToConnectionAndProtocol(pRouter, inetAcces, 0);
+		networkController.addDeviceToConnectionAndProtocol(pZigBee, inetAcces, 1);
+		networkController.addConnection(inetAcces);
+		
+		
+		/*
+		 * Create MQTT Connection
+		 */
+		Connection mqtt = new ConnectionPrecision();
+		mqtt.setName("Automation (MQTT)");
+		networkController.addConnectionToLink(mqtt, zigbee);
+		mqtt.setProtocol(new MQTT_protocol());
+		Port pBroker = new Port(broker, (short)1883);
+		pBroker.setStatus(Port.OPEN);
+		pBroker.setResponseTime((short)2);
+		networkController.addDeviceToConnectionAndProtocol(pBroker, mqtt, 0);
+		networkController.addConnection(mqtt);
+		
+		/*
+		 * Add some MQTT Devices
+		 */
+		FloatSensorDevice floatSensor = new FloatSensorDevice("Thermostat 1");
+		floatSensor.setFSinfoName("home/kitchen/temperature");
+		networkController.addLinkToDevice(zigbee, floatSensor);
+		networkController.moveSmartDevice(floatSensor, 300, 500, 50);
+		floatSensor.setFSmin(15.0f);
+		floatSensor.setFSmax(32.0f);
+		networkController.addSmartDevice(floatSensor);
+		Port pFloatSensor = new Port(floatSensor, (short)1883);
+		pFloatSensor.setStatus(Port.SENDING);
+		pFloatSensor.setLastTrigger(-357L);
+		pFloatSensor.setTriggerInterval(15000);//15sek
+		networkController.addDeviceToConnectionAndProtocol(pFloatSensor, mqtt,1);
+		
+		
+		/* 
+		 * Update visualization 
+		 */
+		controller.notifyObservers();
+	}
 }