View difference between Paste ID: JbhU1Qhm and XGPUy561
SHOW: | | - or go back to the newest paste.
1
#!/usr/bin/python
2
# -*- coding: UTF-8 -*-
3
# Contec CMS 50F firmware 3.7 sample duration test
4
5
6
data = [
7
dict(a='08 80 80 80 a4 80 80 80', l=6),
8
dict(a='08 80 80 80 d2 80 80 80', l=14),
9
dict(a='08 80 80 80 c8 80 80 80', l=12),
10
dict(a='08 84 80 80 ca 80 80 80', l=34),
11
dict(a='08 80 80 80 a2 80 80 80', l=6),
12
dict(a='08 80 80 80 a4 81 80 80', l=49),
13
dict(a='08 84 80 80 98 80 80 80', l=26),
14
dict(a='08 84 80 80 c2 80 80 80', l=33),
15
dict(a='08 84 80 80 d2 84 80 80', l=206),
16
dict(a='08 84 80 80 aa 81 80 80', l=71),
17
dict(a='08 80 80 80 90 80 80 80', l=3),
18
dict(a='08 84 80 80 84 80 80 80', l=22),
19
dict(a='08 84 80 80 c0 93 80 80', l=843)
20
];
21
22
print data
23
24
for entry in data:
25
	d=entry['a'].replace(' ', '').decode("hex")
26
	bytes = [ord(d[i]) for i in range(0, len(d) - 1)]
27
	print bytes
28
29-
	duration = ( ( (bytes[1] & 4) << 5)  | (bytes[4] ^ 0x80) | ((bytes[5] ^ 0x80) << 8)) / 4;
29+
	duration = ( ( (bytes[1] & 4) << 5)  | (bytes[4] ^ 0x80) | ((bytes[5] ^ 0x80) << 8));
30
31-
	print "d: %d l: %d" % (duration, entry['l'] * 3 / 2)
31+
	bit = duration % 2;
32
	duration /= 2;
33
34
	print "d: %d l: %d b: %d" % (duration, entry['l'] * 3, bit)