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  HAL_ERRORS \
44  RTM_ERRORS \
45  _D(ARCS_MAX_ERROR_CODE, -1, "Max error code", "suggest...")
46 
47 // 错误代码枚举
49 {
50 #define _D(n, v, s, r) n = (int)v,
52 #undef _D
53 };
54 
55 inline int str2ErrorCode(const char *err_code_name)
56 {
57 #define _D(n, v, s, r) \
58  if (strcmp(#n, err_code_name) == 0) \
59  return v;
61 #undef _D
62  return ARCS_MAX_ERROR_CODE;
63 }
64 
65 inline const char *errorCode2Str(int err_code)
66 {
67  static const char *errcode_str[] = {
68 #define _D(n, v, s, r) s,
70 #undef _D
71  };
72 
73  enum arcs_index
74  {
75 #define _D(n, v, s, r) n##_INDEX,
77 #undef _D
78  };
79 
80  int index = -1;
81 
82 #define _D(n, v, s, r) \
83  if (err_code == v) \
84  index = n##_INDEX;
86 #undef _D
87 
88  if (index == -1) {
89  index = ARCS_MAX_ERROR_CODE_INDEX;
90  }
91 
92  return errcode_str[(unsigned)index];
93 }
94 
95 inline std::ostream &dump(std::ostream &os)
96 {
97 #define _D(n, v, s, r) \
98  os << std::setw(20) << #n << "\t" << v << "\t" << s << "\t" << r \
99  << std::endl;
100 
102 #undef _D
103 
104  return os;
105 }
106 
107 } // namespace error_stack
108 } // namespace arcs
109 
110 #endif // AUBO_SDK_ERROR_STACK_H
const char * errorCode2Str(int err_code)
Definition: error_stack.h:65
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:55
constexpr int ARCS_ABI_EXPORT mod(int x)
Definition: error_stack.h:32
运行时错误码
std::ostream & dump(std::ostream &os)
Definition: error_stack.h:95
定义硬件抽象层的错误码
Definition: aubo_api.h:17
系统错误码