diff --git a/java/org/contikios/cooja/Cooja.java b/java/org/contikios/cooja/Cooja.java index 3c8e8a79d3..ea56e19871 100644 --- a/java/org/contikios/cooja/Cooja.java +++ b/java/org/contikios/cooja/Cooja.java @@ -67,6 +67,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.MissingResourceException; import java.util.Observable; import java.util.Observer; @@ -3075,8 +3076,9 @@ public static String getAbstractionLevelDescriptionOf(Class * Load configurations and create a GUI. * * @param options Parsed command line options + * @param cfg Map of key-value pairs of configuration */ - public static void go(Main options) { + public static void go(Main options, Map cfg) { externalToolsUserSettingsFileReadOnly = options.externalToolsConfig != null; if (options.externalToolsConfig == null) { externalToolsUserSettingsFile = new File(System.getProperty("user.home"), EXTERNAL_TOOLS_USER_SETTINGS_FILENAME); @@ -3123,7 +3125,9 @@ public static void go(Main options) { System.exit(1); } if (!vis) { - sim.setSpeedLimit(null); + if (Boolean.parseBoolean(cfg.get("ignore-speed-limit"))) { + sim.setSpeedLimit(null); + } sim.startSimulation(); } } diff --git a/java/org/contikios/cooja/Main.java b/java/org/contikios/cooja/Main.java index 105c3673df..bf07731855 100644 --- a/java/org/contikios/cooja/Main.java +++ b/java/org/contikios/cooja/Main.java @@ -28,6 +28,7 @@ package org.contikios.cooja; +import java.util.HashMap; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.core.Filter; import org.apache.logging.log4j.core.appender.ConsoleAppender; @@ -169,9 +170,29 @@ public static void main(String[] args) { System.setProperty("java.awt.headless", "true"); } - // Verify soundness of -nogui/-quickstart argument. + var cfg = new HashMap(); + // Parse and verify soundness of -nogui/-quickstart argument. if (options.action != null) { - String file = options.action.nogui == null ? options.action.quickstart : options.action.nogui; + // Argument on the form "file.csc[,key1=value1,key2=value2, ..]" + String arg = options.action.nogui == null ? options.action.quickstart : options.action.nogui; + String file = null; + for (var item : arg.split(",", -1)) { + if (file == null) { + file = item; + continue; + } + var pair = item.split("=", -1); + if (pair.length != 2) { + System.err.println("Faulty key=value specification: " + item); + System.exit(1); + } + cfg.put(pair[0], pair[1]); + } + if (file == null) { + System.err.println("Failed argument parsing of -nogui/-quickstart"); + System.exit(1); + } + if (!file.endsWith(".csc") && !file.endsWith(".csc.gz")) { String option = options.action.nogui == null ? "-quickstart" : "-nogui"; System.err.println("Cooja " + option + " expects a filename extension of '.csc'"); @@ -181,6 +202,12 @@ public static void main(String[] args) { System.err.println("File '" + file + "' does not exist"); System.exit(1); } + // Put back the file without key-value pairs into the parameter holder. + if (options.action.nogui != null) { + options.action.nogui = file; + } else { + options.action.quickstart = file; + } } if (options.logConfigFile != null && !Files.exists(Path.of(options.logConfigFile))) { @@ -265,10 +292,10 @@ public static void main(String[] args) { // but go immediately returns which causes the log file to be closed // while the simulation is still running. Configurator.initialize(builder.build()); - Cooja.go(options); + Cooja.go(options, cfg); } else { Configurator.initialize("ConfigFile", options.logConfigFile); - Cooja.go(options); + Cooja.go(options, cfg); } } }