-
Notifications
You must be signed in to change notification settings - Fork 1
/
testMTRFlisten.lua
58 lines (57 loc) · 1.5 KB
/
testMTRFlisten.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
do
function setvars()
answer = {}
crcR = 0
gotRAW = {}
counter = 1
startUART = false
end
setvars()
function ptrANSW()
tmr.create():alarm(100, 0, function()
print(answer.raw)
tmr.create():alarm(100, 0, function()
setvars()
gotMTRF()
end)
end)
end
function gotMTRF()
uart.alt(1)
uart.setup(0, 9600, 8, uart.PARITY_NONE, uart.STOPBITS_1, 0)
uart.on("data",1,
function(data)
local bt = string.byte(data, 1) or 0
if (startUART == false and bt == 0xAD) or startUART == true then
startUART = true
table.insert(gotRAW, bt)
if counter < 16 then
crcR = crcR + bt
end
counter = counter + 1
end
if counter == 18 then
if gotRAW[1] == 0xAD and gotRAW[17] == 0xAE and (gotRAW[16]) == bit.band(crcR, 0xFF) then
local s = ""
for k, v in ipairs(gotRAW) do
s = s..k..":"..string.format("%d", v).." "
end
answer.raw = s
-- uart.on("data")
uart.alt(0)
uart.setup(0, 115200, 8, uart.PARITY_NONE, uart.STOPBITS_1, 1)
ptrANSW()
end
end
end, 0)
end
gotMTRF()
--
tmr.create():alarm(300000, 0, function()
uart.on("data")
uart.alt(0)
uart.setup(0, 115200, 8, uart.PARITY_NONE, uart.STOPBITS_1, 1)
print("Stop The Listening!")
end)
--]]
end