ARCS SDK API  0.24.0
error_stack.h
浏览该文件的文档.
1 /** @file error_stack.h
2  * @brief 汇总错误码
3  */
4 #ifndef AUBO_SDK_ERROR_STACK_H
5 #define AUBO_SDK_ERROR_STACK_H
6 
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <string.h>
10 #include <string>
11 #include <sstream>
12 #include <iomanip>
13 
14 #include <aubo/global_config.h>
15 
16 // 格式化占位符,默认是 fmt 的格式
17 #ifndef _PH1_
18 #define _PH1_ "{}"
19 #define _PH2_ "{}"
20 #define _PH3_ "{}"
21 #define _PH4_ "{}"
22 #endif
23 
24 namespace arcs {
25 namespace error_stack {
26 
27 constexpr int ARCS_ABI_EXPORT codeCompose(int aa, int bb, int cccc)
28 {
29  return (int)((aa * 1000000) + (bb * 10000) + cccc);
30 }
31 
32 constexpr int ARCS_ABI_EXPORT mod(int x)
33 {
34  return (x % 1000000);
35 }
36 
40 
41 #define ARCS_ERROR_CODES \
42  SYSTEM_ERRORS \
43  JOINT_ERRORS \
44  SAFETY_INTERFACE_BOARD_ERRORS \
45  RTM_ERRORS \
46  TOOL_ERRORS \
47  PEDSTRAL_ERRORS \
48  HARDWARE_INTERFACE_ERRORS \
49  _D(ARCS_MAX_ERROR_CODE, -1, "Max error code", "suggest...")
50 
51 // 错误代码枚举
53 {
54 #define _D(n, v, s, r) n = (int)v,
56 #undef _D
57 };
58 
59 inline int str2ErrorCode(const char *err_code_name)
60 {
61 #define _D(n, v, s, r) \
62  if (strcmp(#n, err_code_name) == 0) \
63  return v;
65 #undef _D
66  return ARCS_MAX_ERROR_CODE;
67 }
68 
69 inline const char *errorCode2Str(int err_code)
70 {
71  static const char *errcode_str[] = {
72 #define _D(n, v, s, r) s,
74 #undef _D
75  };
76 
77  enum arcs_index
78  {
79 #define _D(n, v, s, r) n##_INDEX,
81 #undef _D
82  };
83 
84  int index = -1;
85 
86 #define _D(n, v, s, r) \
87  if (err_code == v) \
88  index = n##_INDEX;
90 #undef _D
91 
92  if (index == -1) {
93  index = ARCS_MAX_ERROR_CODE_INDEX;
94  }
95 
96  return errcode_str[(unsigned)index];
97 }
98 
99 inline std::ostream &dump(std::ostream &os)
100 {
101 #define _D(n, v, s, r) \
102  os << std::setw(20) << #n << "\t" << v << "\t" << s << "\t" << r \
103  << std::endl;
104 
106 #undef _D
107 
108  return os;
109 }
110 
111 } // namespace error_stack
112 } // namespace arcs
113 
114 #endif // AUBO_SDK_ERROR_STACK_H
const char * errorCode2Str(int err_code)
Definition: error_stack.h:69
constexpr int ARCS_ABI_EXPORT codeCompose(int aa, int bb, int cccc)
Definition: error_stack.h:27
int str2ErrorCode(const char *err_code_name)
Definition: error_stack.h:59
constexpr int ARCS_ABI_EXPORT mod(int x)
Definition: error_stack.h:32
运行时错误码
std::ostream & dump(std::ostream &os)
Definition: error_stack.h:99
定义硬件抽象层的错误码
Definition: aubo_api.h:17
系统错误码