1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-12 18:49:07 +00:00

fix write of empty messages, add loging to wire

This commit is contained in:
Jan Pochyla 2016-06-09 16:10:40 +02:00 committed by Pavol Rusnak
parent 398e46e9ff
commit 1da27dd558
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D

View File

@ -1,6 +1,7 @@
import ustruct
from . import msg
from . import loop
from . import log
IFACE = const(0)
@ -58,7 +59,7 @@ def write_wire_msg(mtype, mbuf):
mbuf = memoryview(mbuf)
data = rep[9:]
while mbuf:
while True:
n = min(len(data), len(mbuf))
data[:n] = mbuf[:n]
i = n
@ -67,10 +68,14 @@ def write_wire_msg(mtype, mbuf):
i += 1
yield from write_report(rep)
mbuf = mbuf[n:]
if not mbuf:
break
data = rep[1:]
def read(*types):
if __debug__:
log.debug(__name__, 'Reading one of %s', types)
mtype, mbuf = yield from read_wire_msg()
for t in types:
if t.wire_type == mtype:
@ -80,6 +85,8 @@ def read(*types):
def write(m):
if __debug__:
log.debug(__name__, 'Writing %s', m)
mbuf = m.dumps()
mtype = m.message_type.wire_type
yield from write_wire_msg(mtype, mbuf)