[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

@@ -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