mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-30 02:31:44 +00:00
[hal] Use MrcLib to talk to DS (#8858)
Using MrcLib on the robot is going to be the plan for the future, to make things easier. MrcLib is how sim is supported going forward. The desktop version of mrclib can act as a robot server. This is set up where the mrclib interface is in shared code. On robot, that is the only backend used. On desktop, a default sim backend is used. However, the sim plugin can switch that to the real robot backend, so the robot code will exactly look like a real robot.
This commit is contained in:
@@ -49,4 +49,14 @@ public final class DriverStationErrors {
|
||||
public static void reportWarning(String warning, StackTraceElement[] stackTrace) {
|
||||
DriverStationBackend.reportWarning(warning, stackTrace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Report crash to Driver Station. Appends provided stack trace to crash message.
|
||||
*
|
||||
* @param details The crash details to report.
|
||||
* @param stackTrace The stack trace to append
|
||||
*/
|
||||
public static void reportCrash(String details, StackTraceElement[] stackTrace) {
|
||||
DriverStationBackend.reportCrash(details, stackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -571,8 +571,45 @@ public final class DriverStationBackend {
|
||||
}
|
||||
}
|
||||
}
|
||||
DriverStationJNI.sendError(
|
||||
isError, code, false, error, locString, traceString.toString(), true);
|
||||
DriverStationJNI.sendError(isError, code, error, locString, traceString.toString(), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Report crash to Driver Station. Appends provided stack trace to crash message.
|
||||
*
|
||||
* @param error The error message
|
||||
* @param stackTrace The stack trace to append
|
||||
*/
|
||||
public static void reportCrash(String error, StackTraceElement[] stackTrace) {
|
||||
reportCrashImpl(error, stackTrace, 0);
|
||||
}
|
||||
|
||||
private static void reportCrashImpl(
|
||||
String error, StackTraceElement[] stackTrace, int stackTraceFirst) {
|
||||
String locString;
|
||||
if (stackTrace.length >= stackTraceFirst + 1) {
|
||||
locString = stackTrace[stackTraceFirst].toString();
|
||||
} else {
|
||||
locString = "";
|
||||
}
|
||||
StringBuilder traceString = new StringBuilder();
|
||||
boolean haveLoc = false;
|
||||
for (int i = stackTraceFirst; i < stackTrace.length; i++) {
|
||||
String loc = stackTrace[i].toString();
|
||||
traceString.append("\tat ").append(loc).append('\n');
|
||||
// get first user function
|
||||
if (!haveLoc && !loc.startsWith("org.wpilib")) {
|
||||
locString = loc;
|
||||
haveLoc = true;
|
||||
}
|
||||
}
|
||||
DriverStationJNI.sendProgramCrash(error, locString, traceString.toString());
|
||||
// Sleep to ensure message is sent before crash
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -347,6 +347,7 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
+ " See https://wpilib.org/stacktrace for more information.\n",
|
||||
false);
|
||||
DriverStationErrors.reportError("Could not instantiate robot " + robotName + "!", false);
|
||||
DriverStationErrors.reportCrash("Could not instantiate robot " + robotName + "!", elements);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -364,6 +365,8 @@ public abstract class RobotBase implements AutoCloseable {
|
||||
}
|
||||
DriverStationErrors.reportError(
|
||||
"Unhandled exception: " + throwable, throwable.getStackTrace());
|
||||
DriverStationErrors.reportCrash(
|
||||
"Unhandled exception: " + throwable, throwable.getStackTrace());
|
||||
errorOnExit = true;
|
||||
} finally {
|
||||
m_runMutex.lock();
|
||||
|
||||
Reference in New Issue
Block a user