From a93b8e5bb3c0749a7e2909b9255d8026cc064c61 Mon Sep 17 00:00:00 2001 From: "S. Seegel" Date: Thu, 8 Feb 2018 00:07:24 +0100 Subject: [PATCH] add intertechno 32 support --- intertechno.py | 91 +++++++++++++++++++++++++++++++++----------------- it32.py | 10 ++++++ rfm69.py | 10 ++++-- xx2262.py | 19 ++++++----- 4 files changed, 89 insertions(+), 41 deletions(-) create mode 100644 it32.py diff --git a/intertechno.py b/intertechno.py index 59c8914..53660bb 100755 --- a/intertechno.py +++ b/intertechno.py @@ -1,6 +1,9 @@ #!/usr/bin/env python2.7 +import rfm69 +from rfm69 import Rfm69 import xx2262 +import it32 import sys import re @@ -15,44 +18,72 @@ def encodeBits(val, num, pol, inv): return result def usage(): - print "usage: intertechno on|off" #12-digit code 12 * ['0' | '1' | 'f'] - print "Example: intertechno A 1 1 on" + print "usage:" + print "intertechno on|off" #12-digit code 12 * ['0' | '1' | 'f'] + print "OR" + print "intertechno <26 bit address> <1 goup bit> <4 bit unit> on|off" + print "Examples:" + print "intertechno A 1 1 on" + print "interttechno 11110000111100001111000010 0 1110 on" sys.exit(1) -if len(sys.argv) != 5: - usage() +if __name__ == "__main__": + import sys + cmd = "" + data = None + for i in range(1, len(sys.argv)): + cmd += " " + sys.argv[i] + cmd = cmd.strip() + daatarate = None -itstr = '' + if re.match('^[01]{32}$', cmd) is not None: + data = it32.MakeFrame(cmd, 5) + datarate = 4 -if re.match('[A-P]$', sys.argv[1]) is None: - print "Invalid housecode" - usage() + if re.match('^[01]{26} [01] [01]{4} (on|off)$', cmd) is not None: + tmp = cmd[0:26] + cmd[27] + if cmd[-2:] == 'on': + tmp += '1' + else: + tmp += '0' + tmp += cmd[29:33] + data = it32.MakeFrame(tmp, 5) + datarate = 1/275E-6/1000 -housecode = ord(sys.argv[1][0]) - ord('A') -itstr += encodeBits(housecode, 4, '0', False) + if re.match('^[A-P] [1-4] [1-4] (on|off)$', cmd) is not None: + housecode = ord(cmd[0]) - ord('A') + itstr = '' + itstr += encodeBits(housecode, 4, '0', False) -if re.match('[1-4]$', sys.argv[3]) is None: - print "Invalid channel" - usage() + ch = ord(cmd[2]) - ord('1') + itstr += encodeBits(ch, 2, '0', False) -ch = ord(sys.argv[3][0]) - ord('1') -itstr += encodeBits(ch, 2, '0', False) + group = ord(cmd[4]) - ord('1') + itstr += encodeBits(group, 2, '0', False) -if re.match('[1-4]$', sys.argv[2]) is None: - print "Invalid group" - usage() + itstr += '0F' -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' + if cmd[-2:] == 'on': + itstr += 'FF' + else: + itstr += 'F0' -print "Sending", itstr + data = xx2262.MakeFrame(itstr, 5) + datarate = 2.66666666 -data = xx2262.MakeFrame(itstr, 8) -xx2262.rfm.SendPacket(data) + if re.match('^[01Ff]{12}$', cmd) is not None: + data = xx2262.MakeFrame(cmd, 5) + datarate = 2.66666666 + +if data is not None: + rfm = Rfm69() + rfm.SetParams( + Freq = 433.92, + Datarate = datarate, #2.666666, + TXPower = 13, + ModulationType = rfm69.OOK, + SyncPattern = [] + ) + rfm.SendPacket(data) +else: + usage() diff --git a/it32.py b/it32.py new file mode 100644 index 0000000..b453b3e --- /dev/null +++ b/it32.py @@ -0,0 +1,10 @@ + +def MakeFrame(code, rep): + data = [0x08, 0x00] #sync + for c in code: + if c == '0': + data.append(0xA0) + elif c == '1': + data.append(0x82) + data += [0x80, 0x00, 0x00, 0x00, 0x00] + return data * rep diff --git a/rfm69.py b/rfm69.py index 7795659..c9544ab 100644 --- a/rfm69.py +++ b/rfm69.py @@ -156,7 +156,7 @@ class Rfm69: config[RegOokPeak] = 0x40 config[RegOokAvg] = 0x80 config[RegOokFix] = 0x06 - config[RegAfcFei] = 0x10 + config[RegAfcFei] = 1<<3 | 1<<2 config[RegAfcMsb] = 0x00 config[RegAfcLsb] = 0x00 config[RegFeiMsb] = 0x00 @@ -362,7 +362,13 @@ class Rfm69: result = [] for x in range(length): result.append(self.ReadReg(RegFifo)) + + afc = self.ReadReg(RegAfcMsb) << 8 + afc = afc | self.ReadReg(RegAfcLsb) + if afc >= 0x8000: + afc = afc - 0x10000 + self.__SetMode(MODE_STDBY) - return (result, rssi) + return (result, rssi, afc) diff --git a/xx2262.py b/xx2262.py index 1471194..14320db 100755 --- a/xx2262.py +++ b/xx2262.py @@ -4,15 +4,6 @@ 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 @@ -44,4 +35,14 @@ if __name__ == "__main__": usage() data = MakeFrame(sys.argv[1], 5) + + rfm = Rfm69() + rfm.SetParams( + Freq = 433.92, + Datarate = 2.666666, + TXPower = 13, + ModulationType = rfm69.OOK, + SyncPattern = [] + ) + rfm.SendPacket(data)