ARCS SDK API  0.25.0
载入中...
搜索中...
未找到
socket.h
浏览该文件的文档.
1/** @file socket.h
2 * @brief socket通信
3 */
4#ifndef AUBO_SDK_SOCKET_INTERFACE_H
5#define AUBO_SDK_SOCKET_INTERFACE_H
6
7#include <vector>
8#include <memory>
9
10#include <aubo/type_def.h>
11#include <aubo/global_config.h>
12
13namespace arcs {
14namespace common_interface {
15
16class ARCS_ABI_EXPORT Socket
17{
18public:
20 virtual ~Socket();
21
22 /**
23 * Open TCP/IP ethernet communication socket
24 *
25 * Instruction
26 *
27 * @param address
28 * @param port
29 * @param socket_name
30 * @return
31 *
32 * @par Python函数原型
33 * socketOpen(self: pyaubo_sdk.Socket, arg0: str, arg1: int, arg2: str) ->
34 * int
35 *
36 * @par Lua函数原型
37 * socketOpen(address: string, port: number, socket_name: string) -> nil
38 *
39 * @par JSON-RPC请求示例
40 * {"jsonrpc":"2.0","method":"Socket.socketOpen","params":["172.16.26.248",8000,"socket_0"],"id":1}
41 *
42 * @par JSON-RPC响应示例
43 * {"id":1,"jsonrpc":"2.0","result":0}
44 *
45 */
46 int socketOpen(const std::string &address, int port,
47 const std::string &socket_name = "socket_0");
48
49 /**
50 * Closes TCP/IP socket communication
51 * Closes down the socket connection to the server.
52 *
53 * Instruction
54 *
55 * @param socket_name
56 * @return
57 *
58 * @par Python函数原型
59 * socketClose(self: pyaubo_sdk.Socket, arg0: str) -> int
60 *
61 * @par Lua函数原型
62 * socketClose(socket_name: string) -> nil
63 *
64 * @par JSON-RPC请求示例
65 * {"jsonrpc":"2.0","method":"Socket.socketClose","params":["socket_0"],"id":1}
66 *
67 * @par JSON-RPC响应示例
68 * {"id":1,"jsonrpc":"2.0","result":0}
69 *
70 */
71 int socketClose(const std::string &socket_name = "socket_0");
72
73 /**
74 * Reads a number of ascii formatted floats from the socket. A maximum
75 * of 30 values can be read in one command.
76 * A list of numbers read (list of floats, length=number+1)
77 *
78 * Instruction
79 *
80 * Result will be store in a register named reg_key. Use getFloatVec
81 * to retrive data
82 *
83 * @param number
84 * @param variable
85 * @param socket_name
86 * @return
87 *
88 * @par Python函数原型
89 * socketReadAsciiFloat(self: pyaubo_sdk.Socket, arg0: int, arg1: str, arg2:
90 * str) -> int
91 *
92 * @par Lua函数原型
93 * socketReadAsciiFloat(number: number, variable: string, socket_name:
94 * string) -> number
95 *
96 */
97 int socketReadAsciiFloat(int number, const std::string &variable,
98 const std::string &socket_name = "socket_0");
99
100 /**
101 * Reads a number of 32 bit integers from the socket. Bytes are in
102 * network byte order. A maximum of 30 values can be read in one
103 * command.
104 * A list of numbers read (list of ints, length=number+1)
105 *
106 * Instruction
107 *
108 * std::vector<int>
109 *
110 * @param number
111 * @param variable
112 * @param socket_name
113 * @return
114 *
115 * @par Python函数原型
116 * socketReadBinaryInteger(self: pyaubo_sdk.Socket, arg0: int, arg1: str,
117 * arg2: str) -> int
118 *
119 * @par Lua函数原型
120 * socketReadBinaryInteger(number: number, variable: string, socket_name:
121 * string) -> number
122 *
123 */
124 int socketReadBinaryInteger(int number, const std::string &variable,
125 const std::string &socket_name = "socket_0");
126
127 /**
128 * Reads a number of bytes from the socket. Bytes are in network byte
129 * order. A maximum of 30 values can be read in one command.
130 * A list of numbers read (list of ints, length=number+1)
131 *
132 * Instruction
133 *
134 * std::vector<char>
135 *
136 * @param number
137 * @param variable
138 * @param socket_name
139 * @return
140 *
141 * @par Python函数原型
142 * socketReadByteList(self: pyaubo_sdk.Socket, arg0: int, arg1: str, arg2:
143 * str) -> int
144 *
145 * @par Lua函数原型
146 * socketReadByteList(number: number, variable: string, socket_name: string)
147 * -> number
148 *
149 */
150 int socketReadByteList(int number, const std::string &variable,
151 const std::string &socket_name = "socket_0");
152
153 /**
154 * Reads all data from the socket and returns the data as a string.
155 * Bytes are in network byte order.
156 *
157 * The optional parameters "prefix" and "suffix", can be used to express
158 * what is extracted from the socket. The "prefix" specifies the start
159 * of the substring (message) extracted from the socket. The data up to
160 * the end of the "prefix" will be ignored and removed from the socket.
161 * The "suffix" specifies the end of the substring (message) extracted
162 * from the socket. Any remaining data on the socket, after the "suffix",
163 * will be preserved. E.g. if the socket server sends a string
164 * "noise>hello<", the controller can receive the "hello" by calling this
165 * script function with the prefix=">" and suffix="<". By using the
166 * "prefix" and "suffix" it is also possible send multiple string to the
167 * controller at once, because the suffix defines where the message ends.
168 * E.g. sending ">hello<>world<"
169 *
170 * Instruction
171 *
172 * std::string
173 *
174 * @param variable
175 * @param socket_name
176 * @param prefix
177 * @param suffix
178 * @param interpret_escape
179 * @return
180 *
181 * @par Python函数原型
182 * socketReadString(self: pyaubo_sdk.Socket, arg0: str, arg1: str, arg2:
183 * str, arg3: str, arg4: bool) -> int
184 *
185 * @par Lua函数原型
186 * socketReadString(variable: string, socket_name: string, prefix: string,
187 * suffix: string, interpret_escape: boolean) -> number
188 *
189 * @par JSON-RPC请求示例
190 * {"jsonrpc":"2.0","method":"Socket.socketReadString","params":["camera","socket_0","","",false],"id":1}
191 *
192 * @par JSON-RPC响应示例
193 * {"id":1,"jsonrpc":"2.0","result":0}
194 *
195 */
196 int socketReadString(const std::string &variable,
197 const std::string &socket_name = "socket_0",
198 const std::string &prefix = "",
199 const std::string &suffix = "",
200 bool interpret_escape = false);
201
202 /**
203 * Instruction
204 * std::vector<char>
205 *
206 * @param variable
207 * @param socket_name
208 * @return
209 *
210 * @par Python函数原型
211 * socketReadAllString(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
212 *
213 * @par Lua函数原型
214 * socketReadAllString(variable: string, socket_name: string) -> number
215 *
216 * @par JSON-RPC请求示例
217 * {"jsonrpc":"2.0","method":"Socket.socketReadAllString","params":["camera","socket_0"],"id":1}
218 *
219 * @par JSON-RPC响应示例
220 * {"id":1,"jsonrpc":"2.0","result":0}
221 *
222 */
223 int socketReadAllString(const std::string &variable,
224 const std::string &socket_name = "socket_0");
225
226 /**
227 * Sends a byte to the server
228 * Sends the byte <value> through the socket. Expects no response. Can
229 * be used to send special ASCII characters; 10 is newline, 2 is start of
230 * text, 3 is end of text.
231 *
232 * Instruction
233 *
234 * @param value
235 * @param socket_name
236 * @return
237 *
238 * @par Python函数原型
239 * socketSendByte(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
240 *
241 * @par Lua函数原型
242 * socketSendByte(value: string, socket_name: string) -> nil
243 *
244 */
245 int socketSendByte(char value, const std::string &socket_name = "socket_0");
246
247 /**
248 * Sends an int (int32_t) to the server
249 * Sends the int <value> through the socket. Send in network byte order.
250 * Expects no response
251 *
252 * Instruction
253 *
254 * @param value
255 * @param socket_name
256 * @return
257 *
258 * @par Python函数原型
259 * socketSendInt(self: pyaubo_sdk.Socket, arg0: int, arg1: str) -> int
260 *
261 * @par Lua函数原型
262 * socketSendInt(value: number, socket_name: string) -> nil
263 *
264 */
265 int socketSendInt(int value, const std::string &socket_name = "socket_0");
266
267 /**
268 * Sends a string with a newline character to the server - useful for
269 * communicatin with the UR dashboard server
270 * Sends the string <str> through the socket in ASCII coding. Expects no
271 * response.
272 *
273 * Instruction
274 *
275 * @param str
276 * @param socket_name
277 * @return
278 *
279 * @par Python函数原型
280 * socketSendLine(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
281 *
282 * @par Lua函数原型
283 * socketSendLine(str: string, socket_name: string) -> nil
284 *
285 * @par JSON-RPC请求示例
286 * {"jsonrpc":"2.0","method":"Socket.socketSendLine","params":["abcd","socket_0"],"id":1}
287 *
288 * @par JSON-RPC响应示例
289 * {"id":1,"jsonrpc":"2.0","result":0}
290 *
291 */
292 int socketSendLine(const std::string &str,
293 const std::string &socket_name = "socket_0");
294
295 /**
296 * Sends a string to the server
297 * Sends the string <str> through the socket in ASCII coding. Expects no
298 * response.
299 *
300 * Instruction
301 *
302 * @param str
303 * @param socket_name
304 * @return
305 *
306 * @par Python函数原型
307 * socketSendString(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
308 *
309 * @par Lua函数原型
310 * socketSendString(str: string, socket_name: string) -> nil
311 *
312 * @par JSON-RPC请求示例
313 * {"jsonrpc":"2.0","method":"Socket.socketSendString","params":["abcd","socket_0"],"id":1}
314 *
315 * @par JSON-RPC响应示例
316 * {"id":1,"jsonrpc":"2.0","result":0}
317 *
318 */
319 int socketSendString(const std::string &str,
320 const std::string &socket_name = "socket_0");
321
322 /**
323 *
324 * @param is_check
325 * @param str
326 * @param socket_name
327 * @return
328 *
329 * @par Python函数原型
330 * socketSendAllString(self: pyaubo_sdk.Socket, arg0: bool, arg1: List[str],
331 * arg2: str) -> int
332 *
333 * @par Lua函数原型
334 * socketSendAllString(is_check: boolean, str: table, socket_name: string)
335 * -> nil
336 *
337 */
338 int socketSendAllString(bool is_check, const std::vector<char> &str,
339 const std::string &socket_name = "socket_0");
340
341protected:
342 void *d_;
343};
344using SocketPtr = std::shared_ptr<Socket>;
345
346// clang-format off
347#define Socket_DECLARES \
348 _INST(Socket, 3, socketOpen, address, port, socket_name) \
349 _INST(Socket, 1, socketClose, socket_name) \
350 _FUNC(Socket, 3, socketReadAsciiFloat, number, variable, socket_name) \
351 _FUNC(Socket, 3, socketReadBinaryInteger, number, variable, socket_name) \
352 _FUNC(Socket, 3, socketReadByteList, number, variable, socket_name) \
353 _FUNC(Socket, 5, socketReadString, variable, socket_name, prefix, suffix, interpret_escape) \
354 _FUNC(Socket, 2, socketReadAllString, variable, socket_name) \
355 _INST(Socket, 2, socketSendByte, value, socket_name) \
356 _INST(Socket, 2, socketSendInt, value, socket_name) \
357 _INST(Socket, 2, socketSendLine, str, socket_name) \
358 _INST(Socket, 2, socketSendString, str, socket_name) \
359 _INST(Socket, 3, socketSendAllString, is_check, str, socket_name)
360// clang-format on
361
362} // namespace common_interface
363} // namespace arcs
364#endif
int socketClose(const std::string &socket_name="socket_0")
Closes TCP/IP socket communication Closes down the socket connection to the server.
int socketSendAllString(bool is_check, const std::vector< char > &str, const std::string &socket_name="socket_0")
int socketReadString(const std::string &variable, const std::string &socket_name="socket_0", const std::string &prefix="", const std::string &suffix="", bool interpret_escape=false)
Reads all data from the socket and returns the data as a string.
int socketReadBinaryInteger(int number, const std::string &variable, const std::string &socket_name="socket_0")
Reads a number of 32 bit integers from the socket.
int socketOpen(const std::string &address, int port, const std::string &socket_name="socket_0")
Open TCP/IP ethernet communication socket
int socketReadAsciiFloat(int number, const std::string &variable, const std::string &socket_name="socket_0")
Reads a number of ascii formatted floats from the socket.
int socketReadByteList(int number, const std::string &variable, const std::string &socket_name="socket_0")
Reads a number of bytes from the socket.
int socketSendInt(int value, const std::string &socket_name="socket_0")
Sends an int (int32_t) to the server Sends the int through the socket.
int socketSendByte(char value, const std::string &socket_name="socket_0")
Sends a byte to the server Sends the byte through the socket.
int socketSendLine(const std::string &str, const std::string &socket_name="socket_0")
Sends a string with a newline character to the server - useful for communicatin with the UR dashboard...
int socketReadAllString(const std::string &variable, const std::string &socket_name="socket_0")
Instruction std::vector<char>
int socketSendString(const std::string &str, const std::string &socket_name="socket_0")
Sends a string to the server Sends the string <str> through the socket in ASCII coding.
std::shared_ptr< Socket > SocketPtr
Definition socket.h:344
数据类型的定义