cmvr-es/third_party/AuboSdk/linux/include/aubo/socket.h

628 lines
20 KiB
C
Raw Normal View History

2025-11-18 10:07:08 +08:00
/** @file socket.h
* @brief socket通信
*/
#ifndef AUBO_SDK_SOCKET_INTERFACE_H
#define AUBO_SDK_SOCKET_INTERFACE_H
#include <vector>
#include <memory>
#include <aubo/type_def.h>
#include <aubo/global_config.h>
namespace arcs {
namespace common_interface {
class ARCS_ABI_EXPORT Socket
{
public:
Socket();
virtual ~Socket();
/**
* \english
* Open TCP/IP ethernet communication socket
*
* Instruction
*
* @param address
* @param port
* @param socket_name
* @return
*
* @par Python function prototype
* socketOpen(self: pyaubo_sdk.Socket, arg0: str, arg1: int, arg2: str) -> int
*
* @par Lua function prototype
* socketOpen(address: string, port: number, socket_name: string) -> nil
*
* @par JSON-RPC request example
* {"jsonrpc":"2.0","method":"Socket.socketOpen","params":["172.16.26.248",8000,"socket_0"],"id":1}
*
* @par JSON-RPC response example
* {"id":1,"jsonrpc":"2.0","result":0}
* \endenglish
* \chinese
* TCP/IP以太网通信socket
*
*
*
* @param address
* @param port
* @param socket_name
* @return
*
* @par Python函数原型
* socketOpen(self: pyaubo_sdk.Socket, arg0: str, arg1: int, arg2: str) -> int
*
* @par Lua函数原型
* socketOpen(address: string, port: number, socket_name: string) -> nil
*
* @par JSON-RPC请求示例
* {"jsonrpc":"2.0","method":"Socket.socketOpen","params":["172.16.26.248",8000,"socket_0"],"id":1}
*
* @par JSON-RPC响应示例
* {"id":1,"jsonrpc":"2.0","result":0}
* \endchinese
*/
int socketOpen(const std::string &address, int port,
const std::string &socket_name = "socket_0");
/**
* \english
* Closes TCP/IP socket communication
* Closes down the socket connection to the server.
*
* Instruction
*
* @param socket_name
* @return
*
* @par Python function prototype
* socketClose(self: pyaubo_sdk.Socket, arg0: str) -> int
*
* @par Lua function prototype
* socketClose(socket_name: string) -> nil
*
* @par JSON-RPC request example
* {"jsonrpc":"2.0","method":"Socket.socketClose","params":["socket_0"],"id":1}
*
* @par JSON-RPC response example
* {"id":1,"jsonrpc":"2.0","result":0}
* \endenglish
* \chinese
* TCP/IP socket
* socket
*
*
*
* @param socket_name
* @return
*
* @par Python函数原型
* socketClose(self: pyaubo_sdk.Socket, arg0: str) -> int
*
* @par Lua函数原型
* socketClose(socket_name: string) -> nil
*
* @par JSON-RPC请求示例
* {"jsonrpc":"2.0","method":"Socket.socketClose","params":["socket_0"],"id":1}
*
* @par JSON-RPC响应示例
* {"id":1,"jsonrpc":"2.0","result":0}
* \endchinese
*/
int socketClose(const std::string &socket_name = "socket_0");
/**
* \english
* Reads a number of ascii formatted floats from the socket. A maximum
* of 30 values can be read in one command.
* A list of numbers read (list of floats, length=number+1)
*
* Result will be stored in a register named reg_key. Use getFloatVec
* to retrieve data
*
* @param number
* @param variable
* @param socket_name
* @return
*
* @par Python function prototype
* socketReadAsciiFloat(self: pyaubo_sdk.Socket, arg0: int, arg1: str, arg2:
* str) -> int
*
* @par Lua function prototype
* socketReadAsciiFloat(number: number, variable: string, socket_name:
* string) -> number
* \endenglish
* \chinese
* socket读取指定数量的ASCII格式浮点数30
* =number+1
*
* reg_key的寄存器中使getFloatVec获取数据
*
* @param number
* @param variable
* @param socket_name
* @return
*
* @par Python函数原型
* socketReadAsciiFloat(self: pyaubo_sdk.Socket, arg0: int, arg1: str, arg2:
* str) -> int
*
* @par Lua函数原型
* socketReadAsciiFloat(number: number, variable: string, socket_name:
* string) -> number
* \endchinese
*/
int socketReadAsciiFloat(int number, const std::string &variable,
const std::string &socket_name = "socket_0");
/**
* \english
* Reads a number of 32 bit integers from the socket. Bytes are in
* network byte order. A maximum of 30 values can be read in one
* command.
* A list of numbers read (list of ints, length=number+1)
*
* Instruction
*
* std::vector<int>
*
* @param number
* @param variable
* @param socket_name
* @return
*
* @par Python function prototype
* socketReadBinaryInteger(self: pyaubo_sdk.Socket, arg0: int, arg1: str,
* arg2: str) -> int
*
* @par Lua function prototype
* socketReadBinaryInteger(number: number, variable: string, socket_name:
* string) -> number
* \endenglish
* \chinese
* socket读取指定数量的32位整数30
* =number+1
*
*
*
* std::vector<int>
*
* @param number
* @param variable
* @param socket_name
* @return
*
* @par Python函数原型
* socketReadBinaryInteger(self: pyaubo_sdk.Socket, arg0: int, arg1: str,
* arg2: str) -> int
*
* @par Lua函数原型
* socketReadBinaryInteger(number: number, variable: string, socket_name:
* string) -> number
* \endchinese
*/
int socketReadBinaryInteger(int number, const std::string &variable,
const std::string &socket_name = "socket_0");
/**
* \english
* Reads a number of bytes from the socket. Bytes are in network byte
* order. A maximum of 30 values can be read in one command.
* A list of numbers read (list of ints, length=number+1)
*
* Instruction
*
* std::vector<char>
*
* @param number
* @param variable
* @param socket_name
* @return
*
* @par Python function prototype
* socketReadByteList(self: pyaubo_sdk.Socket, arg0: int, arg1: str, arg2:
* str) -> int
*
* @par Lua function prototype
* socketReadByteList(number: number, variable: string, socket_name: string)
* -> number
* \endenglish
* \chinese
* socket读取指定数量的字节30
* =number+1
*
*
*
* std::vector<char>
*
* @param number
* @param variable
* @param socket_name
* @return
*
* @par Python函数原型
* socketReadByteList(self: pyaubo_sdk.Socket, arg0: int, arg1: str, arg2:
* str) -> int
*
* @par Lua函数原型
* socketReadByteList(number: number, variable: string, socket_name: string)
* -> number
* \endchinese
*/
int socketReadByteList(int number, const std::string &variable,
const std::string &socket_name = "socket_0");
/**
* \english
* Reads all data from the socket and returns the data as a string.
* Bytes are in network byte order.
*
* The optional parameters "prefix" and "suffix", can be used to express
* what is extracted from the socket. The "prefix" specifies the start
* of the substring (message) extracted from the socket. The data up to
* the end of the "prefix" will be ignored and removed from the socket.
* The "suffix" specifies the end of the substring (message) extracted
* from the socket. Any remaining data on the socket, after the "suffix",
* will be preserved. E.g. if the socket server sends a string
* "noise>hello<", the controller can receive the "hello" by calling this
* script function with the prefix=">" and suffix="<". By using the
* "prefix" and "suffix" it is also possible send multiple string to the
* controller at once, because the suffix defines where the message ends.
* E.g. sending ">hello<>world<"
*
* Instruction
*
* std::string
*
* @param variable
* @param socket_name
* @param prefix
* @param suffix
* @param interpret_escape
* @return
*
* @par Python function prototype
* socketReadString(self: pyaubo_sdk.Socket, arg0: str, arg1: str, arg2:
* str, arg3: str, arg4: bool) -> int
*
* @par Lua function prototype
* socketReadString(variable: string, socket_name: string, prefix: string,
* suffix: string, interpret_escape: boolean) -> number
*
* @par JSON-RPC request example
* {"jsonrpc":"2.0","method":"Socket.socketReadString","params":["camera","socket_0","","",false],"id":1}
*
* @par JSON-RPC response example
* {"id":1,"jsonrpc":"2.0","result":0}
* \endenglish
* \chinese
* socket读取所有数据并将其作为字符串返回
*
*
* "prefix""suffix"socket中提取的内容
* "prefix""prefix"socket中移除
* "suffix""suffix"socket中
* socket服务器发送字符串"noise>hello<"prefix=">"suffix="<""hello"
* 使"prefix""suffix""suffix"">hello<>world<"
*
*
*
* std::string
*
* @param variable
* @param socket_name
* @param prefix
* @param suffix
* @param interpret_escape
* @return
*
* @par Python函数原型
* socketReadString(self: pyaubo_sdk.Socket, arg0: str, arg1: str, arg2:
* str, arg3: str, arg4: bool) -> int
*
* @par Lua函数原型
* socketReadString(variable: string, socket_name: string, prefix: string,
* suffix: string, interpret_escape: boolean) -> number
*
* @par JSON-RPC请求示例
* {"jsonrpc":"2.0","method":"Socket.socketReadString","params":["camera","socket_0","","",false],"id":1}
*
* @par JSON-RPC响应示例
* {"id":1,"jsonrpc":"2.0","result":0}
* \endchinese
*/
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);
/**
* \english
* Reads all data from the socket and returns the data as a vector of chars.
*
* Instruction
* std::vector<char>
*
* @param variable
* @param socket_name
* @return
*
* @par Python function prototype
* socketReadAllString(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
*
* @par Lua function prototype
* socketReadAllString(variable: string, socket_name: string) -> number
*
* @par JSON-RPC request example
* {"jsonrpc":"2.0","method":"Socket.socketReadAllString","params":["camera","socket_0"],"id":1}
*
* @par JSON-RPC response example
* {"id":1,"jsonrpc":"2.0","result":0}
* \endenglish
* \chinese
* socket读取所有数据并将其作为char向量返回
*
*
* std::vector<char>
*
* @param variable
* @param socket_name
* @return
*
* @par Python函数原型
* socketReadAllString(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
*
* @par Lua函数原型
* socketReadAllString(variable: string, socket_name: string) -> number
*
* @par JSON-RPC请求示例
* {"jsonrpc":"2.0","method":"Socket.socketReadAllString","params":["camera","socket_0"],"id":1}
*
* @par JSON-RPC响应示例
* {"id":1,"jsonrpc":"2.0","result":0}
* \endchinese
*/
int socketReadAllString(const std::string &variable,
const std::string &socket_name = "socket_0");
/**
* \english
* Sends a byte to the server
* Sends the byte <value> through the socket. Expects no response. Can
* be used to send special ASCII characters; 10 is newline, 2 is start of
* text, 3 is end of text.
*
* Instruction
*
* @param value
* @param socket_name
* @return
*
* @par Python function prototype
* socketSendByte(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
*
* @par Lua function prototype
* socketSendByte(value: string, socket_name: string) -> nil
*
* \endenglish
* \chinese
*
* socket发送字节<value>ASCII字符1023
*
*
*
* @param value
* @param socket_name
* @return
*
* @par Python函数原型
* socketSendByte(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
*
* @par Lua函数原型
* socketSendByte(value: string, socket_name: string) -> nil
*
* \endchinese
*/
int socketSendByte(char value, const std::string &socket_name = "socket_0");
/**
* \english
* Sends an int (int32_t) to the server
* Sends the int <value> through the socket. Send in network byte order.
* Expects no response
*
* Instruction
*
* @param value
* @param socket_name
* @return
*
* @par Python function prototype
* socketSendInt(self: pyaubo_sdk.Socket, arg0: int, arg1: str) -> int
*
* @par Lua function prototype
* socketSendInt(value: number, socket_name: string) -> nil
*
* \endenglish
* \chinese
* intint32_t
* socket发送int <value>
*
*
*
* @param value
* @param socket_name
* @return
*
* @par Python函数原型
* socketSendInt(self: pyaubo_sdk.Socket, arg0: int, arg1: str) -> int
*
* @par Lua函数原型
* socketSendInt(value: number, socket_name: string) -> nil
*
* \endchinese
*/
int socketSendInt(int value, const std::string &socket_name = "socket_0");
/**
* \english
* Sends a string with a newline character to the server
* Sends the string <str> through the socket in ASCII coding. Expects no
* response.
*
* Instruction
*
* @param str
* @param socket_name
* @return
*
* @par Python function prototype
* socketSendLine(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
*
* @par Lua function prototype
* socketSendLine(str: string, socket_name: string) -> nil
*
* @par JSON-RPC request example
* {"jsonrpc":"2.0","method":"Socket.socketSendLine","params":["abcd","socket_0"],"id":1}
*
* @par JSON-RPC response example
* {"id":1,"jsonrpc":"2.0","result":0}
* \endenglish
* \chinese
* .
* socket以ASCII编码发送字符串<str>
*
*
*
* @param str
* @param socket_name
* @return
*
* @par Python函数原型
* socketSendLine(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
*
* @par Lua函数原型
* socketSendLine(str: string, socket_name: string) -> nil
*
* @par JSON-RPC请求示例
* {"jsonrpc":"2.0","method":"Socket.socketSendLine","params":["abcd","socket_0"],"id":1}
*
* @par JSON-RPC响应示例
* {"id":1,"jsonrpc":"2.0","result":0}
* \endchinese
*/
int socketSendLine(const std::string &str,
const std::string &socket_name = "socket_0");
/**
* \english
* Sends a string to the server
* Sends the string <str> through the socket in ASCII coding. Expects no
* response.
*
* Instruction
*
* @param str
* @param socket_name
* @return
*
* @par Python function prototype
* socketSendString(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
*
* @par Lua function prototype
* socketSendString(str: string, socket_name: string) -> nil
*
* @par JSON-RPC request example
* {"jsonrpc":"2.0","method":"Socket.socketSendString","params":["abcd","socket_0"],"id":1}
*
* @par JSON-RPC response example
* {"id":1,"jsonrpc":"2.0","result":0}
* \endenglish
* \chinese
*
* socket以ASCII编码发送字符串<str>
*
*
*
* @param str
* @param socket_name
* @return
*
* @par Python函数原型
* socketSendString(self: pyaubo_sdk.Socket, arg0: str, arg1: str) -> int
*
* @par Lua函数原型
* socketSendString(str: string, socket_name: string) -> nil
*
* @par JSON-RPC请求示例
* {"jsonrpc":"2.0","method":"Socket.socketSendString","params":["abcd","socket_0"],"id":1}
*
* @par JSON-RPC响应示例
* {"id":1,"jsonrpc":"2.0","result":0}
* \endchinese
*/
int socketSendString(const std::string &str,
const std::string &socket_name = "socket_0");
/**
* \english
* Sends all data in the given vector of chars to the server.
*
* @param is_check Whether to check the sending status
* @param str The data to send as a vector of chars
* @param socket_name The name of the socket
* @return Status code
*
* @par Python function prototype
* socketSendAllString(self: pyaubo_sdk.Socket, arg0: bool, arg1: List[str], arg2: str) -> int
*
* @par Lua function prototype
* socketSendAllString(is_check: boolean, str: table, socket_name: string) -> nil
* \endenglish
* \chinese
* char向量中的所有数据到服务器
*
* @param is_check
* @param str char向量
* @param socket_name
* @return
*
* @par Python函数原型
* socketSendAllString(self: pyaubo_sdk.Socket, arg0: bool, arg1: List[str], arg2: str) -> int
*
* @par Lua函数原型
* socketSendAllString(is_check: boolean, str: table, socket_name: string) -> nil
* \endchinese
*/
int socketSendAllString(bool is_check, const std::vector<char> &str,
const std::string &socket_name = "socket_0");
/**
* \~chinese socket \~english Check if the socket is connected
* @brief socketHasConnected
* @param socket_name
*
* @return
*
* @par Python函数原型
* socketHasConnected(self: pyaubo_sdk.Socket, arg0: str) -> bool
*
* @par Lua函数原型
* socketHasConnected(socket_name: string) -> boolean
*/
bool socketHasConnected(const std::string &socket_name = "socket_0");
protected:
void *d_;
};
using SocketPtr = std::shared_ptr<Socket>;
} // namespace common_interface
} // namespace arcs
#endif