mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 06:48:16 +00:00
Implemented ready_to_read()
This commit is contained in:
parent
b8e60121fe
commit
0c3f723ee7
@ -19,6 +19,9 @@ class Transport(object):
|
||||
def _read(self):
|
||||
raise NotImplemented
|
||||
|
||||
def ready_to_read(self):
|
||||
raise NotImplemented
|
||||
|
||||
def close(self):
|
||||
self._close()
|
||||
|
||||
@ -26,7 +29,7 @@ class Transport(object):
|
||||
ser = msg.SerializeToString()
|
||||
header = struct.pack(">HL", mapping.get_type(msg), len(ser))
|
||||
self._write("##%s%s" % (header, ser))
|
||||
|
||||
|
||||
def read(self):
|
||||
(msg_type, data) = self._read()
|
||||
inst = mapping.get_class(msg_type)()
|
||||
|
@ -2,7 +2,7 @@
|
||||
Use this transport for talking with bitkey simulator.'''
|
||||
|
||||
import os
|
||||
|
||||
from select import select
|
||||
from transport import Transport
|
||||
|
||||
class PipeTransport(Transport):
|
||||
@ -38,6 +38,10 @@ class PipeTransport(Transport):
|
||||
os.unlink(self.filename_read)
|
||||
os.unlink(self.filename_write)
|
||||
|
||||
def ready_to_read(self):
|
||||
rlist, _, _ = select([self.read_f], [], [], 0)
|
||||
return len(rlist) > 0
|
||||
|
||||
def _write(self, msg):
|
||||
try:
|
||||
self.write_f.write(msg)
|
||||
|
@ -3,7 +3,7 @@
|
||||
# Local serial port loopback: socat PTY,link=COM8 PTY,link=COM9
|
||||
|
||||
import serial
|
||||
|
||||
from select import select
|
||||
from transport import Transport
|
||||
|
||||
class SerialTransport(Transport):
|
||||
@ -18,6 +18,10 @@ class SerialTransport(Transport):
|
||||
self.serial.close()
|
||||
self.serial = None
|
||||
|
||||
def ready_to_read(self):
|
||||
rlist, _, _ = select([self.serial], [], [], 0)
|
||||
return len(rlist) > 0
|
||||
|
||||
def _write(self, msg):
|
||||
try:
|
||||
self.serial.write(msg)
|
||||
|
Loading…
Reference in New Issue
Block a user