mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Networking bugfixes, added PixelFormat to resolution selection
This commit is contained in:
@@ -120,6 +120,7 @@ public class Main {
|
||||
|
||||
// Attempt to load the JNI Libraries
|
||||
try {
|
||||
if (CurrentPlatform.equals(Platform.LINUX_ARM64))
|
||||
CameraServerJNI.forceLoad();
|
||||
CameraServerCvJNI.forceLoad();
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -19,45 +19,23 @@ public class LinuxNetworking extends SysNetworking {
|
||||
|
||||
@Override
|
||||
public boolean setDHCP() {
|
||||
var ifaceName = networkInterface.name;
|
||||
var ethResetCmd = String.format("ifconfig %s 0.0.0.0 0.0.0.0", ifaceName);
|
||||
var dhclientCmd = String.format("dhclient %s", ifaceName);
|
||||
|
||||
|
||||
// ifconfig eth0 0.0.0.0 0.0.0.0
|
||||
String[] clearArgs = { "addr", "flush", "dev", networkInterface.name };
|
||||
try {
|
||||
int retCode = shell.execute("ifconfig", null, true, ifaceName, "0.0.0.0", "0.0.0.0");
|
||||
while (!shell.isOutputCompleted() && !shell.isErrorCompleted()) {}
|
||||
var out = shell.getOutput();
|
||||
var err = shell.getError();
|
||||
if (retCode != 0) return false;
|
||||
int clearRetCode = shell.execute("ip", clearArgs);
|
||||
int dhcpRetCode = shell.execute("dhclient", networkInterface.name);
|
||||
return clearRetCode == 0 && dhcpRetCode == 0;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
int retCode = shell.execute("dhclient", null, true, ifaceName);
|
||||
while (!shell.isOutputCompleted() && !shell.isErrorCompleted()) {}
|
||||
var out = shell.getOutput();
|
||||
var err = shell.getError();
|
||||
if (retCode != 0) return false;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setHostname(String newHostname) {
|
||||
var cmdString = String.format("hostnamectl set-hostname %s", newHostname);
|
||||
|
||||
String[] setHostnameArgs = { "set-hostname", newHostname };
|
||||
try {
|
||||
var process = Runtime.getRuntime().exec(cmdString);
|
||||
var returnCode = shell.execute("hostnamectl", null, true, "set-hostname", newHostname);
|
||||
return returnCode == 0;
|
||||
var setHostnameRetCode = shell.execute("hostnamectl", setHostnameArgs);
|
||||
return setHostnameRetCode == 0;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
@@ -67,9 +45,14 @@ public class LinuxNetworking extends SysNetworking {
|
||||
@Override
|
||||
public boolean setStatic(String ipAddress, String netmask, String gateway, String broadcast) {
|
||||
try {
|
||||
int clearRetCode = shell.execute("ip addr flush dev", null, true, networkInterface.name);
|
||||
int setIPRetCode = shell.execute(String.format("ip addr add %s/%s broadcast %s dev %s", ipAddress, netmask, broadcast, networkInterface.name), null, true);
|
||||
int setGatewayRetCode = shell.execute(String.format("ip route replace default via %s dev %s", gateway, networkInterface.name), null, false);
|
||||
String[] clearArgs = { "addr", "flush", "dev", networkInterface.name };
|
||||
String[] setIPArgs = { "addr", "add", String.format("%s/%s", ipAddress, netmask), "broadcast", broadcast, "dev", networkInterface.name };
|
||||
String[] setGatewayArgs = { "route", "replace", "default", "via", gateway, "dev", networkInterface.name };
|
||||
|
||||
int clearRetCode = shell.execute("ip", clearArgs);
|
||||
int setIPRetCode = shell.execute("ip", setIPArgs);
|
||||
int setGatewayRetCode = shell.execute("ip", setGatewayArgs);
|
||||
|
||||
return clearRetCode == 0 && setIPRetCode == 0 && setGatewayRetCode == 0;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -81,7 +81,7 @@ public class NetworkManager {
|
||||
}
|
||||
|
||||
var genSettings = SettingsManager.GeneralSettings;
|
||||
boolean isStatic = genSettings.connection_type.toLowerCase().equals("Static");
|
||||
boolean isStatic = genSettings.connection_type.toLowerCase().equals("static");
|
||||
|
||||
if (isStatic) {
|
||||
var splitIPAddr = genSettings.ip.split("\\.");
|
||||
|
||||
@@ -8,7 +8,8 @@ public enum Platform {
|
||||
WINDOWS_64("Windows x64"),
|
||||
LINUX_64("Linux x64"),
|
||||
LINUX_RASPBIAN("Linux Raspbian"),
|
||||
LINUX_AARCH64("Linux For Tegra"),
|
||||
LINUX_TEGRA("Linux For Tegra"),
|
||||
LINUX_ARM64("Linux ARM64"),
|
||||
MACOS_64("Mac OS x64"),
|
||||
UNSUPPORTED("Unsupported Platform");
|
||||
|
||||
@@ -23,7 +24,7 @@ public enum Platform {
|
||||
}
|
||||
|
||||
public boolean isLinux() {
|
||||
return this == LINUX_64 || this == LINUX_RASPBIAN || this == LINUX_AARCH64;
|
||||
return this == LINUX_64 || this == LINUX_RASPBIAN || this == LINUX_ARM64 || this == LINUX_TEGRA;
|
||||
}
|
||||
|
||||
public boolean isMac() {
|
||||
@@ -63,9 +64,10 @@ public enum Platform {
|
||||
}
|
||||
|
||||
if (osName.contains("Linux")) {
|
||||
if (osName.contains("Tegra")) return Platform.LINUX_TEGRA;
|
||||
if (osArch.equals("amd64")) return Platform.LINUX_64;
|
||||
if (osArch.contains("rasp")) return Platform.LINUX_RASPBIAN;
|
||||
if (osArch.contains("aarch")) return Platform.LINUX_64;
|
||||
if (osArch.contains("aarch")) return Platform.LINUX_ARM64;
|
||||
return Platform.UNSUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,16 @@ public class ShellExec {
|
||||
this.readError = readError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a command in current folder, and wait for process to end
|
||||
* @param command command ("c:/some/folder/script.bat" or "some/folder/script.sh")
|
||||
* @param args 0..n command line arguments
|
||||
* @return process exit code
|
||||
*/
|
||||
public int execute(String command, String... args) throws IOException {
|
||||
return execute(command, null, true, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a command.
|
||||
* @param command command ("c:/some/folder/script.bat" or "some/folder/script.sh")
|
||||
|
||||
@@ -16,7 +16,7 @@ public class Camera {
|
||||
private static final double DEFAULT_FOV = 60.8;
|
||||
private static final int MINIMUM_FPS = 30;
|
||||
private static final int MINIMUM_WIDTH = 320;
|
||||
private static final int MINIMUM_HEIGHT = 240;
|
||||
private static final int MINIMUM_HEIGHT = 200;
|
||||
private static final int MAX_INIT_MS = 1500;
|
||||
|
||||
public final String name;
|
||||
@@ -78,7 +78,7 @@ public class Camera {
|
||||
System.out.printf("Camera initialized in %.2fms\n", initTimeMs);
|
||||
}
|
||||
var trueVideoModes = UsbCam.enumerateVideoModes();
|
||||
availableVideoModes = Arrays.stream(trueVideoModes).filter(v -> v.fps >= MINIMUM_FPS && v.width >= MINIMUM_WIDTH && v.height >= MINIMUM_HEIGHT && v.pixelFormat == VideoMode.PixelFormat.kYUYV).toArray(VideoMode[]::new);
|
||||
availableVideoModes = Arrays.stream(trueVideoModes).filter(v -> v.fps >= MINIMUM_FPS && v.width >= MINIMUM_WIDTH && v.height >= MINIMUM_HEIGHT).toArray(VideoMode[]::new);
|
||||
if (availableVideoModes.length == 0) {
|
||||
System.err.println("Camera not supported!");
|
||||
throw new RuntimeException(new CameraException(CameraException.CameraExceptionType.BAD_CAMERA));
|
||||
|
||||
@@ -118,7 +118,7 @@ public class CameraManager {
|
||||
public static List<String> getResolutionList() throws CameraException {
|
||||
if (!SettingsManager.GeneralSettings.curr_camera.equals("")) {
|
||||
return Arrays.stream(CameraManager.getCamera(SettingsManager.GeneralSettings.curr_camera).getAvailableVideoModes())
|
||||
.map(res -> String.format("%s X %s at %s fps", res.width, res.height, res.fps)).collect(Collectors.toList());
|
||||
.map(res -> String.format("%s X %s at %s fps, mode: %s", res.width, res.height, res.fps, res.pixelFormat.name())).collect(Collectors.toList());
|
||||
}
|
||||
throw new CameraException(CameraException.CameraExceptionType.NO_CAMERA);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user