File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
photon-core/src/main/java/org/photonvision/common/hardware/metrics Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 1717
1818package org .photonvision .common .hardware .metrics ;
1919
20- import edu .wpi .first .cscore .CameraServerJNI ;
2120import edu .wpi .first .networktables .ProtobufPublisher ;
2221import java .io .PrintWriter ;
2322import java .io .StringWriter ;
@@ -47,7 +46,9 @@ public class MetricsManager {
4746 NetworkTablesManager .getInstance ()
4847 .kCoprocTable
4948 .getSubTable ("/metrics" )
50- .getProtobufTopic (CameraServerJNI .getHostname (), DeviceMetrics .proto )
49+ .getProtobufTopic (
50+ ConfigManager .getInstance ().getConfig ().getNetworkConfig ().hostname ,
51+ DeviceMetrics .proto )
5152 .publish ();
5253
5354 private final ShellExec runCommand = new ShellExec (true , true );
@@ -244,6 +245,24 @@ public double getUptime() {
244245
245246 public void publishMetrics () {
246247 logger .debug ("Publishing Metrics..." );
248+
249+ // Check that the hostname hasn't changed
250+ if (!metricPublisher
251+ .getTopic ()
252+ .getName ()
253+ .equals (ConfigManager .getInstance ().getConfig ().getNetworkConfig ().hostname )) {
254+ logger .warn ("Metrics publisher name does not match hostname! Reinitializing publisher..." );
255+ metricPublisher .close ();
256+ metricPublisher =
257+ NetworkTablesManager .getInstance ()
258+ .kCoprocTable
259+ .getSubTable ("/metrics" )
260+ .getProtobufTopic (
261+ ConfigManager .getInstance ().getConfig ().getNetworkConfig ().hostname ,
262+ DeviceMetrics .proto )
263+ .publish ();
264+ }
265+
247266 var metrics =
248267 new DeviceMetrics (
249268 this .getCpuTemp (),
You can’t perform that action at this time.
0 commit comments