AGVC SDK API  0.7.0
script.h
浏览该文件的文档.
1/** @file script.h
2 * @brief 用于SCRIPT模块的交互,如向服务器发送脚本
3 */
4#ifndef AUBO_SDK_SCRIPT_H
5#define AUBO_SDK_SCRIPT_H
6#define AGVC_ABI
7
8#include <string>
9#include <memory>
10#include <functional>
11
12namespace agvc_interface {
13
15{
16public:
17 virtual ~ScriptWriter() = default;
18
19 virtual ScriptWriter &append(const std::string &line) = 0;
20 virtual ScriptWriter &append(const char *buf, size_t len) = 0;
21 virtual ScriptWriter &moveJoint() = 0;
22 virtual ScriptWriter &moveLine() = 0;
23 virtual ScriptWriter &ifCondition() = 0;
27 virtual ScriptWriter &end() = 0;
28};
29
30/// SCRIPT客户端
32{
33public:
39
40 ScriptClient(int mode = 0);
42
43 /**
44 * 设置日志处理器
45 *
46 * 此函数可设置自定义的日志处理函数来处理日志消息。 \n
47 * Aubo SDK 有一套默认的日志系统,按照默认的格式输出到默认的文件。
48 * 如果用户不希望采用默认的格式或者不希望输出到默认的文件,那就可以通过这个接口重新自定义格式,或者输出路径。
49 * 这个函数可以将用户自定义的日志系统与 Aubo SDK 默认的日志系统合并。
50 *
51 * @note setLogHandler函数要放在即将触发的日志之前,
52 * 否则会按照默认的形式输出日志。
53 *
54 * @param handler 日志处理函数 \n
55 * 此日志处理函数的下定义如下: \n
56 * void handler(int level, const char* filename, int line, const
57 * std::string& message) \n
58 * level 表示日志等级 \n
59 * &nbsp; 0: LOGLEVEL_FATAL 严重的错误 \n
60 * &nbsp; 1: LOGLEVEL_ERROR 错误 \n
61 * &nbsp; 2: LOGLEVEL_WARNING 警告 \n
62 * &nbsp; 3: LOGLEVEL_INFO 通知 \n
63 * &nbsp; 4: LOGLEVEL_DEBUG 调试 \n
64 * &nbsp; 5: LOGLEVEL_BACKTRACE 跟踪 \n
65 * filename 表示文件名 \n
66 * line 表示代码行号 \n
67 * message 表示日志信息 \n
68 * @return 无
69 */
71 std::function<void(int /*level*/, const char * /*filename*/, int /*line*/, const std::string & /*message*/)>
72 handler);
73
74 /**
75 * 连接到服务器
76 *
77 * @param ip IP地址
78 * @param port 端口号。SCRIPT端口号为30004
79 * @retval 0 连接成功
80 * @retval 1 在执行函数前,已连接
81 * @retval -1 连接失败
82 */
83 int connect(const std::string &ip = "", int port = 0);
84
85 /**
86 * 是否处于连接状态
87 *
88 * @retval true 已连接
89 * @retval false 未连接
90 */
91 bool hasConnected() const;
92
93 /**
94 * 登录
95 *
96 * @param usrname 用户名
97 * @param passwd 密码
98 * @retval 0 成功
99 * @retval -1 失败
100 */
101 int login(const std::string &usrname, const std::string &passwd);
102
103 /**
104 * 返回客户端是否登录
105 *
106 * @retval true 已登录
107 * @retval false 未登录
108 */
110
111 /**
112 * 登出
113 *
114 * @return 0
115 */
116 int logout();
117
118 /**
119 * 断开连接
120 *
121 * @retval 0 成功
122 * @retval -1 失败
123 */
125
126 /**
127 * 发送脚本文件
128 *
129 * 远程调用机器人的脚本
130 *
131 * @param path 文件在机器人端的路径
132 * @retval 0 成功
133 * @retval -1 失败
134 */
135 int sendFile(const std::string &path);
136
137 /**
138 * 发送脚本内容
139 *
140 * 调用本地的脚本
141 *
142 * @param script 脚本内容
143 * @retval 0 成功
144 * @retval -1 失败
145 */
146 int sendString(const std::string &script);
147
148 /**
149 * 使用ScriptWriter构建服务器脚本
150 *
151 * @param chunck_name
152 * @param cb
153 * @retval 0 成功
154 * @retval -1 失败
155 */
156 int send(const std::string &chunck_name, std::function<int(ScriptWriter &)> cb);
157
158 /**
159 * 设置服务器脚本的全局变量
160 *
161 * @param cb 脚本的全局变量
162 * @return 0
163 */
164 int subscribeVariableUpdate(std::function<void(const std::string &, const std::string &)> cb);
165
166 /**
167 * 设置服务器脚本的错误码
168 *
169 * @param cb 脚本的错误码
170 * @return 0
171 */
172 [[deprecated]] int subscribeScriptError(std::function<void(const std::string &)> cb);
173
174 int subscribeScriptError2(std::function<void(const std::string &, const std::string &)> cb);
175
176 /**
177 * 设置事件处理
178 *
179 * @param cb
180 * @return
181 */
182 int setEventHandler(std::function<void(int /*event*/)> cb);
183
184private:
185 class Impl;
186 Impl *impl;
187};
188using ScriptClientPtr = std::shared_ptr<ScriptClient>;
189
190} // namespace agvc_interface
191#endif
int setEventHandler(std::function< void(int)> cb)
设置事件处理
int sendFile(const std::string &path)
发送脚本文件
void setLogHandler(std::function< void(int, const char *, int, const std::string &)> handler)
设置日志处理器
int sendString(const std::string &script)
发送脚本内容
int subscribeScriptError(std::function< void(const std::string &)> cb)
设置服务器脚本的错误码
int subscribeScriptError2(std::function< void(const std::string &, const std::string &)> cb)
int disconnect()
断开连接
int send(const std::string &chunck_name, std::function< int(ScriptWriter &)> cb)
使用ScriptWriter构建服务器脚本
int login(const std::string &usrname, const std::string &passwd)
登录
int connect(const std::string &ip="", int port=0)
连接到服务器
int subscribeVariableUpdate(std::function< void(const std::string &, const std::string &)> cb)
设置服务器脚本的全局变量
bool hasLogined()
返回客户端是否登录
bool hasConnected() const
是否处于连接状态
virtual ScriptWriter & moveLine()=0
virtual ScriptWriter & whileCondition()=0
virtual ScriptWriter & elseCondition()=0
virtual ScriptWriter & moveJoint()=0
virtual ~ScriptWriter()=default
virtual ScriptWriter & append(const char *buf, size_t len)=0
virtual ScriptWriter & append(const std::string &line)=0
virtual ScriptWriter & ifCondition()=0
virtual ScriptWriter & end()=0
virtual ScriptWriter & elseIfCondition()=0
std::shared_ptr< ScriptClient > ScriptClientPtr
#define AGVC_ABI
定义 rpc.h:7