Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 2 | /* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */ |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
| 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
| 6 | /*----------------------------------------------------------------------------*/ |
| 7 | |
| 8 | #include "hal/PDP.h" |
| 9 | |
| 10 | #include "CANAPIInternal.h" |
| 11 | #include "HALInitializer.h" |
| 12 | #include "PortsInternal.h" |
| 13 | #include "hal/CANAPI.h" |
Austin Schuh | 1e69f94 | 2020-11-14 15:06:14 -0800 | [diff] [blame^] | 14 | #include "hal/Errors.h" |
Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 15 | #include "mockdata/PDPDataInternal.h" |
| 16 | |
| 17 | using namespace hal; |
| 18 | |
| 19 | static constexpr HAL_CANManufacturer manufacturer = |
| 20 | HAL_CANManufacturer::HAL_CAN_Man_kCTRE; |
| 21 | |
| 22 | static constexpr HAL_CANDeviceType deviceType = |
| 23 | HAL_CANDeviceType::HAL_CAN_Dev_kPowerDistribution; |
| 24 | |
| 25 | namespace hal { |
| 26 | namespace init { |
| 27 | void InitializePDP() {} |
| 28 | } // namespace init |
| 29 | } // namespace hal |
| 30 | |
| 31 | extern "C" { |
| 32 | HAL_PDPHandle HAL_InitializePDP(int32_t module, int32_t* status) { |
| 33 | if (!HAL_CheckPDPModule(module)) { |
| 34 | *status = PARAMETER_OUT_OF_RANGE; |
| 35 | return HAL_kInvalidHandle; |
| 36 | } |
| 37 | hal::init::CheckInit(); |
| 38 | SimPDPData[module].initialized = true; |
| 39 | auto handle = HAL_InitializeCAN(manufacturer, module, deviceType, status); |
| 40 | |
| 41 | if (*status != 0) { |
| 42 | HAL_CleanCAN(handle); |
| 43 | return HAL_kInvalidHandle; |
| 44 | } |
| 45 | |
| 46 | return handle; |
| 47 | } |
| 48 | |
| 49 | HAL_Bool HAL_CheckPDPModule(int32_t module) { |
| 50 | return module < kNumPDPModules && module >= 0; |
| 51 | } |
| 52 | |
| 53 | HAL_Bool HAL_CheckPDPChannel(int32_t channel) { |
| 54 | return channel < kNumPDPChannels && channel >= 0; |
| 55 | } |
| 56 | |
| 57 | void HAL_CleanPDP(HAL_PDPHandle handle) { HAL_CleanCAN(handle); } |
| 58 | |
| 59 | double HAL_GetPDPTemperature(HAL_PDPHandle handle, int32_t* status) { |
| 60 | auto module = hal::can::GetCANModuleFromHandle(handle, status); |
| 61 | if (*status != 0) { |
| 62 | return 0.0; |
| 63 | } |
| 64 | return SimPDPData[module].temperature; |
| 65 | } |
| 66 | double HAL_GetPDPVoltage(HAL_PDPHandle handle, int32_t* status) { |
| 67 | auto module = hal::can::GetCANModuleFromHandle(handle, status); |
| 68 | if (*status != 0) { |
| 69 | return 0.0; |
| 70 | } |
| 71 | return SimPDPData[module].voltage; |
| 72 | } |
| 73 | double HAL_GetPDPChannelCurrent(HAL_PDPHandle handle, int32_t channel, |
| 74 | int32_t* status) { |
| 75 | auto module = hal::can::GetCANModuleFromHandle(handle, status); |
| 76 | if (*status != 0) { |
| 77 | return 0.0; |
| 78 | } |
| 79 | return SimPDPData[module].current[channel]; |
| 80 | } |
| 81 | void HAL_GetPDPAllChannelCurrents(HAL_PDPHandle handle, double* currents, |
| 82 | int32_t* status) { |
| 83 | auto module = hal::can::GetCANModuleFromHandle(handle, status); |
| 84 | if (*status != 0) { |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | auto& data = SimPDPData[module]; |
| 89 | for (int i = 0; i < kNumPDPChannels; i++) { |
| 90 | currents[i] = data.current[i]; |
| 91 | } |
| 92 | } |
| 93 | double HAL_GetPDPTotalCurrent(HAL_PDPHandle handle, int32_t* status) { |
| 94 | return 0.0; |
| 95 | } |
| 96 | double HAL_GetPDPTotalPower(HAL_PDPHandle handle, int32_t* status) { |
| 97 | return 0.0; |
| 98 | } |
| 99 | double HAL_GetPDPTotalEnergy(HAL_PDPHandle handle, int32_t* status) { |
| 100 | return 0.0; |
| 101 | } |
| 102 | void HAL_ResetPDPTotalEnergy(HAL_PDPHandle handle, int32_t* status) {} |
| 103 | void HAL_ClearPDPStickyFaults(HAL_PDPHandle handle, int32_t* status) {} |
| 104 | } // extern "C" |