From 3c85291610f3d3120c728e6a45fa6684b61da4f5 Mon Sep 17 00:00:00 2001 From: amquake Date: Wed, 27 Sep 2023 18:37:27 -0700 Subject: [PATCH 1/2] Pi startup fix (#923) --- .../common/networking/NetworkUtils.java | 14 ++++++-- .../vision/camera/LibcameraGpuSettables.java | 33 ++++++++++--------- .../vision/processes/VisionSourceManager.java | 2 +- .../processes/VisionSourceSettables.java | 2 +- .../src/main/java/org/photonvision/Main.java | 6 ++++ 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/photon-core/src/main/java/org/photonvision/common/networking/NetworkUtils.java b/photon-core/src/main/java/org/photonvision/common/networking/NetworkUtils.java index 91d762e205..2bcf0072a0 100644 --- a/photon-core/src/main/java/org/photonvision/common/networking/NetworkUtils.java +++ b/photon-core/src/main/java/org/photonvision/common/networking/NetworkUtils.java @@ -75,16 +75,23 @@ public String toString() { } } - public static ArrayList getAllInterfaces() { + private static List allInterfaces = new ArrayList<>(); + private static long lastReadTimestamp = 0; + + public static List getAllInterfaces() { + long now = System.currentTimeMillis(); + if (now - lastReadTimestamp < 5000) return allInterfaces; + else lastReadTimestamp = now; + var ret = new ArrayList(); if (!Platform.isLinux()) { - // Can't determine interface name on Linux, give up + // Can only determine interface name on Linux, give up return ret; } try { - var shell = new ShellExec(true, true); + var shell = new ShellExec(true, false); shell.executeBashCommand( "nmcli -t -f GENERAL.CONNECTION,GENERAL.DEVICE,GENERAL.TYPE device show"); String out = shell.getOutput(); @@ -103,6 +110,7 @@ public static ArrayList getAllInterfaces() { logger.debug("Found network interfaces:\n" + ret.toString()); + allInterfaces = ret; return ret; } diff --git a/photon-core/src/main/java/org/photonvision/vision/camera/LibcameraGpuSettables.java b/photon-core/src/main/java/org/photonvision/vision/camera/LibcameraGpuSettables.java index f3b32d44c2..22c76131aa 100644 --- a/photon-core/src/main/java/org/photonvision/vision/camera/LibcameraGpuSettables.java +++ b/photon-core/src/main/java/org/photonvision/vision/camera/LibcameraGpuSettables.java @@ -199,26 +199,27 @@ protected void setVideoModeInternal(VideoMode videoMode) { // We need to make sure that other threads don't try to do anything funny while we're recreating // the camera synchronized (LibCameraJNI.CAMERA_LOCK) { - boolean success = false; if (m_initialized) { - success |= LibCameraJNI.stopCamera(); - success |= LibCameraJNI.destroyCamera(); + logger.debug("Stopping libcamera"); + if (!LibCameraJNI.stopCamera()) { + logger.error("Couldn't stop a zero copy Pi Camera while switching video modes"); + } + logger.debug("Destroying libcamera"); + if (!LibCameraJNI.destroyCamera()) { + logger.error("Couldn't destroy a zero copy Pi Camera while switching video modes"); + } } - // if (!success) { - // throw new RuntimeException( - // "Couldn't destroy a zero copy Pi Camera while switching video modes"); - // } - - System.out.println("Starting camera"); - success |= - LibCameraJNI.createCamera( - mode.width, mode.height, (m_rotationMode == ImageRotationMode.DEG_180 ? 180 : 0)); - success |= LibCameraJNI.startCamera(); - if (!success) { - throw new RuntimeException( - "Couldn't create a zero copy Pi Camera while switching video modes"); + logger.debug("Creating libcamera"); + if (!LibCameraJNI.createCamera( + mode.width, mode.height, (m_rotationMode == ImageRotationMode.DEG_180 ? 180 : 0))) { + logger.error("Couldn't create a zero copy Pi Camera while switching video modes"); } + logger.debug("Starting libcamera"); + if (!LibCameraJNI.startCamera()) { + logger.error("Couldn't start a zero copy Pi Camera while switching video modes"); + } + m_initialized = true; } diff --git a/photon-core/src/main/java/org/photonvision/vision/processes/VisionSourceManager.java b/photon-core/src/main/java/org/photonvision/vision/processes/VisionSourceManager.java index 3d9c27046c..bcb75e7f32 100644 --- a/photon-core/src/main/java/org/photonvision/vision/processes/VisionSourceManager.java +++ b/photon-core/src/main/java/org/photonvision/vision/processes/VisionSourceManager.java @@ -326,7 +326,7 @@ private static List loadVisionSourcesFromCamConfigs( List camConfigs) { var cameraSources = new ArrayList(); for (var configuration : camConfigs) { - System.out.println("Creating VisionSource for " + configuration); + logger.debug("Creating VisionSource for " + configuration); // Picams should have csi-video in the path boolean is_picam = diff --git a/photon-core/src/main/java/org/photonvision/vision/processes/VisionSourceSettables.java b/photon-core/src/main/java/org/photonvision/vision/processes/VisionSourceSettables.java index 63e643c8bb..cda7d08e6f 100644 --- a/photon-core/src/main/java/org/photonvision/vision/processes/VisionSourceSettables.java +++ b/photon-core/src/main/java/org/photonvision/vision/processes/VisionSourceSettables.java @@ -26,7 +26,7 @@ import org.photonvision.vision.frame.FrameStaticProperties; public abstract class VisionSourceSettables { - private static final Logger logger = + protected static final Logger logger = new Logger(VisionSourceSettables.class, LogGroup.VisionModule); private final CameraConfiguration configuration; diff --git a/photon-server/src/main/java/org/photonvision/Main.java b/photon-server/src/main/java/org/photonvision/Main.java index 008dad0d54..db8787208d 100644 --- a/photon-server/src/main/java/org/photonvision/Main.java +++ b/photon-server/src/main/java/org/photonvision/Main.java @@ -344,18 +344,23 @@ public static void main(String[] args) { + Platform.getPlatformName() + (Platform.isRaspberryPi() ? (" (Pi " + PiVersion.getPiVersion() + ")") : "")); + logger.debug("Loading ConfigManager..."); ConfigManager.getInstance().load(); // init config manager ConfigManager.getInstance().requestSave(); + logger.debug("Loading HardwareManager..."); // Force load the hardware manager HardwareManager.getInstance(); + logger.debug("Loading NetworkManager..."); NetworkManager.getInstance().reinitialize(); + logger.debug("Loading NetworkTablesManager..."); NetworkTablesManager.getInstance() .setConfig(ConfigManager.getInstance().getConfig().getNetworkConfig()); if (!isTestMode) { + logger.debug("Loading VisionSourceManager..."); VisionSourceManager.getInstance() .registerLoadedConfigs( ConfigManager.getInstance().getConfig().getCameraConfigurations().values()); @@ -369,6 +374,7 @@ public static void main(String[] args) { } } + logger.info("Starting server..."); Server.start(DEFAULT_WEBPORT); } } From 5267b2c70d88d9948ba0862e4d6183e3b9956b09 Mon Sep 17 00:00:00 2001 From: Sriman Achanta <68172138+srimanachanta@users.noreply.github.com> Date: Wed, 27 Sep 2023 22:52:19 -0400 Subject: [PATCH 2/2] Temp fix to revert to hash URLs (#927) --- photon-client/src/router/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/photon-client/src/router/index.ts b/photon-client/src/router/index.ts index 37bcc2cf91..9e3e78f259 100644 --- a/photon-client/src/router/index.ts +++ b/photon-client/src/router/index.ts @@ -10,7 +10,8 @@ import NotFoundView from "@/views/NotFoundView.vue"; Vue.use(VueRouter); const router = new VueRouter({ - mode: "history", + // Using HTML5 History Mode is problematic with Javalin because each route is treated as a server endpoint which causes Javalin to return a 404 error before being redirected to the UI. + // mode: "history", base: import.meta.env.BASE_URL, routes: [ {