Esempio n. 1
0
    def start_sd(self, uuid):
        halrcmd_sd = ServiceDiscovery(
            service_type="_halrcmd._sub._machinekit._tcp", uuid=uuid)
        halrcmd_sd.on_discovered.append(self.halrcmd_discovered)
        halrcmd_sd.start()
        #halrcmd_sd.disappered_callback = disappeared
        #self.halrcmd_sd = halrcmd_sd

        halrcomp_sd = ServiceDiscovery(
            service_type="_halrcomp._sub._machinekit._tcp", uuid=uuid)
        halrcomp_sd.on_discovered.append(self.halrcomp_discovered)
        halrcomp_sd.start()
Esempio n. 2
0
    def run(self):
        timeout = 2.0

        launcher_sd = ServiceDiscovery(
            service_type="_launcher._sub._machinekit._tcp", debug=True)
        print('starting launcher service discovery')
        launcher_sd.start()
        assert launcher_sd.wait_discovered(timeout)
        data = launcher_sd.service_names.values()[0]
        print('launcher discovered %s %s' % (data.name, data.dsn))
        uuid = data.uuid
        print('uuid=%s' % uuid)

        halrcmd_sd = ServiceDiscovery(
            service_type="_halrcmd._sub._machinekit._tcp",
            uuid=uuid,
            debug=True)
        print('starting halrcmd service discovery')
        halrcmd_sd.start()
        assert halrcmd_sd.wait_discovered(timeout)
        data = halrcmd_sd.service_names.values()[0]
        print('halrcmd discovered %s %s' % (data.name, data.dsn))
        halrcmd_dsn = data.dsn

        halrcomp_sd = ServiceDiscovery(
            service_type="_halrcomp._sub._machinekit._tcp",
            uuid=uuid,
            debug=True)
        print('starting halrcomp service discovery')
        halrcomp_sd.start()
        assert halrcomp_sd.wait_discovered(timeout)
        data = halrcomp_sd.service_names.values()[0]
        print('halrcomp discovered %s %s' % (data.name, data.dsn))
        halrcomp_dsn = data.dsn

        halrcomp = halremote.RemoteComponent('anddemo')
        halrcomp.newpin('button0', halremote.HAL_BIT, halremote.HAL_OUT)
        halrcomp.newpin('button1', halremote.HAL_BIT, halremote.HAL_OUT)
        halrcomp.newpin('led', halremote.HAL_BIT, halremote.HAL_IN)
        #halrcomp.no_create = True
        halrcomp.halrcomp_uri = halrcomp_dsn
        halrcomp.halrcmd_uri = halrcmd_dsn

        halrcomp.ready()
        print('waiting for component connected')
        assert halrcomp.wait_connected()
        print('component connected')
        halrcomp.stop()

        self.loop.quit()
Esempio n. 3
0
def get_out_of_estop():
    sd = ServiceDiscovery()
    command = ApplicationCommand(debug=DEBUG)
    if DEBUG:
        command.on_state_changed.append(print_state)
    sd.register(command)
    sd.start()

    connected = command.wait_connected(timeout=MAX_WAIT_CONNECTED)
    if not connected:
        raise RuntimeError('Could not connect')
    else:
        print('connected')

    print('executing ESTOP reset')
    ticket = command.set_task_state(EMC_TASK_STATE_ESTOP_RESET)
    if not command.wait_completed(ticket=ticket, timeout=COMMAND_TIMEOUT):
        raise RuntimeError('Task did not complete')
    else:
        print('done')

    print('executing TASK STATE ON')
    command.set_task_state(EMC_TASK_STATE_OFF)
    if not command.wait_completed(timeout=COMMAND_TIMEOUT):
        raise RuntimeError('Task did not complete')
    else:
        print('done')
Esempio n. 4
0
    def __init__(self, uuid, debug=True):
        self.debug = debug
        self.threads = []
        self.shutdown = threading.Event()
        sd_filter = ServiceDiscoveryFilter(txt_records={'uuid': uuid})
        self.sd = ServiceDiscovery(filter_=sd_filter)
        self.status = ApplicationStatus()
        self.command = ApplicationCommand()
        self.sd.register(self.status)
        self.sd.register(self.command)

        # create ipc sockets
        context = zmq.Context()
        context.linger = 0
        self.context = context
        # self.pubSocket = context.socket(zmq.PUB)
        # self.pubSocket.bind('ipc://machinetalk-server.ipc')
        # self.pubDsname = self.pubSocket.get_string(zmq.LAST_ENDPOINT, encoding='utf-8')
        # if self.debug:
        #     print('bound PUB socket to %s' % self.pubDsname)
        self.zmqSocket = context.socket(zmq.ROUTER)
        self.zmqSocket.bind('ipc://machinetalk-server.ipc')
        self.zmqDsname = self.zmqSocket.get_string(zmq.LAST_ENDPOINT,
                                                   encoding='utf-8')
        if self.debug:
            print('bound ROUTER socket to %s' % self.zmqDsname)
        self.zmqLock = threading.Lock()

        self._tx = Message()
        self._rx = Message()

        self.threads.append(threading.Thread(target=self.socket_worker))
        for thread in self.threads:
            thread.start()
