blob: 1aeed17b999bfccc39f5dacc575bca5c92dc7bd3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
local pm1006 = {}
function pm1006.parse_frame(data)
if string.byte(data, 1) ~= 0x16 or string.byte(data, 2) ~= 0x11 or string.byte(data, 3) ~= 0x0b then
-- invalid header
return nil
end
local checksum = 0
for i = 1, 20 do
checksum = (checksum + string.byte(data, i)) % 256
end
if checksum ~= 0 then
-- invalid checksum
return nil
end
local pm2_5 = string.byte(data, 6) * 256 + string.byte(data, 7)
return pm2_5
end
return pm1006
|