Skip to content

Commit

Permalink
oh whoops duplicating work from 892
Browse files Browse the repository at this point in the history
  • Loading branch information
mcm001 committed Aug 23, 2023
1 parent 8562914 commit e8c0a9e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -76,6 +78,12 @@ public String toString() {

public static ArrayList<NMDeviceInfo> getAllActiveInterfaces() {
var ret = new ArrayList<NMDeviceInfo>();

if (!Platform.isLinux()) {
// Can't determine interface name on Linux, give up
return ret;
}

try {
var shell = new ShellExec(true, true);
shell.executeBashCommand(
Expand Down
56 changes: 22 additions & 34 deletions photon-server/src/main/java/org/photonvision/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<VisionSource> 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<CVPipelineSettings>();
// 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<CVPipelineSettings>();
psList.add(aprilTag);
camConf.pipelineSettings = psList;

return new FileVisionSource(camConf);
} catch (Exception e) {
Expand Down

0 comments on commit e8c0a9e

Please sign in to comment.