Skip to content

Commit bd1e672

Browse files
committed
exit and delete-self on systemcore
1 parent 46ac1ba commit bd1e672

File tree

2 files changed

+57
-0
lines changed
  • photon-server/src/main/java/org/photonvision
  • photon-targeting/src/main/java/org/photonvision/common/hardware

2 files changed

+57
-0
lines changed

photon-server/src/main/java/org/photonvision/Main.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@
1818
package org.photonvision;
1919

2020
import edu.wpi.first.hal.HAL;
21+
import java.io.File;
22+
import java.io.FileWriter;
2123
import java.io.IOException;
24+
import java.net.URISyntaxException;
25+
import java.net.URL;
2226
import java.nio.file.Path;
27+
import java.security.CodeSource;
28+
import java.security.ProtectionDomain;
2329
import java.util.ArrayList;
2430
import java.util.List;
2531
import org.apache.commons.cli.*;
@@ -172,6 +178,36 @@ public static void main(String[] args) {
172178
+ Platform.getPlatformName()
173179
+ (Platform.isRaspberryPi() ? (" (Pi " + PiVersion.getPiVersion() + ")") : ""));
174180

181+
if (Platform.isSystemCore()) {
182+
File jarLocation = getJarLocation();
183+
if (jarLocation == null) {
184+
logger.error("SystemCore is not a supported platform for PhotonVision!");
185+
System.exit(1);
186+
}
187+
// Make a file where the PV JAR is located indicating systemcore is not supported
188+
try {
189+
File notSupportedFile =
190+
new File(jarLocation.getParent(), "SYSTEMCORE_NOT_SUPPORTED_BY_PHOTONVISION.txt");
191+
try (FileWriter writer = new FileWriter(notSupportedFile)) {
192+
writer.write("SystemCore is not a supported platform for PhotonVision.\n");
193+
writer.write("PhotonVision has been uninstalled from this device.\n");
194+
writer.write("Please visit https://docs.photonvision.org for supported platforms.");
195+
}
196+
} catch (IOException e) {
197+
logger.error("Failed to create SystemCore not supported file", e);
198+
System.exit(1);
199+
}
200+
201+
// Delete the PV JAR
202+
if (!jarLocation.delete()) {
203+
logger.error("Failed to delete PhotonVision JAR file on SystemCore!");
204+
System.exit(1);
205+
}
206+
207+
// Exit
208+
System.exit(1);
209+
}
210+
175211
if (OsImageVersion.IMAGE_VERSION.isPresent()) {
176212
logger.info("PhotonVision image version: " + OsImageVersion.IMAGE_VERSION.get());
177213
}
@@ -308,4 +344,21 @@ public static void main(String[] args) {
308344
HardwareManager.getInstance().setRunning(true);
309345
Server.initialize(DEFAULT_WEBPORT);
310346
}
347+
348+
public static File getJarLocation() {
349+
try {
350+
ProtectionDomain protectionDomain = Main.class.getProtectionDomain();
351+
CodeSource codeSource = protectionDomain.getCodeSource();
352+
if (codeSource != null) {
353+
URL location = codeSource.getLocation();
354+
return new File(location.toURI());
355+
} else {
356+
logger.error("Could not determine JAR location: code source is null");
357+
return null;
358+
}
359+
} catch (URISyntaxException e) {
360+
logger.error("Error determining JAR location", e);
361+
return null;
362+
}
363+
}
311364
}

photon-targeting/src/main/java/org/photonvision/common/hardware/Platform.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ public static boolean isRK3588() {
124124
return Platform.isOrangePi() || Platform.isCoolPi4b() || Platform.isRock5C();
125125
}
126126

127+
public static boolean isSystemCore() {
128+
return new File("/home/systemcore").exists();
129+
}
130+
127131
public static boolean isRaspberryPi() {
128132
return currentPlatform.isPi;
129133
}

0 commit comments

Comments
 (0)