more general xx2262

This commit is contained in:
S. Seegel 2017-03-19 20:39:53 +01:00
parent 4e848b1f1f
commit a0a25af39a
2 changed files with 97 additions and 31 deletions

View file

@ -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 <CODE>" #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 <HOUSECODE A-P> <GROUP 1-4> <CHANNEL 1-4> 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)

47
xx2262.py Executable file
View file

@ -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 <CODE>" #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)