ZOCP classes & methods¶
Frequently used methods¶
zocp.ZOCP.register_int(name, value[, ...]) | Register an integer variable |
zocp.ZOCP.register_float(name, value[, ...]) | Register a float variable |
zocp.ZOCP.register_string(name, value[, access]) | Register a string variable |
zocp.ZOCP.get_value(name) | Retrieve the current value of a named parameter in the capability tree |
zocp.ZOCP.signal_subscribe(recv_peer, ...) | Subscribe a receiver to an emitter |
zocp.ZOCP.emit_signal(emitter, value) | Update the value of the emitter and signal all subscribed receivers |
zocp.ZOCP.on_peer_enter(peer, name, headers, ...) | This method is called when a new peer is discovered |
zocp.ZOCP.on_peer_subscribed(peer, name, ...) | Called when a peer subscribes to an emitter on this node. |
zocp.ZOCP.on_peer_signaled(peer, name, data, ...) | Called when a peer signals that some of its data is modified. |
ZOCP class¶
- class ZOCP(*args, **kwargs)¶
The ZOCP class provides all methods for ZOCP nodes
Parameters: name (str) – Name of the node, if not given a random name will be created - set_capability(cap)¶
Set node’s capability, overwites previous :param dict cap: The dictionary replacing the previous capabilities
- get_capability()¶
Return node’s capabilities :return: The capability dictionary
- set_node_location(location=[0, 0, 0])¶
Set node’s location, overwites previous
- set_node_orientation(orientation=[0, 0, 0])¶
Set node’s name, overwites previous
- set_node_scale(scale=[0, 0, 0])¶
Set node’s name, overwites previous
- set_node_matrix(matrix=[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])¶
Set node’s matrix, overwites previous
- set_object(name=None, type='Unknown')¶
Create a new object on this nodes capability
- register_int(name, value, access='r', min=None, max=None, step=None)¶
Register an integer variable
Parameters: - name (str) – the name of the variable as how nodes can refer to it
- value (int) – the variable value
- access (str) – the access state of the variable. ‘r’=readable, ‘w’=writeable, ‘e’=signal emitter, ‘s’=signal sensor
- min (int) – minimal value
- max (int) – maximal value
- step (int) – step value for increments and decrements
- register_float(name, value, access='r', min=None, max=None, step=None)¶
Register a float variable
Parameters: - name (str) – the name of the variable as how nodes can refer to it
- value (float) – the variable value
- access (str) – the access state of the variable. ‘r’=readable, ‘w’=writeable, ‘e’=signal emitter, ‘s’=signal sensor
- min (float) – minimal value
- max (float) – maximal value
- step (float) – step value for increments and decrements
- register_percent(name, value, access='r', min=None, max=None, step=None)¶
Register a percentage variable
Parameters: - name (str) – the name of the variable as how nodes can refer to it
- value (float) – the variable value
- access (str) – the access state of the variable. ‘r’=readable, ‘w’=writeable, ‘e’=signal emitter, ‘s’=signal sensor
- min (float) – minimal value
- max (float) – maximal value
- step (float) – step value for increments and decrements
- register_bool(name, value, access='r')¶
Register an integer variable
Parameters: - name (str) – the name of the variable as how nodes can refer to it
- value (bool) – the variable value
- access (str) – the access state of the variable. ‘r’=readable, ‘w’=writeable, ‘e’=signal emitter, ‘s’=signal sensor
- register_string(name, value, access='r')¶
Register a string variable
Parameters: - name (str) – the name of the variable as how nodes can refer to it
- value (str) – the variable value
- access (str) – set the access state of the variable. ‘r’=readable, ‘w’=writeable, ‘e’=signal emitter, ‘s’=signal sensor
- register_vec2f(name, value, access='r', min=None, max=None, step=None)¶
Register a 2 dimensional vector variable
Parameters: - name (str) – the name of the variable as how nodes can refer to it
- value (tuple) – the variable value
- access (str) – the access state of the variable. ‘r’=readable, ‘w’=writeable, ‘e’=signal emitter, ‘s’=signal sensor
- min (tuple) – minimal value
- max (tuple) – maximal value
- step (tuple) – step value for increments and decrements
- register_vec3f(name, value, access='r', min=None, max=None, step=None)¶
Register a three dimensional vector variable
Parameters: - name (str) – the name of the variable as how nodes can refer to it
- value (tuple) – the variable value
- access (str) – the access state of the variable. ‘r’=readable, ‘w’=writeable, ‘e’=signal emitter, ‘s’=signal sensor
- min (tuple) – minimal value
- max (tuple) – maximal value
- step (tuple) – step value for increments and decrements
- register_vec4f(name, value, access='r', min=None, max=None, step=None)¶
Register a four dimensional vector variable
Parameters: - name (str) – the name of the variable as how nodes can refer to it
- value (tuple) – the variable value
- access (str) – the access state of the variable. ‘r’=readable, ‘w’=writeable, ‘e’=signal emitter, ‘s’=signal sensor
- min (tuple) – minimal value
- max (tuple) – maximal value
- step (tuple) – step value for increments and decrements
- get_value(name)¶
Retrieve the current value of a named parameter in the capability tree
Parameters: name (str) – the name of the variable as how nodes refer to it Returns: the value of the named variable
- peer_get_capability(peer)¶
Get the capabilities of peer
Convenience method since it’s the same a calling GET on a peer with no data
- peer_get(peer, keys)¶
Get items from peer
- peer_set(peer, data)¶
Set items on peer
- peer_call(peer, method, *args)¶
Call method on peer
- signal_subscribe(recv_peer, receiver, emit_peer, emitter)¶
Subscribe a receiver to an emitter
Parameters: - recv_peer (uuid) – the id of the receiving peer
- receiver (str) – the name of the receiving variable. If None, no capability on the receiving peer is updated, but a on_peer_signal event is still fired.
- emit_peer (uuid) – the id of the emitting peer
- emitter (str) – the name the emitter. If None, all capabilities will emit to the receiver
Note
A third node can instruct two nodes to subscribe to one another by specifying the ids of the peers. The subscription request is then sent to the emitter node which in turn forwards the subscribtion request to the receiver node.
- signal_unsubscribe(recv_peer, receiver, emit_peer, emitter)¶
Unsubscribe a receiver from an emitter
Parameters: - recv_peer (uuid) – the id of the receiving peer
- receiver (str) – the name of the receiving variable, or None if no receiver was specified when subscribing.
- emit_peer (uuid) – the id of the emitting peer
- emitter (str) – the name the emitter, or None if no emitter was specified during subscription
Note
A third node can instruct two nodes to unsubscribe from one another by specifying the ids of the peers. The subscription request is then sent to the emitter node which in turn forwards the subscribtion request to the receiver node.
- emit_signal(emitter, value)¶
Update the value of the emitter and signal all subscribed receivers
Parameters: - emitter (str) – name of the emitting variable
- value – the new value
- on_peer_enter(peer, name, headers, *args, **kwargs)¶
This method is called when a new peer is discovered
Parameters: - peer (uuid) – the id of the new peer
- name (str) – the name of the new peer
- hdrs – any headers of the peer
- on_peer_exit(peer, name, *args, **kwargs)¶
This method is called when a peer is exiting
Parameters: - peer (uuid) – the id of the exiting peer
- name (str) – the name of the exiting peer
- on_peer_join(peer, name, grp, *args, **kwargs)¶
This method is called when a peer is joining a group
Parameters: - peer (uuid) – the id of the joining peer
- name (str) – the name of the joining peer
- grp (str) – the name of the group the peer is joining
- on_peer_leave(peer, name, grp, *args, **kwargs)¶
This method is called when a peer is leaving a group
Parameters: - peer (uuid) – the id of the leaving peer
- name (str) – the name of the leaving peer
- grp (str) – the name of the group the peer is leaving
- on_peer_whisper(peer, name, data, *args, **kwargs)¶
This method is called when a peer is whispering
Parameters: - peer (uuid) – the id of the whispering peer
- name (str) – the name of the whispering peer
- data – the data the peer is whispering
- on_peer_shout(peer, name, grp, data, *args, **kwargs)¶
This method is called when a peer is shouting
Parameters: - peer (uuid) – the id of the shouting peer
- name (str) – the name of the shouting peer
- grp (str) – the name of the group the peer is shouting in
- data – the data the peer is shouting
- on_peer_modified(peer, name, data, *args, **kwargs)¶
Called when a peer signals that its capability tree is modified.
Parameters: - peer (uuid) – the id of the shouting peer
- name (str) – the name of the shouting peer
- data (dict) – changed data, formatted as a partial capability dictionary, containing only the changed part(s) of the capability tree of the node
- on_peer_subscribed(peer, name, data, *args, **kwargs)¶
Called when a peer subscribes to an emitter on this node.
Parameters: - peer (uuid) – the id of the shouting peer
- name (str) – the name of the shouting peer
- data (list) – changed data, formatted as [emitter, receiver] emitter: name of the emitter on this node receiver: name of the receiver on the subscriber
- on_peer_unsubscribed(peer, name, data, *args, **kwargs)¶
Called when a peer unsubscribes from an emitter on this node.
Parameters: - peer (uuid) – the id of the shouting peer
- name (str) – the name of the shouting peer
- data (list) – changed data, formatted as [emitter, receiver] emitter: name of the emitter on this node receiver: name of the receiver on the subscriber
- on_peer_signaled(peer, name, data, *args, **kwargs)¶
Called when a peer signals that some of its data is modified.
Parameters: - peer (uuid) – the id of the shouting peer
- name (str) – the name of the shouting peer
- data (list) – changed data, formatted as [emitter, value, [sensors1, ...]] emitter: name of the emitter on the subscribee value: value of the emitter [sensor1,...]: list of names of sensors on the subscriber receiving the signal
- on_modified(peer, name, data, *args, **kwargs)¶
Called when some data is modified on this node.
Parameters: - peer (uuid) – the id of the shouting peer
- name (str) – the name of the shouting peer
- data (dict) – changed data, formatted as a partial capability dictionary, containing only the changed part(s) of the capability tree of the node
- run_once(timeout=None)¶
Run one iteration of getting ZOCP events
If timeout is None it will block until an event has been received. If 0 it will return instantly
The timeout is in milliseconds
- run(timeout=None)¶
Run the ZOCP loop indefinitely