blob: 07f4dcd239a05256911279d1370a0c1e21b1387e [file] [log] [blame]
Brian Silverman41cdd3e2019-01-19 19:48:58 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) 2017-2018 FIRST. All Rights Reserved. */
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"
14#include "hal/handles/IndexedHandleResource.h"
15#include "mockdata/PDPDataInternal.h"
16
17using namespace hal;
18
19static constexpr HAL_CANManufacturer manufacturer =
20 HAL_CANManufacturer::HAL_CAN_Man_kCTRE;
21
22static constexpr HAL_CANDeviceType deviceType =
23 HAL_CANDeviceType::HAL_CAN_Dev_kPowerDistribution;
24
25namespace hal {
26namespace init {
27void InitializePDP() {}
28} // namespace init
29} // namespace hal
30
31extern "C" {
32HAL_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
49HAL_Bool HAL_CheckPDPModule(int32_t module) {
50 return module < kNumPDPModules && module >= 0;
51}
52
53HAL_Bool HAL_CheckPDPChannel(int32_t channel) {
54 return channel < kNumPDPChannels && channel >= 0;
55}
56
57void HAL_CleanPDP(HAL_PDPHandle handle) { HAL_CleanCAN(handle); }
58
59double 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}
66double 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}
73double 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}
81double HAL_GetPDPTotalCurrent(HAL_PDPHandle handle, int32_t* status) {
82 return 0.0;
83}
84double HAL_GetPDPTotalPower(HAL_PDPHandle handle, int32_t* status) {
85 return 0.0;
86}
87double HAL_GetPDPTotalEnergy(HAL_PDPHandle handle, int32_t* status) {
88 return 0.0;
89}
90void HAL_ResetPDPTotalEnergy(HAL_PDPHandle handle, int32_t* status) {}
91void HAL_ClearPDPStickyFaults(HAL_PDPHandle handle, int32_t* status) {}
92} // extern "C"