Files
allwpilib/hal/src/main/native/cpp/jni/HAL.cpp

203 lines
3.8 KiB
C++
Raw Normal View History

// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include <jni.h>
#include "wpi/hal/HALBase.h"
#ifdef __FRC_SYSTEMCORE__
#include <signal.h>
#endif
2018-05-13 17:09:56 -07:00
#include <cassert>
#include <cstring>
#include <fmt/format.h>
2018-05-13 17:09:56 -07:00
#include "HALUtil.hpp"
2025-11-07 19:55:43 -05:00
#include "org_wpilib_hardware_hal_HAL.h"
2025-11-07 19:56:21 -05:00
#include "wpi/hal/DriverStation.h"
#include "wpi/hal/Main.h"
2025-11-07 19:57:55 -05:00
#include "wpi/util/jni_util.hpp"
2025-11-07 20:00:05 -05:00
using namespace wpi::hal;
using namespace wpi::util::java;
extern "C" {
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_HAL
2018-05-13 17:09:56 -07:00
* Method: initialize
* Signature: (II)Z
*/
JNIEXPORT jboolean JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_HAL_initialize
2018-05-13 17:09:56 -07:00
(JNIEnv*, jclass, jint timeout, jint mode)
{
return HAL_Initialize(timeout, mode);
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_HAL
* Method: shutdown
* Signature: ()V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_HAL_shutdown
(JNIEnv*, jclass)
{
return HAL_Shutdown();
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_HAL
* Method: hasMain
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_HAL_hasMain
(JNIEnv*, jclass)
{
return HAL_HasMain();
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_HAL
* Method: runMain
* Signature: ()V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_HAL_runMain
(JNIEnv*, jclass)
{
HAL_RunMain();
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_HAL
* Method: exitMain
* Signature: ()V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_HAL_exitMain
(JNIEnv*, jclass)
{
HAL_ExitMain();
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_HAL
* Method: terminate
* Signature: ()V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_HAL_terminate
(JNIEnv*, jclass)
{
#ifdef __FRC_SYSTEMCORE__
::raise(SIGKILL);
#endif
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_HAL
* Method: simPeriodicBeforeNative
* Signature: ()V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_HAL_simPeriodicBeforeNative
(JNIEnv*, jclass)
{
HAL_SimPeriodicBefore();
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_HAL
* Method: simPeriodicAfterNative
* Signature: ()V
*/
JNIEXPORT void JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_HAL_simPeriodicAfterNative
(JNIEnv*, jclass)
{
HAL_SimPeriodicAfter();
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_HAL
2018-05-13 17:09:56 -07:00
* Method: getSystemActive
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_HAL_getSystemActive
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass)
{
int32_t status = 0;
bool val = HAL_GetSystemActive(&status);
CheckStatus(env, status);
return val;
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_HAL
2018-05-13 17:09:56 -07:00
* Method: getBrownedOut
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_HAL_getBrownedOut
2018-05-13 17:09:56 -07:00
(JNIEnv* env, jclass)
{
int32_t status = 0;
bool val = HAL_GetBrownedOut(&status);
CheckStatus(env, status);
return val;
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_HAL
* Method: getCommsDisableCount
* Signature: ()I
*/
JNIEXPORT jint JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_HAL_getCommsDisableCount
(JNIEnv* env, jclass)
{
int32_t status = 0;
int32_t val = HAL_GetCommsDisableCount(&status);
CheckStatus(env, status);
return val;
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_HAL
* Method: getRSLState
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_HAL_getRSLState
(JNIEnv* env, jclass)
{
int32_t status = 0;
bool val = HAL_GetRSLState(&status);
CheckStatus(env, status);
return val;
}
/*
2025-11-07 19:55:43 -05:00
* Class: org_wpilib_hardware_hal_HAL
* Method: getSystemTimeValid
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL
2025-11-07 19:55:43 -05:00
Java_org_wpilib_hardware_hal_HAL_getSystemTimeValid
(JNIEnv* env, jclass)
{
int32_t status = 0;
bool val = HAL_GetSystemTimeValid(&status);
CheckStatus(env, status);
return val;
}
} // extern "C"