@dobot-plus/template 1.2.7 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dobot/components/DobotPlusApp.tsx +78 -78
- package/.dobot/http/axios.ts +52 -52
- package/.dobot/http/http.ts +22 -22
- package/.dobot/index.ts +2 -2
- package/.dobot/protocol/methodsHandler.ts +15 -15
- package/.dobot/protocol/postMessageHandler.ts +289 -289
- package/.dobot/protocol/websocketHandler.ts +3 -3
- package/.dobot/shim.d.ts +3 -3
- package/.dobot/store/actions/toolActions.ts +69 -69
- package/.dobot/store/actions/userManagementActions.ts +25 -0
- package/.dobot/store/reducers/index.ts +8 -8
- package/.dobot/store/reducers/toolReducer.ts +152 -152
- package/.dobot/store/reducers/userManagementReducer.ts +35 -0
- package/.dobot/store/types.ts +237 -240
- package/.dobot/template/default.tsx.mustache +19 -19
- package/.dobot/template/entry.css +25 -25
- package/.dobot/template/entry.tsx +53 -53
- package/.dobot/template/index.html +23 -23
- package/.dobot/template/index.scss +5 -5
- package/.dobot/utils/i18n.ts +31 -31
- package/.dobot/utils/mqtt.ts +61 -61
- package/.dobot/utils/rem.js +21 -21
- package/.dobot/utils/tool.ts +15 -15
- package/.eslintrc.cjs +18 -18
- package/.luarc.json +8 -8
- package/.vscode/Api.schema.json +103 -103
- package/.vscode/Blocks.schema.json +94 -94
- package/.vscode/Main.schema.json +42 -42
- package/.vscode/Script.schema.json +22 -22
- package/.vscode/Toolbar.schema.json +19 -19
- package/.vscode/extensions.json +8 -8
- package/.vscode/settings.json +51 -51
- package/Resources/i18n/client/de.json +11 -11
- package/Resources/i18n/client/en.json +11 -11
- package/Resources/i18n/client/es.json +11 -11
- package/Resources/i18n/client/hk.json +11 -11
- package/Resources/i18n/client/ja.json +11 -11
- package/Resources/i18n/client/ko.json +11 -11
- package/Resources/i18n/client/ru.json +11 -11
- package/Resources/i18n/client/zh.json +11 -11
- package/Resources/i18n/plugin/de.json +3 -3
- package/Resources/i18n/plugin/en.json +3 -3
- package/Resources/i18n/plugin/es.json +3 -3
- package/Resources/i18n/plugin/hk.json +3 -3
- package/Resources/i18n/plugin/ja.json +3 -3
- package/Resources/i18n/plugin/ko.json +3 -3
- package/Resources/i18n/plugin/ru.json +3 -3
- package/Resources/i18n/plugin/zh.json +3 -3
- package/configs/Blocks.json +21 -21
- package/configs/Main.json +5 -5
- package/configs/Scripts.json +7 -7
- package/configs/Toolbar.json +5 -5
- package/dpt.json +4 -4
- package/lua/control.lua +18 -18
- package/lua/daemon.lua +22 -22
- package/lua/httpAPI.lua +66 -66
- package/lua/userAPI.lua +51 -51
- package/lua/utils/mqtt.lua +16 -16
- package/lua/utils/num_convert.lua +41 -41
- package/lua/utils/tcp.lua +30 -30
- package/lua/utils/util.lua +30 -30
- package/package.json +58 -49
- package/project.json +3 -3
- package/tsconfig.json +26 -26
- package/ui/Blocks.tsx +5 -5
- package/ui/Main.tsx +31 -31
- package/ui/Toolbar.tsx +5 -5
- package/.dobot/store/actions/userMagamentActions.ts +0 -25
- package/.dobot/store/reducers/userMagamentReducer.ts +0 -38
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
{
|
|
2
|
-
"blocks": {
|
|
3
|
-
"blocksDemoKey": "积木中文翻译内容 %1"
|
|
4
|
-
},
|
|
5
|
-
"config": {
|
|
6
|
-
"configDemoKey": "中文内容"
|
|
7
|
-
},
|
|
8
|
-
"scripts": {
|
|
9
|
-
"scriptDemoKey": "脚本中文翻译内容"
|
|
10
|
-
}
|
|
11
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"blocks": {
|
|
3
|
+
"blocksDemoKey": "积木中文翻译内容 %1"
|
|
4
|
+
},
|
|
5
|
+
"config": {
|
|
6
|
+
"configDemoKey": "中文内容"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"scriptDemoKey": "脚本中文翻译内容"
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"testKey": "This is the control page for plugin"
|
|
3
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"testKey": "This is the control page for plugin"
|
|
3
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"testKey": "This is the control page for plugin"
|
|
3
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"testKey": "This is the control page for plugin"
|
|
3
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"testKey": "This is the control page for plugin"
|
|
3
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"testKey": "This is the control page for plugin"
|
|
3
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"testKey": "这是插件的控制界面"
|
|
3
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"testKey": "这是插件的控制界面"
|
|
3
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"testKey": "This is the control page for plugin"
|
|
3
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"testKey": "This is the control page for plugin"
|
|
3
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"testKey": "This is the control page for plugin"
|
|
3
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"testKey": "This is the control page for plugin"
|
|
3
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"testKey": "This is the control page for plugin"
|
|
3
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"testKey": "This is the control page for plugin"
|
|
3
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"testKey": "这是插件的控制界面"
|
|
3
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"testKey": "这是插件的控制界面"
|
|
3
|
+
}
|
package/configs/Blocks.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"block_name": "DemoBlock",
|
|
4
|
-
"block_type": "shape_statement",
|
|
5
|
-
"block_color": "#ffa211",
|
|
6
|
-
"block_configs": [
|
|
7
|
-
{
|
|
8
|
-
"message": "blocksDemoKey",
|
|
9
|
-
"params": [
|
|
10
|
-
{
|
|
11
|
-
"name": "id",
|
|
12
|
-
"param_type": "input_value",
|
|
13
|
-
"data_type": "math_number",
|
|
14
|
-
"default": "9"
|
|
15
|
-
}
|
|
16
|
-
]
|
|
17
|
-
}
|
|
18
|
-
],
|
|
19
|
-
"block_code": ["demoMethod1({id})\n"]
|
|
20
|
-
}
|
|
21
|
-
]
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"block_name": "DemoBlock",
|
|
4
|
+
"block_type": "shape_statement",
|
|
5
|
+
"block_color": "#ffa211",
|
|
6
|
+
"block_configs": [
|
|
7
|
+
{
|
|
8
|
+
"message": "blocksDemoKey",
|
|
9
|
+
"params": [
|
|
10
|
+
{
|
|
11
|
+
"name": "id",
|
|
12
|
+
"param_type": "input_value",
|
|
13
|
+
"data_type": "math_number",
|
|
14
|
+
"default": "9"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"block_code": ["demoMethod1({id})\n"]
|
|
20
|
+
}
|
|
21
|
+
]
|
package/configs/Main.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "demo",
|
|
3
|
-
"version": "1-0-0-test",
|
|
4
|
-
"description": "%{configDemoKey}"
|
|
5
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "demo",
|
|
3
|
+
"version": "1-0-0-test",
|
|
4
|
+
"description": "%{configDemoKey}"
|
|
5
|
+
}
|
package/configs/Scripts.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"script_name": "DemoScript",
|
|
4
|
-
"message": "%{scriptDemoKey}",
|
|
5
|
-
"script_code": "demoMethod1({id = 1})"
|
|
6
|
-
}
|
|
7
|
-
]
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"script_name": "DemoScript",
|
|
4
|
+
"message": "%{scriptDemoKey}",
|
|
5
|
+
"script_code": "demoMethod1({id = 1})"
|
|
6
|
+
}
|
|
7
|
+
]
|
package/configs/Toolbar.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "Toolbar",
|
|
3
|
-
"width": 800,
|
|
4
|
-
"height": 900
|
|
5
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "Toolbar",
|
|
3
|
+
"width": 800,
|
|
4
|
+
"height": 900
|
|
5
|
+
}
|
package/dpt.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{
|
|
2
|
-
"ip": "192.168.5.1",
|
|
3
|
-
"port": 22001
|
|
4
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"ip": "192.168.5.1",
|
|
3
|
+
"port": 22001
|
|
4
|
+
}
|
package/lua/control.lua
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
--- @module control
|
|
2
|
-
--- @description This is the control module for the plugin.
|
|
3
|
-
--- 该模块为插件的功能模块,用于实现各种控制功能。
|
|
4
|
-
|
|
5
|
-
local control = {}
|
|
6
|
-
|
|
7
|
-
control.controlMethod1 = function(params)
|
|
8
|
-
-- TODO 实现函数逻辑
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
control.controlMethod2 = function(params)
|
|
12
|
-
-- TODO 实现函数逻辑
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
control.controlMethod3 = function(params)
|
|
16
|
-
-- TODO 实现函数逻辑
|
|
17
|
-
end
|
|
18
|
-
|
|
1
|
+
--- @module control
|
|
2
|
+
--- @description This is the control module for the plugin.
|
|
3
|
+
--- 该模块为插件的功能模块,用于实现各种控制功能。
|
|
4
|
+
|
|
5
|
+
local control = {}
|
|
6
|
+
|
|
7
|
+
control.controlMethod1 = function(params)
|
|
8
|
+
-- TODO 实现函数逻辑
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
control.controlMethod2 = function(params)
|
|
12
|
+
-- TODO 实现函数逻辑
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
control.controlMethod3 = function(params)
|
|
16
|
+
-- TODO 实现函数逻辑
|
|
17
|
+
end
|
|
18
|
+
|
|
19
19
|
return control
|
package/lua/daemon.lua
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
--- @module daemon
|
|
2
|
-
--- @description This is the daemon module for the plugin.
|
|
3
|
-
--- 该模块插件的入口进程,在插件安装成功后自动执行该文件中的 EventLoop 方法,该方法会不断的执行,直到程序退出。
|
|
4
|
-
|
|
5
|
-
local mqtt = require('utils.mqtt')
|
|
6
|
-
|
|
7
|
-
local function handleInLoop()
|
|
8
|
-
local data = {}
|
|
9
|
-
mqtt.publish(data)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
local function EventLoop()
|
|
13
|
-
while true do
|
|
14
|
-
handleInLoop()
|
|
15
|
-
Wait(1000)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
local thread = systhread.create(EventLoop, 1)
|
|
20
|
-
thread:wait()
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
--- @module daemon
|
|
2
|
+
--- @description This is the daemon module for the plugin.
|
|
3
|
+
--- 该模块插件的入口进程,在插件安装成功后自动执行该文件中的 EventLoop 方法,该方法会不断的执行,直到程序退出。
|
|
4
|
+
|
|
5
|
+
local mqtt = require('utils.mqtt')
|
|
6
|
+
|
|
7
|
+
local function handleInLoop()
|
|
8
|
+
local data = {}
|
|
9
|
+
mqtt.publish(data)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
local function EventLoop()
|
|
13
|
+
while true do
|
|
14
|
+
handleInLoop()
|
|
15
|
+
Wait(1000)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
local thread = systhread.create(EventLoop, 1)
|
|
20
|
+
thread:wait()
|
|
21
|
+
|
|
22
|
+
|
package/lua/httpAPI.lua
CHANGED
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
--- @module httpAPI
|
|
2
|
-
--- @description This is the http module for the plugin.
|
|
3
|
-
--- 该模块为控制器处理插件的 http 请求提供接口
|
|
4
|
-
|
|
5
|
-
local control = require("control")
|
|
6
|
-
|
|
7
|
-
local httpModule = {}
|
|
8
|
-
|
|
9
|
-
--- This function will be called when plugin uninstalled
|
|
10
|
-
--- 插件卸载时执行该函数
|
|
11
|
-
httpModule.OnUninstall = function()
|
|
12
|
-
-- TODO 需要在插件卸载时执行的操作
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
--- This function will be called when plugin installed
|
|
16
|
-
--- 插件安装时自动执行该函数
|
|
17
|
-
httpModule.OnInstall = function()
|
|
18
|
-
-- TODO 需要在插件安装时执行的操作
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
--- This function will be called when plugin installed, this action will export some http method for device hotkey binding
|
|
22
|
-
--- 插件安装时自动执行该函数,该函数会导出一些的http方法,供设备热键绑定使用
|
|
23
|
-
httpModule.OnRegistHotKey = function()
|
|
24
|
-
-- 短按:可选 demoMethod1 demoMethod2 长按:可选 demoMethod3
|
|
25
|
-
return {press = {"demoMethod1", "demoMethod2"}, longPress = {"demoMethod3"}}
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
--- This method will be called when a http '/dobotPlus/[plugin name]_[plugin version]/demoMethod1' request arrived
|
|
29
|
-
--- The return value will response the http request, the return value is not necessory
|
|
30
|
-
--- @param params table
|
|
31
|
-
--- @return string The return value will response the http request, the return value is not necessory
|
|
32
|
-
--- 该方法会在http请求接收到后,自动执行,对应请求的 url为: http://<控制器ip>:<插件端口>/dobotPlus/[插件名]_[插件版本]/demoMethod1。
|
|
33
|
-
httpModule.demoMethod1 = function(params)
|
|
34
|
-
-- TODO 需要在接收到http请求后执行的操作
|
|
35
|
-
control.controlMethod1(params)
|
|
36
|
-
return {
|
|
37
|
-
--- Your responce data
|
|
38
|
-
status = true
|
|
39
|
-
}
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
--- This method will be called when a http '/dobotPlus/[plugin name]_[plugin version]/demoMethod2' request arrived
|
|
43
|
-
--- The return value will response the http request, the return value is not necessory
|
|
44
|
-
--- @param params table
|
|
45
|
-
--- @return string
|
|
46
|
-
httpModule.demoMethod2 = function(params)
|
|
47
|
-
control.controlMethod2(params)
|
|
48
|
-
return {
|
|
49
|
-
--- Your responce data
|
|
50
|
-
status = true
|
|
51
|
-
}
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
--- This method will be called when a http '/dobotPlus/[plugin name]_[plugin version]/demoMethod3' request arrived
|
|
55
|
-
--- The return value will response the http request, the return value is not necessory
|
|
56
|
-
--- @param params table
|
|
57
|
-
--- @return string The return value will response the http request, the return value is not necessory
|
|
58
|
-
httpModule.demoMethod3 = function(params)
|
|
59
|
-
control.controlMethod3(params)
|
|
60
|
-
return {
|
|
61
|
-
--- Your responce data
|
|
62
|
-
status = true
|
|
63
|
-
}
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
return httpModule
|
|
1
|
+
--- @module httpAPI
|
|
2
|
+
--- @description This is the http module for the plugin.
|
|
3
|
+
--- 该模块为控制器处理插件的 http 请求提供接口
|
|
4
|
+
|
|
5
|
+
local control = require("control")
|
|
6
|
+
|
|
7
|
+
local httpModule = {}
|
|
8
|
+
|
|
9
|
+
--- This function will be called when plugin uninstalled
|
|
10
|
+
--- 插件卸载时执行该函数
|
|
11
|
+
httpModule.OnUninstall = function()
|
|
12
|
+
-- TODO 需要在插件卸载时执行的操作
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
--- This function will be called when plugin installed
|
|
16
|
+
--- 插件安装时自动执行该函数
|
|
17
|
+
httpModule.OnInstall = function()
|
|
18
|
+
-- TODO 需要在插件安装时执行的操作
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
--- This function will be called when plugin installed, this action will export some http method for device hotkey binding
|
|
22
|
+
--- 插件安装时自动执行该函数,该函数会导出一些的http方法,供设备热键绑定使用
|
|
23
|
+
httpModule.OnRegistHotKey = function()
|
|
24
|
+
-- 短按:可选 demoMethod1 demoMethod2 长按:可选 demoMethod3
|
|
25
|
+
return {press = {"demoMethod1", "demoMethod2"}, longPress = {"demoMethod3"}}
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
--- This method will be called when a http '/dobotPlus/[plugin name]_[plugin version]/demoMethod1' request arrived
|
|
29
|
+
--- The return value will response the http request, the return value is not necessory
|
|
30
|
+
--- @param params table
|
|
31
|
+
--- @return string The return value will response the http request, the return value is not necessory
|
|
32
|
+
--- 该方法会在http请求接收到后,自动执行,对应请求的 url为: http://<控制器ip>:<插件端口>/dobotPlus/[插件名]_[插件版本]/demoMethod1。
|
|
33
|
+
httpModule.demoMethod1 = function(params)
|
|
34
|
+
-- TODO 需要在接收到http请求后执行的操作
|
|
35
|
+
control.controlMethod1(params)
|
|
36
|
+
return {
|
|
37
|
+
--- Your responce data
|
|
38
|
+
status = true
|
|
39
|
+
}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
--- This method will be called when a http '/dobotPlus/[plugin name]_[plugin version]/demoMethod2' request arrived
|
|
43
|
+
--- The return value will response the http request, the return value is not necessory
|
|
44
|
+
--- @param params table
|
|
45
|
+
--- @return string
|
|
46
|
+
httpModule.demoMethod2 = function(params)
|
|
47
|
+
control.controlMethod2(params)
|
|
48
|
+
return {
|
|
49
|
+
--- Your responce data
|
|
50
|
+
status = true
|
|
51
|
+
}
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
--- This method will be called when a http '/dobotPlus/[plugin name]_[plugin version]/demoMethod3' request arrived
|
|
55
|
+
--- The return value will response the http request, the return value is not necessory
|
|
56
|
+
--- @param params table
|
|
57
|
+
--- @return string The return value will response the http request, the return value is not necessory
|
|
58
|
+
httpModule.demoMethod3 = function(params)
|
|
59
|
+
control.controlMethod3(params)
|
|
60
|
+
return {
|
|
61
|
+
--- Your responce data
|
|
62
|
+
status = true
|
|
63
|
+
}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
return httpModule
|
package/lua/userAPI.lua
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
--- @module userAPI
|
|
2
|
-
--- @description This is the user API module for the plugin.
|
|
3
|
-
--- 该模块为脚本编程和积木编程提供插件接口
|
|
4
|
-
|
|
5
|
-
require("utils.await485")
|
|
6
|
-
local control = require("control")
|
|
7
|
-
|
|
8
|
-
local userApiModule = {}
|
|
9
|
-
|
|
10
|
-
--- This function will be called when you add it in the blockly programming or script programming
|
|
11
|
-
--- This function can be used in the httpAPI module also
|
|
12
|
-
---@param params table
|
|
13
|
-
function userApiModule.demoMethod1(params)
|
|
14
|
-
return control.controlMethod1(params)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
--- This function will be called when you add it in the blockly programming or script programming
|
|
18
|
-
--- This function can be used in the httpAPI module also
|
|
19
|
-
---@param params table
|
|
20
|
-
function userApiModule.demoMethod2(params)
|
|
21
|
-
return control.controlMethod2(params)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
--- This function will be called when you add it in the blockly programming or script programming
|
|
25
|
-
--- This function can be used in the httpAPI module also
|
|
26
|
-
---@param params table
|
|
27
|
-
function userApiModule.demoMethod3(params)
|
|
28
|
-
return control.controlMethod3(params)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
-- This function will be called when the plugin is installed
|
|
32
|
-
-- The export functions will be registered to the corresponding code block or script in blockly programming or script programming
|
|
33
|
-
-- 该函数会在插件安装后自动执行,其中 ExportFunction 函数会将第二个参数的方法导出给脚本编程和积木编程使用
|
|
34
|
-
-- 例如:ExportFunction('A', B) 会将当前模块中的 B 函数导出,并重命名为 'A'
|
|
35
|
-
-- 在脚本编程和积木编程中可以使用 A 来使用该函数
|
|
36
|
-
function userApiModule.OnRegist()
|
|
37
|
-
EcoLog(" --- OnRegist .... --- ")
|
|
38
|
-
-- 0. 接口导出
|
|
39
|
-
local isErr = ExportFunction("demoMethod1", userApiModule.demoMethod1) or
|
|
40
|
-
ExportFunction("demoMethod2", userApiModule.demoMethod2) or
|
|
41
|
-
ExportFunction("demoMethod3", userApiModule.demoMethod3)
|
|
42
|
-
-- 1. 错误的处理
|
|
43
|
-
if isErr then
|
|
44
|
-
EcoLog(" --- ERR to register .... --- ", isErr)
|
|
45
|
-
dobotTool.SetError(0)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
return userApiModule
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
--- @module userAPI
|
|
2
|
+
--- @description This is the user API module for the plugin.
|
|
3
|
+
--- 该模块为脚本编程和积木编程提供插件接口
|
|
4
|
+
|
|
5
|
+
require("utils.await485")
|
|
6
|
+
local control = require("control")
|
|
7
|
+
|
|
8
|
+
local userApiModule = {}
|
|
9
|
+
|
|
10
|
+
--- This function will be called when you add it in the blockly programming or script programming
|
|
11
|
+
--- This function can be used in the httpAPI module also
|
|
12
|
+
---@param params table
|
|
13
|
+
function userApiModule.demoMethod1(params)
|
|
14
|
+
return control.controlMethod1(params)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
--- This function will be called when you add it in the blockly programming or script programming
|
|
18
|
+
--- This function can be used in the httpAPI module also
|
|
19
|
+
---@param params table
|
|
20
|
+
function userApiModule.demoMethod2(params)
|
|
21
|
+
return control.controlMethod2(params)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
--- This function will be called when you add it in the blockly programming or script programming
|
|
25
|
+
--- This function can be used in the httpAPI module also
|
|
26
|
+
---@param params table
|
|
27
|
+
function userApiModule.demoMethod3(params)
|
|
28
|
+
return control.controlMethod3(params)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
-- This function will be called when the plugin is installed
|
|
32
|
+
-- The export functions will be registered to the corresponding code block or script in blockly programming or script programming
|
|
33
|
+
-- 该函数会在插件安装后自动执行,其中 ExportFunction 函数会将第二个参数的方法导出给脚本编程和积木编程使用
|
|
34
|
+
-- 例如:ExportFunction('A', B) 会将当前模块中的 B 函数导出,并重命名为 'A'
|
|
35
|
+
-- 在脚本编程和积木编程中可以使用 A 来使用该函数
|
|
36
|
+
function userApiModule.OnRegist()
|
|
37
|
+
EcoLog(" --- OnRegist .... --- ")
|
|
38
|
+
-- 0. 接口导出
|
|
39
|
+
local isErr = ExportFunction("demoMethod1", userApiModule.demoMethod1) or
|
|
40
|
+
ExportFunction("demoMethod2", userApiModule.demoMethod2) or
|
|
41
|
+
ExportFunction("demoMethod3", userApiModule.demoMethod3)
|
|
42
|
+
-- 1. 错误的处理
|
|
43
|
+
if isErr then
|
|
44
|
+
EcoLog(" --- ERR to register .... --- ", isErr)
|
|
45
|
+
dobotTool.SetError(0)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
return userApiModule
|
|
50
|
+
|
|
51
|
+
|
package/lua/utils/mqtt.lua
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
local jsonLuaUtils = require("luaJson")
|
|
2
|
-
local mqttFunc = require("libplugin_eco")
|
|
3
|
-
|
|
4
|
-
local MQTT_PUBLISH_TOPIC = "$PLUGIN_MSG_TOPIC$"
|
|
5
|
-
local connectId = "$PLUGIN_NAME$"
|
|
6
|
-
|
|
7
|
-
mqttFunc.MQTTCreate(connectId,"127.0.0.1",1883,600)
|
|
8
|
-
mqttFunc.MQTTConnect(connectId)
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
mqtt = mqttFunc,
|
|
12
|
-
--- 发布数据到指定的 MQTT 主题。
|
|
13
|
-
--- @param data table 要发布的数据,数据将被编码为 JSON 格式。
|
|
14
|
-
publish = function(data)
|
|
15
|
-
mqttFunc.MQTTPublish(connectId, MQTT_PUBLISH_TOPIC, jsonLuaUtils.encode(data), 0, false)
|
|
16
|
-
end
|
|
1
|
+
local jsonLuaUtils = require("luaJson")
|
|
2
|
+
local mqttFunc = require("libplugin_eco")
|
|
3
|
+
|
|
4
|
+
local MQTT_PUBLISH_TOPIC = "$PLUGIN_MSG_TOPIC$"
|
|
5
|
+
local connectId = "$PLUGIN_NAME$"
|
|
6
|
+
|
|
7
|
+
mqttFunc.MQTTCreate(connectId,"127.0.0.1",1883,600)
|
|
8
|
+
mqttFunc.MQTTConnect(connectId)
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
mqtt = mqttFunc,
|
|
12
|
+
--- 发布数据到指定的 MQTT 主题。
|
|
13
|
+
--- @param data table 要发布的数据,数据将被编码为 JSON 格式。
|
|
14
|
+
publish = function(data)
|
|
15
|
+
mqttFunc.MQTTPublish(connectId, MQTT_PUBLISH_TOPIC, jsonLuaUtils.encode(data), 0, false)
|
|
16
|
+
end
|
|
17
17
|
}
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
local NumberConversion = {}
|
|
2
|
-
|
|
3
|
-
-- 将二进制字符串转换为十进制数
|
|
4
|
-
function NumberConversion.binaryToDecimal(binaryStr)
|
|
5
|
-
return tonumber(binaryStr, 2)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
-- 将十进制数转换为二进制字符串
|
|
9
|
-
function NumberConversion.decimalToBinary(dec)
|
|
10
|
-
local binaryStr = ""
|
|
11
|
-
while dec > 0 do
|
|
12
|
-
local remainder = dec % 2
|
|
13
|
-
binaryStr = remainder .. binaryStr
|
|
14
|
-
dec = math.floor(dec / 2)
|
|
15
|
-
end
|
|
16
|
-
return binaryStr == "" and "0" or binaryStr
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
-- 将十六进制字符串转换为十进制数
|
|
20
|
-
function NumberConversion.hexToDecimal(hexStr)
|
|
21
|
-
return tonumber(hexStr, 16)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
-- 将十进制数转换为十六进制字符串
|
|
25
|
-
function NumberConversion.decimalToHex(dec)
|
|
26
|
-
return string.format("%X", dec)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
-- 将二进制字符串转换为十六进制字符串
|
|
30
|
-
function NumberConversion.binaryToHex(binaryStr)
|
|
31
|
-
local dec = NumberConversion.binaryToDecimal(binaryStr)
|
|
32
|
-
return NumberConversion.decimalToHex(dec)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
-- 将十六进制字符串转换为二进制字符串
|
|
36
|
-
function NumberConversion.hexToBinary(hexStr)
|
|
37
|
-
local dec = NumberConversion.hexToDecimal(hexStr)
|
|
38
|
-
return NumberConversion.decimalToBinary(dec)
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
return NumberConversion
|
|
1
|
+
local NumberConversion = {}
|
|
2
|
+
|
|
3
|
+
-- 将二进制字符串转换为十进制数
|
|
4
|
+
function NumberConversion.binaryToDecimal(binaryStr)
|
|
5
|
+
return tonumber(binaryStr, 2)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
-- 将十进制数转换为二进制字符串
|
|
9
|
+
function NumberConversion.decimalToBinary(dec)
|
|
10
|
+
local binaryStr = ""
|
|
11
|
+
while dec > 0 do
|
|
12
|
+
local remainder = dec % 2
|
|
13
|
+
binaryStr = remainder .. binaryStr
|
|
14
|
+
dec = math.floor(dec / 2)
|
|
15
|
+
end
|
|
16
|
+
return binaryStr == "" and "0" or binaryStr
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
-- 将十六进制字符串转换为十进制数
|
|
20
|
+
function NumberConversion.hexToDecimal(hexStr)
|
|
21
|
+
return tonumber(hexStr, 16)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
-- 将十进制数转换为十六进制字符串
|
|
25
|
+
function NumberConversion.decimalToHex(dec)
|
|
26
|
+
return string.format("%X", dec)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
-- 将二进制字符串转换为十六进制字符串
|
|
30
|
+
function NumberConversion.binaryToHex(binaryStr)
|
|
31
|
+
local dec = NumberConversion.binaryToDecimal(binaryStr)
|
|
32
|
+
return NumberConversion.decimalToHex(dec)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
-- 将十六进制字符串转换为二进制字符串
|
|
36
|
+
function NumberConversion.hexToBinary(hexStr)
|
|
37
|
+
local dec = NumberConversion.hexToDecimal(hexStr)
|
|
38
|
+
return NumberConversion.decimalToBinary(dec)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
return NumberConversion
|