22static LOG_TAG ID =
"Fault Check";
34typedef struct CanFault {
36 Canbus::Buffer buffer;
45 CanFault(
const uint32_t address,
const uint64_t faultMask) {
46 this->address = address;
47 this->buffer = address;
48 this->faultMask = faultMask;
52 uint64_t curr = buffer.getULong();
53 if (curr & faultMask) {
54 buffer.dump(lastValue.arr);
56 Log.
w(ID,
"Faulted CAN Address:", address);
58 return faulted =
true;
60 return faulted =
false;
65 lastValue.longlong = 0;
70#define X(add, mask, id) \
71 if (address == add && lastValue.longlong & mask) { \
81typedef struct PinFault {
86 PinFault(
const uint8_t GPIO_Pin) {
87 this->GPIO_Pin = GPIO_Pin;
96#define X(pin, comp, value, id) (GPIO_Pin == pin && Pins::getPinValue(pin) comp value) ||
99 Log.
w(ID,
"Faulted pin:", GPIO_Pin);
101 return faulted =
true;
104 return faulted =
false;
108#define X(pin, comp, value, id) \
109 if (GPIO_Pin == pin && this->faulted) { \
120#if PP_NARG_MO(HARD_FAULT_ADD) > 0
122static CanFault hardCanFaults[HARD_CAN_COUNT] = {
123#define X(add, mask, tag) CanFault(add, mask),
130#if PP_NARG_MO(SOFT_FAULT_ADD) > 0
132static CanFault softCanFaults[SOFT_CAN_COUNT] = {
133#define X(add, mask, tag) CanFault(add, mask),
140#if PP_NARG_MO(HARD_PIN_FAULTS) > 0
142static PinFault hardPinFaults[HARD_PIN_COUNT] = {
143#define X(pin, comp, value, id) PinFault(pin),
150#if PP_NARG_MO(SOFT_PIN_FAULTS) > 0
152static PinFault softPinFaults[SOFT_PIN_COUNT] = {
153#define X(pin, comp, value, id) PinFault(pin),
162 bool faulted =
false;
164#if PP_NARG_MO(HARD_FAULT_ADD) > 0
165 for (
size_t i = 0; i < HARD_CAN_COUNT; i++) {
166 faulted |= hardCanFaults[i].check();
170#if PP_NARG_MO(HARD_PIN_FAULTS) > 0
171 for (
size_t i = 0; i < HARD_PIN_COUNT; i++) {
172 faulted |= hardPinFaults[i].check();
180 bool faulted =
false;
182#if PP_NARG_MO(SOFT_FAULT_ADD) > 0
183 for (
size_t i = 0; i < SOFT_CAN_COUNT; i++) {
184 faulted |= softCanFaults[i].check();
188#if PP_NARG_MO(SOFT_PIN_FAULTS) > 0
189 for (
size_t i = 0; i < SOFT_PIN_COUNT; i++) {
190 faulted |= softPinFaults[i].check();
198#if PP_NARG_MO(HARD_FAULT_ADD) > 0
199 for (
size_t i = 0; i < HARD_CAN_COUNT; i++) {
200 hardCanFaults[i].log();
203#if PP_NARG_MO(SOFT_FAULT_ADD) > 0
204 for (
size_t i = 0; i < SOFT_CAN_COUNT; i++) {
205 softCanFaults[i].log();
208#if PP_NARG_MO(HARD_PIN_FAULTS) > 0
209 for (
size_t i = 0; i < HARD_PIN_COUNT; i++) {
210 hardPinFaults[i].log();
213#if PP_NARG_MO(SOFT_PIN_FAULTS) > 0
214 for (
size_t i = 0; i < SOFT_PIN_COUNT; i++) {
215 softPinFaults[i].log();
Configure fault checking.
#define SOFT_PIN_FAULTS
Defines Pins that should be checked for hard faults.
#define SOFT_FAULT_ADD
Defines CAN addresses that should be checked for soft faults.
#define HARD_FAULT_ADD
Defines CAN addresses that should be checked for hard faults.
#define HARD_PIN_FAULTS
Defines Pins that should be checked for hard faults.
#define CAN_FAULT_IDS
Defines address bit field identifiers.
Checks for defined faults from canbus addresses or pins.
Special logging functionality.
const char * LOG_MSG
Type definition for logging messages, only used internally.
const char * LOG_TAG
Type definition of logging tags This typedef is necessary to allow for easier manipulation of code by...
Logging::Log_t Log
The global logging object.
Update, set, and get predefined pin values.
Fault checking functionality.
bool softFault(void)
Check if any non-serious fault has occurred.
bool hardFault(void)
Checks if any serious fault has occurred.
bool anyFault(void)
Checks both hardFault and softFault.
void logFault(void)
Interprets and logs the last fault that was checked using the Log library.
void w(LOG_TAG TAG, LOG_MSG message)
Log a string using a warning tag.