Use new CAN API for PDP (#1081)

This commit is contained in:
Thad House
2018-06-07 22:31:26 -07:00
committed by Peter Johnson
parent f6e4df6a18
commit 056e68f2ae
13 changed files with 413 additions and 427 deletions

View File

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