Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect speed limit in csc file when headless #417

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions java/org/contikios/cooja/Cooja.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -3075,8 +3076,9 @@ public static String getAbstractionLevelDescriptionOf(Class<? extends MoteType>
* 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<String, String> cfg) {
externalToolsUserSettingsFileReadOnly = options.externalToolsConfig != null;
if (options.externalToolsConfig == null) {
externalToolsUserSettingsFile = new File(System.getProperty("user.home"), EXTERNAL_TOOLS_USER_SETTINGS_FILENAME);
Expand Down Expand Up @@ -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();
}
}
Expand Down
35 changes: 31 additions & 4 deletions java/org/contikios/cooja/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String>();
// 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'");
Expand All @@ -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))) {
Expand Down Expand Up @@ -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);
}
}
}