From a0a25af39a75c1ad3a50b3bd0a6501784911d29e Mon Sep 17 00:00:00 2001 From: "S. Seegel" Date: Sun, 19 Mar 2017 20:39:53 +0100 Subject: [PATCH] more general xx2262 --- intertechno.py | 81 +++++++++++++++++++++++++++++++------------------- xx2262.py | 47 +++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+), 31 deletions(-) create mode 100755 xx2262.py diff --git a/intertechno.py b/intertechno.py index 624fce0..59c8914 100755 --- a/intertechno.py +++ b/intertechno.py @@ -1,39 +1,58 @@ #!/usr/bin/env python2.7 -from rfm69 import Rfm69 -import rfm69 +import xx2262 import sys -import time +import re -if len(sys.argv) != 2: - print "usage: intertechno " #12-digit code 12 * ['0' | '1' | 'f'] - print "Example: intertechno 0FF0F0F00FF0" +def encodeBits(val, num, pol, inv): + result = '' + for i in range(num): + if (val & 0x01) ^ inv: + result += 'F' + else: + result += pol + val >>= 1 + return result + +def usage(): + print "usage: intertechno on|off" #12-digit code 12 * ['0' | '1' | 'f'] + print "Example: intertechno A 1 1 on" sys.exit(1) -rfm = Rfm69() -rfm.SetParams( - Freq = 433.92, - Datarate = 2.666666, - TXPower = 13, - ModulationType = rfm69.OOK, - SyncPattern = [] - ) +if len(sys.argv) != 5: + usage() -#Frame generation -def MakeFrame(code, rep): - data = [0x80, 0x00, 0x00, 0x00] #sync - b = 0; - data = [] - for c in code: - if c == '0': - data.append(0x88) - elif c == '1': - data.append(0xEE) - elif c == 'F' or c == 'f': - data.append(0x8E) - data += [0x80, 0x00, 0x00, 0x00] #sync - - return data * rep +itstr = '' -data = MakeFrame(sys.argv[1], 8) -rfm.SendPacket(data) +if re.match('[A-P]$', sys.argv[1]) is None: + print "Invalid housecode" + usage() + +housecode = ord(sys.argv[1][0]) - ord('A') +itstr += encodeBits(housecode, 4, '0', False) + +if re.match('[1-4]$', sys.argv[3]) is None: + print "Invalid channel" + usage() + +ch = ord(sys.argv[3][0]) - ord('1') +itstr += encodeBits(ch, 2, '0', False) + +if re.match('[1-4]$', sys.argv[2]) is None: + print "Invalid group" + usage() + +group = ord(sys.argv[2][0]) - ord('1') +itstr += encodeBits(group, 2, '0', False) + +itstr += '0F' + +if sys.argv[4] == 'on': + itstr += 'FF' +else: + itstr += 'F0' + +print "Sending", itstr + +data = xx2262.MakeFrame(itstr, 8) +xx2262.rfm.SendPacket(data) diff --git a/xx2262.py b/xx2262.py new file mode 100755 index 0000000..1471194 --- /dev/null +++ b/xx2262.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python2.7 + +from rfm69 import Rfm69 +import rfm69 +import re + +rfm = Rfm69() +rfm.SetParams( + Freq = 433.92, + Datarate = 2.666666, + TXPower = 13, + ModulationType = rfm69.OOK, + SyncPattern = [] + ) + +#Frame generation +def MakeFrame(code, rep): + data = [0x80, 0x00, 0x00, 0x00] #sync + b = 0; + data = [] + for c in code: + if c == '0': + data.append(0x88) + elif c == '1': + data.append(0xEE) + elif c == 'F' or c == 'f': + data.append(0x8E) + data += [0x80, 0x00, 0x00, 0x00] #sync + + return data * rep + +def usage(): + print "usage: xx2262.py " #12-digit code 12 * ['0' | '1' | 'f'] + print "Example: sudo ./intertechno.py 0FF0F0F00FF0" + sys.exit(1) + +if __name__ == "__main__": + import sys + if len(sys.argv) != 2: + usage() + + if re.match('[01fF]{12}$', sys.argv[1]) is None: + print "Invalid code" + usage() + + data = MakeFrame(sys.argv[1], 5) + rfm.SendPacket(data)