From 81589c8f2fa87dc55f23ff6c1cf25b6e789b6ad0 Mon Sep 17 00:00:00 2001 From: Jerry Cheng <12589432+Lag1024@users.noreply.github.com> Date: Sat, 15 Apr 2023 19:40:47 +0800 Subject: [PATCH] Create auto-response.lua MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 使用快捷发送编辑带‘~’字符的固定格式,字符可根据需要自定义调整,需要在head.lua增加方法重载,返回转换前的数据,用HEX状态做为生效和不生效的判断状态 apiQuickSendList = function (id, isTrans) if isTrans then return apiQuickSendList(id) else return oldapiQuickSendList(id) end end --- scripts/auto-response.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 scripts/auto-response.lua diff --git a/scripts/auto-response.lua b/scripts/auto-response.lua new file mode 100644 index 00000000..945a8378 --- /dev/null +++ b/scripts/auto-response.lua @@ -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)