Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pi startup fix #923

Merged
merged 5 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,23 @@ public String toString() {
}
}

public static ArrayList<NMDeviceInfo> getAllInterfaces() {
private static List<NMDeviceInfo> allInterfaces = new ArrayList<>();
private static long lastReadTimestamp = 0;

public static List<NMDeviceInfo> getAllInterfaces() {
long now = System.currentTimeMillis();
if (now - lastReadTimestamp < 5000) return allInterfaces;
else lastReadTimestamp = now;

var ret = new ArrayList<NMDeviceInfo>();

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();
Expand All @@ -103,6 +110,7 @@ public static ArrayList<NMDeviceInfo> getAllInterfaces() {

logger.debug("Found network interfaces:\n" + ret.toString());

allInterfaces = ret;
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private static List<VisionSource> loadVisionSourcesFromCamConfigs(
List<CameraConfiguration> camConfigs) {
var cameraSources = new ArrayList<VisionSource>();
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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions photon-server/src/main/java/org/photonvision/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -369,6 +374,7 @@ public static void main(String[] args) {
}
}

logger.info("Starting server...");
Server.start(DEFAULT_WEBPORT);
}
}