mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-26 01:51:40 +00:00
Revert "Make HardwareConfig a record" (#2142)
This commit is contained in:
@@ -21,57 +21,102 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record HardwareConfig(
|
||||
String deviceName,
|
||||
String deviceLogoPath,
|
||||
String supportURL,
|
||||
// LED control
|
||||
public class HardwareConfig {
|
||||
public final String deviceName;
|
||||
public final String deviceLogoPath;
|
||||
public final String supportURL;
|
||||
|
||||
ArrayList<Integer> ledPins,
|
||||
String ledSetCommand,
|
||||
boolean ledsCanDim,
|
||||
ArrayList<Integer> ledBrightnessRange,
|
||||
String ledDimCommand,
|
||||
String ledBlinkCommand,
|
||||
ArrayList<Integer> statusRGBPins,
|
||||
// Metrics
|
||||
// LED control
|
||||
public final ArrayList<Integer> ledPins;
|
||||
public final String ledSetCommand;
|
||||
public final boolean ledsCanDim;
|
||||
public final ArrayList<Integer> ledBrightnessRange;
|
||||
public final String ledDimCommand;
|
||||
public final String ledBlinkCommand;
|
||||
public final ArrayList<Integer> statusRGBPins;
|
||||
|
||||
String cpuTempCommand,
|
||||
String cpuMemoryCommand,
|
||||
String cpuUtilCommand,
|
||||
String cpuThrottleReasonCmd,
|
||||
String cpuUptimeCommand,
|
||||
String gpuMemoryCommand,
|
||||
String ramUtilCommand,
|
||||
String gpuMemUsageCommand,
|
||||
String diskUsageCommand,
|
||||
// Device stuff
|
||||
String restartHardwareCommand,
|
||||
double vendorFOV) { // -1 for unmanaged
|
||||
// Metrics
|
||||
public final String cpuTempCommand;
|
||||
public final String cpuMemoryCommand;
|
||||
public final String cpuUtilCommand;
|
||||
public final String cpuThrottleReasonCmd;
|
||||
public final String cpuUptimeCommand;
|
||||
public final String gpuMemoryCommand;
|
||||
public final String ramUtilCommand;
|
||||
public final String gpuMemUsageCommand;
|
||||
public final String diskUsageCommand;
|
||||
|
||||
// Device stuff
|
||||
public final String restartHardwareCommand;
|
||||
public final double vendorFOV; // -1 for unmanaged
|
||||
|
||||
public HardwareConfig(
|
||||
String deviceName,
|
||||
String deviceLogoPath,
|
||||
String supportURL,
|
||||
ArrayList<Integer> ledPins,
|
||||
String ledSetCommand,
|
||||
boolean ledsCanDim,
|
||||
ArrayList<Integer> ledBrightnessRange,
|
||||
String ledDimCommand,
|
||||
String ledBlinkCommand,
|
||||
ArrayList<Integer> statusRGBPins,
|
||||
String cpuTempCommand,
|
||||
String cpuMemoryCommand,
|
||||
String cpuUtilCommand,
|
||||
String cpuThrottleReasonCmd,
|
||||
String cpuUptimeCommand,
|
||||
String gpuMemoryCommand,
|
||||
String ramUtilCommand,
|
||||
String gpuMemUsageCommand,
|
||||
String diskUsageCommand,
|
||||
String restartHardwareCommand,
|
||||
double vendorFOV) {
|
||||
this.deviceName = deviceName;
|
||||
this.deviceLogoPath = deviceLogoPath;
|
||||
this.supportURL = supportURL;
|
||||
this.ledPins = ledPins;
|
||||
this.ledSetCommand = ledSetCommand;
|
||||
this.ledsCanDim = ledsCanDim;
|
||||
this.ledBrightnessRange = ledBrightnessRange;
|
||||
this.ledDimCommand = ledDimCommand;
|
||||
this.ledBlinkCommand = ledBlinkCommand;
|
||||
this.statusRGBPins = statusRGBPins;
|
||||
this.cpuTempCommand = cpuTempCommand;
|
||||
this.cpuMemoryCommand = cpuMemoryCommand;
|
||||
this.cpuUtilCommand = cpuUtilCommand;
|
||||
this.cpuThrottleReasonCmd = cpuThrottleReasonCmd;
|
||||
this.cpuUptimeCommand = cpuUptimeCommand;
|
||||
this.gpuMemoryCommand = gpuMemoryCommand;
|
||||
this.ramUtilCommand = ramUtilCommand;
|
||||
this.gpuMemUsageCommand = gpuMemUsageCommand;
|
||||
this.diskUsageCommand = diskUsageCommand;
|
||||
this.restartHardwareCommand = restartHardwareCommand;
|
||||
this.vendorFOV = vendorFOV;
|
||||
}
|
||||
|
||||
public HardwareConfig() {
|
||||
this(
|
||||
"", // deviceName
|
||||
"", // deviceLogoPath
|
||||
"", // supportURL
|
||||
new ArrayList<>(), // ledPins
|
||||
"", // ledSetCommand
|
||||
false, // ledsCanDim
|
||||
new ArrayList<>(), // ledBrightnessRange
|
||||
"", // ledDimCommand
|
||||
"", // ledBlinkCommand
|
||||
new ArrayList<>(), // statusRGBPins
|
||||
"", // cpuTempCommand
|
||||
"", // cpuMemoryCommand
|
||||
"", // cpuUtilCommand
|
||||
"", // cpuThrottleReasonCmd
|
||||
"", // cpuUptimeCommand
|
||||
"", // gpuMemoryCommand
|
||||
"", // ramUtilCommand
|
||||
"", // gpuMemUsageCommand
|
||||
"", // diskUsageCommand
|
||||
"", // restartHardwareCommand
|
||||
-1); // vendorFOV
|
||||
deviceName = "";
|
||||
deviceLogoPath = "";
|
||||
supportURL = "";
|
||||
ledPins = new ArrayList<>();
|
||||
ledSetCommand = "";
|
||||
ledsCanDim = false;
|
||||
ledBrightnessRange = new ArrayList<>();
|
||||
ledDimCommand = "";
|
||||
ledBlinkCommand = "";
|
||||
statusRGBPins = new ArrayList<>();
|
||||
cpuTempCommand = "";
|
||||
cpuMemoryCommand = "";
|
||||
cpuUtilCommand = "";
|
||||
cpuThrottleReasonCmd = "";
|
||||
cpuUptimeCommand = "";
|
||||
gpuMemoryCommand = "";
|
||||
ramUtilCommand = "";
|
||||
gpuMemUsageCommand = "";
|
||||
diskUsageCommand = "";
|
||||
restartHardwareCommand = "";
|
||||
vendorFOV = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,4 +141,51 @@ public record HardwareConfig(
|
||||
|| gpuMemUsageCommand != ""
|
||||
|| diskUsageCommand != "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HardwareConfig[deviceName="
|
||||
+ deviceName
|
||||
+ ", deviceLogoPath="
|
||||
+ deviceLogoPath
|
||||
+ ", supportURL="
|
||||
+ supportURL
|
||||
+ ", ledPins="
|
||||
+ ledPins
|
||||
+ ", ledSetCommand="
|
||||
+ ledSetCommand
|
||||
+ ", ledsCanDim="
|
||||
+ ledsCanDim
|
||||
+ ", ledBrightnessRange="
|
||||
+ ledBrightnessRange
|
||||
+ ", ledDimCommand="
|
||||
+ ledDimCommand
|
||||
+ ", ledBlinkCommand="
|
||||
+ ledBlinkCommand
|
||||
+ ", statusRGBPins="
|
||||
+ statusRGBPins
|
||||
+ ", cpuTempCommand="
|
||||
+ cpuTempCommand
|
||||
+ ", cpuMemoryCommand="
|
||||
+ cpuMemoryCommand
|
||||
+ ", cpuUtilCommand="
|
||||
+ cpuUtilCommand
|
||||
+ ", cpuThrottleReasonCmd="
|
||||
+ cpuThrottleReasonCmd
|
||||
+ ", cpuUptimeCommand="
|
||||
+ cpuUptimeCommand
|
||||
+ ", gpuMemoryCommand="
|
||||
+ gpuMemoryCommand
|
||||
+ ", ramUtilCommand="
|
||||
+ ramUtilCommand
|
||||
+ ", gpuMemUsageCommand="
|
||||
+ gpuMemUsageCommand
|
||||
+ ", diskUsageCommand="
|
||||
+ diskUsageCommand
|
||||
+ ", restartHardwareCommand="
|
||||
+ restartHardwareCommand
|
||||
+ ", vendorFOV="
|
||||
+ vendorFOV
|
||||
+ "]";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class UIPhotonConfiguration {
|
||||
NetworkManager.getInstance().networkingIsDisabled),
|
||||
new UILightingConfig(
|
||||
c.getHardwareSettings().ledBrightnessPercentage,
|
||||
!c.getHardwareConfig().ledPins().isEmpty()),
|
||||
!c.getHardwareConfig().ledPins.isEmpty()),
|
||||
new UIGeneralSettings(
|
||||
PhotonVersion.versionString,
|
||||
// TODO add support for other types of GPU accel
|
||||
@@ -57,9 +57,9 @@ public class UIPhotonConfiguration {
|
||||
MrCalJNILoader.getInstance().isLoaded(),
|
||||
c.neuralNetworkPropertyManager().getModels(),
|
||||
NeuralNetworkModelManager.getInstance().getSupportedBackends(),
|
||||
c.getHardwareConfig().deviceName().isEmpty()
|
||||
c.getHardwareConfig().deviceName.isEmpty()
|
||||
? Platform.getHardwareModel()
|
||||
: c.getHardwareConfig().deviceName(),
|
||||
: c.getHardwareConfig().deviceName,
|
||||
Platform.getPlatformName(),
|
||||
NetworkTablesManager.getInstance().conflictingHostname,
|
||||
NetworkTablesManager.getInstance().conflictingCameras),
|
||||
|
||||
@@ -92,8 +92,8 @@ public class CustomGPIO extends GPIOBase {
|
||||
|
||||
public static void setConfig(HardwareConfig config) {
|
||||
if (Platform.isRaspberryPi()) return;
|
||||
commands.replace("setState", config.ledSetCommand());
|
||||
commands.replace("dim", config.ledDimCommand());
|
||||
commands.replace("blink", config.ledBlinkCommand());
|
||||
commands.replace("setState", config.ledSetCommand);
|
||||
commands.replace("dim", config.ledDimCommand);
|
||||
commands.replace("blink", config.ledBlinkCommand);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,22 +97,22 @@ public class HardwareManager {
|
||||
}
|
||||
|
||||
statusLED =
|
||||
hardwareConfig.statusRGBPins().size() == 3
|
||||
? new StatusLED(hardwareConfig.statusRGBPins())
|
||||
hardwareConfig.statusRGBPins.size() == 3
|
||||
? new StatusLED(hardwareConfig.statusRGBPins)
|
||||
: null;
|
||||
|
||||
if (statusLED != null) {
|
||||
TimedTaskManager.getInstance().addTask("StatusLEDUpdate", this::statusLEDUpdate, 150);
|
||||
}
|
||||
|
||||
var hasBrightnessRange = hardwareConfig.ledBrightnessRange().size() == 2;
|
||||
var hasBrightnessRange = hardwareConfig.ledBrightnessRange.size() == 2;
|
||||
visionLED =
|
||||
hardwareConfig.ledPins().isEmpty()
|
||||
hardwareConfig.ledPins.isEmpty()
|
||||
? null
|
||||
: new VisionLED(
|
||||
hardwareConfig.ledPins(),
|
||||
hasBrightnessRange ? hardwareConfig.ledBrightnessRange().get(0) : 0,
|
||||
hasBrightnessRange ? hardwareConfig.ledBrightnessRange().get(1) : 100,
|
||||
hardwareConfig.ledPins,
|
||||
hasBrightnessRange ? hardwareConfig.ledBrightnessRange.get(0) : 0,
|
||||
hasBrightnessRange ? hardwareConfig.ledBrightnessRange.get(1) : 100,
|
||||
pigpioSocket,
|
||||
ledModeState::set);
|
||||
|
||||
@@ -161,7 +161,7 @@ public class HardwareManager {
|
||||
}
|
||||
}
|
||||
try {
|
||||
return shellExec.executeBashCommand(hardwareConfig.restartHardwareCommand()) == 0;
|
||||
return shellExec.executeBashCommand(hardwareConfig.restartHardwareCommand) == 0;
|
||||
} catch (IOException e) {
|
||||
logger.error("Could not restart device!", e);
|
||||
return false;
|
||||
|
||||
@@ -22,18 +22,18 @@ import org.photonvision.common.configuration.HardwareConfig;
|
||||
public class FileCmds extends CmdBase {
|
||||
@Override
|
||||
public void initCmds(HardwareConfig config) {
|
||||
cpuTemperatureCommand = config.cpuTempCommand();
|
||||
cpuUtilizationCommand = config.cpuUtilCommand();
|
||||
cpuThrottleReasonCmd = config.cpuThrottleReasonCmd();
|
||||
cpuTemperatureCommand = config.cpuTempCommand;
|
||||
cpuUtilizationCommand = config.cpuUtilCommand;
|
||||
cpuThrottleReasonCmd = config.cpuThrottleReasonCmd;
|
||||
|
||||
ramMemCommand = config.cpuMemoryCommand();
|
||||
ramUtilCommand = config.ramUtilCommand();
|
||||
ramMemCommand = config.cpuMemoryCommand;
|
||||
ramUtilCommand = config.ramUtilCommand;
|
||||
|
||||
gpuMemCommand = config.gpuMemoryCommand();
|
||||
gpuMemUtilCommand = config.gpuMemUsageCommand();
|
||||
gpuMemCommand = config.gpuMemoryCommand;
|
||||
gpuMemUtilCommand = config.gpuMemUsageCommand;
|
||||
|
||||
diskUsageCommand = config.diskUsageCommand();
|
||||
diskUsageCommand = config.diskUsageCommand;
|
||||
|
||||
uptimeCommand = config.cpuUptimeCommand();
|
||||
uptimeCommand = config.cpuUptimeCommand;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class LibcameraGpuSource extends VisionSource {
|
||||
|
||||
@Override
|
||||
public boolean hasLEDs() {
|
||||
return (ConfigManager.getInstance().getConfig().getHardwareConfig().ledPins().size() > 0);
|
||||
return (ConfigManager.getInstance().getConfig().getHardwareConfig().ledPins.size() > 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -160,7 +160,7 @@ public class VisionModule {
|
||||
|
||||
// Set vendor FOV
|
||||
if (isVendorCamera()) {
|
||||
var fov = ConfigManager.getInstance().getConfig().getHardwareConfig().vendorFOV();
|
||||
var fov = ConfigManager.getInstance().getConfig().getHardwareConfig().vendorFOV;
|
||||
logger.info("Setting FOV of vendor camera to " + fov);
|
||||
visionSource.getSettables().setFOV(fov);
|
||||
}
|
||||
|
||||
@@ -34,10 +34,13 @@ public class HardwareConfigTest {
|
||||
System.out.println("Loading Hardware configs...");
|
||||
var config =
|
||||
new ObjectMapper().readValue(TestUtils.getHardwareConfigJson(), HardwareConfig.class);
|
||||
assertEquals(config.deviceName(), "PhotonVision");
|
||||
assertEquals(config.deviceLogoPath(), "photonvision.png");
|
||||
assertEquals(config.supportURL(), "https://support.photonvision.com");
|
||||
assertArrayEquals(config.ledPins().stream().mapToInt(i -> i).toArray(), new int[] {2, 13});
|
||||
assertEquals(config.deviceName, "PhotonVision");
|
||||
assertEquals(config.deviceLogoPath, "photonvision.png");
|
||||
assertEquals(config.supportURL, "https://support.photonvision.com");
|
||||
// Ensure defaults are not null
|
||||
assertEquals(config.cpuThrottleReasonCmd, "");
|
||||
assertEquals(config.diskUsageCommand, "");
|
||||
assertArrayEquals(config.ledPins.stream().mapToInt(i -> i).toArray(), new int[] {2, 13});
|
||||
CustomGPIO.setConfig(config);
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
Reference in New Issue
Block a user