summaryrefslogtreecommitdiff
path: root/host/mex/node.py
diff options
context:
space:
mode:
authorNicolas Schodet2011-03-30 20:08:34 +0200
committerNicolas Schodet2011-03-30 20:08:34 +0200
commit057180987cacfe47edbe21bf2f8c0573901ded2f (patch)
treece5eb7c68525ead0430d43051428a9234ebfa053 /host/mex/node.py
parentc9a004ed32389dd17167f19be7916ef9320e8e39 (diff)
host/mex, digital/avr/modules/host: add message type reservation, refs #157
Diffstat (limited to 'host/mex/node.py')
-rw-r--r--host/mex/node.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/host/mex/node.py b/host/mex/node.py
index 8fcf9ae0..a1f226cd 100644
--- a/host/mex/node.py
+++ b/host/mex/node.py
@@ -122,6 +122,21 @@ class Node:
assert mtype not in self.__handlers
self.__handlers[mtype] = handler
+ def reserve (self, mtype_str):
+ """Request a message type reservation."""
+ # Send request.
+ res = Msg (mex.RES)
+ res.push (mtype_str)
+ self.send (res)
+ # Wait for response.
+ rsp = self.__recv ()
+ while rsp.mtype != mex.RES:
+ self.__dispatch (rsp)
+ rsp = self.__recv ()
+ # Return allocated message type.
+ mtype, = rsp.pop ('B')
+ return mtype
+
def schedule (self, date, action):
"""Schedule an action for the given date, return the event identifier."""
assert date > self.date