Esempio n. 5
0
    def __init__(self, debug=False):
        self._sd = ServiceDiscovery()

        log = application.ApplicationLog(debug=debug)
        log.log_level = application.log.RTAPI_MSG_DBG
        log.on_message_received.append(self._on_log_message_received)

        self._sd.register(log)
Esempio n. 6
0
    def __init__(self, uuid, debug=True):
        self.debug = debug
        self.threads = []
        self.shutdown = threading.Event()
        self.status = ApplicationStatus()
        self.command = ApplicationCommand()

        status_sd = ServiceDiscovery(service_type="_status._sub._machinekit._tcp", uuid=uuid)
        status_sd.on_discovered.append(self.status_discovered)
        status_sd.on_disappeared.append(self.status_disappeared)
        status_sd.start()
        self.status_sd = status_sd

        command_sd = ServiceDiscovery(service_type="_command._sub._machinekit._tcp", uuid=uuid)
        command_sd.on_discovered.append(self.command_discovered)
        command_sd.on_disappeared.append(self.command_disappeared)
        command_sd.start()

        # create ipc sockets
        context = zmq.Context()
        context.linger = 0
        self.context = context
        # self.pubSocket = context.socket(zmq.PUB)
        # self.pubSocket.bind('ipc://machinetalk-server.ipc')
        # self.pubDsname = self.pubSocket.get_string(zmq.LAST_ENDPOINT, encoding='utf-8')
        # if self.debug:
        #     print('bound PUB socket to %s' % self.pubDsname)
        self.zmqSocket = context.socket(zmq.ROUTER)
        self.zmqSocket.bind('ipc://machinetalk-server.ipc')
        self.zmqDsname = self.zmqSocket.get_string(zmq.LAST_ENDPOINT, encoding='utf-8')
        if self.debug:
            print('bound ROUTER socket to %s' % self.zmqDsname)
        self.zmqLock = threading.Lock()

        self.tx = Message()
        self.rx = Message()

        self.threads.append(threading.Thread(target=self.socket_worker))
        for thread in self.threads:
            thread.start()
Esempio n. 7
0
    def __init__(self, uuid, use_curses, debug=False):
        sd_filter = ServiceDiscoveryFilter(txt_records={'uuid': uuid})
        self.sd = ServiceDiscovery(filter_=sd_filter)

        halrcomp = halremote.component('test')
        halrcomp.debug = debug
        halrcomp.newpin("coolant-iocontrol", halremote.HAL_BIT, halremote.HAL_IN)
        halrcomp.newpin("coolant", halremote.HAL_BIT, halremote.HAL_OUT)
        self.halrcomp = halrcomp
        self.sd.register(halrcomp)

        halrcomp2 = halremote.RemoteComponent(name='test2', debug=debug)
        halrcomp2.newpin("coolant-iocontrol", halremote.HAL_BIT, halremote.HAL_IN)
        halrcomp2.newpin("coolant", halremote.HAL_BIT, halremote.HAL_OUT)
        self.halrcomp2 = halrcomp2
        self.sd.register(halrcomp2)

        self.status = ApplicationStatus(debug=debug)
        self.status.on_synced_changed.append(self._on_status_synced)
        self.sd.register(self.status)
        self.command = ApplicationCommand(debug=debug)
        self.sd.register(self.command)
        self.error = ApplicationError(debug=debug)
        self.sd.register(self.error)
        self.fileservice = ApplicationFile(debug=debug)
        self.fileservice.local_file_path = 'test.ngc'
        self.fileservice.local_path = './ngc/'
        self.fileservice.remote_path = '/home/xy/'
        self.fileservice.remote_file_path = '/home/xy/test.ngc'
        self.fileservice.on_ready_changed.append(self._on_fileservice_ready)
        self.sd.register(self.fileservice)

        self.timer = None
        self.timer_interval = 0.1

        self.use_curses = use_curses
        if not self.use_curses:
            return

        self.messages = []

        self.screen = curses.initscr()
        self.screen.keypad(True)
        self.dro_window = curses.newwin(10, 40, 1, 2)
        self.status_window = curses.newwin(10, 40, 1, 44)
        self.command_window = curses.newwin(10, 40, 1, 86)
        self.connection_window = curses.newwin(10, 80, 12, 2)
        self.error_window = curses.newwin(20, 120, 12, 84)
        self.file_window = curses.newwin(10, 80, 1, 108)
        curses.noecho()
        curses.cbreak()
