mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-03 13:08:17 +00:00
all: docs, logging
This commit is contained in:
parent
3db1bf89fa
commit
a235a6b38b
@ -1,6 +1,24 @@
|
||||
'''
|
||||
Extremely minimal streaming codec for a subset of protobuf. Supports uint32,
|
||||
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
|
||||
|
@ -120,16 +120,19 @@ def _step_task(task, value):
|
||||
else:
|
||||
result = task.send(value)
|
||||
except StopIteration as e:
|
||||
log.debug(__name__, '%s finished', task)
|
||||
if __debug__:
|
||||
log.debug(__name__, 'finish: %s', task)
|
||||
except Exception as e:
|
||||
log.exception(__name__, e)
|
||||
if __debug__:
|
||||
log.exception(__name__, e)
|
||||
else:
|
||||
if isinstance(result, Syscall):
|
||||
result.handle(task)
|
||||
elif result is None:
|
||||
schedule_task(task)
|
||||
else:
|
||||
log.error(__name__, '%s is unknown syscall', result)
|
||||
if __debug__:
|
||||
log.error(__name__, 'unknown syscall: %s', result)
|
||||
if after_step_hook:
|
||||
after_step_hook()
|
||||
|
||||
|
@ -46,6 +46,10 @@ class Context:
|
||||
'''
|
||||
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
|
||||
|
||||
# if we got a message with unexpected type, raise the reader via
|
||||
@ -63,6 +67,10 @@ class Context:
|
||||
'''
|
||||
writer = self.getwriter()
|
||||
|
||||
if __debug__:
|
||||
log.debug(__name__, '%s:%x write: %s',
|
||||
self.iface.iface_num(), self.sid, msg)
|
||||
|
||||
# get the message size
|
||||
counter = protobuf.CountingWriter()
|
||||
await protobuf.dump_message(counter, msg)
|
||||
|
@ -100,7 +100,7 @@ class Writer:
|
||||
self.ofs = 0
|
||||
|
||||
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):
|
||||
'''
|
||||
|
@ -124,6 +124,9 @@ class Writer:
|
||||
self.ofs = 0
|
||||
self.seq = 0
|
||||
|
||||
def __repr__(self):
|
||||
return '<WriterV2: type=%d size=%dB>' % (self.type, self.size)
|
||||
|
||||
def setheader(self, mtype, msize):
|
||||
'''
|
||||
Reset the writer state and load the message header with passed type and
|
||||
|
Loading…
Reference in New Issue
Block a user