mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-24 01:31:46 +00:00
Use new CAN API for PDP (#1081)
This commit is contained in:
committed by
Peter Johnson
parent
f6e4df6a18
commit
056e68f2ae
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <wpi/DenseMap.h>
|
||||
|
||||
#include "CANAPIInternal.h"
|
||||
#include "HAL/CAN.h"
|
||||
#include "HAL/Errors.h"
|
||||
#include "HAL/HAL.h"
|
||||
@@ -57,6 +58,16 @@ void InitializeCANAPI() {
|
||||
canHandles = &cH;
|
||||
}
|
||||
} // namespace init
|
||||
namespace can {
|
||||
int32_t GetCANModuleFromHandle(HAL_CANHandle handle, int32_t* status) {
|
||||
auto can = canHandles->Get(handle);
|
||||
if (!can) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return -1;
|
||||
}
|
||||
return can->deviceId;
|
||||
}
|
||||
} // namespace can
|
||||
} // namespace hal
|
||||
|
||||
static int32_t CreateCANId(CANStorage* storage, int32_t apiId) {
|
||||
|
||||
16
hal/src/main/native/sim/CANAPIInternal.h
Normal file
16
hal/src/main/native/sim/CANAPIInternal.h
Normal file
@@ -0,0 +1,16 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 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. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "HAL/Types.h"
|
||||
|
||||
namespace hal {
|
||||
namespace can {
|
||||
int32_t GetCANModuleFromHandle(HAL_CANHandle handle, int32_t* status);
|
||||
} // namespace can
|
||||
} // namespace hal
|
||||
@@ -7,12 +7,21 @@
|
||||
|
||||
#include "HAL/PDP.h"
|
||||
|
||||
#include "CANAPIInternal.h"
|
||||
#include "HAL/CANAPI.h"
|
||||
#include "HAL/handles/IndexedHandleResource.h"
|
||||
#include "HALInitializer.h"
|
||||
#include "MockData/PDPDataInternal.h"
|
||||
#include "PortsInternal.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 {
|
||||
namespace init {
|
||||
void InitializePDP() {}
|
||||
@@ -20,10 +29,23 @@ void InitializePDP() {}
|
||||
} // namespace hal
|
||||
|
||||
extern "C" {
|
||||
void HAL_InitializePDP(int32_t module, int32_t* status) {
|
||||
HAL_PDPHandle HAL_InitializePDP(int32_t module, int32_t* status) {
|
||||
if (!HAL_CheckPDPModule(module)) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
hal::init::CheckInit();
|
||||
SimPDPData[module].SetInitialized(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;
|
||||
}
|
||||
@@ -31,19 +53,40 @@ HAL_Bool HAL_CheckPDPModule(int32_t module) {
|
||||
HAL_Bool HAL_CheckPDPChannel(int32_t channel) {
|
||||
return channel < kNumPDPChannels && channel >= 0;
|
||||
}
|
||||
double HAL_GetPDPTemperature(int32_t module, int32_t* status) {
|
||||
|
||||
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].GetTemperature();
|
||||
}
|
||||
double HAL_GetPDPVoltage(int32_t module, int32_t* status) {
|
||||
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].GetVoltage();
|
||||
}
|
||||
double HAL_GetPDPChannelCurrent(int32_t module, int32_t channel,
|
||||
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].GetCurrent(channel);
|
||||
}
|
||||
double HAL_GetPDPTotalCurrent(int32_t module, int32_t* status) { return 0.0; }
|
||||
double HAL_GetPDPTotalPower(int32_t module, int32_t* status) { return 0.0; }
|
||||
double HAL_GetPDPTotalEnergy(int32_t module, int32_t* status) { return 0.0; }
|
||||
void HAL_ResetPDPTotalEnergy(int32_t module, int32_t* status) {}
|
||||
void HAL_ClearPDPStickyFaults(int32_t module, int32_t* status) {}
|
||||
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"
|
||||
|
||||
Reference in New Issue
Block a user