mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
Merge remote-tracking branch 'origin/Java' into Java
This commit is contained in:
@@ -8,7 +8,7 @@ import com.chameleonvision.web.Server;
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
if (CameraManager.initializeCameras()) {
|
||||
SettingsManager.intialize();
|
||||
SettingsManager.initialize();
|
||||
for (var camSet : CameraManager.getAllCamerasByName().entrySet()) {
|
||||
new Thread(new CameraProcess(camSet.getValue())).start();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.chameleonvision.settings;
|
||||
|
||||
import java.net.*;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.apache.commons.lang3.SystemUtils;
|
||||
|
||||
public class NetworkSettings {
|
||||
public String connectionType, ip, netmask, gateway, hostname;
|
||||
|
||||
public void run() {
|
||||
String adapter = getAdapter();
|
||||
if (SystemUtils.IS_OS_LINUX) {//TODO check linux commands
|
||||
if (!adapter.equals("")) {
|
||||
executeCommand("ifconfig " + adapter + " down");
|
||||
if (connectionType.equals("DHCP"))
|
||||
executeCommand("dhclient -r " + adapter);
|
||||
else if (connectionType.equals("Static")) {
|
||||
executeCommand("ifconfig " + adapter + " " + this.ip + " netmask " + this.netmask);
|
||||
executeCommand("route add default gw " + this.gateway + " " + adapter);
|
||||
}
|
||||
executeCommand("ifconfig " + adapter + " up");
|
||||
}
|
||||
executeCommand("hostnamectl set-hostname " + this.hostname);
|
||||
}
|
||||
//TODO add windows networking commands
|
||||
|
||||
// else
|
||||
// if (SystemUtils.IS_OS_WINDOWS)
|
||||
// {
|
||||
// executeCommand("cmd /c COMMAND HERE");
|
||||
// }
|
||||
}
|
||||
|
||||
private void executeCommand(String command) {
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
p.waitFor();
|
||||
p.destroy();
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error while executing command!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getAdapter() {
|
||||
try {
|
||||
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) {
|
||||
System.out.println("found robot network interface at " + netint.getName() + " ip: " + addr.getHostAddress());
|
||||
return netint.getName();
|
||||
}
|
||||
}
|
||||
} catch (SocketException e) {
|
||||
System.err.println("Socket exception while trying to find current ip");
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -12,16 +12,24 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SettingsManager {
|
||||
public static final Path SettingsPath = Paths.get(System.getProperty("user.dir"), "Settings");
|
||||
public static com.chameleonvision.vision.GeneralSettings GeneralSettings;
|
||||
// public static HashMap<String, String> CameraPorts = new HashMap<>();//TODO Implement ports
|
||||
public static HashMap<String, Integer> CameraPorts = new HashMap<>();
|
||||
|
||||
private SettingsManager() {}
|
||||
|
||||
public static void intialize() {
|
||||
public static void initialize() {
|
||||
initGeneralSettings();
|
||||
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) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.chameleonvision.vision.camera;
|
||||
|
||||
import com.chameleonvision.settings.SettingsManager;
|
||||
import com.chameleonvision.vision.Pipeline;
|
||||
import edu.wpi.cscore.*;
|
||||
import edu.wpi.first.cameraserver.CameraServer;
|
||||
@@ -68,6 +69,8 @@ public class Camera {
|
||||
|
||||
cvSink = cs.getVideo(UsbCam);
|
||||
cvSource = cs.putVideo(name, camVals.ImageWidth, camVals.ImageHeight);
|
||||
var s = (MjpegServer) cs.getServer("serve_" + name);
|
||||
SettingsManager.CameraPorts.put(name, s.getPort());
|
||||
}
|
||||
|
||||
public void setCamVideoMode(int videoMode) {
|
||||
|
||||
@@ -65,7 +65,10 @@ public class CameraProcess implements Runnable {
|
||||
|
||||
camera.setExposure(pipeline.exposure);
|
||||
camera.setBrightness(pipeline.brightness);
|
||||
//TODO Send Pipeline change using websocket to client
|
||||
HashMap<String,Object> pipeChange = new HashMap<>();
|
||||
pipeChange.put("curr_pipeline",ntPipelineIndex);
|
||||
Server.handler.broadcastMessage(pipeChange);
|
||||
|
||||
} else {
|
||||
ntPipelineEntry.setString("pipeline" + camera.getCurrentPipelineIndex());
|
||||
}
|
||||
@@ -113,7 +116,6 @@ public class CameraProcess implements Runnable {
|
||||
ntTimeStampEntry.setNumber(TimeStamp);
|
||||
}
|
||||
|
||||
// TODO: Separate video output to separate function, maybe even second thread
|
||||
private PipelineResult runVisionProcess(Mat inputImage, Mat outputImage) {
|
||||
var pipelineResult = new PipelineResult();
|
||||
|
||||
|
||||
@@ -83,8 +83,9 @@ public class ServerHandler {
|
||||
String newCamera = (String) value;
|
||||
System.out.printf("Changing camera to %s\n", newCamera);
|
||||
CameraManager.setCurrentCamera(newCamera);
|
||||
//broadcastMessage((Map<String, Object>) new HashMap<String, Object>(){}.put("port",SettingsManager.CameraPorts.get(SettingsManager.GeneralSettings.curr_camera)));
|
||||
broadcastMessage(new HashMap<String, Object>(){}.put("port",SettingsManager.CameraPorts.get(SettingsManager.GeneralSettings.curr_camera)));
|
||||
broadcastMessage(CameraManager.getCurrentCamera()); //TODO CHECK JSON FOR CAMERA CHANGE
|
||||
|
||||
break;
|
||||
case "curr_pipeline":
|
||||
String newPipeline = (String) value;
|
||||
@@ -182,7 +183,7 @@ public class ServerHandler {
|
||||
fullSettings.put("resolutionList", CameraManager.getResolutionList());
|
||||
fullSettings.put("resolution", currentCamera.getVideoModeIndex());
|
||||
fullSettings.put("FOV", currentCamera.getFOV());
|
||||
// fullSettings.put("port", SettingsManager.CameraPorts.get(SettingsManager.GeneralSettings.curr_camera));
|
||||
fullSettings.put("port", SettingsManager.CameraPorts.get(SettingsManager.GeneralSettings.curr_camera));
|
||||
} catch (CameraException e) {
|
||||
System.err.println("No camera found!");
|
||||
//TODO: add message to ui to inform that there are no cameras
|
||||
|
||||
Reference in New Issue
Block a user