-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrors.h
198 lines (168 loc) · 5.63 KB
/
errors.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/// @file
/// Implementation of Error handle that is used within each API call function
#ifndef LABVIEW_ERRORS_H
#define LABVIEW_ERRORS_H
#include <cstring>
#include <string>
#ifdef USE_LABVIEW_ENV
// Including Labviewv.lib in case of project is compiled for LabVIEW
#pragma comment(lib,"labviewv.lib")
// Including extcode.h in case of project is compiled for LabVIEW
#include "extcode.h"
#endif
/// Generic error handle that is returned from each API function.
///
/// In contrast to a LabVIEW error handle (LVErrorCluster_t) that includes a specific type of Error string, the
/// Generic Error Handle (GenericErrHandle) consists of generic C types (int and char*) for both error code and
/// error message.
///
/// GenericErrHandle is used as pointer for all Indradrive API Functions (see @ref ss_overview "API Function Overview").
///
/// @remarks Depending on the USE_LABVIEW_ENV switch, the GenericErrHandle can be replaced by LStrHandle.
typedef struct GenericErrHandle {
/// Error code.
uint32_t code;
/// Error message [2048].
char msg[2048];
/// Constructor.
///
/// @param _code (Optional) Error code. Can be later on set also via set() function.
/// @param _msg (Optional) Error message. Parameter will not be used.
GenericErrHandle(uint32_t _code = 0, const char* _msg = "") :
code(_code)
{}
/// Sets error code and error message.
///
/// @param _code Error code.
/// @param _msg Error message.
void set(uint32_t _code, const char* _msg)
{
code = _code;
for (size_t i = 0; i < strlen(_msg); i++)
msg[i] = _msg[i];
}
/// Sets an error message.
///
/// @param _msg Error message.
void set_msg(const char* _msg)
{
set(code, _msg);
}
/// Sets an error code.
///
/// @param _code Error code.
void set_code(uint32_t _code)
{
set(_code, msg);
}
} GenericErrHandle;
#ifdef USE_LABVIEW_ENV
/// Defines an alias representing handle of the error via LStrHandle for LabVIEW.
///
/// @remarks The alias is used since the USE_LABVIEW_ENV switch can the LStrHandle by GenericErrHandle.
typedef LStrHandle ErrHandle;
#else
/// Defines an alias representing a pointer to GenericErrHandle.
///
/// @remarks The alias is used since the USE_LABVIEW_ENV switch can the GenericErrHandle by LStrHandle.
typedef GenericErrHandle* ErrHandle;
#endif
#ifdef USE_LABVIEW_ENV
#pragma pack(push,1)
#include "extcode.h"
#pragma pack(pop)
#endif
#ifdef USE_LABVIEW_ENV
#pragma pack(push,1)
/// LabVIEW error cluster that is used for LabVIEW environment.
/// @deprecated This cluster is not used anymore since error cluster compilation is done directly in LabVIEW VI.
typedef struct {
LVBoolean status;
int32 code;
LStrHandle msg;
} LVErrorCluster_t;
#pragma pack(pop)
#endif
#ifdef USE_LABVIEW_ENV
/// A macro that defines Error base that is used for coding the final error code in LabVIEW environment.
///
/// @sa set_error()
#define Err_Base (0x08EF)
#else
/// A macro that defines Error base that is used for coding the final error code.
///
/// @sa set_error()
#define Err_Base (0x0)
#endif
/// Values that represent error blocks to be used as block_code paramater for set_error() function.
///
/// @sa set_error()
typedef enum EErrorBlocks
{
/// An enum constant representing the Error: no error
Err_NoError = 0,
/// An enum constant representing the Error on open by com
Err_Block_OpenByCOM = 1,
/// An enum constant representing the Error on close
Err_Block_Close = 2,
/// An enum constant representing the Error on test
Err_Block_Test = 3,
/// An enum constant representing the Error on Sequence init
Err_Block_SeqInit = 6,
/// An enum constant representing the Error on Sequence write
Err_Block_SeqWrite = 7,
/// An enum constant representing the Error on Speed Contrl init
Err_Block_VelCInit = 8,
/// An enum constant representing the Error on Speed Control write
Err_Block_VelCWrite = 9,
/// An enum constant representing the Error on get status
Err_Block_GetStatus = 10,
/// An enum constant representing the Error on set control
Err_Block_SetControl = 11,
/// An enum constant representing the Error of invalid API reference
Err_Invalid_Pointer = 12
} EErrorBlocks;
#ifdef USE_LABVIEW_ENV
/// Writes a error string to a LabVIEW error handle.
///
/// @param [out] lvhandle LabVIEW error handle.
/// @param [in] str Error message.
///
/// @return Return code on successful execution.
static MgErr write_string(ErrHandle lvhandle, std::string str)
{
//Initializes the buffer
MgErr err = NumericArrayResize(uB, 1, (UHandle*)&lvhandle, str.length());
if (err) return err;
//Informs the LabVIEW string handle about the size of the size
(**lvhandle).cnt = str.length();
//Fills the string buffer with str
strcpy((char*)(**lvhandle).str, str.c_str());
return noErr;
}
#endif
/// Sets an error handle to the errhndl parameter.
///
/// This static function can be utilized to set an error message as well as a error code in the following scheme to
/// an Error handle: Error code: 0 << 8 | block_code << 4 | issue_code, whereas "|" indicates an OR-
/// concatenation.
///
/// @param [out] errhndl Error handle pointer.
/// @param [in] errstr Error message.
/// @param [in] block_code Error block code defined by EErrorBlocks enum.
/// @param [in] issue_code (Optional) The issue code.
///
/// @return The final error code.
///
/// @sa EErrorBlocks
inline static int32_t set_error(ErrHandle errhndl, std::string errstr, int32_t block_code, int32_t issue_code = 1)
{
int32_t retcode = (Err_Base << 8) | (block_code << 4) | issue_code;
#ifdef USE_LABVIEW_ENV
write_string(errhndl, errstr);
#else
errhndl->set(retcode, errstr.c_str());
#endif
return retcode;
}
#endif // LABVIEW_ERRORS_H