[hal] Rename PowerDistributionPanel to PowerDistribution (#3466)

Makes HAL more generic for the PDP, to enable the Rev PDH in the future.
This commit is contained in:
Thad House
2021-08-04 20:31:17 -07:00
committed by GitHub
parent 2014115bca
commit 1ac73a247e
50 changed files with 1612 additions and 1177 deletions

View File

@@ -183,7 +183,7 @@ HAL_CTREPCMHandle HAL_InitializeCTREPCM(int32_t module,
pcm->previousAllocation);
} else {
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for CTRE PCM", 0,
kNumAccumulators, module);
kNumCTREPCMModules, module);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}

View File

@@ -2,7 +2,7 @@
// 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 "hal/PDP.h"
#include "CTREPDP.h"
#include <fmt/format.h>
#include <wpi/mutex.h>
@@ -12,6 +12,7 @@
#include "PortsInternal.h"
#include "hal/CANAPI.h"
#include "hal/Errors.h"
#include "hal/handles/IndexedHandleResource.h"
using namespace hal;
@@ -102,20 +103,29 @@ union PdpStatusEnergy {
} bits;
};
static wpi::mutex pdpHandleMutex;
static HAL_PDPHandle pdpHandles[kNumPDPModules];
namespace {
struct PDP {
HAL_CANHandle canHandle;
std::string previousAllocation;
};
} // namespace
static IndexedHandleResource<HAL_PDPHandle, PDP, kNumPDPModules,
HAL_HandleEnum::CTREPDP>* pdpHandles;
namespace hal::init {
void InitializePDP() {
for (int i = 0; i < kNumPDPModules; i++) {
pdpHandles[i] = HAL_kInvalidHandle;
}
static IndexedHandleResource<HAL_PDPHandle, PDP, kNumPDPModules,
HAL_HandleEnum::CTREPDP>
pH;
pdpHandles = &pH;
}
} // namespace hal::init
extern "C" {
HAL_PDPHandle HAL_InitializePDP(int32_t module, int32_t* status) {
HAL_PDPHandle HAL_InitializePDP(int32_t module, const char* allocationLocation,
int32_t* status) {
hal::init::CheckInit();
if (!HAL_CheckPDPModule(module)) {
*status = PARAMETER_OUT_OF_RANGE;
@@ -123,34 +133,37 @@ HAL_PDPHandle HAL_InitializePDP(int32_t module, int32_t* status) {
return HAL_kInvalidHandle;
}
std::scoped_lock lock(pdpHandleMutex);
if (pdpHandles[module] != HAL_kInvalidHandle) {
*status = 0;
return pdpHandles[module];
}
auto handle = HAL_InitializeCAN(manufacturer, module, deviceType, status);
HAL_PDPHandle handle;
auto pdp = pdpHandles->Allocate(module, &handle, status);
if (*status != 0) {
HAL_CleanCAN(handle);
if (pdp) {
hal::SetLastErrorPreviouslyAllocated(status, "CTRE PDP", module,
pdp->previousAllocation);
} else {
hal::SetLastErrorIndexOutOfRange(status, "Invalid Index for CTRE PDP", 0,
kNumPDPModules, module);
}
return HAL_kInvalidHandle; // failed to allocate. Pass error back.
}
pdp->canHandle = HAL_InitializeCAN(manufacturer, module, deviceType, status);
if (*status != 0) {
pdpHandles->Free(handle);
return HAL_kInvalidHandle;
}
pdpHandles[module] = handle;
pdp->previousAllocation = allocationLocation ? allocationLocation : "";
return handle;
}
void HAL_CleanPDP(HAL_PDPHandle handle) {
HAL_CleanCAN(handle);
for (int i = 0; i < kNumPDPModules; i++) {
if (pdpHandles[i] == handle) {
pdpHandles[i] = HAL_kInvalidHandle;
return;
}
auto pdp = pdpHandles->Get(handle);
if (pdp) {
HAL_CleanCAN(pdp->canHandle);
}
pdpHandles->Free(handle);
}
HAL_Bool HAL_CheckPDPModule(int32_t module) {
@@ -162,11 +175,17 @@ HAL_Bool HAL_CheckPDPChannel(int32_t channel) {
}
double HAL_GetPDPTemperature(HAL_PDPHandle handle, int32_t* status) {
auto pdp = pdpHandles->Get(handle);
if (pdp == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
PdpStatus3 pdpStatus;
int32_t length = 0;
uint64_t receivedTimestamp = 0;
HAL_ReadCANPacketTimeout(handle, Status3, pdpStatus.data, &length,
HAL_ReadCANPacketTimeout(pdp->canHandle, Status3, pdpStatus.data, &length,
&receivedTimestamp, TimeoutMs, status);
if (*status != 0) {
@@ -177,11 +196,17 @@ double HAL_GetPDPTemperature(HAL_PDPHandle handle, int32_t* status) {
}
double HAL_GetPDPVoltage(HAL_PDPHandle handle, int32_t* status) {
auto pdp = pdpHandles->Get(handle);
if (pdp == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
PdpStatus3 pdpStatus;
int32_t length = 0;
uint64_t receivedTimestamp = 0;
HAL_ReadCANPacketTimeout(handle, Status3, pdpStatus.data, &length,
HAL_ReadCANPacketTimeout(pdp->canHandle, Status3, pdpStatus.data, &length,
&receivedTimestamp, TimeoutMs, status);
if (*status != 0) {
@@ -199,6 +224,12 @@ double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
return 0;
}
auto pdp = pdpHandles->Get(handle);
if (pdp == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
int32_t length = 0;
uint64_t receivedTimestamp = 0;
@@ -206,7 +237,7 @@ double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
if (channel <= 5) {
PdpStatus1 pdpStatus;
HAL_ReadCANPacketTimeout(handle, Status1, pdpStatus.data, &length,
HAL_ReadCANPacketTimeout(pdp->canHandle, Status1, pdpStatus.data, &length,
&receivedTimestamp, TimeoutMs, status);
if (*status != 0) {
return 0;
@@ -239,7 +270,7 @@ double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
}
} else if (channel <= 11) {
PdpStatus2 pdpStatus;
HAL_ReadCANPacketTimeout(handle, Status2, pdpStatus.data, &length,
HAL_ReadCANPacketTimeout(pdp->canHandle, Status2, pdpStatus.data, &length,
&receivedTimestamp, TimeoutMs, status);
if (*status != 0) {
return 0;
@@ -272,7 +303,7 @@ double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
}
} else {
PdpStatus3 pdpStatus;
HAL_ReadCANPacketTimeout(handle, Status3, pdpStatus.data, &length,
HAL_ReadCANPacketTimeout(pdp->canHandle, Status3, pdpStatus.data, &length,
&receivedTimestamp, TimeoutMs, status);
if (*status != 0) {
return 0;
@@ -303,22 +334,28 @@ double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
void HAL_GetPDPAllChannelCurrents(HAL_PDPHandle handle, double* currents,
int32_t* status) {
auto pdp = pdpHandles->Get(handle);
if (pdp == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
int32_t length = 0;
uint64_t receivedTimestamp = 0;
PdpStatus1 pdpStatus;
HAL_ReadCANPacketTimeout(handle, Status1, pdpStatus.data, &length,
HAL_ReadCANPacketTimeout(pdp->canHandle, Status1, pdpStatus.data, &length,
&receivedTimestamp, TimeoutMs, status);
if (*status != 0) {
return;
}
PdpStatus2 pdpStatus2;
HAL_ReadCANPacketTimeout(handle, Status2, pdpStatus2.data, &length,
HAL_ReadCANPacketTimeout(pdp->canHandle, Status2, pdpStatus2.data, &length,
&receivedTimestamp, TimeoutMs, status);
if (*status != 0) {
return;
}
PdpStatus3 pdpStatus3;
HAL_ReadCANPacketTimeout(handle, Status3, pdpStatus3.data, &length,
HAL_ReadCANPacketTimeout(pdp->canHandle, Status3, pdpStatus3.data, &length,
&receivedTimestamp, TimeoutMs, status);
if (*status != 0) {
return;
@@ -377,12 +414,18 @@ void HAL_GetPDPAllChannelCurrents(HAL_PDPHandle handle, double* currents,
}
double HAL_GetPDPTotalCurrent(HAL_PDPHandle handle, int32_t* status) {
auto pdp = pdpHandles->Get(handle);
if (pdp == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
PdpStatusEnergy pdpStatus;
int32_t length = 0;
uint64_t receivedTimestamp = 0;
HAL_ReadCANPacketTimeout(handle, StatusEnergy, pdpStatus.data, &length,
&receivedTimestamp, TimeoutMs, status);
HAL_ReadCANPacketTimeout(pdp->canHandle, StatusEnergy, pdpStatus.data,
&length, &receivedTimestamp, TimeoutMs, status);
if (*status != 0) {
return 0;
}
@@ -395,12 +438,18 @@ double HAL_GetPDPTotalCurrent(HAL_PDPHandle handle, int32_t* status) {
}
double HAL_GetPDPTotalPower(HAL_PDPHandle handle, int32_t* status) {
auto pdp = pdpHandles->Get(handle);
if (pdp == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
PdpStatusEnergy pdpStatus;
int32_t length = 0;
uint64_t receivedTimestamp = 0;
HAL_ReadCANPacketTimeout(handle, StatusEnergy, pdpStatus.data, &length,
&receivedTimestamp, TimeoutMs, status);
HAL_ReadCANPacketTimeout(pdp->canHandle, StatusEnergy, pdpStatus.data,
&length, &receivedTimestamp, TimeoutMs, status);
if (*status != 0) {
return 0;
}
@@ -415,12 +464,18 @@ double HAL_GetPDPTotalPower(HAL_PDPHandle handle, int32_t* status) {
}
double HAL_GetPDPTotalEnergy(HAL_PDPHandle handle, int32_t* status) {
auto pdp = pdpHandles->Get(handle);
if (pdp == nullptr) {
*status = HAL_HANDLE_ERROR;
return 0;
}
PdpStatusEnergy pdpStatus;
int32_t length = 0;
uint64_t receivedTimestamp = 0;
HAL_ReadCANPacketTimeout(handle, StatusEnergy, pdpStatus.data, &length,
&receivedTimestamp, TimeoutMs, status);
HAL_ReadCANPacketTimeout(pdp->canHandle, StatusEnergy, pdpStatus.data,
&length, &receivedTimestamp, TimeoutMs, status);
if (*status != 0) {
return 0;
}
@@ -443,13 +498,25 @@ double HAL_GetPDPTotalEnergy(HAL_PDPHandle handle, int32_t* status) {
}
void HAL_ResetPDPTotalEnergy(HAL_PDPHandle handle, int32_t* status) {
auto pdp = pdpHandles->Get(handle);
if (pdp == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
uint8_t pdpControl[] = {0x40}; /* only bit set is ResetEnergy */
HAL_WriteCANPacket(handle, pdpControl, 1, Control1, status);
HAL_WriteCANPacket(pdp->canHandle, pdpControl, 1, Control1, status);
}
void HAL_ClearPDPStickyFaults(HAL_PDPHandle handle, int32_t* status) {
auto pdp = pdpHandles->Get(handle);
if (pdp == nullptr) {
*status = HAL_HANDLE_ERROR;
return;
}
uint8_t pdpControl[] = {0x80}; /* only bit set is ClearStickyFaults */
HAL_WriteCANPacket(handle, pdpControl, 1, Control1, status);
HAL_WriteCANPacket(pdp->canHandle, pdpControl, 1, Control1, status);
}
} // extern "C"

View File

@@ -25,7 +25,8 @@ extern "C" {
* @param module the module number to initialize
* @return the created PDP
*/
HAL_PDPHandle HAL_InitializePDP(int32_t module, int32_t* status);
HAL_PDPHandle HAL_InitializePDP(int32_t module, const char* allocationLocation,
int32_t* status);
/**
* Cleans a PDP module.

View File

@@ -0,0 +1,171 @@
// 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 "hal/PowerDistribution.h"
#include "CTREPDP.h"
#include "HALInternal.h"
#include "PortsInternal.h"
#include "hal/Errors.h"
#include "hal/handles/HandlesInternal.h"
using namespace hal;
extern "C" {
HAL_PowerDistributionHandle HAL_InitializePowerDistribution(
int32_t moduleNumber, HAL_PowerDistributionType type, int32_t* status) {
if (type == HAL_PowerDistributionType::HAL_PowerDistributionType_kAutomatic) {
type = HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE;
}
if (type == HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE) {
return static_cast<HAL_PowerDistributionHandle>(
HAL_InitializePDP(moduleNumber, nullptr, status)); // TODO
} else {
*status = PARAMETER_OUT_OF_RANGE;
SetLastError(status, "Rev Power not currently supported");
return HAL_kInvalidHandle;
}
}
#define IsCtre(handle) ::hal::isHandleType(handle, HAL_HandleEnum::CTREPDP)
void HAL_CleanPowerDistribution(HAL_PowerDistributionHandle handle) {
if (IsCtre(handle)) {
HAL_CleanPDP(handle);
} else {
// TODO
}
}
HAL_Bool HAL_CheckPowerDistributionChannel(HAL_PowerDistributionHandle handle,
int32_t channel) {
if (IsCtre(handle)) {
return HAL_CheckPDPChannel(channel);
} else {
return false;
// TODO
}
}
HAL_Bool HAL_CheckPowerDistributionModule(int32_t module,
HAL_PowerDistributionType type) {
if (type == HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE) {
return HAL_CheckPDPModule(module);
} else {
return false;
// TODO
}
}
HAL_PowerDistributionType HAL_GetPowerDistributionType(
HAL_PowerDistributionHandle handle, int32_t* status) {
return IsCtre(handle)
? HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE
: HAL_PowerDistributionType::HAL_PowerDistributionType_kRev;
}
double HAL_GetPowerDistributionTemperature(HAL_PowerDistributionHandle handle,
int32_t* status) {
if (IsCtre(handle)) {
return HAL_GetPDPTemperature(handle, status);
} else {
*status = PARAMETER_OUT_OF_RANGE;
SetLastError(status, "Rev Power not currently supported");
return false;
}
}
double HAL_GetPowerDistributionVoltage(HAL_PowerDistributionHandle handle,
int32_t* status) {
if (IsCtre(handle)) {
return HAL_GetPDPVoltage(handle, status);
} else {
*status = PARAMETER_OUT_OF_RANGE;
SetLastError(status, "Rev Power not currently supported");
return false;
}
}
double HAL_GetPowerDistributionChannelCurrent(
HAL_PowerDistributionHandle handle, int32_t channel, int32_t* status) {
if (IsCtre(handle)) {
return HAL_GetPDPChannelCurrent(handle, channel, status);
} else {
*status = PARAMETER_OUT_OF_RANGE;
SetLastError(status, "Rev Power not currently supported");
return 0;
}
}
void HAL_GetPowerDistributionAllChannelCurrents(
HAL_PowerDistributionHandle handle, double* currents,
int32_t currentsLength, int32_t* status) {
if (IsCtre(handle)) {
if (currentsLength < kNumPDPChannels) {
*status = PARAMETER_OUT_OF_RANGE;
SetLastError(status, "Output array not large enough");
return;
}
return HAL_GetPDPAllChannelCurrents(handle, currents, status);
} else {
*status = PARAMETER_OUT_OF_RANGE;
SetLastError(status, "Rev Power not currently supported");
}
}
double HAL_GetPowerDistributionTotalCurrent(HAL_PowerDistributionHandle handle,
int32_t* status) {
if (IsCtre(handle)) {
return HAL_GetPDPTotalCurrent(handle, status);
} else {
*status = PARAMETER_OUT_OF_RANGE;
SetLastError(status, "Rev Power not currently supported");
return 0;
}
}
double HAL_GetPowerDistributionTotalPower(HAL_PowerDistributionHandle handle,
int32_t* status) {
if (IsCtre(handle)) {
return HAL_GetPDPTotalPower(handle, status);
} else {
*status = PARAMETER_OUT_OF_RANGE;
SetLastError(status, "Rev Power not currently supported");
return 0;
}
}
double HAL_GetPowerDistributionTotalEnergy(HAL_PowerDistributionHandle handle,
int32_t* status) {
if (IsCtre(handle)) {
return HAL_GetPDPTotalEnergy(handle, status);
} else {
*status = PARAMETER_OUT_OF_RANGE;
SetLastError(status, "Rev Power not currently supported");
return 0;
}
}
void HAL_ResetPowerDistributionTotalEnergy(HAL_PowerDistributionHandle handle,
int32_t* status) {
if (IsCtre(handle)) {
HAL_ResetPDPTotalEnergy(handle, status);
} else {
*status = PARAMETER_OUT_OF_RANGE;
SetLastError(status, "Rev Power not currently supported");
}
}
void HAL_ClearPowerDistributionStickyFaults(HAL_PowerDistributionHandle handle,
int32_t* status) {
if (IsCtre(handle)) {
HAL_ClearPDPStickyFaults(handle, status);
} else {
*status = PARAMETER_OUT_OF_RANGE;
SetLastError(status, "Rev Power not currently supported");
}
}
} // extern "C"

View File

@@ -1,33 +0,0 @@
// 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 "hal/simulation/PDPData.h"
#include "../PortsInternal.h"
#include "hal/simulation/SimDataValue.h"
extern "C" {
void HALSIM_ResetPDPData(int32_t index) {}
#define DEFINE_CAPI(TYPE, CAPINAME, RETURN) \
HAL_SIMDATAVALUE_STUB_CAPI(TYPE, HALSIM, PDP##CAPINAME, RETURN)
DEFINE_CAPI(HAL_Bool, Initialized, false)
DEFINE_CAPI(double, Temperature, 0)
DEFINE_CAPI(double, Voltage, 0)
HAL_SIMDATAVALUE_STUB_CAPI_CHANNEL(double, HALSIM, PDPCurrent, 0)
void HALSIM_GetPDPAllCurrents(int32_t index, double* currents) {
for (int i = 0; i < hal::kNumPDPChannels; i++) {
currents[i] = 0;
}
}
void HALSIM_SetPDPAllCurrents(int32_t index, const double* currents) {}
void HALSIM_RegisterPDPAllNonCurrentCallbacks(int32_t index, int32_t channel,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {}
} // extern "C"

View File

@@ -0,0 +1,33 @@
// 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 "hal/simulation/PowerDistributionData.h"
#include "../PortsInternal.h"
#include "hal/simulation/SimDataValue.h"
extern "C" {
void HALSIM_ResetPowerDistributionData(int32_t index) {}
#define DEFINE_CAPI(TYPE, CAPINAME, RETURN) \
HAL_SIMDATAVALUE_STUB_CAPI(TYPE, HALSIM, PowerDistribution##CAPINAME, RETURN)
DEFINE_CAPI(HAL_Bool, Initialized, false)
DEFINE_CAPI(double, Temperature, 0)
DEFINE_CAPI(double, Voltage, 0)
HAL_SIMDATAVALUE_STUB_CAPI_CHANNEL(double, HALSIM, PowerDistributionCurrent, 0)
void HALSIM_GetPowerDistributionAllCurrents(int32_t index, double* currents) {
for (int i = 0; i < hal::kNumPDPChannels; i++) {
currents[i] = 0;
}
}
void HALSIM_SetPowerDistributionAllCurrents(int32_t index,
const double* currents) {}
void HALSIM_RegisterPowerDistributionAllNonCurrentCallbacks(
int32_t index, int32_t channel, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {}
} // extern "C"

View File

@@ -1,190 +0,0 @@
// 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 "HALUtil.h"
#include "edu_wpi_first_hal_PDPJNI.h"
#include "hal/PDP.h"
#include "hal/Ports.h"
using namespace hal;
extern "C" {
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: initializePDP
* Signature: (I)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_PDPJNI_initializePDP
(JNIEnv* env, jclass, jint module)
{
int32_t status = 0;
auto handle = HAL_InitializePDP(module, &status);
CheckStatusRange(env, status, 0, HAL_GetNumPDPModules(), module);
return static_cast<jint>(handle);
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: checkPDPChannel
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_PDPJNI_checkPDPChannel
(JNIEnv* env, jclass, jint channel)
{
return HAL_CheckPDPChannel(channel);
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: checkPDPModule
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_PDPJNI_checkPDPModule
(JNIEnv* env, jclass, jint module)
{
return HAL_CheckPDPModule(module);
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPTemperature
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPTemperature
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double temperature = HAL_GetPDPTemperature(handle, &status);
CheckStatus(env, status, false);
return temperature;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPVoltage
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPVoltage
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double voltage = HAL_GetPDPVoltage(handle, &status);
CheckStatus(env, status, false);
return voltage;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPChannelCurrent
* Signature: (BI)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPChannelCurrent
(JNIEnv* env, jclass, jbyte channel, jint handle)
{
int32_t status = 0;
double current = HAL_GetPDPChannelCurrent(handle, channel, &status);
CheckStatus(env, status, false);
return current;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPAllCurrents
* Signature: (I[D)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPAllCurrents
(JNIEnv* env, jclass, jint handle, jdoubleArray jarr)
{
double storage[16];
int32_t status = 0;
HAL_GetPDPAllChannelCurrents(handle, storage, &status);
if (!CheckStatus(env, status, false)) {
return;
}
env->SetDoubleArrayRegion(jarr, 0, 16, storage);
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPTotalCurrent
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPTotalCurrent
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double current = HAL_GetPDPTotalCurrent(handle, &status);
CheckStatus(env, status, false);
return current;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPTotalPower
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPTotalPower
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double power = HAL_GetPDPTotalPower(handle, &status);
CheckStatus(env, status, false);
return power;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: getPDPTotalEnergy
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PDPJNI_getPDPTotalEnergy
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double energy = HAL_GetPDPTotalEnergy(handle, &status);
CheckStatus(env, status, false);
return energy;
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: resetPDPTotalEnergy
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PDPJNI_resetPDPTotalEnergy
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
HAL_ResetPDPTotalEnergy(handle, &status);
CheckStatus(env, status, false);
}
/*
* Class: edu_wpi_first_hal_PDPJNI
* Method: clearPDPStickyFaults
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PDPJNI_clearPDPStickyFaults
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
HAL_ClearPDPStickyFaults(handle, &status);
CheckStatus(env, status, false);
}
} // extern "C"

View File

@@ -0,0 +1,209 @@
// 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 "HALUtil.h"
#include "edu_wpi_first_hal_PowerDistributionJNI.h"
#include "hal/Ports.h"
#include "hal/PowerDistribution.h"
using namespace hal;
extern "C" {
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: initialize
* Signature: (II)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_initialize
(JNIEnv* env, jclass, jint module, jint type)
{
int32_t status = 0;
auto handle = HAL_InitializePowerDistribution(
module, static_cast<HAL_PowerDistributionType>(type), &status);
CheckStatusForceThrow(env, status);
return static_cast<jint>(handle);
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: checkChannel
* Signature: (II)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_checkChannel
(JNIEnv* env, jclass, jint handle, jint channel)
{
return HAL_CheckPowerDistributionChannel(handle, channel);
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: checkModule
* Signature: (II)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_checkModule
(JNIEnv* env, jclass, jint module, jint type)
{
return HAL_CheckPowerDistributionModule(
module, static_cast<HAL_PowerDistributionType>(type));
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: getType
* Signature: (I)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_getType
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
auto result = HAL_GetPowerDistributionType(handle, &status);
CheckStatus(env, status);
return result;
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: getTemperature
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_getTemperature
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double temperature = HAL_GetPowerDistributionTemperature(handle, &status);
CheckStatus(env, status, false);
return temperature;
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: getVoltage
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_getVoltage
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double voltage = HAL_GetPowerDistributionVoltage(handle, &status);
CheckStatus(env, status, false);
return voltage;
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: getChannelCurrent
* Signature: (BI)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_getChannelCurrent
(JNIEnv* env, jclass, jbyte channel, jint handle)
{
int32_t status = 0;
double current =
HAL_GetPowerDistributionChannelCurrent(handle, channel, &status);
CheckStatus(env, status, false);
return current;
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: getAllCurrents
* Signature: (I[D)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_getAllCurrents
(JNIEnv* env, jclass, jint handle, jdoubleArray jarr)
{
double storage[16];
int32_t status = 0;
// TODO fix me
HAL_GetPowerDistributionAllChannelCurrents(handle, storage, 16, &status);
if (!CheckStatus(env, status, false)) {
return;
}
env->SetDoubleArrayRegion(jarr, 0, 16, storage);
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: getTotalCurrent
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_getTotalCurrent
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double current = HAL_GetPowerDistributionTotalCurrent(handle, &status);
CheckStatus(env, status, false);
return current;
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: getTotalPower
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_getTotalPower
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double power = HAL_GetPowerDistributionTotalPower(handle, &status);
CheckStatus(env, status, false);
return power;
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: getTotalEnergy
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_getTotalEnergy
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
double energy = HAL_GetPowerDistributionTotalEnergy(handle, &status);
CheckStatus(env, status, false);
return energy;
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: resetTotalEnergy
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_resetTotalEnergy
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
HAL_ResetPowerDistributionTotalEnergy(handle, &status);
CheckStatus(env, status, false);
}
/*
* Class: edu_wpi_first_hal_PowerDistributionJNI
* Method: clearStickyFaults
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_PowerDistributionJNI_clearStickyFaults
(JNIEnv* env, jclass, jint handle)
{
int32_t status = 0;
HAL_ClearPowerDistributionStickyFaults(handle, &status);
CheckStatus(env, status, false);
}
} // extern "C"

View File

@@ -1,229 +0,0 @@
// 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 "CallbackStore.h"
#include "edu_wpi_first_hal_simulation_PDPDataJNI.h"
#include "hal/simulation/PDPData.h"
using namespace hal;
extern "C" {
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: registerInitializedCallback
* Signature: (ILjava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_registerInitializedCallback
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallback(env, index, callback, initialNotify,
&HALSIM_RegisterPDPInitializedCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: cancelInitializedCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_cancelInitializedCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
return sim::FreeCallback(env, handle, index,
&HALSIM_CancelPDPInitializedCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: getInitialized
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_getInitialized
(JNIEnv*, jclass, jint index)
{
return HALSIM_GetPDPInitialized(index);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: setInitialized
* Signature: (IZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_setInitialized
(JNIEnv*, jclass, jint index, jboolean value)
{
HALSIM_SetPDPInitialized(index, value);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: registerTemperatureCallback
* Signature: (ILjava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_registerTemperatureCallback
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallback(env, index, callback, initialNotify,
&HALSIM_RegisterPDPTemperatureCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: cancelTemperatureCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_cancelTemperatureCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
return sim::FreeCallback(env, handle, index,
&HALSIM_CancelPDPTemperatureCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: getTemperature
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_getTemperature
(JNIEnv*, jclass, jint index)
{
return HALSIM_GetPDPTemperature(index);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: setTemperature
* Signature: (ID)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_setTemperature
(JNIEnv*, jclass, jint index, jdouble value)
{
HALSIM_SetPDPTemperature(index, value);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: registerVoltageCallback
* Signature: (ILjava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_registerVoltageCallback
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallback(env, index, callback, initialNotify,
&HALSIM_RegisterPDPVoltageCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: cancelVoltageCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_cancelVoltageCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
return sim::FreeCallback(env, handle, index,
&HALSIM_CancelPDPVoltageCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: getVoltage
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_getVoltage
(JNIEnv*, jclass, jint index)
{
return HALSIM_GetPDPVoltage(index);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: setVoltage
* Signature: (ID)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_setVoltage
(JNIEnv*, jclass, jint index, jdouble value)
{
HALSIM_SetPDPVoltage(index, value);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: registerCurrentCallback
* Signature: (IILjava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_registerCurrentCallback
(JNIEnv* env, jclass, jint index, jint channel, jobject callback,
jboolean initialNotify)
{
return sim::AllocateChannelCallback(env, index, channel, callback,
initialNotify,
&HALSIM_RegisterPDPCurrentCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: cancelCurrentCallback
* Signature: (III)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_cancelCurrentCallback
(JNIEnv* env, jclass, jint index, jint channel, jint handle)
{
return sim::FreeChannelCallback(env, handle, index, channel,
&HALSIM_CancelPDPCurrentCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: getCurrent
* Signature: (II)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_getCurrent
(JNIEnv*, jclass, jint index, jint channel)
{
return HALSIM_GetPDPCurrent(index, channel);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: setCurrent
* Signature: (IID)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_setCurrent
(JNIEnv*, jclass, jint index, jint channel, jdouble value)
{
HALSIM_SetPDPCurrent(index, channel, value);
}
/*
* Class: edu_wpi_first_hal_simulation_PDPDataJNI
* Method: resetData
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PDPDataJNI_resetData
(JNIEnv*, jclass, jint index)
{
HALSIM_ResetPDPData(index);
}
} // extern "C"

View File

@@ -0,0 +1,233 @@
// 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 "CallbackStore.h"
#include "edu_wpi_first_hal_simulation_PowerDistributionDataJNI.h"
#include "hal/simulation/PowerDistributionData.h"
using namespace hal;
extern "C" {
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: registerInitializedCallback
* Signature: (ILjava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_registerInitializedCallback
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallback(
env, index, callback, initialNotify,
&HALSIM_RegisterPowerDistributionInitializedCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: cancelInitializedCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_cancelInitializedCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
return sim::FreeCallback(env, handle, index,
&HALSIM_CancelPowerDistributionInitializedCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: getInitialized
* Signature: (I)Z
*/
JNIEXPORT jboolean JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_getInitialized
(JNIEnv*, jclass, jint index)
{
return HALSIM_GetPowerDistributionInitialized(index);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: setInitialized
* Signature: (IZ)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_setInitialized
(JNIEnv*, jclass, jint index, jboolean value)
{
HALSIM_SetPowerDistributionInitialized(index, value);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: registerTemperatureCallback
* Signature: (ILjava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_registerTemperatureCallback
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallback(
env, index, callback, initialNotify,
&HALSIM_RegisterPowerDistributionTemperatureCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: cancelTemperatureCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_cancelTemperatureCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
return sim::FreeCallback(env, handle, index,
&HALSIM_CancelPowerDistributionTemperatureCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: getTemperature
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_getTemperature
(JNIEnv*, jclass, jint index)
{
return HALSIM_GetPowerDistributionTemperature(index);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: setTemperature
* Signature: (ID)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_setTemperature
(JNIEnv*, jclass, jint index, jdouble value)
{
HALSIM_SetPowerDistributionTemperature(index, value);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: registerVoltageCallback
* Signature: (ILjava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_registerVoltageCallback
(JNIEnv* env, jclass, jint index, jobject callback, jboolean initialNotify)
{
return sim::AllocateCallback(
env, index, callback, initialNotify,
&HALSIM_RegisterPowerDistributionVoltageCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: cancelVoltageCallback
* Signature: (II)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_cancelVoltageCallback
(JNIEnv* env, jclass, jint index, jint handle)
{
return sim::FreeCallback(env, handle, index,
&HALSIM_CancelPowerDistributionVoltageCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: getVoltage
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_getVoltage
(JNIEnv*, jclass, jint index)
{
return HALSIM_GetPowerDistributionVoltage(index);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: setVoltage
* Signature: (ID)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_setVoltage
(JNIEnv*, jclass, jint index, jdouble value)
{
HALSIM_SetPowerDistributionVoltage(index, value);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: registerCurrentCallback
* Signature: (IILjava/lang/Object;Z)I
*/
JNIEXPORT jint JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_registerCurrentCallback
(JNIEnv* env, jclass, jint index, jint channel, jobject callback,
jboolean initialNotify)
{
return sim::AllocateChannelCallback(
env, index, channel, callback, initialNotify,
&HALSIM_RegisterPowerDistributionCurrentCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: cancelCurrentCallback
* Signature: (III)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_cancelCurrentCallback
(JNIEnv* env, jclass, jint index, jint channel, jint handle)
{
return sim::FreeChannelCallback(
env, handle, index, channel,
&HALSIM_CancelPowerDistributionCurrentCallback);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: getCurrent
* Signature: (II)D
*/
JNIEXPORT jdouble JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_getCurrent
(JNIEnv*, jclass, jint index, jint channel)
{
return HALSIM_GetPowerDistributionCurrent(index, channel);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: setCurrent
* Signature: (IID)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_setCurrent
(JNIEnv*, jclass, jint index, jint channel, jdouble value)
{
HALSIM_SetPowerDistributionCurrent(index, channel, value);
}
/*
* Class: edu_wpi_first_hal_simulation_PowerDistributionDataJNI
* Method: resetData
* Signature: (I)V
*/
JNIEXPORT void JNICALL
Java_edu_wpi_first_hal_simulation_PowerDistributionDataJNI_resetData
(JNIEnv*, jclass, jint index)
{
HALSIM_ResetPowerDistributionData(index);
}
} // extern "C"

View File

@@ -27,7 +27,6 @@
#include "hal/Interrupts.h"
#include "hal/Main.h"
#include "hal/Notifier.h"
#include "hal/PDP.h"
#include "hal/PWM.h"
#include "hal/Ports.h"
#include "hal/Power.h"

View File

@@ -0,0 +1,163 @@
// 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.
#pragma once
#include <stdint.h>
#include "hal/Types.h"
/**
* @defgroup hal_pd Power Distribution Functions
* @ingroup hal_capi
* Functions to control Power Distribution devices.
* @{
*/
// clang-format off
/**
* The acceptable accelerometer ranges.
*/
HAL_ENUM(HAL_PowerDistributionType) {
HAL_PowerDistributionType_kAutomatic = 0,
HAL_PowerDistributionType_kCTRE = 1,
HAL_PowerDistributionType_kRev = 2,
};
// clang-format on
#ifdef __cplusplus
extern "C" {
#endif
/**
* Initializes a Power Distribution Panel.
*
* @param module the module number to initialize
* @param type the type of module to intialize
* @return the created PowerDistribution
*/
HAL_PowerDistributionHandle HAL_InitializePowerDistribution(
int32_t moduleNumber, HAL_PowerDistributionType type, int32_t* status);
/**
* Cleans a PowerDistribution module.
*
* @param handle the module handle
*/
void HAL_CleanPowerDistribution(HAL_PowerDistributionHandle handle);
/**
* Checks if a PowerDistribution channel is valid.
*
* @param handle the module handle
* @param channel the channel to check
* @return true if the channel is valid, otherwise false
*/
HAL_Bool HAL_CheckPowerDistributionChannel(HAL_PowerDistributionHandle handle,
int32_t channel);
/**
* Checks if a PowerDistribution module is valid.
*
* @param channel the module to check
* @return true if the module is valid, otherwise false
*/
HAL_Bool HAL_CheckPowerDistributionModule(int32_t module,
HAL_PowerDistributionType type);
/**
* Gets the type of PowerDistribution module.
*
* @return the type of module
*/
HAL_PowerDistributionType HAL_GetPowerDistributionType(
HAL_PowerDistributionHandle handle, int32_t* status);
/**
* Gets the temperature of the PowerDistribution.
*
* @param handle the module handle
* @return the module temperature (celsius)
*/
double HAL_GetPowerDistributionTemperature(HAL_PowerDistributionHandle handle,
int32_t* status);
/**
* Gets the PowerDistribution input voltage.
*
* @param handle the module handle
* @return the input voltage (volts)
*/
double HAL_GetPowerDistributionVoltage(HAL_PowerDistributionHandle handle,
int32_t* status);
/**
* Gets the current of a specific PowerDistribution channel.
*
* @param module the module
* @param channel the channel
* @return the channel current (amps)
*/
double HAL_GetPowerDistributionChannelCurrent(
HAL_PowerDistributionHandle handle, int32_t channel, int32_t* status);
/**
* Gets the current of all 16 channels on the PowerDistribution.
*
* The array must be large enough to hold all channels.
*
* @param handle the module handle
* @param currents the currents (output)
* @param currentsLength the length of the currents array
*/
void HAL_GetPowerDistributionAllChannelCurrents(
HAL_PowerDistributionHandle handle, double* currents,
int32_t currentsLength, int32_t* status);
/**
* Gets the total current of the PowerDistribution.
*
* @param handle the module handle
* @return the total current (amps)
*/
double HAL_GetPowerDistributionTotalCurrent(HAL_PowerDistributionHandle handle,
int32_t* status);
/**
* Gets the total power of the PowerDistribution.
*
* @param handle the module handle
* @return the total power (watts)
*/
double HAL_GetPowerDistributionTotalPower(HAL_PowerDistributionHandle handle,
int32_t* status);
/**
* Gets the total energy of the PowerDistribution.
*
* @param handle the module handle
* @return the total energy (joules)
*/
double HAL_GetPowerDistributionTotalEnergy(HAL_PowerDistributionHandle handle,
int32_t* status);
/**
* Resets the PowerDistribution accumulated energy.
*
* @param handle the module handle
*/
void HAL_ResetPowerDistributionTotalEnergy(HAL_PowerDistributionHandle handle,
int32_t* status);
/**
* Clears any PowerDistribution sticky faults.
*
* @param handle the module handle
*/
void HAL_ClearPowerDistributionStickyFaults(HAL_PowerDistributionHandle handle,
int32_t* status);
#ifdef __cplusplus
} // extern "C"
#endif
/** @} */

View File

@@ -62,6 +62,8 @@ typedef HAL_Handle HAL_AddressableLEDHandle;
typedef HAL_CANHandle HAL_PDPHandle;
typedef HAL_Handle HAL_PowerDistributionHandle;
typedef HAL_Handle HAL_CTREPCMHandle;
typedef int32_t HAL_Bool;

View File

@@ -67,6 +67,7 @@ enum class HAL_HandleEnum {
DMA = 22,
AddressableLED = 23,
CTREPCM = 24,
CTREPDP = 25
};
/**

View File

@@ -1,56 +0,0 @@
// 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.
#pragma once
#include "hal/Types.h"
#include "hal/simulation/NotifyListener.h"
#ifdef __cplusplus
extern "C" {
#endif
void HALSIM_ResetPDPData(int32_t index);
int32_t HALSIM_RegisterPDPInitializedCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void HALSIM_CancelPDPInitializedCallback(int32_t index, int32_t uid);
HAL_Bool HALSIM_GetPDPInitialized(int32_t index);
void HALSIM_SetPDPInitialized(int32_t index, HAL_Bool initialized);
int32_t HALSIM_RegisterPDPTemperatureCallback(int32_t index,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
void HALSIM_CancelPDPTemperatureCallback(int32_t index, int32_t uid);
double HALSIM_GetPDPTemperature(int32_t index);
void HALSIM_SetPDPTemperature(int32_t index, double temperature);
int32_t HALSIM_RegisterPDPVoltageCallback(int32_t index,
HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void HALSIM_CancelPDPVoltageCallback(int32_t index, int32_t uid);
double HALSIM_GetPDPVoltage(int32_t index);
void HALSIM_SetPDPVoltage(int32_t index, double voltage);
int32_t HALSIM_RegisterPDPCurrentCallback(int32_t index, int32_t channel,
HAL_NotifyCallback callback,
void* param, HAL_Bool initialNotify);
void HALSIM_CancelPDPCurrentCallback(int32_t index, int32_t channel,
int32_t uid);
double HALSIM_GetPDPCurrent(int32_t index, int32_t channel);
void HALSIM_SetPDPCurrent(int32_t index, int32_t channel, double current);
void HALSIM_GetPDPAllCurrents(int32_t index, double* currents);
void HALSIM_SetPDPAllCurrents(int32_t index, const double* currents);
void HALSIM_RegisterPDPAllNonCurrentCallbacks(int32_t index, int32_t channel,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify);
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -0,0 +1,59 @@
// 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.
#pragma once
#include "hal/Types.h"
#include "hal/simulation/NotifyListener.h"
#ifdef __cplusplus
extern "C" {
#endif
void HALSIM_ResetPowerDistributionData(int32_t index);
int32_t HALSIM_RegisterPowerDistributionInitializedCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void HALSIM_CancelPowerDistributionInitializedCallback(int32_t index,
int32_t uid);
HAL_Bool HALSIM_GetPowerDistributionInitialized(int32_t index);
void HALSIM_SetPowerDistributionInitialized(int32_t index,
HAL_Bool initialized);
int32_t HALSIM_RegisterPowerDistributionTemperatureCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void HALSIM_CancelPowerDistributionTemperatureCallback(int32_t index,
int32_t uid);
double HALSIM_GetPowerDistributionTemperature(int32_t index);
void HALSIM_SetPowerDistributionTemperature(int32_t index, double temperature);
int32_t HALSIM_RegisterPowerDistributionVoltageCallback(
int32_t index, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void HALSIM_CancelPowerDistributionVoltageCallback(int32_t index, int32_t uid);
double HALSIM_GetPowerDistributionVoltage(int32_t index);
void HALSIM_SetPowerDistributionVoltage(int32_t index, double voltage);
int32_t HALSIM_RegisterPowerDistributionCurrentCallback(
int32_t index, int32_t channel, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
void HALSIM_CancelPowerDistributionCurrentCallback(int32_t index,
int32_t channel,
int32_t uid);
double HALSIM_GetPowerDistributionCurrent(int32_t index, int32_t channel);
void HALSIM_SetPowerDistributionCurrent(int32_t index, int32_t channel,
double current);
void HALSIM_GetPowerDistributionAllCurrents(int32_t index, double* currents);
void HALSIM_SetPowerDistributionAllCurrents(int32_t index,
const double* currents);
void HALSIM_RegisterPowerDistributionAllNonCurrentCallbacks(
int32_t index, int32_t channel, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify);
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -74,7 +74,7 @@ void InitializeHAL() {
InitializeEncoderData();
InitializeI2CData();
InitializeCTREPCMData();
InitializePDPData();
InitializePowerDistributionData();
InitializePWMData();
InitializeRelayData();
InitializeRoboRioData();
@@ -103,7 +103,7 @@ void InitializeHAL() {
InitializeMain();
InitializeMockHooks();
InitializeNotifier();
InitializePDP();
InitializePowerDistribution();
InitializePorts();
InitializePower();
InitializeCTREPCM();

View File

@@ -32,7 +32,7 @@ extern void InitializeDriverStationData();
extern void InitializeEncoderData();
extern void InitializeI2CData();
extern void InitializeCTREPCMData();
extern void InitializePDPData();
extern void InitializePowerDistributionData();
extern void InitializePWMData();
extern void InitializeRelayData();
extern void InitializeRoboRioData();
@@ -61,7 +61,7 @@ extern void InitializeInterrupts();
extern void InitializeMain();
extern void InitializeMockHooks();
extern void InitializeNotifier();
extern void InitializePDP();
extern void InitializePowerDistribution();
extern void InitializePorts();
extern void InitializePower();
extern void InitializeCTREPCM();

View File

@@ -1,105 +0,0 @@
// 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 "hal/PDP.h"
#include <fmt/format.h>
#include "CANAPIInternal.h"
#include "HALInitializer.h"
#include "HALInternal.h"
#include "PortsInternal.h"
#include "hal/CANAPI.h"
#include "hal/Errors.h"
#include "mockdata/PDPDataInternal.h"
using namespace hal;
static constexpr HAL_CANManufacturer manufacturer =
HAL_CANManufacturer::HAL_CAN_Man_kCTRE;
static constexpr HAL_CANDeviceType deviceType =
HAL_CANDeviceType::HAL_CAN_Dev_kPowerDistribution;
namespace hal::init {
void InitializePDP() {}
} // namespace hal::init
extern "C" {
HAL_PDPHandle HAL_InitializePDP(int32_t module, int32_t* status) {
if (!HAL_CheckPDPModule(module)) {
*status = PARAMETER_OUT_OF_RANGE;
hal::SetLastError(status, fmt::format("Invalid pdp module {}", module));
return HAL_kInvalidHandle;
}
hal::init::CheckInit();
SimPDPData[module].initialized = true;
auto handle = HAL_InitializeCAN(manufacturer, module, deviceType, status);
if (*status != 0) {
HAL_CleanCAN(handle);
return HAL_kInvalidHandle;
}
return handle;
}
HAL_Bool HAL_CheckPDPModule(int32_t module) {
return module < kNumPDPModules && module >= 0;
}
HAL_Bool HAL_CheckPDPChannel(int32_t channel) {
return channel < kNumPDPChannels && channel >= 0;
}
void HAL_CleanPDP(HAL_PDPHandle handle) {
HAL_CleanCAN(handle);
}
double HAL_GetPDPTemperature(HAL_PDPHandle handle, int32_t* status) {
auto module = hal::can::GetCANModuleFromHandle(handle, status);
if (*status != 0) {
return 0.0;
}
return SimPDPData[module].temperature;
}
double HAL_GetPDPVoltage(HAL_PDPHandle handle, int32_t* status) {
auto module = hal::can::GetCANModuleFromHandle(handle, status);
if (*status != 0) {
return 0.0;
}
return SimPDPData[module].voltage;
}
double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel,
int32_t* status) {
auto module = hal::can::GetCANModuleFromHandle(handle, status);
if (*status != 0) {
return 0.0;
}
return SimPDPData[module].current[channel];
}
void HAL_GetPDPAllChannelCurrents(HAL_PDPHandle handle, double* currents,
int32_t* status) {
auto module = hal::can::GetCANModuleFromHandle(handle, status);
if (*status != 0) {
return;
}
auto& data = SimPDPData[module];
for (int i = 0; i < kNumPDPChannels; i++) {
currents[i] = data.current[i];
}
}
double HAL_GetPDPTotalCurrent(HAL_PDPHandle handle, int32_t* status) {
return 0.0;
}
double HAL_GetPDPTotalPower(HAL_PDPHandle handle, int32_t* status) {
return 0.0;
}
double HAL_GetPDPTotalEnergy(HAL_PDPHandle handle, int32_t* status) {
return 0.0;
}
void HAL_ResetPDPTotalEnergy(HAL_PDPHandle handle, int32_t* status) {}
void HAL_ClearPDPStickyFaults(HAL_PDPHandle handle, int32_t* status) {}
} // extern "C"

View File

@@ -0,0 +1,121 @@
// 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 "hal/PowerDistribution.h"
#include <fmt/format.h>
#include "CANAPIInternal.h"
#include "HALInitializer.h"
#include "HALInternal.h"
#include "PortsInternal.h"
#include "hal/CANAPI.h"
#include "hal/Errors.h"
#include "mockdata/PowerDistributionDataInternal.h"
using namespace hal;
static constexpr HAL_CANManufacturer manufacturer =
HAL_CANManufacturer::HAL_CAN_Man_kCTRE;
static constexpr HAL_CANDeviceType deviceType =
HAL_CANDeviceType::HAL_CAN_Dev_kPowerDistribution;
namespace hal::init {
void InitializePowerDistribution() {}
} // namespace hal::init
extern "C" {
HAL_PowerDistributionHandle HAL_InitializePowerDistribution(
int32_t module, HAL_PowerDistributionType type, int32_t* status) {
if (!HAL_CheckPowerDistributionModule(module, type)) {
*status = PARAMETER_OUT_OF_RANGE;
hal::SetLastError(status, fmt::format("Invalid pdp module {}", module));
return HAL_kInvalidHandle;
}
hal::init::CheckInit();
SimPowerDistributionData[module].initialized = true;
auto handle = HAL_InitializeCAN(manufacturer, module, deviceType, status);
if (*status != 0) {
HAL_CleanCAN(handle);
return HAL_kInvalidHandle;
}
return handle;
}
HAL_Bool HAL_CheckPowerDistributionModule(int32_t module,
HAL_PowerDistributionType type) {
return module < kNumPDPModules && module >= 0;
}
HAL_Bool HAL_CheckPowerDistributionChannel(HAL_PowerDistributionHandle handle,
int32_t channel) {
return channel < kNumPDPChannels && channel >= 0;
}
HAL_PowerDistributionType HAL_GetPowerDistributionType(
HAL_PowerDistributionHandle handle, int32_t* status) {
return HAL_PowerDistributionType::HAL_PowerDistributionType_kCTRE;
}
void HAL_CleanPowerDistribution(HAL_PowerDistributionHandle handle) {
HAL_CleanCAN(handle);
}
double HAL_GetPowerDistributionTemperature(HAL_PowerDistributionHandle handle,
int32_t* status) {
auto module = hal::can::GetCANModuleFromHandle(handle, status);
if (*status != 0) {
return 0.0;
}
return SimPowerDistributionData[module].temperature;
}
double HAL_GetPowerDistributionVoltage(HAL_PowerDistributionHandle handle,
int32_t* status) {
auto module = hal::can::GetCANModuleFromHandle(handle, status);
if (*status != 0) {
return 0.0;
}
return SimPowerDistributionData[module].voltage;
}
double HAL_GetPowerDistributionChannelCurrent(
HAL_PowerDistributionHandle handle, int32_t channel, int32_t* status) {
auto module = hal::can::GetCANModuleFromHandle(handle, status);
if (*status != 0) {
return 0.0;
}
return SimPowerDistributionData[module].current[channel];
}
void HAL_GetPowerDistributionAllChannelCurrents(
HAL_PowerDistributionHandle handle, double* currents,
int32_t currentsLength, int32_t* status) {
auto module = hal::can::GetCANModuleFromHandle(handle, status);
if (*status != 0) {
return;
}
auto& data = SimPowerDistributionData[module];
for (int i = 0; i < kNumPDPChannels; i++) {
currents[i] = data.current[i];
}
}
double HAL_GetPowerDistributionTotalCurrent(HAL_PowerDistributionHandle handle,
int32_t* status) {
return 0.0;
}
double HAL_GetPowerDistributionTotalPower(HAL_PowerDistributionHandle handle,
int32_t* status) {
return 0.0;
}
double HAL_GetPowerDistributionTotalEnergy(HAL_PowerDistributionHandle handle,
int32_t* status) {
return 0.0;
}
void HAL_ResetPowerDistributionTotalEnergy(HAL_PowerDistributionHandle handle,
int32_t* status) {}
void HAL_ClearPowerDistributionStickyFaults(HAL_PowerDistributionHandle handle,
int32_t* status) {}
} // extern "C"

View File

@@ -1,67 +0,0 @@
// 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 "../PortsInternal.h"
#include "PDPDataInternal.h"
using namespace hal;
namespace hal::init {
void InitializePDPData() {
static PDPData spd[kNumPDPModules];
::hal::SimPDPData = spd;
}
} // namespace hal::init
PDPData* hal::SimPDPData;
void PDPData::ResetData() {
initialized.Reset(false);
temperature.Reset(0.0);
voltage.Reset(12.0);
for (int i = 0; i < kNumPDPChannels; i++) {
current[i].Reset(0.0);
}
}
extern "C" {
void HALSIM_ResetPDPData(int32_t index) {
SimPDPData[index].ResetData();
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, PDP##CAPINAME, SimPDPData, \
LOWERNAME)
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
DEFINE_CAPI(double, Temperature, temperature)
DEFINE_CAPI(double, Voltage, voltage)
HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(double, HALSIM, PDPCurrent, SimPDPData,
current)
void HALSIM_GetPDPAllCurrents(int32_t index, double* currents) {
auto& data = SimPDPData[index].current;
for (int i = 0; i < kNumPDPChannels; i++) {
currents[i] = data[i];
}
}
void HALSIM_SetPDPAllCurrents(int32_t index, const double* currents) {
auto& data = SimPDPData[index].current;
for (int i = 0; i < kNumPDPChannels; i++) {
data[i] = currents[i];
}
}
#define REGISTER(NAME) \
SimPDPData[index].NAME.RegisterCallback(callback, param, initialNotify)
void HALSIM_RegisterPDPAllNonCurrentCallbacks(int32_t index, int32_t channel,
HAL_NotifyCallback callback,
void* param,
HAL_Bool initialNotify) {
REGISTER(initialized);
REGISTER(temperature);
REGISTER(voltage);
}
} // extern "C"

View File

@@ -0,0 +1,68 @@
// 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 "../PortsInternal.h"
#include "PowerDistributionDataInternal.h"
using namespace hal;
namespace hal::init {
void InitializePowerDistributionData() {
static PowerDistributionData spd[kNumPDPChannels];
::hal::SimPowerDistributionData = spd;
}
} // namespace hal::init
PowerDistributionData* hal::SimPowerDistributionData;
void PowerDistributionData::ResetData() {
initialized.Reset(false);
temperature.Reset(0.0);
voltage.Reset(12.0);
for (int i = 0; i < kNumPDPChannels; i++) {
current[i].Reset(0.0);
}
}
extern "C" {
void HALSIM_ResetPowerDistributionData(int32_t index) {
SimPowerDistributionData[index].ResetData();
}
#define DEFINE_CAPI(TYPE, CAPINAME, LOWERNAME) \
HAL_SIMDATAVALUE_DEFINE_CAPI(TYPE, HALSIM, PowerDistribution##CAPINAME, \
SimPowerDistributionData, LOWERNAME)
DEFINE_CAPI(HAL_Bool, Initialized, initialized)
DEFINE_CAPI(double, Temperature, temperature)
DEFINE_CAPI(double, Voltage, voltage)
HAL_SIMDATAVALUE_DEFINE_CAPI_CHANNEL(double, HALSIM, PowerDistributionCurrent,
SimPowerDistributionData, current)
void HALSIM_GetPowerDistributionAllCurrents(int32_t index, double* currents) {
auto& data = SimPowerDistributionData[index].current;
for (int i = 0; i < kNumPDPChannels; i++) {
currents[i] = data[i];
}
}
void HALSIM_SetPowerDistributionAllCurrents(int32_t index,
const double* currents) {
auto& data = SimPowerDistributionData[index].current;
for (int i = 0; i < kNumPDPChannels; i++) {
data[i] = currents[i];
}
}
#define REGISTER(NAME) \
SimPowerDistributionData[index].NAME.RegisterCallback(callback, param, \
initialNotify)
void HALSIM_RegisterPowerDistributionAllNonCurrentCallbacks(
int32_t index, int32_t channel, HAL_NotifyCallback callback, void* param,
HAL_Bool initialNotify) {
REGISTER(initialized);
REGISTER(temperature);
REGISTER(voltage);
}
} // extern "C"

View File

@@ -5,11 +5,11 @@
#pragma once
#include "../PortsInternal.h"
#include "hal/simulation/PDPData.h"
#include "hal/simulation/PowerDistributionData.h"
#include "hal/simulation/SimDataValue.h"
namespace hal {
class PDPData {
class PowerDistributionData {
HAL_SIMDATAVALUE_DEFINE_NAME(Initialized)
HAL_SIMDATAVALUE_DEFINE_NAME(Temperature)
HAL_SIMDATAVALUE_DEFINE_NAME(Voltage)
@@ -29,5 +29,5 @@ class PDPData {
virtual void ResetData();
};
extern PDPData* SimPDPData;
extern PowerDistributionData* SimPowerDistributionData;
} // namespace hal