如果内容不一致就上报到服务器 那个uart我看了很久没搞明白!!!上代码!!
local uartID = 2
local function taskRead()
local cacheData = ""
while true do
local s = uart.read(uartID,"*l")
if s == "" then
uart.on(uartID,"receive",function() sys.publish("UART_RECEIVE") end)
if not sys.waitUntil("UART_RECEIVE",50) then
sys.publish("UART_RECV_DATA",cacheData:sub(1,1024))
cacheData = cacheData:sub(1025,-1)
end
uart.on(uartID,"receive")
else
cacheData = cacheData..s
if cacheData:len()>=1024 then
sys.publish("UART_RECV_DATA",cacheData:sub(1,1024))
cacheData = cacheData:sub(1025,-1)
end
end
end
end
local function socketRecvData(data)
uart.write(uartID,data)
end
pm.wake("mcuUart.lua")
uart.setup(uartID,9600,8,uart.PAR_NONE,uart.STOP_1)
sys.taskInit(taskRead)
sys.subscribe("SOCKET_RECV_DATA",socketRecvData)