Ejemplo n.º 1
0
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))
Ejemplo n.º 2
0
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()])))
Ejemplo n.º 3
0
    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()
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
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))
Ejemplo n.º 6
0
def cmd_call(taskname, command):
    task = pyrock.TaskProxy(taskname)
    getattr(task, command)()
Ejemplo n.º 7
0
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()
Ejemplo n.º 8
0
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)