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

Automatically detect and report hardware model for most SBCs #1540

Merged
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 @@ -151,7 +151,11 @@ public Map<String, Object> toHashMap() {
generalSubmap.put("availableModels", NeuralNetworkModelManager.getInstance().getModels());
generalSubmap.put(
"supportedBackends", NeuralNetworkModelManager.getInstance().getSupportedBackends());
generalSubmap.put("hardwareModel", hardwareConfig.deviceName);
generalSubmap.put(
"hardwareModel",
hardwareConfig.deviceName.isEmpty()
? Platform.getHardwareModel()
: hardwareConfig.deviceName);
generalSubmap.put("hardwarePlatform", Platform.getPlatformName());
settingsSubmap.put("general", generalSubmap);
// AprilTagFieldLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,63 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.function.Supplier;

@SuppressWarnings("unused")
public enum Platform {
// WPILib Supported (JNI)
WINDOWS_64("Windows x64", "winx64", false, OSType.WINDOWS, true),
LINUX_32("Linux x86", "linuxx64", false, OSType.LINUX, true),
LINUX_64("Linux x64", "linuxx64", false, OSType.LINUX, true),
WINDOWS_64("Windows x64", Platform::getUnknownModel, "winx64", false, OSType.WINDOWS, true),
LINUX_32("Linux x86", Platform::getUnknownModel, "linuxx64", false, OSType.LINUX, true),
LINUX_64("Linux x64", Platform::getUnknownModel, "linuxx64", false, OSType.LINUX, true),
LINUX_RASPBIAN32(
"Linux Raspbian 32-bit",
Platform::getLinuxDeviceTreeModel,
"linuxarm32",
true,
OSType.LINUX,
true), // Raspberry Pi 3/4 with a 32-bit image
LINUX_RASPBIAN64(
"Linux Raspbian 64-bit",
Platform::getLinuxDeviceTreeModel,
"linuxarm64",
true,
OSType.LINUX,
true), // Raspberry Pi 3/4 with a 64-bit image
LINUX_RK3588_64("Linux AARCH 64-bit with RK3588", "linuxarm64", false, OSType.LINUX, true),
LINUX_RK3588_64(
"Linux AARCH 64-bit with RK3588",
Platform::getLinuxDeviceTreeModel,
"linuxarm64",
false,
OSType.LINUX,
true),
LINUX_AARCH64(
"Linux AARCH64", "linuxarm64", false, OSType.LINUX, true), // Jetson Nano, Jetson TX2
"Linux AARCH64",
Platform::getLinuxDeviceTreeModel,
"linuxarm64",
false,
OSType.LINUX,
true), // Jetson Nano, Jetson TX2

// PhotonVision Supported (Manual build/install)
LINUX_ARM64("Linux ARM64", "linuxarm64", false, OSType.LINUX, true), // ODROID C2, N2
LINUX_ARM64(
"Linux ARM64",
Platform::getLinuxDeviceTreeModel,
"linuxarm64",
false,
OSType.LINUX,
true), // ODROID C2, N2

// Completely unsupported
WINDOWS_32("Windows x86", "windowsx64", false, OSType.WINDOWS, false),
MACOS("Mac OS", "osxuniversal", false, OSType.MACOS, false),
LINUX_ARM32("Linux ARM32", "linuxarm32", false, OSType.LINUX, false), // ODROID XU4, C1+
UNKNOWN("Unsupported Platform", "", false, OSType.UNKNOWN, false);
WINDOWS_32("Windows x86", Platform::getUnknownModel, "windowsx64", false, OSType.WINDOWS, false),
MACOS("Mac OS", Platform::getUnknownModel, "osxuniversal", false, OSType.MACOS, false),
LINUX_ARM32(
"Linux ARM32",
Platform::getUnknownModel,
"linuxarm32",
false,
OSType.LINUX,
false), // ODROID XU4, C1+
UNKNOWN("Unsupported Platform", Platform::getUnknownModel, "", false, OSType.UNKNOWN, false);

public enum OSType {
WINDOWS,
Expand All @@ -62,6 +88,7 @@ public enum OSType {
}

public final String description;
public final String hardwareModel;
public final String nativeLibraryFolderName;
public final boolean isPi;
public final OSType osType;
Expand All @@ -72,11 +99,13 @@ public enum OSType {

Platform(
String description,
Supplier<String> getHardwareModel,
String nativeLibFolderName,
boolean isPi,
OSType osType,
boolean isSupported) {
this.description = description;
this.hardwareModel = getHardwareModel.get();
this.isPi = isPi;
this.osType = osType;
this.isSupported = isSupported;
Expand Down Expand Up @@ -107,6 +136,10 @@ public static String getPlatformName() {
}
}

public static String getHardwareModel() {
return currentPlatform.hardwareModel;
}

public static String getNativeLibraryFolderName() {
return currentPlatform.nativeLibraryFolderName;
}
Expand All @@ -122,6 +155,7 @@ public static boolean isSupported() {
private static final String OS_ARCH = System.getProperty("os.arch");
private static final String UnknownPlatformString =
String.format("Unknown Platform. OS: %s, Architecture: %s", OS_NAME, OS_ARCH);
private static final String UnknownDeviceModelString = "Unknown";

public static Platform getCurrentPlatform() {
if (RuntimeDetector.isWindows()) {
Expand Down Expand Up @@ -199,6 +233,22 @@ private static boolean isJetsonSBC() {
return fileHasText("/proc/device-tree/model", "NVIDIA Jetson");
}

static String getLinuxDeviceTreeModel() {
var deviceTreeModelPath = Paths.get("/proc/device-tree/model");
try {
if (Files.exists(deviceTreeModelPath)) {
return Files.readString(deviceTreeModelPath).trim();
}
} catch (Exception ex) {
return UnknownDeviceModelString;
}
return UnknownDeviceModelString;
}

static String getUnknownModel() {
return UnknownDeviceModelString;
}

// Checks for various names of linux OS
private static boolean isStretch() {
// TODO - this is a total guess
Expand Down
Loading