summaryrefslogtreecommitdiffhomepage
path: root/host/proto/proto.py
diff options
context:
space:
mode:
authorNicolas Schodet2008-04-10 01:18:46 +0200
committerNicolas Schodet2008-04-10 01:18:46 +0200
commit334f1427233510aa5249e4e2dea4b1e5c76c514f (patch)
treedd978a9fb3a92a82a66c3babed1327ef619f9a5c /host/proto/proto.py
parent91233c681919a79f76206d8845b16006608803ad (diff)
* host/proto:
- added program io utility. - added Proto.wait.
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."""