AUBO SDK  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 * \english
24 * Open TCP/IP ethernet communication socket
25 *
26 * Instruction
27 *
28 * @param address
29 * @param port
30 * @param socket_name
31 * @return
32 *
33 * @par Python function prototype
34 * socketOpen(self: pyaubo_sdk.Socket, arg0: str, arg1: int, arg2: str) -> int
35 *
36 * @par Lua function prototype
37 * socketOpen(address: string, port: number, socket_name: string) -> nil
38 *
39 * @par JSON-RPC request example
40 * {"jsonrpc":"2.0","method":"Socket.socketOpen","params":["172.16.26.248",8000,"socket_0"],"id":1}
41 *
42 * @par JSON-RPC response example
43 * {"id":1,"jsonrpc":"2.0","result":0}
44 * \endenglish
45 * \chinese
46 * 打开TCP/IP以太网通信socket
47 *
48 * 指令
49 *
50 * @param address 地址
51 * @param port 端口
52 * @param socket_name 套接字名称
53 * @return 返回值
54 *
55 * @par Python函数原型
56 * socketOpen(self: pyaubo_sdk.Socket, arg0: str, arg1: int, arg2: str) -> int
57 *
58 * @par Lua函数原型
59 * socketOpen(address: string, port: number, socket_name: string) -> nil
60 *
61 * @par JSON-RPC请求示例
62 * {"jsonrpc":"2.0","method":"Socket.socketOpen","params":["172.16.26.248",8000,"socket_0"],"id":1}
63 *
64 * @par JSON-RPC响应示例
65 * {"id":1,"jsonrpc":"2.0","result":0}
66 * \endchinese
67 */
68 int socketOpen(const std::string &address, int port,
69 const std::string &socket_name = "socket_0");
70
71 /**
72 * \english
73 * Closes TCP/IP socket communication
74 * Closes down the socket connection to the server.
75 *
76 * Instruction
77 *
78 * @param socket_name
79 * @return
80 *
81 * @par Python function prototype
82 * socketClose(self: pyaubo_sdk.Socket, arg0: str) -> int
83 *
84 * @par Lua function prototype
85 * socketClose(socket_name: string) -> nil
86 *
87 * @par JSON-RPC request example
88 * {"jsonrpc":"2.0","method":"Socket.socketClose","params":["socket_0"],"id":1}
89 *
90 * @par JSON-RPC response example
91 * {"id":1,"jsonrpc":"2.0","result":0}
92 * \endenglish
93 * \chinese
94 * 关闭TCP/IP socket 通信
95 * 关闭与服务器的 socket 连接。
96 *
97 * 指令
98 *
99 * @param socket_name 套接字名称
100 * @return 返回值
101 *
102 * @par Python函数原型
103 * socketClose(self: pyaubo_sdk.Socket, arg0: str) -> int
104 *
105 * @par Lua函数原型
106 * socketClose(socket_name: string) -> nil
107 *
108 * @par JSON-RPC请求示例
109 * {"jsonrpc":"2.0","method":"Socket.socketClose","params":["socket_0"],"id":1}
110 *
111 * @par JSON-RPC响应示例
112 * {"id":1,"jsonrpc":"2.0","result":0}
113 * \endchinese
114 */
115 int socketClose(const std::string &socket_name = "socket_0");
116
117 /**
118 * \english
119 * Reads a number of ascii formatted floats from the socket. A maximum
120 * of 30 values can be read in one command.
121 * A list of numbers read (list of floats, length=number+1)
122 *
123 * Result will be stored in a register named reg_key. Use getFloatVec
124 * to retrieve data
125 *
126 * @param number
127 * @param variable
128 * @param socket_name
129 * @return
130 *
131 * @par Python function prototype
132 * socketReadAsciiFloat(self: pyaubo_sdk.Socket, arg0: int, arg1: str, arg2:
133 * str) -> int
134 *
135 * @par Lua function prototype
136 * socketReadAsciiFloat(number: number, variable: string, socket_name:
137 * string) -> number
138 * \endenglish
139 * \chinese
140 * 从socket读取指定数量的ASCII格式浮点数。一次最多可读取30个值。
141 * 读取到的数字列表(浮点数列表,长度=number+1)
142 *
143 * 结果将存储在名为reg_key的寄存器中。使用getFloatVec获取数据
144 *
145 * @param number 数量
146 * @param variable 变量名
147 * @param socket_name 套接字名称
148 * @return 返回值
149 *
150 * @par Python函数原型
151 * socketReadAsciiFloat(self: pyaubo_sdk.Socket, arg0: int, arg1: str, arg2:
152 * str) -> int
153 *
154 * @par Lua函数原型
155 * socketReadAsciiFloat(number: number, variable: string, socket_name:
156 * string) -> number
157 * \endchinese
158 */
159 int socketReadAsciiFloat(int number, const std::string &variable,
160 const std::string &socket_name = "socket_0");
161
162 /**
163 * \english
164 * Reads a number of 32 bit integers from the socket. Bytes are in
165 * network byte order. A maximum of 30 values can be read in one
166 * command.
167 * A list of numbers read (list of ints, length=number+1)
168 *
169 * Instruction
170 *
171 * std::vector<int>
172 *
173 * @param number
174 * @param variable
175 * @param socket_name
176 * @return
177 *
178 * @par Python function prototype
179 * socketReadBinaryInteger(self: pyaubo_sdk.Socket, arg0: int, arg1: str,
180 * arg2: str) -> int
181 *
182 * @par Lua function prototype
183 * socketReadBinaryInteger(number: number, variable: string, socket_name:
184 * string) -> number
185 * \endenglish
186 * \chinese
187 * 从socket读取指定数量的32位整数。字节为网络字节序。一次最多可读取30个值。
188 * 读取到的数字列表(整数列表,长度=number+1)
189 *
190 * 指令
191 *
192 * std::vector<int>
193 *
194 * @param number 数量
195 * @param variable 变量名
196 * @param socket_name 套接字名称
197 * @return 返回值
198 *
199 * @par Python函数原型
200 * socketReadBinaryInteger(self: pyaubo_sdk.Socket, arg0: int, arg1: str,
201 * arg2: str) -> int
202 *
203 * @par Lua函数原型
204 * socketReadBinaryInteger(number: number, variable: string, socket_name:
205 * string) -> number
206 * \endchinese
207 */
208 int socketReadBinaryInteger(int number, const std::string &variable,
209 const std::string &socket_name = "socket_0");
210
211 /**
212 * \english
213 * Reads a number of bytes from the socket. Bytes are in network byte
214 * order. A maximum of 30 values can be read in one command.
215 * A list of numbers read (list of ints, length=number+1)
216 *
217 * Instruction
218 *
219 * std::vector<char>
220 *
221 * @param number
222 * @param variable
223 * @param socket_name
224 * @return
225 *
226 * @par Python function prototype
227 * socketReadByteList(self: pyaubo_sdk.Socket, arg0: int, arg1: str, arg2:
228 * str) -> int
229 *
230 * @par Lua function prototype
231 * socketReadByteList(number: number, variable: string, socket_name: string)
232 * -> number
233 * \endenglish
234 * \chinese
235 * 从socket读取指定数量的字节。字节为网络字节序。一次最多可读取30个值。
236 * 读取到的数字列表(整数列表,长度=number+1)
237 *
238 * 指令
239 *
240 * std::vector<char>
241 *
242 * @param number 数量
243 * @param variable 变量名
244 * @param socket_name 套接字名称
245 * @return 返回值
246 *
247 * @par Python函数原型
248 * socketReadByteList(self: pyaubo_sdk.Socket, arg0: int, arg1: str, arg2:
249 * str) -> int
250 *
251 * @par Lua函数原型
252 * socketReadByteList(number: number, variable: string, socket_name: string)
253 * -> number
254 * \endchinese
255 */
256 int socketReadByteList(int number, const std::string &variable,
257 const std::string &socket_name = "socket_0");
258
259 /**
260 * \english
261 * Reads all data from the socket and returns the data as a string.
262 * Bytes are in network byte order.
263 *
264 * The optional parameters "prefix" and "suffix", can be used to express
265 * what is extracted from the socket. The "prefix" specifies the start
266 * of the substring (message) extracted from the socket. The data up to
267 * the end of the "prefix" will be ignored and removed from the socket.
268 * The "suffix" specifies the end of the substring (message) extracted
269 * from the socket. Any remaining data on the socket, after the "suffix",
270 * will be preserved. E.g. if the socket server sends a string
271 * "noise>hello<", the controller can receive the "hello" by calling this
272 * script function with the prefix=">" and suffix="<". By using the
273 * "prefix" and "suffix" it is also possible send multiple string to the
274 * controller at once, because the suffix defines where the message ends.
275 * E.g. sending ">hello<>world<"
276 *
277 * Instruction
278 *
279 * std::string
280 *
281 * @param variable
282 * @param socket_name
283 * @param prefix
284 * @param suffix
285 * @param interpret_escape
286 * @return
287 *
288 * @par Python function prototype
289 * socketReadString(self: pyaubo_sdk.Socket, arg0: str, arg1: str, arg2:
290 * str, arg3: str, arg4: bool) -> int
291 *
292 * @par Lua function prototype
293 * socketReadString(variable: string, socket_name: string, prefix: string,
294 * suffix: string, interpret_escape: boolean) -> number
295 *
296 * @par JSON-RPC request example
297 * {"jsonrpc":"2.0","method":"Socket.socketReadString","params":["camera","socket_0","","",false],"id":1}
298 *
299 * @par JSON-RPC response example
300 * {"id":1,"jsonrpc":"2.0","result":0}
301 * \endenglish
302 * \chinese
303 * 从socket读取所有数据并将其作为字符串返回。
304 * 字节为网络字节序。
305 *
306 * 可选参数"prefix"和"suffix"可用于指定从socket中提取的内容。
307 * "prefix"指定提取子字符串(消息)的起始位置。直到"prefix"结尾的数据将被忽略并从socket中移除。
308 * "suffix"指定提取子字符串(消息)的结束位置。"suffix"之后的任何剩余数据将保留在socket中。
309 * 例如,如果socket服务器发送字符串"noise>hello<",控制器可以通过调用此脚本函数并设置prefix=">"和suffix="<"来接收"hello"。
310 * 通过使用"prefix"和"suffix",还可以一次向控制器发送多条字符串,因为"suffix"定义了消息的结束位置。例如发送">hello<>world<"
311 *
312 * 指令
313 *
314 * std::string
315 *
316 * @param variable 变量名
317 * @param socket_name 套接字名称
318 * @param prefix 前缀
319 * @param suffix 后缀
320 * @param interpret_escape 是否解释转义字符
321 * @return 返回值
322 *
323 * @par Python函数原型
324 * socketReadString(self: pyaubo_sdk.Socket, arg0: str, arg1: str, arg2:
325 * str, arg3: str, arg4: bool) -> int
326 *
327 * @par Lua函数原型
328 * socketReadString(variable: string, socket_name: string, prefix: string,
329 * suffix: string, interpret_escape: boolean) -> number
330 *
331 * @par JSON-RPC请求示例
332 * {"jsonrpc":"2.0","method":"Socket.socketReadString","params":["camera","socket_0","","",false],"id":1}
333 *
334 * @par JSON-RPC响应示例
335 * {"id":1,"jsonrpc":"2.0","result":0}
336 * \endchinese
337 */
338 int socketReadString(const std::string &variable,
339 const std::string &socket_name = "socket_0",
340 const std::string &prefix = "",
341 const std::string &suffix = "",
342 bool interpret_escape = false);
343
344 /**
345 * \english
346 * Reads all data from the socket and returns the data as a vector of chars.
347 *
348 * Instruction
349 * std::vector<char>
350 *
351 * @param variable
352 * @param socket_name
353 * @return
354 *
355 * @par Python function prototype
356 * socketReadAllString(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
357 *
358 * @par Lua function prototype
359 * socketReadAllString(variable: string, socket_name: string) -> number
360 *
361 * @par JSON-RPC request example
362 * {"jsonrpc":"2.0","method":"Socket.socketReadAllString","params":["camera","socket_0"],"id":1}
363 *
364 * @par JSON-RPC response example
365 * {"id":1,"jsonrpc":"2.0","result":0}
366 * \endenglish
367 * \chinese
368 * 从socket读取所有数据并将其作为char向量返回。
369 *
370 * 指令
371 * std::vector<char>
372 *
373 * @param variable 变量名
374 * @param socket_name 套接字名称
375 * @return 返回值
376 *
377 * @par Python函数原型
378 * socketReadAllString(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
379 *
380 * @par Lua函数原型
381 * socketReadAllString(variable: string, socket_name: string) -> number
382 *
383 * @par JSON-RPC请求示例
384 * {"jsonrpc":"2.0","method":"Socket.socketReadAllString","params":["camera","socket_0"],"id":1}
385 *
386 * @par JSON-RPC响应示例
387 * {"id":1,"jsonrpc":"2.0","result":0}
388 * \endchinese
389 */
390 int socketReadAllString(const std::string &variable,
391 const std::string &socket_name = "socket_0");
392
393 /**
394 * \english
395 * Sends a byte to the server
396 * Sends the byte <value> through the socket. Expects no response. Can
397 * be used to send special ASCII characters; 10 is newline, 2 is start of
398 * text, 3 is end of text.
399 *
400 * Instruction
401 *
402 * @param value
403 * @param socket_name
404 * @return
405 *
406 * @par Python function prototype
407 * socketSendByte(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
408 *
409 * @par Lua function prototype
410 * socketSendByte(value: string, socket_name: string) -> nil
411 *
412 * \endenglish
413 * \chinese
414 * 发送一个字节到服务器
415 * 通过socket发送字节<value>,不期望响应。可用于发送特殊ASCII字符;10为换行符,2为文本开始,3为文本结束。
416 *
417 * 指令
418 *
419 * @param value 字节值
420 * @param socket_name 套接字名称
421 * @return 返回值
422 *
423 * @par Python函数原型
424 * socketSendByte(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
425 *
426 * @par Lua函数原型
427 * socketSendByte(value: string, socket_name: string) -> nil
428 *
429 * \endchinese
430 */
431 int socketSendByte(char value, const std::string &socket_name = "socket_0");
432
433 /**
434 * \english
435 * Sends an int (int32_t) to the server
436 * Sends the int <value> through the socket. Send in network byte order.
437 * Expects no response
438 *
439 * Instruction
440 *
441 * @param value
442 * @param socket_name
443 * @return
444 *
445 * @par Python function prototype
446 * socketSendInt(self: pyaubo_sdk.Socket, arg0: int, arg1: str) -> int
447 *
448 * @par Lua function prototype
449 * socketSendInt(value: number, socket_name: string) -> nil
450 *
451 * \endenglish
452 * \chinese
453 * 发送一个int(int32_t)到服务器
454 * 通过socket发送int <value>,以网络字节序发送。不期望响应。
455 *
456 * 指令
457 *
458 * @param value 整数值
459 * @param socket_name 套接字名称
460 * @return 返回值
461 *
462 * @par Python函数原型
463 * socketSendInt(self: pyaubo_sdk.Socket, arg0: int, arg1: str) -> int
464 *
465 * @par Lua函数原型
466 * socketSendInt(value: number, socket_name: string) -> nil
467 *
468 * \endchinese
469 */
470 int socketSendInt(int value, const std::string &socket_name = "socket_0");
471
472 /**
473 * \english
474 * Sends a string with a newline character to the server
475 * Sends the string <str> through the socket in ASCII coding. Expects no
476 * response.
477 *
478 * Instruction
479 *
480 * @param str
481 * @param socket_name
482 * @return
483 *
484 * @par Python function prototype
485 * socketSendLine(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
486 *
487 * @par Lua function prototype
488 * socketSendLine(str: string, socket_name: string) -> nil
489 *
490 * @par JSON-RPC request example
491 * {"jsonrpc":"2.0","method":"Socket.socketSendLine","params":["abcd","socket_0"],"id":1}
492 *
493 * @par JSON-RPC response example
494 * {"id":1,"jsonrpc":"2.0","result":0}
495 * \endenglish
496 * \chinese
497 * 发送带有换行符的字符串到服务器.
498 * 通过socket以ASCII编码发送字符串<str>,不期望响应。
499 *
500 * 指令
501 *
502 * @param str 字符串
503 * @param socket_name 套接字名称
504 * @return 返回值
505 *
506 * @par Python函数原型
507 * socketSendLine(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
508 *
509 * @par Lua函数原型
510 * socketSendLine(str: string, socket_name: string) -> nil
511 *
512 * @par JSON-RPC请求示例
513 * {"jsonrpc":"2.0","method":"Socket.socketSendLine","params":["abcd","socket_0"],"id":1}
514 *
515 * @par JSON-RPC响应示例
516 * {"id":1,"jsonrpc":"2.0","result":0}
517 * \endchinese
518 */
519 int socketSendLine(const std::string &str,
520 const std::string &socket_name = "socket_0");
521
522 /**
523 * \english
524 * Sends a string to the server
525 * Sends the string <str> through the socket in ASCII coding. Expects no
526 * response.
527 *
528 * Instruction
529 *
530 * @param str
531 * @param socket_name
532 * @return
533 *
534 * @par Python function prototype
535 * socketSendString(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
536 *
537 * @par Lua function prototype
538 * socketSendString(str: string, socket_name: string) -> nil
539 *
540 * @par JSON-RPC request example
541 * {"jsonrpc":"2.0","method":"Socket.socketSendString","params":["abcd","socket_0"],"id":1}
542 *
543 * @par JSON-RPC response example
544 * {"id":1,"jsonrpc":"2.0","result":0}
545 * \endenglish
546 * \chinese
547 * 发送字符串到服务器
548 * 通过socket以ASCII编码发送字符串<str>,不期望响应。
549 *
550 * 指令
551 *
552 * @param str 字符串
553 * @param socket_name 套接字名称
554 * @return 返回值
555 *
556 * @par Python函数原型
557 * socketSendString(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
558 *
559 * @par Lua函数原型
560 * socketSendString(str: string, socket_name: string) -> nil
561 *
562 * @par JSON-RPC请求示例
563 * {"jsonrpc":"2.0","method":"Socket.socketSendString","params":["abcd","socket_0"],"id":1}
564 *
565 * @par JSON-RPC响应示例
566 * {"id":1,"jsonrpc":"2.0","result":0}
567 * \endchinese
568 */
569 int socketSendString(const std::string &str,
570 const std::string &socket_name = "socket_0");
571
572 /**
573 * \english
574 * Sends all data in the given vector of chars to the server.
575 *
576 * @param is_check Whether to check the sending status
577 * @param str The data to send as a vector of chars
578 * @param socket_name The name of the socket
579 * @return Status code
580 *
581 * @par Python function prototype
582 * socketSendAllString(self: pyaubo_sdk.Socket, arg0: bool, arg1: List[str], arg2: str) -> int
583 *
584 * @par Lua function prototype
585 * socketSendAllString(is_check: boolean, str: table, socket_name: string) -> nil
586 * \endenglish
587 * \chinese
588 * 发送给定char向量中的所有数据到服务器。
589 *
590 * @param is_check 是否检查发送状态
591 * @param str 要发送的数据,char向量
592 * @param socket_name 套接字名称
593 * @return 状态码
594 *
595 * @par Python函数原型
596 * socketSendAllString(self: pyaubo_sdk.Socket, arg0: bool, arg1: List[str], arg2: str) -> int
597 *
598 * @par Lua函数原型
599 * socketSendAllString(is_check: boolean, str: table, socket_name: string) -> nil
600 * \endchinese
601 */
602 int socketSendAllString(bool is_check, const std::vector<char> &str,
603 const std::string &socket_name = "socket_0");
604
605 /**
606 * 检测 socket 连接是否成功
607 * @brief socketHasConnected
608 * @param socket_name
609 *
610 * @return
611 *
612 * @par Python函数原型
613 * socketHasConnected(self: pyaubo_sdk.Socket, arg0: str) -> bool
614 *
615 * @par Lua函数原型
616 * socketHasConnected(socket_name: string) -> boolean
617 */
618 bool socketHasConnected(const std::string &socket_name = "socket_0");
619
620protected:
621 void *d_;
622};
623using SocketPtr = std::shared_ptr<Socket>;
624
625} // namespace common_interface
626} // namespace arcs
627#endif
bool socketHasConnected(const std::string &socket_name="socket_0")
检测 socket 连接是否成功
int socketClose(const std::string &socket_name="socket_0")
关闭TCP/IP socket 通信 关闭与服务器的 socket 连接。
int socketSendAllString(bool is_check, const std::vector< char > &str, const std::string &socket_name="socket_0")
发送给定char向量中的所有数据到服务器。
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)
从socket读取所有数据并将其作为字符串返回。 字节为网络字节序。
int socketReadBinaryInteger(int number, const std::string &variable, const std::string &socket_name="socket_0")
从socket读取指定数量的32位整数。字节为网络字节序。一次最多可读取30个值。 读取到的数字列表(整数列表,长度=number+1)
int socketOpen(const std::string &address, int port, const std::string &socket_name="socket_0")
打开TCP/IP以太网通信socket
int socketReadAsciiFloat(int number, const std::string &variable, const std::string &socket_name="socket_0")
从socket读取指定数量的ASCII格式浮点数。一次最多可读取30个值。 读取到的数字列表(浮点数列表,长度=number+1)
int socketReadByteList(int number, const std::string &variable, const std::string &socket_name="socket_0")
从socket读取指定数量的字节。字节为网络字节序。一次最多可读取30个值。 读取到的数字列表(整数列表,长度=number+1)
int socketSendInt(int value, const std::string &socket_name="socket_0")
发送一个int(int32_t)到服务器 通过socket发送int ,以网络字节序发送。不期望响应。
int socketSendByte(char value, const std::string &socket_name="socket_0")
发送一个字节到服务器 通过socket发送字节<value>,不期望响应。可用于发送特殊ASCII字符;10为换行符,2为文本开始,3为文本结束。
int socketSendLine(const std::string &str, const std::string &socket_name="socket_0")
发送带有换行符的字符串到服务器.
int socketReadAllString(const std::string &variable, const std::string &socket_name="socket_0")
从socket读取所有数据并将其作为char向量返回。
int socketSendString(const std::string &str, const std::string &socket_name="socket_0")
发送字符串到服务器 通过socket以ASCII编码发送字符串<str>,不期望响应。
std::shared_ptr< Socket > SocketPtr
Definition socket.h:623
数据类型的定义