summaryrefslogtreecommitdiffhomepage
path: root/host/proto/proto.py
diff options
context:
space:
mode:
Diffstat (limited to 'host/proto/proto.py')
-rw-r--r--host/proto/proto.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/host/proto/proto.py b/host/proto/proto.py
index e6d3ab32..36616d9c 100644
--- a/host/proto/proto.py
+++ b/host/proto/proto.py
@@ -22,7 +22,7 @@
#
# }}}
"""Proto interface module."""
-import binascii, struct
+import binascii, struct, select
START = 0
BANG = 1
@@ -68,6 +68,14 @@ class Proto:
self.send_head ()
return not self.send_queue
+ def wait (self, cond = None):
+ """Wait forever or until cond () is True."""
+ while not (self.sync () and (cond is None or cond ())):
+ fds = select.select ((self,), (), (), self.timeout)[0]
+ for i in fds:
+ assert i is self
+ i.read ()
+
def register (self, command, fmt, handler):
"""Register a handler for the specified command and format. The
handler will receive decoded arguments."""