2019-09-15 15:03:44 -04:00
|
|
|
package com.chameleonvision.settings;
|
2019-09-16 04:10:26 +03:00
|
|
|
|
2019-09-19 14:07:42 -04:00
|
|
|
import com.chameleonvision.FileHelper;
|
2019-09-15 15:03:44 -04:00
|
|
|
import com.chameleonvision.vision.GeneralSettings;
|
2019-09-19 14:07:42 -04:00
|
|
|
import com.chameleonvision.vision.camera.CameraManager;
|
2019-09-12 23:23:36 +03:00
|
|
|
import com.google.gson.Gson;
|
2019-09-20 02:17:22 -04:00
|
|
|
import com.google.gson.GsonBuilder;
|
2019-09-16 04:10:26 +03:00
|
|
|
|
2019-09-20 02:17:22 -04:00
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.FileReader;
|
|
|
|
|
import java.io.FileWriter;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.Paths;
|
2019-09-11 22:07:24 +03:00
|
|
|
|
2019-09-16 04:10:26 +03:00
|
|
|
public class SettingsManager {
|
2019-09-26 15:01:51 -04:00
|
|
|
public static final Path SettingsPath = Paths.get(System.getProperty("user.dir"), "settings");
|
2019-09-20 19:54:59 -04:00
|
|
|
public static com.chameleonvision.vision.GeneralSettings GeneralSettings;
|
2019-09-16 04:10:26 +03:00
|
|
|
|
2019-09-20 19:54:59 -04:00
|
|
|
private SettingsManager() {}
|
2019-09-16 04:10:26 +03:00
|
|
|
|
2019-09-21 18:38:08 +03:00
|
|
|
public static void initialize() {
|
2019-09-20 19:54:59 -04:00
|
|
|
initGeneralSettings();
|
2019-09-21 18:38:08 +03:00
|
|
|
NetworkSettings netSettings = new NetworkSettings();
|
2019-09-21 13:05:00 -04:00
|
|
|
netSettings.hostname = GeneralSettings.hostname;
|
|
|
|
|
netSettings.gateway = GeneralSettings.gateway;
|
|
|
|
|
netSettings.netmask = GeneralSettings.netmask;
|
|
|
|
|
netSettings.connectionType = GeneralSettings.connection_type;
|
|
|
|
|
netSettings.ip = GeneralSettings.ip;
|
2019-09-21 18:38:08 +03:00
|
|
|
netSettings.run();
|
2019-09-16 04:10:26 +03:00
|
|
|
|
2019-09-20 19:54:59 -04:00
|
|
|
var allCameras = CameraManager.getAllCamerasByName();
|
|
|
|
|
if (!allCameras.containsKey(GeneralSettings.curr_camera) && allCameras.size() > 0) {
|
|
|
|
|
var cam = allCameras.entrySet().stream().findFirst().get().getValue();
|
|
|
|
|
GeneralSettings.curr_camera = cam.name;
|
|
|
|
|
GeneralSettings.curr_pipeline = cam.getCurrentPipelineIndex();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-16 04:10:26 +03:00
|
|
|
|
2019-09-24 10:35:14 -04:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-20 19:54:59 -04:00
|
|
|
private static void initGeneralSettings() {
|
|
|
|
|
FileHelper.CheckPath(SettingsPath);
|
|
|
|
|
try {
|
2019-09-26 15:01:51 -04:00
|
|
|
GeneralSettings = new Gson().fromJson(new FileReader(Paths.get(SettingsPath.toString(), "settings.json").toString()), com.chameleonvision.vision.GeneralSettings.class);
|
2019-09-20 19:54:59 -04:00
|
|
|
} catch (FileNotFoundException e) {
|
|
|
|
|
GeneralSettings = new GeneralSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-11 22:07:24 +03:00
|
|
|
|
2019-09-20 19:54:59 -04:00
|
|
|
public static void updateCameraSetting(String cameraName, int pipelineNumber) {
|
|
|
|
|
GeneralSettings.curr_camera = cameraName;
|
|
|
|
|
GeneralSettings.curr_pipeline = pipelineNumber;
|
|
|
|
|
}
|
2019-09-14 17:14:49 +03:00
|
|
|
|
2019-09-20 19:54:59 -04:00
|
|
|
public static void updatePipelineSetting(int pipelineNumber) {
|
|
|
|
|
GeneralSettings.curr_pipeline = pipelineNumber;
|
|
|
|
|
}
|
2019-09-12 01:05:27 +03:00
|
|
|
|
2019-09-20 19:54:59 -04:00
|
|
|
public static void saveSettings() {
|
|
|
|
|
CameraManager.saveCameras();
|
|
|
|
|
saveGeneralSettings();
|
|
|
|
|
}
|
2019-09-16 04:10:26 +03:00
|
|
|
|
2019-09-20 19:54:59 -04:00
|
|
|
private static void saveGeneralSettings() {
|
|
|
|
|
try {
|
|
|
|
|
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
|
|
|
FileWriter writer = new FileWriter(Paths.get(SettingsPath.toString(), "settings.json").toString());
|
|
|
|
|
gson.toJson(GeneralSettings, writer);
|
|
|
|
|
writer.flush();
|
|
|
|
|
writer.close();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-10 23:47:06 +03:00
|
|
|
}
|