Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create auto-response.lua #128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions scripts/auto-response.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
--注册串口接收函数
uartReceive = function (data)
sys.publish("UART",data)--发布消息
end

--自动回复
sys.taskInit(function()
while true do
--等待消息,超时1000ms
local r,udata = sys.waitUntil("UART",1000)
if r then
local receiveHex=string.toHex(udata)
log.info("收到:",receiveHex)

-- 由于没有API获取快捷发送列表数量,这里写100或者更大数字,通过判断跳出
for i = 1, 100 do
local data = apiQuickSendList(i, false)
if data and #data>0 then
if data:sub(1,1) == "H" then
if data:find(receiveHex) then
local tmpData = data:gsub('H'..receiveHex..'~', '')
log.info("发送", apiSendUartData(tmpData:fromHex()), tmpData)
break
end
end
else
log.info("Current Complet")
break
end
end
end
end
end)