CTRE Phoenix C++ 5.33.1
CANdleFaults.h
Go to the documentation of this file.
1/* Copyright (C) Cross The Road Electronics 2024 */
2#pragma once
3
4#include <cstdint>
5
6namespace ctre {
7namespace phoenix {
8namespace led{
9
10/**
11 * Faults available to CANdle (Currently has none)
12 */
14 /**
15 * Device detects hardware failure
16 */
18 /**
19 * API error detected. Make sure API and firmware versions are compatible.
20 */
22 /**
23 * Boot while receiving an enable frame
24 */
26 /**
27 * VBat is under 5V
28 */
30 /**
31 * VBat is over 30V
32 */
34 /**
35 * 5V Line is under 4 V
36 */
38 /**
39 * 5V Line is over 6V
40 */
42 /**
43 * Exceeded output current of 6 amps
44 */
46 /**
47 * Device is over temperature
48 */
50 /**
51 * Output pin is shorted to something
52 */
54
55 /**
56 * @return true if any faults are tripped
57 */
58 bool HasAnyFault() const {
59 return HardwareFault |
60 APIError |
64 V5TooLow |
65 V5TooHigh |
69 }
70 /**
71 * @return Current fault list as a bit field
72 */
73 int ToBitfield() const {
74 uint64_t commonFaults = 0;
75 commonFaults |= ShortCircuit ? 1 : 0; commonFaults <<= 1;
76 commonFaults |= ThermalFault ? 1 : 0; commonFaults <<= 1;
77 commonFaults |= SoftwareFuse ? 1 : 0; commonFaults <<= 1;
78 commonFaults |= V5TooLow ? 1 : 0; commonFaults <<= 1;
79 commonFaults |= V5TooHigh ? 1 : 0; commonFaults <<= 1;
80 commonFaults |= VBatTooLow ? 1 : 0; commonFaults <<= 1;
81 commonFaults |= VBatTooHigh ? 1 : 0; commonFaults <<= 1;
82 commonFaults |= BootDuringEnable ? 1 : 0; commonFaults <<= 1;
83 commonFaults |= APIError ? 1 : 0; commonFaults <<= 1;
84 commonFaults |= HardwareFault ? 1 : 0;
85
86 return commonFaults;
87 }
88 void Update(uint64_t bits) {
89 uint64_t mask = 1;
90 HardwareFault = (bits & mask) ? true : false; mask <<= 1;
91 APIError = (bits & mask) ? true : false; mask <<= 1;
92 BootDuringEnable = (bits & mask) ? true : false; mask <<= 1;
93 VBatTooHigh = (bits & mask) ? true : false; mask <<= 1;
94 VBatTooLow = (bits & mask) ? true : false; mask <<= 1;
95 V5TooHigh = (bits & mask) ? true : false; mask <<= 1;
96 V5TooLow = (bits & mask) ? true : false; mask <<= 1;
97 SoftwareFuse = (bits & mask) ? true : false; mask <<= 1;
98 ThermalFault = (bits & mask) ? true : false; mask <<= 1;
99 ShortCircuit = (bits & mask) ? true : false; mask <<= 1;
100 }
101 /**
102 * Updates current fault list with specified bit field of faults
103 *
104 * @param bits bit field of faults to update with
105 */
106 CANdleFaults(int bits) {
107 Update(bits);
108 }
110 Update(0);
111 }
112};
113/**
114 * Faults available to CANdle (Currently has none)
115 */
117 /**
118 * Device detects hardware failure
119 */
121 /**
122 * API error detected. Make sure API and firmware versions are compatible.
123 */
125 /**
126 * Boot while receiving an enable frame
127 */
129 /**
130 * VBat is under 5V
131 */
133 /**
134 * VBat is over 30V
135 */
137 /**
138 * 5V Line is under 4 V
139 */
141 /**
142 * 5V Line is over 6V
143 */
145 /**
146 * Exceeded output current of 6 amps
147 */
149 /**
150 * Device is over temperature
151 */
153 /**
154 * Output pin is shorted to something
155 */
157
158 /**
159 * @return true if any faults are tripped
160 */
161 bool HasAnyFault() const {
162 return HardwareFault |
163 APIError |
165 VBatTooLow |
167 V5TooLow |
168 V5TooHigh |
172 }
173 /**
174 * @return Current fault list as a bit field
175 */
176 int ToBitfield() const {
177 uint64_t commonFaults = 0;
178 commonFaults |= ShortCircuit ? 1 : 0; commonFaults <<= 1;
179 commonFaults |= ThermalFault ? 1 : 0; commonFaults <<= 1;
180 commonFaults |= SoftwareFuse ? 1 : 0; commonFaults <<= 1;
181 commonFaults |= V5TooLow ? 1 : 0; commonFaults <<= 1;
182 commonFaults |= V5TooHigh ? 1 : 0; commonFaults <<= 1;
183 commonFaults |= VBatTooLow ? 1 : 0; commonFaults <<= 1;
184 commonFaults |= VBatTooHigh ? 1 : 0; commonFaults <<= 1;
185 commonFaults |= BootDuringEnable ? 1 : 0; commonFaults <<= 1;
186 commonFaults |= APIError ? 1 : 0; commonFaults <<= 1;
187 commonFaults |= HardwareFault ? 1 : 0;
188
189 return commonFaults;
190 }
191 void Update(uint64_t bits) {
192 uint64_t mask = 1;
193 HardwareFault = (bits & mask) ? true : false; mask <<= 1;
194 APIError = (bits & mask) ? true : false; mask <<= 1;
195 BootDuringEnable = (bits & mask) ? true : false; mask <<= 1;
196 VBatTooHigh = (bits & mask) ? true : false; mask <<= 1;
197 VBatTooLow = (bits & mask) ? true : false; mask <<= 1;
198 V5TooHigh = (bits & mask) ? true : false; mask <<= 1;
199 V5TooLow = (bits & mask) ? true : false; mask <<= 1;
200 SoftwareFuse = (bits & mask) ? true : false; mask <<= 1;
201 ThermalFault = (bits & mask) ? true : false; mask <<= 1;
202 ShortCircuit = (bits & mask) ? true : false; mask <<= 1;
203 }
204 /**
205 * Updates current fault list with specified bit field of faults
206 *
207 * @param bits bit field of faults to update with
208 */
210 Update(bits);
211 }
213 Update(0);
214 }
215};
216
217} // led
218} // phoenix
219} // ctre
220
namespace ctre
Definition: paramEnum.h:5
Faults available to CANdle (Currently has none)
Definition: CANdleFaults.h:13
bool VBatTooLow
VBat is under 5V.
Definition: CANdleFaults.h:29
bool V5TooHigh
5V Line is over 6V
Definition: CANdleFaults.h:41
bool V5TooLow
5V Line is under 4 V
Definition: CANdleFaults.h:37
bool VBatTooHigh
VBat is over 30V.
Definition: CANdleFaults.h:33
int ToBitfield() const
Definition: CANdleFaults.h:73
bool BootDuringEnable
Boot while receiving an enable frame.
Definition: CANdleFaults.h:25
bool ThermalFault
Device is over temperature.
Definition: CANdleFaults.h:49
bool ShortCircuit
Output pin is shorted to something.
Definition: CANdleFaults.h:53
bool HasAnyFault() const
Definition: CANdleFaults.h:58
bool HardwareFault
Device detects hardware failure.
Definition: CANdleFaults.h:17
bool SoftwareFuse
Exceeded output current of 6 amps.
Definition: CANdleFaults.h:45
CANdleFaults(int bits)
Updates current fault list with specified bit field of faults.
Definition: CANdleFaults.h:106
CANdleFaults()
Definition: CANdleFaults.h:109
bool APIError
API error detected.
Definition: CANdleFaults.h:21
void Update(uint64_t bits)
Definition: CANdleFaults.h:88
Faults available to CANdle (Currently has none)
Definition: CANdleFaults.h:116
CANdleStickyFaults(int bits)
Updates current fault list with specified bit field of faults.
Definition: CANdleFaults.h:209
bool HasAnyFault() const
Definition: CANdleFaults.h:161
int ToBitfield() const
Definition: CANdleFaults.h:176
bool HardwareFault
Device detects hardware failure.
Definition: CANdleFaults.h:120
bool ThermalFault
Device is over temperature.
Definition: CANdleFaults.h:152
bool ShortCircuit
Output pin is shorted to something.
Definition: CANdleFaults.h:156
CANdleStickyFaults()
Definition: CANdleFaults.h:212
bool VBatTooLow
VBat is under 5V.
Definition: CANdleFaults.h:132
void Update(uint64_t bits)
Definition: CANdleFaults.h:191
bool APIError
API error detected.
Definition: CANdleFaults.h:124
bool SoftwareFuse
Exceeded output current of 6 amps.
Definition: CANdleFaults.h:148
bool BootDuringEnable
Boot while receiving an enable frame.
Definition: CANdleFaults.h:128
bool V5TooLow
5V Line is under 4 V
Definition: CANdleFaults.h:140
bool V5TooHigh
5V Line is over 6V
Definition: CANdleFaults.h:144
bool VBatTooHigh
VBat is over 30V.
Definition: CANdleFaults.h:136