Esempio n. 8
0
    def __init__(self):
        self.sd = ServiceDiscovery()

        rcomp = halremote.RemoteComponent('anddemo', debug=False)
        rcomp.no_create = True
        rcomp.newpin('button0', halremote.HAL_BIT, halremote.HAL_OUT)
        rcomp.newpin('button1', halremote.HAL_BIT, halremote.HAL_OUT)
        led_pin = rcomp.newpin('led', halremote.HAL_BIT, halremote.HAL_IN)
        led_pin.on_value_changed.append(self.led_pin_changed)
        led_pin.on_synced_changed.append(self.led_pin_synced)
        rcomp.on_connected_changed.append(self._connected)

        self.halrcomp = rcomp
        self.sd.register(rcomp)
Esempio n. 9
0
    def __init__(self, debug=False):
        self.debug = debug
        context = zmq.Context()
        context.linger = 0
        self.context = context

        services = ['launchercmd', 'halrcmd', 'command', 'config']
        for service in services:
            sd = ServiceDiscovery(service_type="_%s._sub._machinekit._tcp" % service)
            sd.on_discovered.append(self.service_discovered)
            sd.on_disappeared.append(self.service_disappeared)
            sd.start()
            #self.launcher_sd = launcher_sd

        self.tx = Container()
        self.rx = Container()
Esempio n. 10
0
    def __init__(self, debug=False):
        self.debug = debug
        context = zmq.Context()
        context.linger = 0
        self.context = context

        self.sd = ServiceDiscovery()
        services = ['launchercmd', 'halrcmd', 'command', 'config']
        for name in services:
            service = Service(type_=name)
            self.sd.register(service)
            service.on_ready_changed.append(
                partial(self.service_ready, service=service))

        self._tx = Container()
        self._rx = Container()
Esempio n. 11
0
    def __init__(self):
        launcher_sd = ServiceDiscovery(
            service_type="_launcher._sub._machinekit._tcp")
        launcher_sd.on_discovered.append(self.service_discovered)
        launcher_sd.on_disappeared.append(self.service_disappeared)
        launcher_sd.start()
        self.launcher_sd = launcher_sd

        self.halrcompReady = False
        self.halrcmdReady = False
        halrcomp = halremote.RemoteComponent('anddemo')
        halrcomp.newpin('button0', halremote.HAL_BIT, halremote.HAL_OUT)
        halrcomp.newpin('button1', halremote.HAL_BIT, halremote.HAL_OUT)
        halrcomp.newpin('led', halremote.HAL_BIT, halremote.HAL_IN)
        halrcomp.no_create = True
        self.halrcomp = halrcomp
Esempio n. 12
0
    def run(self):
        timeout = 2.0

        sd = ServiceDiscovery()
        halrcomp = halremote.RemoteComponent('anddemo')
        halrcomp.newpin('button0', halremote.HAL_BIT, halremote.HAL_OUT)
        halrcomp.newpin('button1', halremote.HAL_BIT, halremote.HAL_OUT)
        halrcomp.newpin('led', halremote.HAL_BIT, halremote.HAL_IN)
        sd.register(halrcomp)

        sd.start()
        print('waiting for component connected')
        assert halrcomp.wait_connected(timeout)
        print('component connected')
        print('stopping service discovery')
        sd.stop()
        print('completed')
Esempio n. 13
0
    def __init__(self, com_pin=board.D18, num_pixels=16, debug=False):
        self.pixels = neopixel.NeoPixel(com_pin, num_pixels)
        self._connected = False
        self._enabled = False
        self._update_light()

        rcomp = halremote.RemoteComponent('neopixel', debug=debug)
        rcomp.no_create = True
        enable_pin = rcomp.newpin('enable', halremote.HAL_BIT,
                                  halremote.HAL_IN)
        enable_pin.on_value_changed.append(self._enable_pin_changed)
        mode_pin = rcomp.newpin('mode', halremote.HAL_U32, halremote.HAL_IN)
        mode_pin.on_value_changed.append(self._mode_pin_changed)
        rcomp.on_connected_changed.append(self._connected_changed)

        self.rcomp = rcomp
        self.sd = ServiceDiscovery(filter_=ServiceDiscoveryFilter(
            txt_records={b'uuid': MK_UUID}))
        self.sd.register(rcomp)
