-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_rx.py
More file actions
executable file
·82 lines (63 loc) · 2.27 KB
/
test_rx.py
File metadata and controls
executable file
·82 lines (63 loc) · 2.27 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
import sys
class OOKParser:
# Generic ASK/OOK parser for 433MHz keyfobs
# Assumption: every bit is composed of two level transitions
name = ""
# bitseq LH = bit is formed by a transition to low, then a transition to high
# and first transition is a delimiter
# Chirp examples: 001=1, 011=0
# bitseq HL = bit is formed by a transition to high, then a transition to low
# and last transition is a delimiter
# Chirp examples: 1110=1, 1000=0
bitseq = "LH"
# bit1 LS = bit 1 is formed by a long-timed level followed by a short-timed level
# (and bit 0 is the opposite)
# Chirp examples: 1110=1 and 1000=0, or 001=1 and 011=0
# bit1 SL = bit 1 is formed by a short-timed level followed by a long-timed level
# Chirp examples: 1110=0 and 1000=1, or 001=0 and 011=1
bit1 = "LS"
def __init__(self, sequence):
self.sequence = sequence[:]
self.code = 0
def res(self):
return "%s:%d" % (self.name, self.code)
# Parsing routine
def parse(self):
if len(self.sequence) != self.exp_sequence_len:
return False
lh = (self.bitseq == "LH") and 1 or 0
ls = (self.bitseq == "LS") and 1 or 0
bitcount = len(self.sequence) // 2
self.code = 0
for i in range(0, bitcount):
lsbit = (self.sequence[i*2+lh][1] > self.sequence[i*2+1+lh][1]) and 1 or 0
self.code = (self.code << 1) | (lsbit ^ ls)
return True
class HT6P20(OOKParser):
name = "HT6P20"
exp_sequence_len = 57
bitseq = "LH" # low then high (011, 001)
bit1 = "LS" # long then short (001)
class EV1527(OOKParser):
name = "EV1527"
exp_sequence_len = 49
bitseq = "HL" # high then low (1000 and 1110)
bit1 = "LS" # long then short (1110)
parsers = [EV1527, HT6P20]
def parse(sequence):
for parser_class in parsers:
parser = parser_class(sequence)
if parser.parse():
print(parser.res())
break
else:
print("Failed to parse")
for row in sys.stdin.readlines():
row = row.strip()
if not row:
continue
row = eval(row)
print("----------------")
print(row)
parse(row)