mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-21 01:01:43 +00:00
[wpilib] Add usage reporting for dashboards as instances (#7294)
Detects dashboards based on network tables client identity.
This commit is contained in:
@@ -14,6 +14,7 @@ import edu.wpi.first.math.MathShared;
|
||||
import edu.wpi.first.math.MathSharedStore;
|
||||
import edu.wpi.first.math.MathUsageId;
|
||||
import edu.wpi.first.networktables.MultiSubscriber;
|
||||
import edu.wpi.first.networktables.NetworkTableEvent;
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
import edu.wpi.first.util.WPIUtilJNI;
|
||||
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
|
||||
@@ -43,6 +44,10 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
|
||||
private final MultiSubscriber m_suball;
|
||||
|
||||
private final int m_connListenerHandle;
|
||||
|
||||
private boolean m_dashboardDetected;
|
||||
|
||||
private static void setupCameraServerShared() {
|
||||
CameraServerShared shared =
|
||||
new CameraServerShared() {
|
||||
@@ -158,6 +163,65 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
System.err.println("timed out while waiting for NT server to start");
|
||||
}
|
||||
|
||||
m_connListenerHandle =
|
||||
inst.addConnectionListener(
|
||||
false,
|
||||
event -> {
|
||||
if (event.is(NetworkTableEvent.Kind.kConnected)) {
|
||||
if (event.connInfo.remote_id.startsWith("glass")) {
|
||||
HAL.report(tResourceType.kResourceType_Dashboard, tInstances.kDashboard_Glass);
|
||||
m_dashboardDetected = true;
|
||||
} else if (event.connInfo.remote_id.startsWith("SmartDashboard")) {
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Dashboard, tInstances.kDashboard_SmartDashboard);
|
||||
m_dashboardDetected = true;
|
||||
} else if (event.connInfo.remote_id.startsWith("shuffleboard")) {
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Dashboard, tInstances.kDashboard_Shuffleboard);
|
||||
m_dashboardDetected = true;
|
||||
} else if (event.connInfo.remote_id.startsWith("elastic")
|
||||
|| event.connInfo.remote_id.startsWith("Elastic")) {
|
||||
HAL.report(tResourceType.kResourceType_Dashboard, tInstances.kDashboard_Elastic);
|
||||
m_dashboardDetected = true;
|
||||
} else if (event.connInfo.remote_id.startsWith("Dashboard")) {
|
||||
HAL.report(tResourceType.kResourceType_Dashboard, tInstances.kDashboard_LabVIEW);
|
||||
m_dashboardDetected = true;
|
||||
} else if (event.connInfo.remote_id.startsWith("AdvantageScope")) {
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Dashboard, tInstances.kDashboard_AdvantageScope);
|
||||
m_dashboardDetected = true;
|
||||
} else if (event.connInfo.remote_id.startsWith("QFRCDashboard")) {
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Dashboard, tInstances.kDashboard_QFRCDashboard);
|
||||
m_dashboardDetected = true;
|
||||
} else if (event.connInfo.remote_id.startsWith("FRC Web Components")) {
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Dashboard,
|
||||
tInstances.kDashboard_FRCWebComponents);
|
||||
m_dashboardDetected = true;
|
||||
} else {
|
||||
// Only report unknown if there wasn't another dashboard already reported
|
||||
// (unknown could also be another device)
|
||||
if (!m_dashboardDetected) {
|
||||
int delim = event.connInfo.remote_id.indexOf('@');
|
||||
if (delim != -1) {
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Dashboard,
|
||||
tInstances.kDashboard_Unknown,
|
||||
0,
|
||||
event.connInfo.remote_id.substring(0, delim));
|
||||
} else {
|
||||
HAL.report(
|
||||
tResourceType.kResourceType_Dashboard,
|
||||
tInstances.kDashboard_Unknown,
|
||||
0,
|
||||
event.connInfo.remote_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
LiveWindow.setEnabled(false);
|
||||
Shuffleboard.disableActuatorWidgets();
|
||||
}
|
||||
@@ -174,6 +238,7 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
@Override
|
||||
public void close() {
|
||||
m_suball.close();
|
||||
NetworkTableInstance.getDefault().removeListener(m_connListenerHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user