summaryrefslogtreecommitdiffstats
path: root/mdb/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'mdb/utils.py')
-rw-r--r--mdb/utils.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/mdb/utils.py b/mdb/utils.py
new file mode 100644
index 0000000..37459fa
--- /dev/null
+++ b/mdb/utils.py
@@ -0,0 +1,10 @@
+from functools import reduce
+
+def compute_chk(data):
+ return reduce(lambda a, b: (a+b)%256, data, 0)
+
+def compute_checksum(cmd, data):
+ return compute_chk(bytearray([cmd]) + data)
+
+def bcd_decode(b):
+ return 10 * ((b & 0xf0) >> 4) + (b & 0x0f)