log.hpp
Go to the documentation of this file.
1 // =========================================================================
2 // This library is placed under the MIT License
3 // Copyright 2017-2018 Natanael Josue Rabello. All rights reserved.
4 // For the license information refer to LICENSE file in root directory.
5 // =========================================================================
6 
15 #ifndef _MPU_LOG_HPP_
16 #define _MPU_LOG_HPP_
17 
18 #include "sdkconfig.h"
19 #include "esp_log.h"
20 #include "esp_err.h"
21 
22 // Note: declare TAG before include this header
23 // Note: include only in .cpp files from this library
24 
25 #define MPU_LOGE(format, ...) if (CONFIG_MPU_LOG_LEVEL >= ESP_LOG_ERROR) { ESP_LOGE(TAG, format, ##__VA_ARGS__); }
26 #define MPU_LOGW(format, ...) if (CONFIG_MPU_LOG_LEVEL >= ESP_LOG_WARN) { ESP_LOGW(TAG, format, ##__VA_ARGS__); }
27 #define MPU_LOGI(format, ...) if (CONFIG_MPU_LOG_LEVEL >= ESP_LOG_INFO) { ESP_LOGI(TAG, format, ##__VA_ARGS__); }
28 #define MPU_LOGD(format, ...) if (CONFIG_MPU_LOG_LEVEL >= ESP_LOG_DEBUG) { ESP_LOGD(TAG, format, ##__VA_ARGS__); }
29 #define MPU_LOGV(format, ...) if (CONFIG_MPU_LOG_LEVEL >= ESP_LOG_VERBOSE) { ESP_LOGV(TAG, format, ##__VA_ARGS__); }
30 
31 #define MPU_LOGEMSG(msg, format, ...) MPU_LOGE("%s()-> %s" format, __FUNCTION__, msg, ##__VA_ARGS__)
32 #define MPU_LOGWMSG(msg, format, ...) MPU_LOGW("%s()-> %s" format, __FUNCTION__, msg, ##__VA_ARGS__)
33 #define MPU_LOGIMSG(msg, format, ...) MPU_LOGI("%s()-> %s" format, __FUNCTION__, msg, ##__VA_ARGS__)
34 #define MPU_LOGDMSG(msg, format, ...) MPU_LOGD("%s()-> %s" format, __FUNCTION__, msg, ##__VA_ARGS__)
35 #define MPU_LOGVMSG(msg, format, ...) MPU_LOGV("%s()-> %s" format, __FUNCTION__, msg, ##__VA_ARGS__)
36 
37 #ifdef MPU_LOG_ERROR_TRACES
38 #define MPU_ERR_CHECK(x) mpud::log::errorCheckLogger(x, __ASSERT_FUNC, __LINE__, #x)
39 #else
40 #define MPU_ERR_CHECK(x) (x)
41 #endif
42 
44 namespace mpud {
45 
47 inline namespace log {
48 
50 namespace msgs {
51 
52 static const char INVALID_ARG[] = "Invalid Argument";
53 static const char INVALID_STATE[] = "Invalid State";
54 static const char INVALID_LENGTH[] = "Invalid length";
55 static const char INVALID_FIFO_RATE[] = "Invalid FIFO rate";
56 static const char INVALID_SAMPLE_RATE[] = "Invalid Sample rate";
57 static const char INVALID_TAP_THRESH[] = "Invalid Tap threshold";
58 static const char DMP_LOAD_FAIL[] = "Failed to load DMP firmware";
59 static const char DMP_NOT_LOADED[] = "DMP firmware has not been loaded";
60 static const char UNKNOWN_DMP_CFG_STATE[] = "Unknown DMP config state";
61 static const char NO_AXIS_PASSED[] = "No Axis passed";
62 static const char BANK_BOUNDARIES[] = "Bank boundaries overpass";
63 static const char FIFO_CORRUPTION[] = "FIFO Corruption. Quaternion data outside of the acceptable threshold";
64 static const char AUX_I2C_DISABLED[] = "Auxiliary I2C is disabled";
65 static const char AUX_I2C_SLAVE_NACK[] = "Auxiliary I2C Slave NACK";
66 static const char AUX_I2C_LOST_ARB[] = "Auxiliary I2C Master loose abitraion of the bus";
67 static const char COMPASS_DISABLED[] = "Compass is disabled";
68 static const char NOT_SUPPORTED[] = "Not supported";
69 static const char TIMEOUT[] = "Timeout";
70 static const char EMPTY[] = "";
71 
72 } // namespace msgs
73 
74 static inline esp_err_t errorCheckLogger(esp_err_t x, const char* func, const int line, const char* expr) {
75  if (x)
76  MPU_LOGE("func:%s @ line:%d, expr:\"%s\", error:0x%X ", func, line, expr, x);
77  return x;
78 }
79 
80 } // namespace log
81 
82 } // namespace mpud
83 
84 #endif /* end of include guard: _MPU_LOG_HPP_ */
static const char UNKNOWN_DMP_CFG_STATE[]
Definition: log.hpp:60
static const char COMPASS_DISABLED[]
Definition: log.hpp:67
static const char INVALID_FIFO_RATE[]
Definition: log.hpp:55
static const char NO_AXIS_PASSED[]
Definition: log.hpp:61
static const char INVALID_SAMPLE_RATE[]
Definition: log.hpp:56
static const char BANK_BOUNDARIES[]
Definition: log.hpp:62
static const char EMPTY[]
Definition: log.hpp:70
static esp_err_t errorCheckLogger(esp_err_t x, const char *func, const int line, const char *expr)
Definition: log.hpp:74
static const char DMP_LOAD_FAIL[]
Definition: log.hpp:58
static const char FIFO_CORRUPTION[]
Definition: log.hpp:63
static const char INVALID_TAP_THRESH[]
Definition: log.hpp:57
static const char AUX_I2C_DISABLED[]
Definition: log.hpp:64
static const char AUX_I2C_LOST_ARB[]
Definition: log.hpp:66
static const char INVALID_LENGTH[]
Definition: log.hpp:54
static const char NOT_SUPPORTED[]
Definition: log.hpp:68
static const char INVALID_STATE[]
Definition: log.hpp:53
static const char TIMEOUT[]
Definition: log.hpp:69
static const char DMP_NOT_LOADED[]
Definition: log.hpp:59
static const char INVALID_ARG[]
Definition: log.hpp:52
static const char AUX_I2C_SLAVE_NACK[]
Definition: log.hpp:65