mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-20 00:51:41 +00:00
[Hardware] Run command to start pigpio daemon before connecting to it (#107)
* Don't start metrics thread * Start pigpio daemon before connecting to it Co-authored-by: Matt <matthew.morley.ca@gmail.com>
This commit is contained in:
@@ -189,9 +189,11 @@ public class PiGPIO extends GPIOBase {
|
||||
|
||||
static {
|
||||
try {
|
||||
// Make sure daemon is running before connecting to it
|
||||
execute("pigpiod");
|
||||
INSTANCE = new PigpioSocket("localhost", 8888);
|
||||
} catch (PigpioException e) {
|
||||
logger.error("Could not connect to pigpio daemon");
|
||||
logger.error("Could not connect to pigpio daemon.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.photonvision.common.hardware.GPIO.CustomGPIO;
|
||||
import org.photonvision.common.hardware.GPIO.GPIOBase;
|
||||
import org.photonvision.common.hardware.VisionLED.VisionLEDMode;
|
||||
import org.photonvision.common.hardware.metrics.MetricsBase;
|
||||
import org.photonvision.common.hardware.metrics.MetricsPublisher;
|
||||
import org.photonvision.common.logging.LogGroup;
|
||||
import org.photonvision.common.logging.Logger;
|
||||
import org.photonvision.common.util.ShellExec;
|
||||
@@ -71,8 +70,8 @@ public class HardwareManager {
|
||||
ledModeEntry.setNumber(VisionLEDMode.VLM_DEFAULT.value);
|
||||
ledModeListener = new NTDataChangeListener(ledModeEntry, visionLED::onLedModeChange);
|
||||
|
||||
// Start hardware metrics thread
|
||||
if (Platform.isLinux()) MetricsPublisher.getInstance().startTask();
|
||||
// Start hardware metrics thread (Disabled until implemented)
|
||||
// if (Platform.isLinux()) MetricsPublisher.getInstance().startTask();
|
||||
}
|
||||
|
||||
public boolean restartDevice() {
|
||||
|
||||
@@ -21,18 +21,18 @@ public class CPUMetrics extends MetricsBase {
|
||||
|
||||
public CPUMetrics() {}
|
||||
|
||||
public double getMemory() {
|
||||
if (cpuMemoryCommand.isEmpty()) return 0;
|
||||
public String getMemory() {
|
||||
if (cpuMemoryCommand.isEmpty()) return "";
|
||||
return execute(cpuMemoryCommand);
|
||||
}
|
||||
|
||||
// TODO: Command should return in Celsius
|
||||
public double getTemp() {
|
||||
if (cpuTemperatureCommand.isEmpty()) return 0;
|
||||
return execute(cpuTemperatureCommand) / 1000;
|
||||
public String getTemp() {
|
||||
if (cpuTemperatureCommand.isEmpty()) return "";
|
||||
return execute(cpuTemperatureCommand);
|
||||
}
|
||||
|
||||
public double getUtilization() {
|
||||
public String getUtilization() {
|
||||
return execute(cpuUtilizationCommand);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@
|
||||
package org.photonvision.common.hardware.metrics;
|
||||
|
||||
public class GPUMetrics extends MetricsBase {
|
||||
public double getMemory() {
|
||||
public String getMemory() {
|
||||
return execute(gpuMemoryCommand);
|
||||
}
|
||||
|
||||
public double getTemp() {
|
||||
return execute(gpuTemperatureCommand) / 10;
|
||||
public String getTemp() {
|
||||
return execute(gpuTemperatureCommand);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
package org.photonvision.common.hardware.metrics;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.photonvision.common.configuration.HardwareConfig;
|
||||
import org.photonvision.common.hardware.Platform;
|
||||
import org.photonvision.common.logging.LogGroup;
|
||||
@@ -54,15 +53,15 @@ public abstract class MetricsBase {
|
||||
ramUsageCommand = config.ramUtilCommand;
|
||||
}
|
||||
|
||||
public static double execute(String command) {
|
||||
public static String execute(String command) {
|
||||
try {
|
||||
runCommand.executeBashCommand(command);
|
||||
return Double.parseDouble(runCommand.getOutput());
|
||||
} catch (NumberFormatException e) {
|
||||
return runCommand.getOutput();
|
||||
} catch (Exception e) {
|
||||
logger.error(
|
||||
"Command: \""
|
||||
+ command
|
||||
+ "\" returned a non-double output!"
|
||||
+ "\" returned an error!"
|
||||
+ "\nOutput Received: "
|
||||
+ runCommand.getOutput()
|
||||
+ "\nStandard Error: "
|
||||
@@ -73,10 +72,7 @@ public abstract class MetricsBase {
|
||||
+ runCommand.isErrorCompleted()
|
||||
+ "\nExit code: "
|
||||
+ runCommand.getExitCode());
|
||||
return Double.NaN;
|
||||
} catch (IOException e) {
|
||||
MetricsPublisher.getInstance().stopTask();
|
||||
return -1;
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ import org.photonvision.common.logging.Logger;
|
||||
import org.photonvision.common.util.TimedTaskManager;
|
||||
|
||||
public class MetricsPublisher {
|
||||
private final HashMap<String, Double> metrics;
|
||||
private final HashMap<String, String> metrics;
|
||||
private static final Logger logger = new Logger(MetricsPublisher.class, LogGroup.General);
|
||||
private static CPUMetrics cpuMetrics;
|
||||
// private static GPUMetrics gpuMetrics;
|
||||
// private static RAMMetrics ramMetrics;
|
||||
private static GPUMetrics gpuMetrics;
|
||||
private static RAMMetrics ramMetrics;
|
||||
|
||||
public static MetricsPublisher getInstance() {
|
||||
return Singleton.INSTANCE;
|
||||
@@ -37,8 +37,8 @@ public class MetricsPublisher {
|
||||
|
||||
private MetricsPublisher() {
|
||||
cpuMetrics = new CPUMetrics();
|
||||
// gpuMetrics = new GPUMetrics();
|
||||
// ramMetrics = new RAMMetrics();
|
||||
gpuMetrics = new GPUMetrics();
|
||||
ramMetrics = new RAMMetrics();
|
||||
|
||||
metrics = new HashMap<>();
|
||||
}
|
||||
@@ -51,12 +51,9 @@ public class MetricsPublisher {
|
||||
metrics.put("cpuTemp", cpuMetrics.getTemp());
|
||||
metrics.put("cpuUtil", cpuMetrics.getUtilization());
|
||||
metrics.put("cpuMem", cpuMetrics.getMemory());
|
||||
/*Following metrics throw occasional errors and hence are commented out
|
||||
until a better solution for grabbing the metrics is found or patch for error is found.
|
||||
*/
|
||||
// metrics.put("gpuTemp", gpuMetrics.getTemp());
|
||||
// metrics.put("gpuMem", gpuMetrics.getMemory());
|
||||
// metrics.put("ramUtil", ramMetrics.getUsedRam());
|
||||
metrics.put("gpuTemp", gpuMetrics.getTemp());
|
||||
metrics.put("gpuMem", gpuMetrics.getMemory());
|
||||
metrics.put("ramUtil", ramMetrics.getUsedRam());
|
||||
|
||||
DataChangeService.getInstance()
|
||||
.publishEvent(new OutgoingUIEvent<>("metrics", metrics));
|
||||
|
||||
@@ -19,8 +19,8 @@ package org.photonvision.common.hardware.metrics;
|
||||
|
||||
public class RAMMetrics extends MetricsBase {
|
||||
// TODO: Output in MBs for consistency
|
||||
public double getUsedRam() {
|
||||
if (ramUsageCommand.isEmpty()) return 0;
|
||||
return execute(ramUsageCommand) / 1000;
|
||||
public String getUsedRam() {
|
||||
if (ramUsageCommand.isEmpty()) return "";
|
||||
return execute(ramUsageCommand);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user