Logic_library
Library for Logic board by RoboticsBrno.
Loading...
Searching...
No Matches
Error.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <esp_debug_helpers.h>
5#include <esp_log.h>
6#include <freertos/FreeRTOS.h>
7#include <freertos/task.h>
8#include <string>
9
10#ifndef ENABLE_CZECH_ERRORS
11#define ENABLE_CZECH_ERRORS false
12#endif
13
14[[gnu::always_inline]] inline void sanityCheck(bool expression, const char* tag, const char* errorMessage, unsigned stackTraceDepth = 10) {
15 if (!expression) {
16 ESP_LOGE(tag, "%s", errorMessage);
17 esp_backtrace_print(stackTraceDepth);
18 while (true)
19 vTaskDelay(100000 / portTICK_PERIOD_MS);
20 }
21}
22
27};
28
29static const std::string errors[] = {
30 "No error",
31 "Variable overflow",
32 "Variable underflow",
33};
34
35static const std::string errorsCs[] = {
36 "Zadna chyba",
37 "Preteceni promenne",
38 "Podteceni promenne",
39};
40
41[[gnu::always_inline]] inline void sanityCheck(bool expression, const char* tag, ErrorCodes errorCode, unsigned stackTraceDepth = 10) {
42 sanityCheck(expression, tag, (ENABLE_CZECH_ERRORS ? errorsCs : errors)[errorCode].c_str(), stackTraceDepth);
43}
44
45[[gnu::always_inline]] inline void checkRange(int value, int min, int max, const char* tag, unsigned stackTraceDepth = 10) {
46 sanityCheck(value <= max, tag, VariableOverflow);
47 sanityCheck(value >= min, tag, VariableUnderflow);
48}
static const std::string errors[]
Definition: Error.hpp:29
#define ENABLE_CZECH_ERRORS
Definition: Error.hpp:11
ErrorCodes
Definition: Error.hpp:23
@ VariableUnderflow
Definition: Error.hpp:26
@ VariableOverflow
Definition: Error.hpp:25
@ NoError
Definition: Error.hpp:24
void checkRange(int value, int min, int max, const char *tag, unsigned stackTraceDepth=10)
Definition: Error.hpp:45
static const std::string errorsCs[]
Definition: Error.hpp:35
void sanityCheck(bool expression, const char *tag, const char *errorMessage, unsigned stackTraceDepth=10)
Definition: Error.hpp:14