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