diff --git a/photon-core/src/main/java/org/photonvision/common/configuration/NetworkConfig.java b/photon-core/src/main/java/org/photonvision/common/configuration/NetworkConfig.java index 8bb9701165..560492698e 100644 --- a/photon-core/src/main/java/org/photonvision/common/configuration/NetworkConfig.java +++ b/photon-core/src/main/java/org/photonvision/common/configuration/NetworkConfig.java @@ -19,10 +19,8 @@ import com.fasterxml.jackson.annotation.JsonAlias; import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSetter; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.HashMap; import java.util.Map; @@ -38,20 +36,26 @@ public class NetworkConfig { public String staticIp = ""; public String hostname = "photonvision"; public boolean runNTServer = false; + public boolean shouldManage; @JsonIgnore public static final String NM_IFACE_STRING = "${interface}"; @JsonIgnore public static final String NM_IP_STRING = "${ipaddr}"; - public String networkManagerIface = "Wired connection 1"; + public String networkManagerIface; public String setStaticCommand = "nmcli con mod ${interface} ipv4.addresses ${ipaddr}/8 ipv4.method \"manual\" ipv6.method \"disabled\""; public String setDHCPcommand = "nmcli con mod ${interface} ipv4.method \"auto\" ipv6.method \"disabled\""; - private boolean shouldManage; public NetworkConfig() { - setShouldManage(false); + if (Platform.isLinux()) { + // Default to the name of the first Ethernet connection. Otherwise, "Wired connection 1" is a reasonable guess + this.networkManagerIface = NetworkUtils.getAllWiredInterfaces().stream().map(it -> it.connName).findFirst().orElse("Wired connection 1"); + } + + // We can (usually) manage networking on Linux devices, and if we can we should try to. Command line inhibitions happen at a level above this class + setShouldManage(Platform.isLinux()); } @JsonCreator @@ -96,14 +100,14 @@ public String getEscapedInterfaceName() { return "\"" + networkManagerIface + "\""; } - @JsonGetter("shouldManage") + @JsonIgnore public boolean shouldManage() { - return this.shouldManage || Platform.isLinux(); + return this.shouldManage; } - @JsonSetter("shouldManage") + @JsonIgnore public void setShouldManage(boolean shouldManage) { - this.shouldManage = shouldManage || Platform.isLinux(); + this.shouldManage = shouldManage; } @Override diff --git a/photon-core/src/main/java/org/photonvision/common/networking/NetworkUtils.java b/photon-core/src/main/java/org/photonvision/common/networking/NetworkUtils.java index 014aede1bc..582dcc882c 100644 --- a/photon-core/src/main/java/org/photonvision/common/networking/NetworkUtils.java +++ b/photon-core/src/main/java/org/photonvision/common/networking/NetworkUtils.java @@ -23,6 +23,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; + +import org.photonvision.common.hardware.Platform; import org.photonvision.common.logging.LogGroup; import org.photonvision.common.logging.Logger; import org.photonvision.common.util.ShellExec; @@ -76,6 +78,12 @@ public String toString() { public static ArrayList getAllActiveInterfaces() { var ret = new ArrayList(); + + if (!Platform.isLinux()) { + // Can't determine interface name on Linux, give up + return ret; + } + try { var shell = new ShellExec(true, true); shell.executeBashCommand( diff --git a/photon-server/src/main/java/org/photonvision/Main.java b/photon-server/src/main/java/org/photonvision/Main.java index 7e363ac8c5..e4f72a0f8d 100644 --- a/photon-server/src/main/java/org/photonvision/Main.java +++ b/photon-server/src/main/java/org/photonvision/Main.java @@ -80,6 +80,11 @@ private static boolean handleArgs(String[] args) throws ParseException { "ignore-cameras", true, "Ignore cameras that match a regex. Uses camera name as provided by cscore."); + options.addOption( + "n", + "disable-networking", + false, + ""); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); @@ -117,46 +122,29 @@ private static void addTestModeFromFolder() { ConfigManager.getInstance().load(); try { - var reflective = new ReflectivePipelineSettings(); - var shape = new ColoredShapePipelineSettings(); - var aprilTag = new AprilTagPipelineSettings(); List collectedSources = Files.list(testModeFolder) .filter(p -> p.toFile().isFile()) .map( p -> { try { - // var camConf = - // - // ConfigManager.getInstance() - // .getConfig() - // - // .getCameraConfigurations() - // - // .get(p.getFileName().toString()); - - // if (camConf == null && false) { - CameraConfiguration camConf; - if (true) { - camConf = - new CameraConfiguration( - p.getFileName().toString(), p.toAbsolutePath().toString()); - camConf.FOV = TestUtils.WPI2019Image.FOV; // Good guess? - camConf.addCalibration(TestUtils.get2020LifeCamCoeffs(false)); - - var pipeSettings = new AprilTagPipelineSettings(); - pipeSettings.pipelineNickname = p.getFileName().toString(); - pipeSettings.outputShowMultipleTargets = true; - pipeSettings.inputShouldShow = true; - pipeSettings.outputShouldShow = false; - pipeSettings.solvePNPEnabled = true; - - var psList = new ArrayList(); - // psList.add(reflective); - // psList.add(shape); - psList.add(aprilTag); - camConf.pipelineSettings = psList; - } + CameraConfiguration camConf = + new CameraConfiguration( + p.getFileName().toString(), p.toAbsolutePath().toString()); + camConf.FOV = TestUtils.WPI2019Image.FOV; // Good guess? + camConf.addCalibration(TestUtils.get2020LifeCamCoeffs(false)); + + var pipeSettings = new AprilTagPipelineSettings(); + pipeSettings.pipelineNickname = p.getFileName().toString(); + pipeSettings.outputShowMultipleTargets = true; + pipeSettings.inputShouldShow = true; + pipeSettings.outputShouldShow = false; + pipeSettings.solvePNPEnabled = true; + + var aprilTag = new AprilTagPipelineSettings(); + var psList = new ArrayList(); + psList.add(aprilTag); + camConf.pipelineSettings = psList; return new FileVisionSource(camConf); } catch (Exception e) {