|
@@ -1,5 +1,10 @@
|
|
|
package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
|
|
|
|
|
|
+import java.io.BufferedWriter;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileWriter;
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
/**
|
|
|
* Manages the Simulation by calling the relevant methods.
|
|
|
*
|
|
@@ -14,6 +19,7 @@ public class SimulationManager {
|
|
|
* True if packets should be printed
|
|
|
*/
|
|
|
boolean printPackets = false;
|
|
|
+ BufferedWriter writer;
|
|
|
/**
|
|
|
* Creates a new Simulationmanager
|
|
|
*
|
|
@@ -32,21 +38,39 @@ public class SimulationManager {
|
|
|
* @param duration
|
|
|
* Duration of the simulation interval in milliseconds
|
|
|
*/
|
|
|
- public void simulateTimeIntervall(long startTime, long duration){
|
|
|
+ public void simulateTimeIntervall(long startTime, long duration) {
|
|
|
//Simulate all Links, and their connections
|
|
|
model.getConnectionNetworks().forEach(d -> d.simulateTimeInterval(startTime, duration));
|
|
|
//Simulate SmartDevices - if they need some logic
|
|
|
model.getDevices().forEach(d -> d.simulateTimeStep(startTime, duration));
|
|
|
//Store Packages/Export Packages etc. (for debug purposes)
|
|
|
- if(printPackets)
|
|
|
- model.getConnectionNetworks().forEach(d->d.getPackets()
|
|
|
- .forEach(p->
|
|
|
- {
|
|
|
- if(p == null)
|
|
|
- System.out.println("Packet: Null");
|
|
|
- else
|
|
|
- System.out.println(p.getTextualRepresentation());
|
|
|
- }));
|
|
|
+
|
|
|
+ if(printPackets){
|
|
|
+ try {
|
|
|
+ File f = new File("testPackets.log");
|
|
|
+ f.createNewFile();
|
|
|
+ writer = new BufferedWriter(new FileWriter(f.getAbsolutePath(),true));
|
|
|
+ model.getConnectionNetworks().forEach(d->d.getPackets()
|
|
|
+ .forEach(p->
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ if(p == null)
|
|
|
+ writer.append("Packet: Null\n");
|
|
|
+ else
|
|
|
+ writer.append(p.getTextualRepresentation()+"\n");
|
|
|
+ } catch (Exception e) {
|
|
|
+ // TODO: handle exception
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ } catch (Exception e) {
|
|
|
+ // TODO: handle exception
|
|
|
+ } finally {
|
|
|
+ if(writer != null)
|
|
|
+ try {
|
|
|
+ writer.close();
|
|
|
+ } catch (IOException e) {}
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|