Begin network rewrite

This commit is contained in:
Banks Troutman
2019-10-04 15:55:45 -04:00
parent 2d32fa21ce
commit 7699766091
20 changed files with 338 additions and 83 deletions

View File

@@ -1,7 +1,7 @@
package com.chameleonvision.settings;
import com.chameleonvision.FileHelper;
import com.chameleonvision.vision.GeneralSettings;
import com.chameleonvision.settings.network.NetworkManager;
import com.chameleonvision.util.FileHelper;
import com.chameleonvision.vision.camera.CameraManager;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -15,20 +15,21 @@ import java.nio.file.Paths;
public class SettingsManager {
public static final Path SettingsPath = Paths.get(System.getProperty("user.dir"), "settings");
public static com.chameleonvision.vision.GeneralSettings GeneralSettings;
public static com.chameleonvision.settings.GeneralSettings GeneralSettings;
private SettingsManager() {}
public static void initialize(boolean manageNetwork) {
initGeneralSettings();
if (manageNetwork) {
NetworkSettings netSettings = new NetworkSettings();
netSettings.hostname = GeneralSettings.hostname;
netSettings.gateway = GeneralSettings.gateway;
netSettings.netmask = GeneralSettings.netmask;
netSettings.connectionType = GeneralSettings.connection_type;
netSettings.ip = GeneralSettings.ip;
netSettings.run();
NetworkManager.init();
// NetworkSettings netSettings = new NetworkSettings();
// netSettings.hostname = GeneralSettings.hostname;
// netSettings.gateway = GeneralSettings.gateway;
// netSettings.netmask = GeneralSettings.netmask;
// netSettings.connectionType = GeneralSettings.connection_type;
// netSettings.ip = GeneralSettings.ip;
// netSettings.run();
}
var allCameras = CameraManager.getAllCamerasByName();
if (!allCameras.containsKey(GeneralSettings.curr_camera) && allCameras.size() > 0) {
@@ -38,49 +39,10 @@ public class SettingsManager {
}
}
public enum Platform {
WINDOWS_64("Windows x64"),
LINUX_64("Linux x64"),
LINUX_RASPBIAN("Linux Raspbian"),
LINUX_AARCH64("Linux ARM 64bit"),
MACOS_64("Mac OS x64"),
UNSUPPORTED("Unsupported Platform");
public final String value;
Platform(String value) {
this.value = value;
}
}
public static Platform getCurrentPlatform() {
var osName = System.getProperty("os.name");
var osArch = System.getProperty("os.arch");
if (osName.contains("Windows")) {
if (osArch.equals("amd64")) return Platform.WINDOWS_64;
return Platform.UNSUPPORTED;
}
if (osName.contains("Linux")) {
if (osArch.equals("amd64")) return Platform.LINUX_64;
if (osArch.contains("rasp")) return Platform.LINUX_RASPBIAN;
if (osArch.contains("aarch")) return Platform.LINUX_64;
return Platform.UNSUPPORTED;
}
if (osName.contains("Mac")) {
if (osArch.equals("amd64")) return Platform.MACOS_64;
return Platform.UNSUPPORTED;
}
return Platform.UNSUPPORTED;
}
private static void initGeneralSettings() {
FileHelper.CheckPath(SettingsPath);
try {
GeneralSettings = new Gson().fromJson(new FileReader(Paths.get(SettingsPath.toString(), "settings.json").toString()), com.chameleonvision.vision.GeneralSettings.class);
GeneralSettings = new Gson().fromJson(new FileReader(Paths.get(SettingsPath.toString(), "settings.json").toString()), com.chameleonvision.settings.GeneralSettings.class);
} catch (FileNotFoundException e) {
GeneralSettings = new GeneralSettings();
}