rewrite Emylo & voltcraft

This commit is contained in:
S. Seegel 2020-12-04 02:00:11 +01:00
parent a79cca2d1f
commit 95d94586db
2 changed files with 71 additions and 51 deletions

View file

@ -357,8 +357,6 @@ class Emylo(PWM1):
if self.__keys[k] == symbols[-4:]: if self.__keys[k] == symbols[-4:]:
key = k key = k
break break
print(k)
print(symbols[-4:])
if key is None: if key is None:
return return
@ -411,17 +409,22 @@ class FS20(RcProtocol):
return self._build_frame(symbols, timebase, repetitions) return self._build_frame(symbols, timebase, repetitions)
def decode(self, pulsetrain): def decode(self, pulsetrain):
code, tb, rep = self._decode_symbols(pulsetrain[0:-2]) symbols, tb, rep = self._decode_symbols(pulsetrain[0:-2])
print(code) if symbols:
if code:
params = { params = {
"house": int(code[13:21] + code[22:30] , 2), "id": int(symbols[13:21] + symbols[22:30], 2),
"unit": int(code[31:39], 2) + 1, "unit": int(symbols[31:39], 2) + 1,
"command": int(code[40:48], 2), "command": int(symbols[40:48], 2),
} }
return self._name, params, tb, rep return self._name, params, tb, rep
class Voltcraft(RcProtocol): class Voltcraft(RcProtocol):
'''
PPM: Pulse Position Modulation
Pulse in middle of a symbol: 0, end of symbol: 1
Used by Voltcraft RC30
'''
__commands = {0: "off", 1: "alloff", 2: "on", 3: "allon", 5: "dimup", 7: "dimdown"}
def __init__(self): def __init__(self):
self._name = "voltcraft" self._name = "voltcraft"
self._timebase = 600 self._timebase = 600
@ -431,44 +434,54 @@ class Voltcraft(RcProtocol):
'0': [1, 2], '0': [1, 2],
'1': [2, 1], '1': [2, 1],
} }
self._header = [1]
self._footer = [132]
self.params = [
('i', 'id'),
('u', 'unit'),
('a', 'command')
]
RcProtocol.__init__(self) RcProtocol.__init__(self)
self._parser.add_argument("-i", "--id", type=int, required=True)
self._parser.add_argument("-u", "--unit", type=int, required=True)
self._parser.add_argument("-s", "--state", type=int, required=True)
def decode(self, pulsetrain): def encode(self, params, timebase=None, repetitions=None):
code, tb, rep = self._decode_symbols(pulsetrain[1:-1]) cmd = None
if code: for k in self.__commands:
return { if self.__commands[k] == params["command"]:
"protocol": self._name, cmd = k
"code": code, break
"timebase": tb,
"id": int(code[0:12][::-1], 2),
"unit": int(code[12:14][::-1], 2) + 1,
"state": int(code[14:17][::-1], 2) #0=off, 1=alloff, 2=on, 3=allon, 5=bright, 7=dim
}, rep
def encode(self, args): if not (cmd in [0, 2]):
if not (args.state in [0, 2]):
unit = 3 unit = 3
else: else:
unit = args.unit -1 unit = int(params["unit"])-1
symbols = "{:012b}".format(args.id)[::-1]
symbols = "{:012b}".format(int(params["id"]))[::-1]
symbols += "{:02b}".format(unit)[::-1] symbols += "{:02b}".format(unit)[::-1]
symbols += "{:03b}".format(args.state)[::-1] symbols += "{:03b}".format(cmd)[::-1]
symbols += "0" symbols += "0"
symbols += "1" if (symbols[12] == "1") ^ (symbols[14] == "1") ^ (symbols[16] == "1") else "0" symbols += "1" if (symbols[12] == "1") ^ (symbols[14] == "1") ^ (symbols[16] == "1") else "0"
symbols += "1" if (symbols[13] == "1") ^ (symbols[15] == "1") ^ (symbols[17] == "1") else "0" symbols += "1" if (symbols[13] == "1") ^ (symbols[15] == "1") ^ (symbols[17] == "1") else "0"
self._reset() return self._build_frame(symbols, timebase, repetitions)
self._add_pulses([1])
self._add_symbols(symbols)
self._add_pulses([132])
self._add_finish()
return self._ookdata, self._timebase, self._repetitions
class PDM32(RcProtocol): def decode(self, pulsetrain):
symbols, tb, rep = self._decode_symbols(pulsetrain[1:-1])
if symbols:
params = {
"id": int(symbols[0:12][::-1], 2),
"unit": int(symbols[12:14][::-1], 2) + 1,
"command": self.__commands[int(symbols[14:17][::-1], 2)]
}
return self._name, params, tb, rep
class PWM2(RcProtocol):
'''
PWM2: Pulse Width Modulation
Wide pulse -> 0, small pulse -> 1
Frame: header, payload, footer
Used by Pilota casa
'''
def __init__(self): def __init__(self):
self._name = "pdm32" self._name = "pwm2"
self._timebase = 600 self._timebase = 600
self._repetitions = 6 self._repetitions = 6
self._pattern = "[01]{32}" self._pattern = "[01]{32}"
@ -476,24 +489,31 @@ class PDM32(RcProtocol):
'1': [1, 2], '1': [1, 2],
'0': [2, 1], '0': [2, 1],
} }
self._footer = [1, 11]
self.params = [
('c', 'code')
]
RcProtocol.__init__(self) RcProtocol.__init__(self)
self._parser.add_argument("-c", "--code")
def decode(self, pulsetrain): def decode(self, pulsetrain):
code, tb, rep = self._decode_symbols(pulsetrain[0:-2]) symbols, tb, rep = self._decode_symbols(pulsetrain[:-2])
if code:
if symbols:
x1 = symbols[2:8]
x2 = x1[5] + x1[4] + x1[3] + x1[2] + x1[1] + x1[0]
print(symbols, symbols[2:4], symbols[4:8], int(x1, 2), int(x2, 2))
return
if symbols:
return { return {
"protocol": self._name, "protocol": self._name,
"code": code, "code": code,
"timebase": tb, "timebase": tb,
}, rep }, rep
def encode(self, args): def encode(self, params, timebase=None, repetitions=None):
self._reset() symbols = params["code"]
self._add_symbols(args.code) return self._build_frame(symbols, timebase, repetitions)
self._add_pulses([1, 11])
self._add_finish()
return self._ookdata, self._timebase, self._repetitions
class PCPIR(RcProtocol): #pilota casa PIR sensor class PCPIR(RcProtocol): #pilota casa PIR sensor
def __init__(self): def __init__(self):
@ -531,8 +551,8 @@ protocols = [
Hama(), Hama(),
Logilight(), Logilight(),
Emylo(), Emylo(),
PWM2(),
#Voltcraft(), Voltcraft(),
#PDM32(), #PDM32(),
#PCPIR(), #PCPIR(),
#PDM1(), #PDM1(),
@ -552,7 +572,7 @@ class RfmPulseTRX(threading.Thread):
self.__rfm = RaspyRFM(module, RFM69) self.__rfm = RaspyRFM(module, RFM69)
self.__rfm.set_params( self.__rfm.set_params(
Freq = frequency, #MHz Freq = frequency, #MHz
Bandwidth = 200, #kHz Bandwidth = 500, #kHz
SyncPattern = [], SyncPattern = [],
RssiThresh = -105, #dBm RssiThresh = -105, #dBm
ModulationType = rfm69.OOK, ModulationType = rfm69.OOK,

View file

@ -45,7 +45,7 @@ state = "on"
while True: while True:
time.sleep(15) time.sleep(15)
rctrx.send("ittristate", {"house": "A", "group": 1, "unit": 1, "command": state}) #rctrx.send("ittristate", {"house": "A", "group": 1, "unit": 1, "command": state})
if (state == "on"): if (state == "on"):
state = "off" state = "off"
else: else: