Pilota casa allon / alloff
rx for rcpulsegw refactoring
This commit is contained in:
parent
9812b0ff7c
commit
4756181207
3 changed files with 56 additions and 42 deletions
|
@ -185,7 +185,7 @@ class Tristate(TristateBase): #old intertechno
|
||||||
def decode(self, pulsetrain):
|
def decode(self, pulsetrain):
|
||||||
symbols, tb, rep = self._decode_symbols(pulsetrain[0:-2])
|
symbols, tb, rep = self._decode_symbols(pulsetrain[0:-2])
|
||||||
if symbols:
|
if symbols:
|
||||||
return self._name, {"code": symbols}, tb, rep
|
return {"code": symbols}, tb, rep
|
||||||
|
|
||||||
class ITTristate(TristateBase): #old intertechno
|
class ITTristate(TristateBase): #old intertechno
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -206,13 +206,12 @@ class ITTristate(TristateBase): #old intertechno
|
||||||
def decode(self, pulsetrain):
|
def decode(self, pulsetrain):
|
||||||
symbols, tb, rep = self._decode_symbols(pulsetrain[0:-2])
|
symbols, tb, rep = self._decode_symbols(pulsetrain[0:-2])
|
||||||
if symbols:
|
if symbols:
|
||||||
params = {
|
return {
|
||||||
"house": chr(self._decode_int(symbols[:4]) + ord('A')),
|
"house": chr(self._decode_int(symbols[:4]) + ord('A')),
|
||||||
"unit": self._decode_int(symbols[4:6]) + 1,
|
"unit": self._decode_int(symbols[4:6]) + 1,
|
||||||
"group": self._decode_int(symbols[6:8]) + 1,
|
"group": self._decode_int(symbols[6:8]) + 1,
|
||||||
"command": self._decode_command(symbols[10:12].upper()),
|
"command": self._decode_command(symbols[10:12].upper()),
|
||||||
}
|
}, tb, rep
|
||||||
return self._name, params, tb, rep
|
|
||||||
|
|
||||||
class Brennenstuhl(TristateBase): #old intertechno
|
class Brennenstuhl(TristateBase): #old intertechno
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -243,12 +242,11 @@ class Brennenstuhl(TristateBase): #old intertechno
|
||||||
if u == '0':
|
if u == '0':
|
||||||
break
|
break
|
||||||
|
|
||||||
params = {
|
return {
|
||||||
"dips": dips,
|
"dips": dips,
|
||||||
"unit": unit,
|
"unit": unit,
|
||||||
"command": self._decode_command(symbols[10:12].upper()),
|
"command": self._decode_command(symbols[10:12].upper()),
|
||||||
}
|
}, tb, rep
|
||||||
return self._name, params, tb, rep
|
|
||||||
|
|
||||||
class PPM1(RcProtocol): #Intertechno, Hama, ...
|
class PPM1(RcProtocol): #Intertechno, Hama, ...
|
||||||
'''
|
'''
|
||||||
|
@ -294,12 +292,11 @@ class Intertechno(PPM1):
|
||||||
def decode(self, pulsetrain):
|
def decode(self, pulsetrain):
|
||||||
symbols, tb, rep = self._decode_symbols(pulsetrain[2:-2])
|
symbols, tb, rep = self._decode_symbols(pulsetrain[2:-2])
|
||||||
if symbols:
|
if symbols:
|
||||||
params = {
|
return {
|
||||||
"id": int(symbols[:26], 2),
|
"id": int(symbols[:26], 2),
|
||||||
"unit": self._decode_unit(symbols[28:32]),
|
"unit": self._decode_unit(symbols[28:32]),
|
||||||
"command": self._decode_command(symbols[27])
|
"command": self._decode_command(symbols[27])
|
||||||
}
|
}, tb, rep
|
||||||
return self._name, params, tb, rep
|
|
||||||
|
|
||||||
class Hama(Intertechno):
|
class Hama(Intertechno):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -368,12 +365,11 @@ class Logilight(PWM1):
|
||||||
def decode(self, pulsetrain):
|
def decode(self, pulsetrain):
|
||||||
symbols, tb, rep = self._decode_symbols(pulsetrain[:-2])
|
symbols, tb, rep = self._decode_symbols(pulsetrain[:-2])
|
||||||
if symbols:
|
if symbols:
|
||||||
params = {
|
return {
|
||||||
"id": int(symbols[:20], 2),
|
"id": int(symbols[:20], 2),
|
||||||
"unit": self._decode_unit(symbols[21:24]),
|
"unit": self._decode_unit(symbols[21:24]),
|
||||||
"command": self._decode_command(symbols[20])
|
"command": self._decode_command(symbols[20])
|
||||||
}
|
}, tb, rep
|
||||||
return self._name, params, tb, rep
|
|
||||||
|
|
||||||
class Emylo(PWM1):
|
class Emylo(PWM1):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -391,11 +387,10 @@ class Emylo(PWM1):
|
||||||
def decode(self, pulsetrain):
|
def decode(self, pulsetrain):
|
||||||
symbols, tb, rep = self._decode_symbols(pulsetrain[:-2])
|
symbols, tb, rep = self._decode_symbols(pulsetrain[:-2])
|
||||||
if symbols:
|
if symbols:
|
||||||
params = {
|
return {
|
||||||
"id": int(symbols[:20], 2),
|
"id": int(symbols[:20], 2),
|
||||||
"command": self._decode_command(symbols[-4:])
|
"command": self._decode_command(symbols[-4:])
|
||||||
}
|
}, tb, rep
|
||||||
return self._name, params, tb, rep
|
|
||||||
|
|
||||||
class FS20(RcProtocol):
|
class FS20(RcProtocol):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -438,12 +433,11 @@ class FS20(RcProtocol):
|
||||||
def decode(self, pulsetrain):
|
def decode(self, pulsetrain):
|
||||||
symbols, tb, rep = self._decode_symbols(pulsetrain[0:-2])
|
symbols, tb, rep = self._decode_symbols(pulsetrain[0:-2])
|
||||||
if symbols:
|
if symbols:
|
||||||
params = {
|
return {
|
||||||
"id": int(symbols[13:21] + symbols[22:30], 2),
|
"id": int(symbols[13:21] + symbols[22:30], 2),
|
||||||
"unit": int(symbols[31:39], 2) + 1,
|
"unit": int(symbols[31:39], 2) + 1,
|
||||||
"command": int(symbols[40:48], 2),
|
"command": int(symbols[40:48], 2),
|
||||||
}
|
}, tb, rep
|
||||||
return self._name, params, tb, rep
|
|
||||||
|
|
||||||
class Voltcraft(RcProtocol):
|
class Voltcraft(RcProtocol):
|
||||||
'''
|
'''
|
||||||
|
@ -483,12 +477,11 @@ class Voltcraft(RcProtocol):
|
||||||
def decode(self, pulsetrain):
|
def decode(self, pulsetrain):
|
||||||
symbols, tb, rep = self._decode_symbols(pulsetrain[1:-1])
|
symbols, tb, rep = self._decode_symbols(pulsetrain[1:-1])
|
||||||
if symbols:
|
if symbols:
|
||||||
params = {
|
return {
|
||||||
"id": int(symbols[0:12][::-1], 2),
|
"id": int(symbols[0:12][::-1], 2),
|
||||||
"unit": int(symbols[12:14][::-1], 2) + 1,
|
"unit": int(symbols[12:14][::-1], 2) + 1,
|
||||||
"command": self._decode_command(symbols[14:17])
|
"command": self._decode_command(symbols[14:17])
|
||||||
}
|
}, tb, rep
|
||||||
return self._name, params, tb, rep
|
|
||||||
|
|
||||||
class PWM2(RcProtocol):
|
class PWM2(RcProtocol):
|
||||||
'''
|
'''
|
||||||
|
@ -524,6 +517,7 @@ class PilotaCasa(PWM2):
|
||||||
'111101': (4, 1, 'on'), '110101': (4, 1, 'off'),
|
'111101': (4, 1, 'on'), '110101': (4, 1, 'off'),
|
||||||
'010011': (4, 2, 'on'), '011101': (4, 2, 'off'),
|
'010011': (4, 2, 'on'), '011101': (4, 2, 'off'),
|
||||||
'100011': (4, 3, 'on'), '101101': (4, 3, 'off'),
|
'100011': (4, 3, 'on'), '101101': (4, 3, 'off'),
|
||||||
|
'101100': (-1, -1 , 'allon'), '011100': (-1, -1, 'alloff')
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -534,6 +528,9 @@ class PilotaCasa(PWM2):
|
||||||
def encode(self, params, timebase=None, repetitions=None):
|
def encode(self, params, timebase=None, repetitions=None):
|
||||||
symbols = '01'
|
symbols = '01'
|
||||||
u = None
|
u = None
|
||||||
|
if params["command"] in ["allon", "alloff"]:
|
||||||
|
params["unit"] = -1
|
||||||
|
params["group"] = -1
|
||||||
for k, v in self.__codes.items():
|
for k, v in self.__codes.items():
|
||||||
if v[0] == int(params["group"]) and v[1] == int(params["unit"]) and v[2] == params["command"]:
|
if v[0] == int(params["group"]) and v[1] == int(params["unit"]) and v[2] == params["command"]:
|
||||||
u = k
|
u = k
|
||||||
|
@ -545,16 +542,14 @@ class PilotaCasa(PWM2):
|
||||||
|
|
||||||
def decode(self, pulsetrain):
|
def decode(self, pulsetrain):
|
||||||
symbols, tb, rep = self._decode_symbols(pulsetrain[:-2])
|
symbols, tb, rep = self._decode_symbols(pulsetrain[:-2])
|
||||||
|
|
||||||
if symbols and (symbols[2:8] in self.__codes):
|
if symbols and (symbols[2:8] in self.__codes):
|
||||||
c = self.__codes[symbols[2:8]]
|
c = self.__codes[symbols[2:8]]
|
||||||
params = {
|
return {
|
||||||
"id": int(symbols[8:24][::-1], 2),
|
"id": int(symbols[8:24][::-1], 2),
|
||||||
"group": c[0],
|
"group": c[0],
|
||||||
"unit": c[1],
|
"unit": c[1],
|
||||||
"command": c[2],
|
"command": c[2],
|
||||||
}
|
}, tb, rep
|
||||||
return self._name, params, tb, rep
|
|
||||||
|
|
||||||
class PCPIR(RcProtocol): #pilota casa PIR sensor
|
class PCPIR(RcProtocol): #pilota casa PIR sensor
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -595,7 +590,6 @@ protocols = [
|
||||||
Emylo(),
|
Emylo(),
|
||||||
#PWM2(),
|
#PWM2(),
|
||||||
Voltcraft(),
|
Voltcraft(),
|
||||||
#PDM32(),
|
|
||||||
#PCPIR(),
|
#PCPIR(),
|
||||||
#PDM1(),
|
#PDM1(),
|
||||||
FS20(),
|
FS20(),
|
||||||
|
@ -709,18 +703,19 @@ class RcTransceiver(threading.Thread):
|
||||||
self.__lock.release()
|
self.__lock.release()
|
||||||
|
|
||||||
def __decode(self, train):
|
def __decode(self, train):
|
||||||
dec = None
|
|
||||||
res = []
|
res = []
|
||||||
succ = False
|
succ = False
|
||||||
for p in protocols:
|
for p in protocols:
|
||||||
try:
|
try:
|
||||||
dec = p.decode(train)
|
params, tb, rep = p.decode(train)
|
||||||
except:
|
if params:
|
||||||
continue
|
succ = True
|
||||||
if dec:
|
if not rep:
|
||||||
print(dec)
|
res.append({"protocol": p._name, "params": params})
|
||||||
succ = True
|
except Exception as e:
|
||||||
return res, succ
|
pass
|
||||||
|
|
||||||
|
self.__rxcb(res if succ else None, train)
|
||||||
|
|
||||||
def send(self, protocol, params, timebase=None, repeats=None):
|
def send(self, protocol, params, timebase=None, repeats=None):
|
||||||
proto = get_protocol(protocol)
|
proto = get_protocol(protocol)
|
||||||
|
|
|
@ -17,10 +17,11 @@ parser.add_argument("-p", "--protocol", help=u"Protocol for sending")
|
||||||
args, remainargs = parser.parse_known_args()
|
args, remainargs = parser.parse_known_args()
|
||||||
|
|
||||||
def rxcb(dec, train):
|
def rxcb(dec, train):
|
||||||
for p in dec:
|
if dec is None:
|
||||||
print(p)
|
print("raw", train)
|
||||||
if len(dec) == 0:
|
return
|
||||||
print(train)
|
for d in dec:
|
||||||
|
print(d)
|
||||||
|
|
||||||
if not raspyrfm_test(args.module, RFM69):
|
if not raspyrfm_test(args.module, RFM69):
|
||||||
print("Error! RaspyRFM not found")
|
print("Error! RaspyRFM not found")
|
||||||
|
|
|
@ -17,8 +17,21 @@ srvsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
srvsock.bind(('', 1989))
|
srvsock.bind(('', 1989))
|
||||||
srvsock.listen(5)
|
srvsock.listen(5)
|
||||||
|
|
||||||
|
clients = []
|
||||||
|
|
||||||
def rxcb(dec, train):
|
def rxcb(dec, train):
|
||||||
pass
|
payload = None
|
||||||
|
if dec is None:
|
||||||
|
payload = {"raw": train}
|
||||||
|
else:
|
||||||
|
if len(dec) > 0:
|
||||||
|
payload = {"decode": dec, "raw": train}
|
||||||
|
|
||||||
|
print(payload)
|
||||||
|
if payload is not None:
|
||||||
|
for client in clients:
|
||||||
|
client.send(payload)
|
||||||
|
|
||||||
|
|
||||||
if not raspyrfm_test(args.module, RFM69):
|
if not raspyrfm_test(args.module, RFM69):
|
||||||
print("Error! RaspyRFM not found")
|
print("Error! RaspyRFM not found")
|
||||||
|
@ -33,6 +46,9 @@ class clientthread(threading.Thread):
|
||||||
self.__socket = socket
|
self.__socket = socket
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
|
def send(self, obj):
|
||||||
|
self.__socket.send(json.dumps(obj))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while True:
|
while True:
|
||||||
chunk = self.__socket.recv(1024)
|
chunk = self.__socket.recv(1024)
|
||||||
|
@ -40,16 +56,18 @@ class clientthread(threading.Thread):
|
||||||
del self.__socket
|
del self.__socket
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
print(chunk)
|
#print(chunk)
|
||||||
lock.acquire()
|
lock.acquire()
|
||||||
d = json.loads(chunk)
|
d = json.loads(chunk)
|
||||||
rctrx.send(d["protocol"], d["params"])
|
rctrx.send(d["protocol"], d["params"])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
lock.release()
|
lock.release()
|
||||||
|
clients.remove(self)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
(client, address) = srvsock.accept()
|
(client, address) = srvsock.accept()
|
||||||
ct = clientthread(client)
|
ct = clientthread(client)
|
||||||
ct.daemon = True
|
ct.daemon = True
|
||||||
ct.start()
|
ct.start()
|
||||||
|
clients.append(ct)
|
Loading…
Reference in a new issue