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