mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Pass errors to DS in C++ and Java
Squashed commit of the following: commit f317b3522e312cf7e7bb9eb0494f2f96a7f6363c Author: Kevin O'Connor <koconnor@usfirst.org> Date: Mon Oct 20 17:15:46 2014 -0400 Send unhandled exceptions back to the DS. Change-Id: I0e658fdb6d43593ee20457f20f71f4f4cd2d21c3 commit f834ef8c791945697ad483c27b4167eb917ac242 Author: Kevin O'Connor <koconnor@usfirst.org> Date: Mon Oct 20 16:05:24 2014 -0400 Add StackTrace to Java errors Change-Id: I83b162afcc5f294703705770fbcd8623b0895539 commit 02e040b0c79067ce046ada29e26004e0460fceb0 Author: Kevin O'Connor <koconnor@usfirst.org> Date: Mon Oct 20 15:07:44 2014 -0400 HAL Errors to DS in Java Change-Id: I5fb51e4066bbc26ea59ca513c03c5ec5ace98831 commit 03775ddc42b129c27fdf403f17f0796009311c3c Author: Kevin O'Connor <koconnor@usfirst.org> Date: Mon Oct 20 13:38:18 2014 -0400 Update AnalogInput to report errors for getting and setting sample rate Change-Id: I00eb78f52fc5b17a60bc84456f0ec9842cc40ef7 commit 4c10cb79612ae81e3cbb6bd4d6da8cf3b8955821 Author: Kevin O'Connor <koconnor@usfirst.org> Date: Mon Oct 20 11:46:03 2014 -0400 Define errors in HAL Change-Id: I96595472e42ba61f0f3d0da17caf01a748d0422a commit 56cb5dcd93e5e849a016f63ac9d0dc245a23eb2b Author: Kevin O'Connor <koconnor@usfirst.org> Date: Fri Oct 17 10:59:29 2014 -0400 Throttle errors (1 report per second per error code) and fix issue with GetTime conflicting with GetTime from Timer.h/Timer.cpp Change-Id: Ibe4dc2e400fc4671b240b876a46959256ea65ad7 commit 71c78826e548682ecd0c1548255f8a6552cece32 Author: Kevin O'Connor <koconnor@usfirst.org> Date: Thu Oct 16 16:41:04 2014 -0400 Feed errors to DS from C++ Change-Id: I009a7798499fd93e9fdd976ff00aa74c0bd094ae commit 81030c6cee7f18a5ddf0e95c4e402a6cf7b5de6c Author: Kevin O'Connor <koconnor@usfirst.org> Date: Thu Oct 16 16:40:50 2014 -0400 Don't try to de-mangle lines without any symbols in them Change-Id: Icea02494b68f2ec9116d6cbf20a35a3a132234f8 Change-Id: If7717025b03914183736ccd95da5c9d49819a6f3
This commit is contained in:
committed by
Brad Miller
parent
26419ec209
commit
003dc0dc2b
@@ -400,6 +400,26 @@ public class DriverStation implements RobotState.Interface {
|
||||
}
|
||||
return Timer.getFPGATimestamp() - m_approxMatchTimeOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report error to Driver Station.
|
||||
* Also prints error to System.err
|
||||
* Optionally appends Stack trace to error message
|
||||
* @param printTrace If true, append stack trace to error string
|
||||
*/
|
||||
public static void reportError(String error, boolean printTrace) {
|
||||
String errorString = error;
|
||||
if(printTrace) {
|
||||
errorString += " at ";
|
||||
StackTraceElement[] traces = Thread.currentThread().getStackTrace();
|
||||
for (int i=2; i<traces.length; i++)
|
||||
{
|
||||
errorString += traces[i].toString() + "\n";
|
||||
}
|
||||
}
|
||||
System.err.println(errorString);
|
||||
FRCNetworkCommunicationsLibrary.HALSetErrorData(errorString);
|
||||
}
|
||||
|
||||
/** Only to be used to tell the Driver Station what code you claim to be executing
|
||||
* for diagnostic purposes only
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.Manifest;
|
||||
import java.util.Arrays;
|
||||
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary.tInstances;
|
||||
@@ -19,6 +20,7 @@ import edu.wpi.first.wpilibj.communication.UsageReporting;
|
||||
import edu.wpi.first.wpilibj.internal.HardwareHLUsageReporting;
|
||||
import edu.wpi.first.wpilibj.internal.HardwareTimer;
|
||||
import edu.wpi.first.wpilibj.networktables.NetworkTable;
|
||||
import edu.wpi.first.wpilibj.Utility;
|
||||
|
||||
/**
|
||||
* Implement a Robot Program framework.
|
||||
@@ -197,7 +199,7 @@ public abstract class RobotBase {
|
||||
try {
|
||||
robot.startCompetition();
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
DriverStation.reportError("ERROR Unhandled exception: " + t.toString() + " at " + Arrays.toString(t.getStackTrace()), false);
|
||||
errorOnExit = true;
|
||||
} finally {
|
||||
// startCompetition never returns unless exception occurs....
|
||||
|
||||
@@ -10,9 +10,11 @@ package edu.wpi.first.wpilibj;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.IntBuffer;
|
||||
import java.lang.StackTraceElement;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.HALLibrary;
|
||||
import edu.wpi.first.wpilibj.hal.HALUtil;
|
||||
import edu.wpi.first.wpilibj.communication.FRCNetworkCommunicationsLibrary;
|
||||
|
||||
/**
|
||||
* Contains global utility functions
|
||||
|
||||
@@ -468,42 +468,6 @@ public class FRCNetworkCommunicationsLibrary extends JNIWrapper {
|
||||
return HALAllianceStationID.Blue2;
|
||||
case 5:
|
||||
return HALAllianceStationID.Blue3;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static int kMaxJoystickAxes = 12;
|
||||
public static int kMaxJoystickPOVs = 12;
|
||||
public static native short[] HALGetJoystickAxes(byte joystickNum);
|
||||
public static native short[] HALGetJoystickPOVs(byte joystickNum);
|
||||
public static native int HALGetJoystickButtons(byte joystickNum);
|
||||
|
||||
/*
|
||||
public static class pthread_mutex_t extends PointerType {
|
||||
public pthread_mutex_t(Pointer address) {
|
||||
super(address);
|
||||
}
|
||||
public pthread_mutex_t() {
|
||||
super();
|
||||
}
|
||||
};
|
||||
public static class STATUS extends PointerType {
|
||||
public STATUS(Pointer address) {
|
||||
super(address);
|
||||
}
|
||||
public STATUS() {
|
||||
super();
|
||||
}
|
||||
};*/
|
||||
|
||||
//
|
||||
// JNI Testing
|
||||
//
|
||||
public static native void JNIValueParameterTest(boolean booleanValue, byte byteValue, char charValue, short shortValue, int intValue, long longValue, float floatValue, double doubleValue );
|
||||
public static native boolean JNIValueReturnBooleanTest(boolean booleanValue);
|
||||
public static native byte JNIValueReturnByteTest(byte byteValue);
|
||||
public static native char JNIValueReturnCharTest(char charValue);
|
||||
public static native short JNIValueReturnShortTest(short shortValue);
|
||||
public static native int JNIValueReturnIntTest(int intValue);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -2,16 +2,17 @@ package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import edu.wpi.first.wpilibj.DriverStation;
|
||||
|
||||
public class HALUtil extends JNIWrapper {
|
||||
public static final int NULL_PARAMETER = -5;
|
||||
public static final int SAMPLE_RATE_TOO_HIGH = 1;
|
||||
public static final int VOLTAGE_OUT_OF_RANGE = 2;
|
||||
public static final int LOOP_TIMING_ERROR = 4;
|
||||
public static final int INCOMPATIBLE_STATE = 15;
|
||||
public static final int ANALOG_TRIGGER_PULSE_OUTPUT_ERROR = -11;
|
||||
public static final int NO_AVAILABLE_RESOURCES = -4;
|
||||
public static final int PARAMETER_OUT_OF_RANGE = -28;
|
||||
public static final int NULL_PARAMETER = -1005;
|
||||
public static final int SAMPLE_RATE_TOO_HIGH = 1001;
|
||||
public static final int VOLTAGE_OUT_OF_RANGE = 1002;
|
||||
public static final int LOOP_TIMING_ERROR = 1004;
|
||||
public static final int INCOMPATIBLE_STATE = 1015;
|
||||
public static final int ANALOG_TRIGGER_PULSE_OUTPUT_ERROR = -1011;
|
||||
public static final int NO_AVAILABLE_RESOURCES = -104;
|
||||
public static final int PARAMETER_OUT_OF_RANGE = -1028;
|
||||
|
||||
//public static final int SEMAPHORE_WAIT_FOREVER = -1;
|
||||
//public static final int SEMAPHORE_Q_PRIORITY = 0x01;
|
||||
@@ -38,22 +39,13 @@ public class HALUtil extends JNIWrapper {
|
||||
public static void checkStatus(IntBuffer status)
|
||||
{
|
||||
int s = status.get(0);
|
||||
if (s != 0)
|
||||
if (s < 0)
|
||||
{
|
||||
String message = "Code: " + s + ". " + HALUtil.getHALErrorMessage(s);
|
||||
if (s == HALUtil.NULL_PARAMETER
|
||||
|| s == HALUtil.SAMPLE_RATE_TOO_HIGH
|
||||
|| s == HALUtil.VOLTAGE_OUT_OF_RANGE)
|
||||
throw new IllegalArgumentException(message);
|
||||
else if (s == HALUtil.LOOP_TIMING_ERROR)
|
||||
throw new RuntimeException(message);
|
||||
else if (s == HALUtil.INCOMPATIBLE_STATE
|
||||
|| s == HALUtil.ANALOG_TRIGGER_PULSE_OUTPUT_ERROR)
|
||||
throw new IllegalStateException(message);
|
||||
else if (s == HALUtil.NO_AVAILABLE_RESOURCES)
|
||||
throw new RuntimeException(message);
|
||||
else
|
||||
throw new RuntimeException("Unknown error. Code: " + s + ". " + message);
|
||||
String message = getHALErrorMessage(s);
|
||||
throw new RuntimeException(" Code: " + s + ". " + message);
|
||||
} else if (s > 0) {
|
||||
String message = getHALErrorMessage(s);
|
||||
DriverStation.reportError(message, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user