]> vault307.fbx.one Git - ir_decoder.git/blob - validate_code.py
ir decoder
[ir_decoder.git] / validate_code.py
1 class InvalidCodeException(Exception):
2 pass
3
4
5 def validate_code(code):
6 if len(code) < 32:
7 raise InvalidCodeException
8
9 if len(code) > 32:
10 raise InvalidCodeException
11
12 # check 8-bit device address
13 # following 8-bits have to be a logical inverse of the device address
14 for i in range(0, 8):
15 if code[i] == code[i + 8]:
16 raise InvalidCodeException
17
18 # check 8-bit command
19 # following 8-bits have to be a logical inverse of the command
20 for i in range(16, 24):
21 if code[i] == code[i + 8]:
22 raise InvalidCodeException