Run wpiformat on merged repo (#1021)

This commit is contained in:
Tyler Veness
2018-05-13 17:09:56 -07:00
committed by Peter Johnson
parent 0babbf317c
commit 6729a7d6b1
481 changed files with 9581 additions and 6828 deletions

View File

@@ -1,5 +1,5 @@
/*----------------------------------------------------------------------------*/
/* Copyright (c) FIRST 2016. All Rights Reserved. */
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
/* Open Source Software - may be modified and shared by FRC teams. The code */
/* must be accompanied by the FIRST BSD license file in the root directory of */
/* the project. */
@@ -7,23 +7,24 @@
#include "HALUtil.h"
#include <assert.h>
#include <errno.h>
#include <jni.h>
#include <cassert>
#include <cerrno>
#include <cstdio>
#include <cstring>
#include <string>
#include <wpi/SmallString.h>
#include <wpi/jni_util.h>
#include <wpi/raw_ostream.h>
#include "HAL/CAN.h"
#include "HAL/HAL.h"
#include "HAL/DriverStation.h"
#include "HAL/Errors.h"
#include "HAL/HAL.h"
#include "HAL/cpp/Log.h"
#include "edu_wpi_first_wpilibj_hal_HALUtil.h"
#include "wpi/SmallString.h"
#include "wpi/jni_util.h"
#include "wpi/raw_ostream.h"
using namespace wpi::java;
@@ -34,7 +35,7 @@ TLogLevel halUtilLogLevel = logWARNING;
if (level > halUtilLogLevel) \
; \
else \
Log().Get(level)
Log().Get(level)
#define kRioStatusOffset -63000
#define kRioStatusSuccess 0
@@ -43,7 +44,7 @@ TLogLevel halUtilLogLevel = logWARNING;
#define kRIOStatusFeatureNotSupported (kRioStatusOffset - 193)
#define kRIOStatusResourceNotInitialized -52010
static JavaVM *jvm = nullptr;
static JavaVM* jvm = nullptr;
static JException runtimeExCls;
static JException illegalArgExCls;
static JException boundaryExCls;
@@ -61,32 +62,32 @@ static JClass accumulatorResultCls;
namespace frc {
void ThrowAllocationException(JNIEnv *env, int32_t minRange, int32_t maxRange,
int32_t requestedValue, int32_t status) {
const char *message = HAL_GetErrorMessage(status);
void ThrowAllocationException(JNIEnv* env, int32_t minRange, int32_t maxRange,
int32_t requestedValue, int32_t status) {
const char* message = HAL_GetErrorMessage(status);
wpi::SmallString<1024> buf;
wpi::raw_svector_ostream oss(buf);
oss << " Code: " << status << ". " << message << ", Minimum Value: "
<< minRange << ", Maximum Value: " << maxRange << ", Requested Value: "
<< requestedValue;
oss << " Code: " << status << ". " << message
<< ", Minimum Value: " << minRange << ", Maximum Value: " << maxRange
<< ", Requested Value: " << requestedValue;
env->ThrowNew(allocationExCls, buf.c_str());
allocationExCls.Throw(env, buf.c_str());
}
void ThrowHalHandleException(JNIEnv *env, int32_t status) {
const char *message = HAL_GetErrorMessage(status);
void ThrowHalHandleException(JNIEnv* env, int32_t status) {
const char* message = HAL_GetErrorMessage(status);
wpi::SmallString<1024> buf;
wpi::raw_svector_ostream oss(buf);
oss << " Code: " << status << ". " << message;
halHandleExCls.Throw(env, buf.c_str());
}
void ReportError(JNIEnv *env, int32_t status, bool doThrow) {
void ReportError(JNIEnv* env, int32_t status, bool doThrow) {
if (status == 0) return;
if (status == HAL_HANDLE_ERROR) {
ThrowHalHandleException(env, status);
}
const char *message = HAL_GetErrorMessage(status);
const char* message = HAL_GetErrorMessage(status);
if (doThrow && status < 0) {
wpi::SmallString<1024> buf;
wpi::raw_svector_ostream oss(buf);
@@ -99,25 +100,24 @@ void ReportError(JNIEnv *env, int32_t status, bool doThrow) {
}
}
void ThrowError(JNIEnv *env, int32_t status, int32_t minRange, int32_t maxRange,
void ThrowError(JNIEnv* env, int32_t status, int32_t minRange, int32_t maxRange,
int32_t requestedValue) {
if (status == 0) return;
if (status == NO_AVAILABLE_RESOURCES ||
status == RESOURCE_IS_ALLOCATED ||
if (status == NO_AVAILABLE_RESOURCES || status == RESOURCE_IS_ALLOCATED ||
status == RESOURCE_OUT_OF_RANGE) {
ThrowAllocationException(env, minRange, maxRange, requestedValue, status);
}
if (status == HAL_HANDLE_ERROR) {
ThrowHalHandleException(env, status);
}
const char *message = HAL_GetErrorMessage(status);
const char* message = HAL_GetErrorMessage(status);
wpi::SmallString<1024> buf;
wpi::raw_svector_ostream oss(buf);
oss << " Code: " << status << ". " << message;
runtimeExCls.Throw(env, buf.c_str());
}
void ReportCANError(JNIEnv *env, int32_t status, int message_id) {
void ReportCANError(JNIEnv* env, int32_t status, int message_id) {
if (status >= 0) return;
switch (status) {
case kRioStatusSuccess:
@@ -174,11 +174,11 @@ void ReportCANError(JNIEnv *env, int32_t status, int message_id) {
}
}
void ThrowIllegalArgumentException(JNIEnv *env, const char *msg) {
void ThrowIllegalArgumentException(JNIEnv* env, const char* msg) {
illegalArgExCls.Throw(env, msg);
}
void ThrowBoundaryException(JNIEnv *env, double value, double lower,
void ThrowBoundaryException(JNIEnv* env, double value, double lower,
double upper) {
static jmethodID getMessage = nullptr;
if (!getMessage)
@@ -190,69 +190,61 @@ void ThrowBoundaryException(JNIEnv *env, double value, double lower,
constructor =
env->GetMethodID(boundaryExCls, "<init>", "(Ljava/lang/String;)V");
jobject msg =
env->CallStaticObjectMethod(boundaryExCls, getMessage,
static_cast<jdouble>(value),
static_cast<jdouble>(lower),
static_cast<jdouble>(upper));
jobject msg = env->CallStaticObjectMethod(
boundaryExCls, getMessage, static_cast<jdouble>(value),
static_cast<jdouble>(lower), static_cast<jdouble>(upper));
jobject ex = env->NewObject(boundaryExCls, constructor, msg);
env->Throw(static_cast<jthrowable>(ex));
}
jobject CreatePWMConfigDataResult(JNIEnv *env, int32_t maxPwm,
int32_t deadbandMaxPwm, int32_t centerPwm,
int32_t deadbandMinPwm, int32_t minPwm) {
jobject CreatePWMConfigDataResult(JNIEnv* env, int32_t maxPwm,
int32_t deadbandMaxPwm, int32_t centerPwm,
int32_t deadbandMinPwm, int32_t minPwm) {
static jmethodID constructor =
env->GetMethodID(pwmConfigDataResultCls, "<init>",
"(IIIII)V");
env->GetMethodID(pwmConfigDataResultCls, "<init>", "(IIIII)V");
return env->NewObject(pwmConfigDataResultCls, constructor, maxPwm,
deadbandMaxPwm, centerPwm, deadbandMinPwm,
minPwm);
deadbandMaxPwm, centerPwm, deadbandMinPwm, minPwm);
}
void SetCanStatusObject(JNIEnv *env, jobject canStatus,
float percentBusUtilization,
uint32_t busOffCount, uint32_t txFullCount,
uint32_t receiveErrorCount,
void SetCanStatusObject(JNIEnv* env, jobject canStatus,
float percentBusUtilization, uint32_t busOffCount,
uint32_t txFullCount, uint32_t receiveErrorCount,
uint32_t transmitErrorCount) {
static jmethodID func = env->GetMethodID(canStatusCls, "setStatus",
"(DIIII)V");
static jmethodID func =
env->GetMethodID(canStatusCls, "setStatus", "(DIIII)V");
env->CallVoidMethod(canStatus, func, (jdouble)percentBusUtilization,
(jint)busOffCount, (jint)txFullCount,
(jint)receiveErrorCount, (jint)transmitErrorCount);
(jint)busOffCount, (jint)txFullCount,
(jint)receiveErrorCount, (jint)transmitErrorCount);
}
void SetMatchInfoObject(JNIEnv* env, jobject matchStatus,
const HAL_MatchInfo& matchInfo) {
static jmethodID func = env->GetMethodID(matchInfoDataCls, "setData",
"(Ljava/lang/String;Ljava/lang/String;III)V");
static jmethodID func =
env->GetMethodID(matchInfoDataCls, "setData",
"(Ljava/lang/String;Ljava/lang/String;III)V");
env->CallVoidMethod(matchStatus, func,
MakeJString(env, matchInfo.eventName),
MakeJString(env, matchInfo.gameSpecificMessage),
(jint)matchInfo.matchNumber,
(jint)matchInfo.replayNumber,
(jint)matchInfo.matchType);
env->CallVoidMethod(matchStatus, func, MakeJString(env, matchInfo.eventName),
MakeJString(env, matchInfo.gameSpecificMessage),
(jint)matchInfo.matchNumber, (jint)matchInfo.replayNumber,
(jint)matchInfo.matchType);
}
void SetAccumulatorResultObject(JNIEnv* env, jobject accumulatorResult,
int64_t value, int64_t count) {
static jmethodID func = env->GetMethodID(accumulatorResultCls, "set",
"(JJ)V");
static jmethodID func =
env->GetMethodID(accumulatorResultCls, "set", "(JJ)V");
env->CallVoidMethod(accumulatorResult, func, (jlong)value, (jlong)count);
}
JavaVM* GetJVM() {
return jvm;
}
JavaVM* GetJVM() { return jvm; }
} // namespace frc
namespace sim {
jint SimOnLoad(JavaVM* vm, void* reserved);
void SimOnUnload(JavaVM* vm, void* reserved);
}
jint SimOnLoad(JavaVM* vm, void* reserved);
void SimOnUnload(JavaVM* vm, void* reserved);
} // namespace sim
using namespace frc;
@@ -261,14 +253,14 @@ extern "C" {
//
// indicate JNI version support desired and load classes
//
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
jvm = vm;
// set our logging level
Log::ReportingLevel() = logDEBUG;
JNIEnv *env;
if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK)
JNIEnv* env;
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
return JNI_ERR;
runtimeExCls = JException(env, "java/lang/RuntimeException");
@@ -277,31 +269,40 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
illegalArgExCls = JException(env, "java/lang/IllegalArgumentException");
if (!illegalArgExCls) return JNI_ERR;
boundaryExCls = JException(env, "edu/wpi/first/wpilibj/util/BoundaryException");
boundaryExCls =
JException(env, "edu/wpi/first/wpilibj/util/BoundaryException");
if (!boundaryExCls) return JNI_ERR;
allocationExCls = JException(env, "edu/wpi/first/wpilibj/util/AllocationException");
allocationExCls =
JException(env, "edu/wpi/first/wpilibj/util/AllocationException");
if (!allocationExCls) return JNI_ERR;
halHandleExCls = JException(env, "edu/wpi/first/wpilibj/util/HalHandleException");
halHandleExCls =
JException(env, "edu/wpi/first/wpilibj/util/HalHandleException");
if (!halHandleExCls) return JNI_ERR;
canInvalidBufferExCls = JException(env, "edu/wpi/first/wpilibj/can/CANInvalidBufferException");
canInvalidBufferExCls =
JException(env, "edu/wpi/first/wpilibj/can/CANInvalidBufferException");
if (!canInvalidBufferExCls) return JNI_ERR;
canMessageNotFoundExCls = JException(env, "edu/wpi/first/wpilibj/can/CANMessageNotFoundException");
canMessageNotFoundExCls =
JException(env, "edu/wpi/first/wpilibj/can/CANMessageNotFoundException");
if (!canMessageNotFoundExCls) return JNI_ERR;
canMessageNotAllowedExCls = JException(env, "edu/wpi/first/wpilibj/can/CANMessageNotAllowedException");
canMessageNotAllowedExCls = JException(
env, "edu/wpi/first/wpilibj/can/CANMessageNotAllowedException");
if (!canMessageNotAllowedExCls) return JNI_ERR;
canNotInitializedExCls = JException(env, "edu/wpi/first/wpilibj/can/CANNotInitializedException");
canNotInitializedExCls =
JException(env, "edu/wpi/first/wpilibj/can/CANNotInitializedException");
if (!canNotInitializedExCls) return JNI_ERR;
uncleanStatusExCls = JException(env,"edu/wpi/first/wpilibj/util/UncleanStatusException");
uncleanStatusExCls =
JException(env, "edu/wpi/first/wpilibj/util/UncleanStatusException");
if (!uncleanStatusExCls) return JNI_ERR;
pwmConfigDataResultCls = JClass(env, "edu/wpi/first/wpilibj/PWMConfigDataResult");
pwmConfigDataResultCls =
JClass(env, "edu/wpi/first/wpilibj/PWMConfigDataResult");
if (!pwmConfigDataResultCls) return JNI_ERR;
canStatusCls = JClass(env, "edu/wpi/first/wpilibj/can/CANStatus");
@@ -316,11 +317,11 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
return sim::SimOnLoad(vm, reserved);
}
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
JNIEXPORT void JNICALL JNI_OnUnload(JavaVM* vm, void* reserved) {
sim::SimOnUnload(vm, reserved);
JNIEnv *env;
if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) != JNI_OK)
JNIEnv* env;
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK)
return;
// Delete global references
runtimeExCls.free(env);
@@ -346,7 +347,9 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) {
* Signature: ()S
*/
JNIEXPORT jshort JNICALL
Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAVersion(JNIEnv *env, jclass) {
Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAVersion
(JNIEnv* env, jclass)
{
HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGAVersion";
int32_t status = 0;
jshort returnValue = HAL_GetFPGAVersion(&status);
@@ -362,7 +365,9 @@ Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAVersion(JNIEnv *env, jclass) {
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGARevision(JNIEnv *env, jclass) {
Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGARevision
(JNIEnv* env, jclass)
{
HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGARevision";
int32_t status = 0;
jint returnValue = HAL_GetFPGARevision(&status);
@@ -378,7 +383,9 @@ Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGARevision(JNIEnv *env, jclass) {
* Signature: ()J
*/
JNIEXPORT jlong JNICALL
Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGATime(JNIEnv *env, jclass) {
Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGATime
(JNIEnv* env, jclass)
{
// HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGATime";
int32_t status = 0;
jlong returnValue = HAL_GetFPGATime(&status);
@@ -394,7 +401,9 @@ Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGATime(JNIEnv *env, jclass) {
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALRuntimeType(JNIEnv *env, jclass) {
Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALRuntimeType
(JNIEnv* env, jclass)
{
// HALUTIL_LOG(logDEBUG) << "Calling HALUtil getHALRuntimeType";
jint returnValue = HAL_GetRuntimeType();
// HALUTIL_LOG(logDEBUG) << "RuntimeType = " << returnValue;
@@ -404,10 +413,12 @@ Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALRuntimeType(JNIEnv *env, jclass) {
/*
* Class: edu_wpi_first_wpilibj_hal_HALUtil
* Method: getFPGAButton
* Signature: ()I
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAButton(JNIEnv *env, jclass) {
Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAButton
(JNIEnv* env, jclass)
{
// HALUTIL_LOG(logDEBUG) << "Calling HALUtil getFPGATime";
int32_t status = 0;
jboolean returnValue = HAL_GetFPGAButton(&status);
@@ -423,9 +434,10 @@ Java_edu_wpi_first_wpilibj_hal_HALUtil_getFPGAButton(JNIEnv *env, jclass) {
* Signature: (I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL
Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALErrorMessage(
JNIEnv *paramEnv, jclass, jint paramId) {
const char *msg = HAL_GetErrorMessage(paramId);
Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALErrorMessage
(JNIEnv* paramEnv, jclass, jint paramId)
{
const char* msg = HAL_GetErrorMessage(paramId);
HALUTIL_LOG(logDEBUG) << "Calling HALUtil HAL_GetErrorMessage id=" << paramId
<< " msg=" << msg;
return MakeJString(paramEnv, msg);
@@ -437,7 +449,9 @@ Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALErrorMessage(
* Signature: ()I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALErrno(JNIEnv *, jclass) {
Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALErrno
(JNIEnv*, jclass)
{
return errno;
}
@@ -446,9 +460,11 @@ Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALErrno(JNIEnv *, jclass) {
* Method: getHALstrerror
* Signature: (I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALstrerror(
JNIEnv *env, jclass, jint errorCode) {
const char *msg = strerror(errno);
JNIEXPORT jstring JNICALL
Java_edu_wpi_first_wpilibj_hal_HALUtil_getHALstrerror
(JNIEnv* env, jclass, jint errorCode)
{
const char* msg = std::strerror(errno);
HALUTIL_LOG(logDEBUG) << "Calling HALUtil getHALstrerror errorCode="
<< errorCode << " msg=" << msg;
return MakeJString(env, msg);