Esempio n. 14
0
    def __init__(self):
        self.sd = ServiceDiscovery(nameservers=['192.168.7.2'])

        rcomp = halremote.RemoteComponent('command-interface', debug=False)
        rcomp.no_create = False
        for i in range(MAX_AXES):
            rcomp.newpin('joint%i.position-cmd' % i, halremote.HAL_FLOAT,
                         halremote.HAL_OUT)
            rcomp.newpin('joint%i.position-fb' % i, halremote.HAL_FLOAT,
                         halremote.HAL_IN)
            rcomp.newpin('joint%i.enable' % i, halremote.HAL_BIT,
                         halremote.HAL_IO)
            rcomp.newpin('joint%i.position-max' % i, halremote.HAL_FLOAT,
                         halremote.HAL_IO)
            rcomp.newpin('joint%i.position-min' % i, halremote.HAL_FLOAT,
                         halremote.HAL_IO)
        rcomp.on_connected_changed.append(self._connected)

        self.halrcomp = rcomp
        self.sd.register(rcomp)
Esempio n. 15
0
    def __init__(self, uuid, use_curses):
        self.halrcmdReady = False
        self.halrcompReady = False

        halrcomp = halremote.component('test')
        halrcomp.newpin("coolant-iocontrol", halremote.HAL_BIT,
                        halremote.HAL_IN)
        halrcomp.newpin("coolant", halremote.HAL_BIT, halremote.HAL_OUT)
        self.halrcomp = halrcomp

        halrcomp2 = halremote.RemoteComponent(name='test2')
        halrcomp2.newpin("coolant-iocontrol", halremote.HAL_BIT,
                         halremote.HAL_IN)
        halrcomp2.newpin("coolant", halremote.HAL_BIT, halremote.HAL_OUT)
        self.halrcomp2 = halrcomp2

        self.status = ApplicationStatus()
        self.command = ApplicationCommand()
        self.error = ApplicationError()
        self.fileservice = ApplicationFile()
        self.fileservice.local_file_path = 'test.ngc'
        self.fileservice.local_path = './ngc/'
        self.fileservice.remote_path = '/home/xy/'
        self.fileservice.remote_file_path = '/home/xy/test.ngc'

        halrcmd_sd = ServiceDiscovery(
            service_type="_halrcmd._sub._machinekit._tcp", uuid=uuid)
        halrcmd_sd.on_discovered.append(self.halrcmd_discovered)
        halrcmd_sd.start()
        #halrcmd_sd.disappered_callback = disappeared
        self.halrcmd_sd = halrcmd_sd

        halrcomp_sd = ServiceDiscovery(
            service_type="_halrcomp._sub._machinekit._tcp", uuid=uuid)
        halrcomp_sd.on_discovered.append(self.halrcomp_discovered)
        halrcomp_sd.start()
        self.harcomp_sd = halrcomp_sd

        status_sd = ServiceDiscovery(
            service_type="_status._sub._machinekit._tcp", uuid=uuid)
        status_sd.on_discovered.append(self.status_discovered)
        status_sd.on_disappeared.append(self.status_disappeared)
        status_sd.start()
        self.status_sd = status_sd

        command_sd = ServiceDiscovery(
            service_type="_command._sub._machinekit._tcp", uuid=uuid)
        command_sd.on_discovered.append(self.command_discovered)
        command_sd.on_disappeared.append(self.command_disappeared)
        command_sd.start()

        error_sd = ServiceDiscovery(
            service_type="_error._sub._machinekit._tcp", uuid=uuid)
        error_sd.on_discovered.append(self.error_discovered)
        error_sd.on_disappeared.append(self.error_disappeared)
        error_sd.start()

        file_sd = ServiceDiscovery(service_type="_file._sub._machinekit._tcp",
                                   uuid=uuid)
        file_sd.on_discovered.append(self.file_discovered)
        file_sd.on_disappeared.append(self.file_disappeared)
        file_sd.start()

        self.timer = None

        self.use_curses = use_curses
        if not self.use_curses:
            return

        self.messages = []

        self.screen = curses.initscr()
        self.screen.keypad(True)
        self.dro_window = curses.newwin(10, 40, 1, 2)
        self.status_window = curses.newwin(10, 40, 1, 44)
        self.command_window = curses.newwin(10, 40, 1, 86)
        self.connection_window = curses.newwin(10, 80, 12, 2)
        self.error_window = curses.newwin(20, 120, 12, 84)
        self.file_window = curses.newwin(10, 80, 1, 108)
        curses.noecho()
        curses.cbreak()