def cmd_list(state=False): names = pyrock.nameservice.names() if not names: return if state: print('\n'.join([ '%s [%s]' % (name, pyrock.TaskProxy(name).state()) for name in names ])) else: print('\n'.join(names))
def cmd_info(taskname): task = pyrock.TaskProxy(taskname) print("""Task [%s] State: %s Input ports:%s Output ports:%s """ % (task.name, task.state(), ports2str( [p for p in task.ports(port_type=pyrock.Port.CInput).values()]), ports2str( [p for p in task.ports(port_type=pyrock.Port.COutput).values()])))
def refresh(self): task_names = set(pyrock.nameservice.names()) proxy_names = set([p.name for p in self.model.tasks]) if len(task_names) == len(proxy_names) == len(task_names & proxy_names): return # delete tasks for task_name in proxy_names - task_names: idx = [p.name for p in self.model.tasks].index(task_name) self.model.beginRemoveRows(QtCore.QModelIndex(), idx, idx) del self.model.tasks[idx] self.model.endRemoveRows() # add tasks for task_name in task_names - proxy_names: proxy = pyrock.TaskProxy(task_name) idx = len(self.model.tasks) self.model.beginInsertRows(QtCore.QModelIndex(), idx, idx) self.model.tasks.append(proxy) self.model.endInsertRows()
def cmd_echo(taskname, portname, indent=None): proxy = pyrock.TaskProxy(taskname) proxy.subscriber( portname, lambda msg: print(json.dumps(msg, cls=DictEncoder, indent=indent))) proxy.spin()
def cmd_ports(taskname, porttype): task = pyrock.TaskProxy(taskname) portnames = [p.name for p in task.ports(port_type=porttype).values()] if not portnames: return print('\n'.join(portnames))
def cmd_call(taskname, command): task = pyrock.TaskProxy(taskname) getattr(task, command)()
from __future__ import print_function import pyrock proxy = pyrock.TaskProxy('message_producer') proxy.subscriber( 'messages', lambda msg: print('[%s] %s' % (msg.time.to_str(), msg.content))) if not proxy.is_configured(): proxy.configure() if not proxy.is_running(): proxy.start() proxy.spin()
import sys import time import pyrock import omniORB.any as _any proxy = pyrock.TaskProxy('message_consumer') pub = proxy.publisher('messages') if not proxy.is_configured(): proxy.configure() if not proxy.is_running(): proxy.start() while True: msg = pyrock.message_driver.Message() msg.time = pyrock.base.Time.now() msg.content = 'hello' print(msg) pub.write(msg) time.sleep(1)