1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-12 09:28:10 +00:00

all: docs, logging

This commit is contained in:
Jan Pochyla 2017-08-21 13:22:35 +02:00
parent 3db1bf89fa
commit a235a6b38b
5 changed files with 36 additions and 4 deletions

View File

@ -1,6 +1,24 @@
''' '''
Extremely minimal streaming codec for a subset of protobuf. Supports uint32, Extremely minimal streaming codec for a subset of protobuf. Supports uint32,
bytes, string, embedded message and repeated fields. bytes, string, embedded message and repeated fields.
For de-sererializing (loading) protobuf types, object with `AsyncReader`
interface is required:
class AsyncReader:
async def areadinto(self, buffer):
"""
Reads `len(buffer)` bytes into `buffer`, or raises `EOFError`.
"""
For serializing (dumping) protobuf types, object with `AsyncWriter` interface is
required:
class AsyncWriter:
async def awrite(self, buffer):
"""
Writes all bytes from `buffer`, or raises `EOFError`.
"""
''' '''
from micropython import const from micropython import const

View File

@ -120,8 +120,10 @@ def _step_task(task, value):
else: else:
result = task.send(value) result = task.send(value)
except StopIteration as e: except StopIteration as e:
log.debug(__name__, '%s finished', task) if __debug__:
log.debug(__name__, 'finish: %s', task)
except Exception as e: except Exception as e:
if __debug__:
log.exception(__name__, e) log.exception(__name__, e)
else: else:
if isinstance(result, Syscall): if isinstance(result, Syscall):
@ -129,7 +131,8 @@ def _step_task(task, value):
elif result is None: elif result is None:
schedule_task(task) schedule_task(task)
else: else:
log.error(__name__, '%s is unknown syscall', result) if __debug__:
log.error(__name__, 'unknown syscall: %s', result)
if after_step_hook: if after_step_hook:
after_step_hook() after_step_hook()

View File

@ -46,6 +46,10 @@ class Context:
''' '''
reader = self.getreader() reader = self.getreader()
if __debug__:
log.debug(__name__, '%s:%x read: %s',
self.iface.iface_num(), self.sid, types)
await reader.aopen() # wait for the message header await reader.aopen() # wait for the message header
# if we got a message with unexpected type, raise the reader via # if we got a message with unexpected type, raise the reader via
@ -63,6 +67,10 @@ class Context:
''' '''
writer = self.getwriter() writer = self.getwriter()
if __debug__:
log.debug(__name__, '%s:%x write: %s',
self.iface.iface_num(), self.sid, msg)
# get the message size # get the message size
counter = protobuf.CountingWriter() counter = protobuf.CountingWriter()
await protobuf.dump_message(counter, msg) await protobuf.dump_message(counter, msg)

View File

@ -100,7 +100,7 @@ class Writer:
self.ofs = 0 self.ofs = 0
def __repr__(self): def __repr__(self):
return '<WriterV2: type=%d size=%dB>' % (self.type, self.size) return '<WriterV1: type=%d size=%dB>' % (self.type, self.size)
def setheader(self, mtype, msize): def setheader(self, mtype, msize):
''' '''

View File

@ -124,6 +124,9 @@ class Writer:
self.ofs = 0 self.ofs = 0
self.seq = 0 self.seq = 0
def __repr__(self):
return '<WriterV2: type=%d size=%dB>' % (self.type, self.size)
def setheader(self, mtype, msize): def setheader(self, mtype, msize):
''' '''
Reset the writer state and load the message header with passed type and Reset the writer state and load the message header with passed type and