1
0
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:
slush 2012-11-15 20:08:02 +00:00
parent b8e60121fe
commit 0c3f723ee7
3 changed files with 14 additions and 3 deletions

View File

@ -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)()

View File

@ -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)

View File

@ -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)