RaspyRFM/intertechno.py

92 lines
2 KiB
Python
Raw Normal View History

2017-03-05 22:42:34 +01:00
#!/usr/bin/env python2.7
2018-02-08 00:07:24 +01:00
import rfm69
from rfm69 import Rfm69
2017-03-19 20:39:53 +01:00
import xx2262
2018-02-08 00:07:24 +01:00
import it32
2017-03-05 22:42:34 +01:00
import sys
2017-03-19 20:39:53 +01:00
import re
2017-03-05 22:42:34 +01:00
2017-03-19 20:39:53 +01:00
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():
2018-02-08 00:07:24 +01:00
print "usage:"
print "intertechno <HOUSECODE A-P> <GROUP 1-4> <CHANNEL 1-4> on|off" #12-digit code 12 * ['0' | '1' | 'f']
2018-04-23 23:09:32 +02:00
print "intertechno <12 symbols tristate code>"
2018-02-08 00:07:24 +01:00
print "intertechno <26 bit address> <1 goup bit> <4 bit unit> on|off"
2018-04-23 23:09:32 +02:00
print "intertechno <32 bit code>"
2018-02-08 00:07:24 +01:00
print "Examples:"
print "intertechno A 1 1 on"
2018-04-23 23:09:32 +02:00
print "intertechno 0000FFFF0FFF"
2019-12-30 01:27:52 +01:00
print "intertechno 11110000111100001111000010 0 1110 on"
print "intertechno 11110000111100001111000010010000"
2017-03-05 22:42:34 +01:00
sys.exit(1)
2018-02-08 00:07:24 +01:00
if __name__ == "__main__":
import sys
cmd = ""
data = None
for i in range(1, len(sys.argv)):
cmd += " " + sys.argv[i]
cmd = cmd.strip()
2017-03-19 20:39:53 +01:00
2018-02-08 00:07:24 +01:00
if re.match('^[01]{32}$', cmd) is not None:
data = it32.MakeFrame(cmd, 5)
datarate = 4
2017-03-19 20:39:53 +01:00
2018-02-08 00:07:24 +01:00
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
2017-03-19 20:39:53 +01:00
2018-02-08 00:07:24 +01:00
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)
2017-03-19 20:39:53 +01:00
2018-04-23 23:09:32 +02:00
ch = ord(cmd[4]) - 1
2018-02-08 00:07:24 +01:00
itstr += encodeBits(ch, 2, '0', False)
2017-03-19 20:39:53 +01:00
2018-04-23 23:09:32 +02:00
group = ord(cmd[2]) - 1
2018-02-08 00:07:24 +01:00
itstr += encodeBits(group, 2, '0', False)
2017-03-19 20:39:53 +01:00
2018-02-08 00:07:24 +01:00
itstr += '0F'
2017-03-19 20:39:53 +01:00
2018-02-08 00:07:24 +01:00
if cmd[-2:] == 'on':
itstr += 'FF'
else:
itstr += 'F0'
2018-04-23 23:09:32 +02:00
2018-02-08 00:07:24 +01:00
data = xx2262.MakeFrame(itstr, 5)
datarate = 2.66666666
2017-03-19 20:39:53 +01:00
2018-02-08 00:07:24 +01:00
if re.match('^[01Ff]{12}$', cmd) is not None:
data = xx2262.MakeFrame(cmd, 5)
datarate = 2.66666666
2017-03-19 20:39:53 +01:00
2018-02-08 00:07:24 +01:00
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)
2017-03-19 20:39:53 +01:00
else:
2018-02-08 00:07:24 +01:00
usage()