|
@@ -15,11 +15,22 @@ public class SimulationManager {
|
|
|
* Model which should be simulated
|
|
|
*/
|
|
|
Model model;
|
|
|
+
|
|
|
/**
|
|
|
* True if packets should be printed
|
|
|
*/
|
|
|
boolean printPackets = false;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Whether the model status changed during the last simulation and the panel should be repainted
|
|
|
+ */
|
|
|
+ boolean statusChanged = false;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Writer to write the packets to a file
|
|
|
+ */
|
|
|
BufferedWriter writer;
|
|
|
+
|
|
|
/**
|
|
|
* Creates a new Simulationmanager
|
|
|
*
|
|
@@ -39,12 +50,27 @@ public class SimulationManager {
|
|
|
* Duration of the simulation interval in milliseconds
|
|
|
*/
|
|
|
public void simulateTimeIntervall(long startTime, long duration) {
|
|
|
+ //Nothing changed so far
|
|
|
+ statusChanged = false;
|
|
|
//Simulate all Links, and their connections
|
|
|
- model.getConnectionNetworks().forEach(d -> d.simulateTimeInterval(startTime, duration));
|
|
|
+ model.getConnectionNetworks().forEach(d -> {
|
|
|
+ d.simulateTimeInterval(startTime, duration);
|
|
|
+ if(d.getStatusChanged()){
|
|
|
+ for(Connection c:d.getConnections()){
|
|
|
+ if(c.getStatus()==Connection.DONE){
|
|
|
+ model.getConnections().remove(c);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ statusChanged = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
//Simulate SmartDevices - if they need some logic
|
|
|
model.getDevices().forEach(d -> d.simulateTimeStep(startTime, duration));
|
|
|
//Store Packages/Export Packages etc. (for debug purposes)
|
|
|
-
|
|
|
+ if(statusChanged){
|
|
|
+ model.setChanged();
|
|
|
+ model.notifyObservers();
|
|
|
+ }
|
|
|
if(printPackets){
|
|
|
try {
|
|
|
File f = new File("testPackets.log");
|
|
@@ -73,6 +99,8 @@ public class SimulationManager {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|