blob: b33479fa18ffec3dc823fb582b62044d898129f4 [file] [log] [blame]
Brian Silverman8fce7482020-01-05 13:18:21 -08001/*----------------------------------------------------------------------------*/
Austin Schuh1e69f942020-11-14 15:06:14 -08002/* Copyright (c) 2017-2020 FIRST. All Rights Reserved. */
Brian Silverman8fce7482020-01-05 13:18:21 -08003/* 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 "frc/RobotController.h"
9
10#include <hal/CAN.h>
Brian Silverman8fce7482020-01-05 13:18:21 -080011#include <hal/HALBase.h>
12#include <hal/Power.h>
13
14#include "frc/ErrorBase.h"
15
16using namespace frc;
17
18int RobotController::GetFPGAVersion() {
19 int32_t status = 0;
20 int version = HAL_GetFPGAVersion(&status);
21 wpi_setGlobalHALError(status);
22 return version;
23}
24
25int64_t RobotController::GetFPGARevision() {
26 int32_t status = 0;
27 int64_t revision = HAL_GetFPGARevision(&status);
28 wpi_setGlobalHALError(status);
29 return revision;
30}
31
32uint64_t RobotController::GetFPGATime() {
33 int32_t status = 0;
34 uint64_t time = HAL_GetFPGATime(&status);
35 wpi_setGlobalHALError(status);
36 return time;
37}
38
39bool RobotController::GetUserButton() {
40 int32_t status = 0;
41
42 bool value = HAL_GetFPGAButton(&status);
43 wpi_setGlobalError(status);
44
45 return value;
46}
47
48bool RobotController::IsSysActive() {
49 int32_t status = 0;
50 bool retVal = HAL_GetSystemActive(&status);
51 wpi_setGlobalHALError(status);
52 return retVal;
53}
54
55bool RobotController::IsBrownedOut() {
56 int32_t status = 0;
57 bool retVal = HAL_GetBrownedOut(&status);
58 wpi_setGlobalHALError(status);
59 return retVal;
60}
61
62double RobotController::GetInputVoltage() {
63 int32_t status = 0;
64 double retVal = HAL_GetVinVoltage(&status);
65 wpi_setGlobalHALError(status);
66 return retVal;
67}
68
69double RobotController::GetInputCurrent() {
70 int32_t status = 0;
71 double retVal = HAL_GetVinCurrent(&status);
72 wpi_setGlobalHALError(status);
73 return retVal;
74}
75
76double RobotController::GetVoltage3V3() {
77 int32_t status = 0;
78 double retVal = HAL_GetUserVoltage3V3(&status);
79 wpi_setGlobalHALError(status);
80 return retVal;
81}
82
83double RobotController::GetCurrent3V3() {
84 int32_t status = 0;
85 double retVal = HAL_GetUserCurrent3V3(&status);
86 wpi_setGlobalHALError(status);
87 return retVal;
88}
89
90bool RobotController::GetEnabled3V3() {
91 int32_t status = 0;
92 bool retVal = HAL_GetUserActive3V3(&status);
93 wpi_setGlobalHALError(status);
94 return retVal;
95}
96
97int RobotController::GetFaultCount3V3() {
98 int32_t status = 0;
99 int retVal = HAL_GetUserCurrentFaults3V3(&status);
100 wpi_setGlobalHALError(status);
101 return retVal;
102}
103
104double RobotController::GetVoltage5V() {
105 int32_t status = 0;
106 double retVal = HAL_GetUserVoltage5V(&status);
107 wpi_setGlobalHALError(status);
108 return retVal;
109}
110
111double RobotController::GetCurrent5V() {
112 int32_t status = 0;
113 double retVal = HAL_GetUserCurrent5V(&status);
114 wpi_setGlobalHALError(status);
115 return retVal;
116}
117
118bool RobotController::GetEnabled5V() {
119 int32_t status = 0;
120 bool retVal = HAL_GetUserActive5V(&status);
121 wpi_setGlobalHALError(status);
122 return retVal;
123}
124
125int RobotController::GetFaultCount5V() {
126 int32_t status = 0;
127 int retVal = HAL_GetUserCurrentFaults5V(&status);
128 wpi_setGlobalHALError(status);
129 return retVal;
130}
131
132double RobotController::GetVoltage6V() {
133 int32_t status = 0;
134 double retVal = HAL_GetUserVoltage6V(&status);
135 wpi_setGlobalHALError(status);
136 return retVal;
137}
138
139double RobotController::GetCurrent6V() {
140 int32_t status = 0;
141 double retVal = HAL_GetUserCurrent6V(&status);
142 wpi_setGlobalHALError(status);
143 return retVal;
144}
145
146bool RobotController::GetEnabled6V() {
147 int32_t status = 0;
148 bool retVal = HAL_GetUserActive6V(&status);
149 wpi_setGlobalHALError(status);
150 return retVal;
151}
152
153int RobotController::GetFaultCount6V() {
154 int32_t status = 0;
155 int retVal = HAL_GetUserCurrentFaults6V(&status);
156 wpi_setGlobalHALError(status);
157 return retVal;
158}
159
160CANStatus RobotController::GetCANStatus() {
161 int32_t status = 0;
162 float percentBusUtilization = 0;
163 uint32_t busOffCount = 0;
164 uint32_t txFullCount = 0;
165 uint32_t receiveErrorCount = 0;
166 uint32_t transmitErrorCount = 0;
167 HAL_CAN_GetCANStatus(&percentBusUtilization, &busOffCount, &txFullCount,
168 &receiveErrorCount, &transmitErrorCount, &status);
169 if (status != 0) {
170 wpi_setGlobalHALError(status);
171 return {};
172 }
173 return {percentBusUtilization, static_cast<int>(busOffCount),
174 static_cast<int>(txFullCount), static_cast<int>(receiveErrorCount),
175 static_cast<int>(transmitErrorCount)};
176}