PDF
AUBO SDK  0.26.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
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
24namespace arcs {
25namespace error_stack {
26
27constexpr int ARCS_ABI_EXPORT codeCompose(int aa, int bb, int cccc)
28{
29 return (int)((aa * 1000000) + (bb * 10000) + cccc);
30}
31
32constexpr 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 JOINT_EX_ERRORS \
45 EXT_AXIS_ERRORS \
46 SAFETY_INTERFACE_BOARD_ERRORS \
47 RTM_ERRORS \
48 TOOL_ERRORS \
49 EX_TOOL_ERRORS \
50 PEDSTRAL_ERRORS \
51 EX_PEDSTRAL_ERRORS \
52 HARDWARE_INTERFACE_ERRORS \
53 _D(ARCS_MAX_ERROR_CODE, -1, "Max error code", "suggest...")
54
55// 错误代码枚举
57{
58#define _D(n, v, s, r) n = (int)v,
60#undef _D
61};
62
63inline int str2ErrorCode(const char *err_code_name)
64{
65#define _D(n, v, s, r) \
66 if (strcmp(#n, err_code_name) == 0) \
67 return v;
69#undef _D
70 return ARCS_MAX_ERROR_CODE;
71}
72
73inline const char *errorCode2Str(int err_code)
74{
75 static const char *errcode_str[] = {
76#define _D(n, v, s, r) s,
78#undef _D
79 };
80
81 enum arcs_index
82 {
83#define _D(n, v, s, r) n##_INDEX,
85#undef _D
86 };
87
88 int index = -1;
89
90#define _D(n, v, s, r) \
91 if (err_code == v) \
92 index = n##_INDEX;
94#undef _D
95
96 if (index == -1) {
97 index = ARCS_MAX_ERROR_CODE_INDEX;
98 }
99
100 return errcode_str[(unsigned)index];
101}
102
103inline std::ostream &dump(std::ostream &os)
104{
105#define _D(n, v, s, r) \
106 os << std::setw(20) << #n << "\t" << v << "\t" << s << "\t" << r \
107 << std::endl;
108
110#undef _D
111
112 return os;
113}
114
115} // namespace error_stack
116} // namespace arcs
117
118#endif // AUBO_SDK_ERROR_STACK_H
#define ARCS_ERROR_CODES
定义硬件抽象层的错误码
int str2ErrorCode(const char *err_code_name)
std::ostream & dump(std::ostream &os)
constexpr int ARCS_ABI_EXPORT codeCompose(int aa, int bb, int cccc)
constexpr int ARCS_ABI_EXPORT mod(int x)
const char * errorCode2Str(int err_code)
运行时错误码
系统错误码