summaryrefslogtreecommitdiff
path: root/pm1006.lua
diff options
context:
space:
mode:
Diffstat (limited to 'pm1006.lua')
-rw-r--r--pm1006.lua20
1 files changed, 20 insertions, 0 deletions
diff --git a/pm1006.lua b/pm1006.lua
new file mode 100644
index 0000000..1aeed17
--- /dev/null
+++ b/pm1006.lua
@@ -0,0 +1,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