From 6687cc1f1bd9576a61f4260fbd2dd3937fc5f624 Mon Sep 17 00:00:00 2001 From: "S. Seegel" Date: Thu, 19 Nov 2020 09:12:59 +0100 Subject: [PATCH] encode dict --- apps/rcprotocols.py | 26 +++++++++++++++++++++++--- apps/rcpulse.py | 43 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/apps/rcprotocols.py b/apps/rcprotocols.py index 2cede00..2e063b8 100644 --- a/apps/rcprotocols.py +++ b/apps/rcprotocols.py @@ -127,7 +127,7 @@ class IT32(RcProtocol): #switch1 return self._ookdata def encode(self, args): - if args.code: + if hasattr(args, "code") and args.code: if re.match("^[01]{32}$", args.code): return self.__encode(args.code) @@ -193,13 +193,13 @@ class ITTristate(RcProtocol): #old intertechno systems return code def encode(self, args): - if args.code: + if hasattr(args, 'code') and args.code: if re.match("^[01Ff]{12}$", args.code): return self.__encode(args.code) code = "" code += self.__encode_int(ord(args.house[0]) - ord('A'), 4) - if args.group: + if hasattr(args, 'group') and args.group: code += self.__encode_int(args.group - 1, 2) code += self.__encode_int(args.unit - 1, 2) else: @@ -403,6 +403,7 @@ class PDM32(RcProtocol): '0': [2, 1], } RcProtocol.__init__(self) + self._parser.add_argument("-c", "--code") def decode(self, pulsetrain): code, tb = self._decode_symbols(pulsetrain[0:-2]) @@ -413,6 +414,14 @@ class PDM32(RcProtocol): "timebase": tb, } + def encode(self, args): + self._reset() + self._add_symbols(args.code) + self._add_pulses([1, 11]) + self._add_finish() + return self._ookdata + + protocols = [ IT32(), Switch15(), @@ -426,9 +435,20 @@ protocols = [ def encode(protocol, args): for p in protocols: if (protocol): + print("found ptoto") if p._name == protocol: return (p.encode(p._parser.parse_args(args)), p._timebase, p._repetitions) +class RCStruct: + def __init__(self, **entries): + self.__dict__.update(entries) + +def encode_dict(dict): + s = RCStruct(**dict) + for p in protocols: + if p._name == s.protocol: + return (p.encode(s), p._timebase, p._repetitions) + def decode(pulsetrain): dec = None res = [] diff --git a/apps/rcpulse.py b/apps/rcpulse.py index f20b836..b433658 100755 --- a/apps/rcpulse.py +++ b/apps/rcpulse.py @@ -3,10 +3,10 @@ from raspyrfm import * import sys import time -import it32 -import tristate -import bistate24 -import fs20 +#import it32 +#import tristate +#import bistate24 +#import fs20 from argparse import ArgumentParser import wave, struct import threading @@ -61,6 +61,8 @@ trainbuf = [] class RxThread(threading.Thread): def __init__(self): + self.__event = threading.Event() + self.__event.set() threading.Thread.__init__(self) def __rxcb(self, rfm): @@ -75,7 +77,7 @@ class RxThread(threading.Thread): else: wf = None - while True: + while self.__event.isSet(): fifo = rfm.read_fifo_wait(64) ba = bytearray() @@ -109,11 +111,25 @@ class RxThread(threading.Thread): wf.writeframes('') def run(self): + self.__event.wait() + rfm.set_params( + Datarate = 20.0 #kbit/s + ) rfm.start_receive(self.__rxcb) + def suspend(self): + self.__event.clear() + + def resume(self): + self.__event.set() + rxthread = RxThread() rxthread.daemon = True rxthread.start() +lasttime = 0 + +class Args: + pass while True: time.sleep(0.1) @@ -125,5 +141,18 @@ while True: dec = rcprotocols.decode(train) if (dec): print(dec) - else: - print(train) + #else: + print(train) + + if time.time() > lasttime: + lasttime = time.time() + 5 + print("sdfkl") + args = Args() + #rxthread.suspend() + args.code = "01010011110011111110000111111111" + #rfm.set_params( + # Datarate = 1000.0 / 600 + #) + #txdata = rcprotocols.encode("PDM32", args) + #print(txdata) + #rxthread.resume()