mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Removed windows support for networksettings
This commit is contained in:
@@ -10,8 +10,9 @@ public class NetworkSettings {
|
||||
public String connectionType, ip, netmask, gateway, hostname;
|
||||
|
||||
public void run() {
|
||||
String adapter = getAdapter();
|
||||
// String adapter = getAdapter();
|
||||
if (SystemUtils.IS_OS_LINUX) {//TODO check linux commands
|
||||
String adapter = getAdapter();
|
||||
if (!adapter.equals("")) {
|
||||
executeCommand("ifconfig " + adapter + " down");
|
||||
if (connectionType.equals("DHCP"))
|
||||
@@ -24,22 +25,24 @@ public class NetworkSettings {
|
||||
}
|
||||
executeCommand("hostnamectl set-hostname " + this.hostname);
|
||||
}
|
||||
//TODO check windows commands
|
||||
else if (SystemUtils.IS_OS_WINDOWS) {
|
||||
if (!adapter.equals("")) {
|
||||
if (connectionType.equals("DHCP"))
|
||||
executeCommand("cmd /c interface ip set address \"" + adapter + "\" dhcp");
|
||||
else if (connectionType.equals("Static")) {
|
||||
executeCommand("cmd /c netsh interface ip set address \"" + adapter + "\" static " + this.ip + " " + this.netmask + " " + this.gateway + "1");
|
||||
}
|
||||
}
|
||||
//TODO find a way to change hostname in windows
|
||||
}
|
||||
// //TODO check windows commands
|
||||
// else if (SystemUtils.IS_OS_WINDOWS) {
|
||||
// if (!adapter.equals("")) {
|
||||
// if (connectionType.equals("DHCP")){
|
||||
// executeCommand("cmd /c interface ip set address \"" + adapter + "\" dhcp");
|
||||
// }
|
||||
// else if (connectionType.equals("Static")) {
|
||||
// executeCommand("cmd /c netsh interface ip set address \"" + adapter + "\" static " + this.ip + " " + this.netmask + " " + this.gateway + "1");
|
||||
// }
|
||||
// }
|
||||
// //TODO find a way to change hostname in windows
|
||||
// }
|
||||
}
|
||||
|
||||
private void executeCommand(String command) {
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
System.out.println("Executing "+ command);
|
||||
p.waitFor();
|
||||
p.destroy();
|
||||
} catch (Exception e) {
|
||||
@@ -49,13 +52,13 @@ public class NetworkSettings {
|
||||
}
|
||||
|
||||
public static String getAdapter() {
|
||||
try {
|
||||
try {//TODO fix windows get adapter
|
||||
Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
|
||||
for (NetworkInterface netint : Collections.list(nets)) {
|
||||
Enumeration<InetAddress> ee = netint.getInetAddresses();
|
||||
for (InetAddress addr : Collections.list(ee))
|
||||
if (addr instanceof Inet4Address)
|
||||
if ((addr.getAddress()[0] & 0xFF) == 10 && (addr.getAddress()[1] & 0xFF) == SettingsManager.GeneralSettings.team_number) {
|
||||
if ((addr.getAddress()[0] & 0xFF) == 192 && (addr.getAddress()[1] & 0xFF) == 168) {
|
||||
System.out.println("found robot network interface at " + netint.getName() + " ip: " + addr.getHostAddress());
|
||||
return netint.getName();
|
||||
}
|
||||
|
||||
@@ -86,9 +86,9 @@ public class ServerHandler {
|
||||
switch (key) {
|
||||
case "change_general_settings_values":
|
||||
JSONObject newSettings = (JSONObject) value;
|
||||
// setFields(SettingsManager.GeneralSettings, newSettings);
|
||||
Map<String, Object> map = newSettings.toMap();
|
||||
map.forEach((s, o) -> setField(SettingsManager.GeneralSettings, s, o));
|
||||
SettingsManager.saveSettings();
|
||||
break;
|
||||
case "curr_camera":
|
||||
String newCamera = (String) value;
|
||||
|
||||
Reference in New Issue
Block a user