From ee9b9ca351f6c8b493830e7508d90c777c05e41c Mon Sep 17 00:00:00 2001 From: slush0 Date: Mon, 4 Apr 2016 23:51:25 +0200 Subject: [PATCH] Polished binding to protobuf, msg. --- emu.sh | 3 ++- src/playground/__init__.py | 4 ++-- src/trezor/__init__.py | 5 ----- src/trezor/{msg2.py => msg.py} | 14 ++++++++++++-- src/trezor/protobuf.py | 9 +++++++++ 5 files changed, 25 insertions(+), 10 deletions(-) rename src/trezor/{msg2.py => msg.py} (53%) create mode 100644 src/trezor/protobuf.py diff --git a/emu.sh b/emu.sh index 1a873bbfe4..dac981a10d 100755 --- a/emu.sh +++ b/emu.sh @@ -1,4 +1,5 @@ #!/bin/bash cd `dirname $0`/src -../vendor/micropython/unix/micropython -i -O0 -X heapsize=100000 main.py +rm -f ../pipe.* +../vendor/micropython/unix/micropython -O0 -X heapsize=100000 main.py diff --git a/src/playground/__init__.py b/src/playground/__init__.py index fbcbbc1fdc..70e26a8c59 100644 --- a/src/playground/__init__.py +++ b/src/playground/__init__.py @@ -13,8 +13,8 @@ import gc from uasyncio import core # import transport_pipe as pipe -from trezor import ui, io -from trezor import msg2 as msg +from trezor import ui +from trezor import msg logging.basicConfig(level=logging.INFO) loop = core.get_event_loop() diff --git a/src/trezor/__init__.py b/src/trezor/__init__.py index deed03d6df..e69de29bb2 100644 --- a/src/trezor/__init__.py +++ b/src/trezor/__init__.py @@ -1,5 +0,0 @@ -from TrezorMsg import Msg -from TrezorProtobuf import Protobuf - -msg = Msg() -protobuf = Protobuf() diff --git a/src/trezor/msg2.py b/src/trezor/msg.py similarity index 53% rename from src/trezor/msg2.py rename to src/trezor/msg.py index b4cbbaa9b1..6b3e462dee 100644 --- a/src/trezor/msg2.py +++ b/src/trezor/msg.py @@ -3,7 +3,7 @@ import sys if sys.platform == 'linux': import transport_pipe as pipe - def write(msg): + def send(msg): return pipe.write(msg) def read(): @@ -15,4 +15,14 @@ if sys.platform == 'linux': pipe.init('../pipe') else: - NotImplemented("HID transport") + from TrezorMsg import Msg + + def send(msg): + return Msg.send(msg) + + def read(): + raise NotImplemented + return Msg.receive() + + def set_notify(_on_read): + raise NotImplemented diff --git a/src/trezor/protobuf.py b/src/trezor/protobuf.py new file mode 100644 index 0000000000..74c8c6b83f --- /dev/null +++ b/src/trezor/protobuf.py @@ -0,0 +1,9 @@ +from TrezorProtobuf import Protobuf + +_protobuf = Protobuf() + +def encode(data): + return _protobuf.encode(data) + +def decode(data): + return _protobuf.decode(data)