def main(): class FrameCollector(object): def __init__(self): self.frame = None def __call__(self, x): self.frame = x collector = FrameCollector() loop = echolib.IOLoop() client = echolib.Client() loop.add_handler(client) sub = FrameSubscriber(client, "camera", collector) try: while loop.wait(10): if collector.frame is not None: display(collector.frame) collector.frame = None except KeyboardInterrupt: pass sys.exit(1)
def __init__(self, bounds=None): self.loop = echolib.IOLoop() self.client = echolib.Client( name=os.environ.get("APPLICATION_NAME", "")) self.loop.add_handler(self.client) self.bounds = bounds self.camera = Camera(self, "camera0") self.manipulator = Manipulator(self, "manipulator0") self.markers_pub = MarkersPublisher(self.client, "markers") while not (self.camera.is_ready() and self.manipulator.is_ready()): self.wait(100)
def start_app(app): from manus.apps import AppCommandType, AppCommandPublisher, AppCommand loop = echolib.IOLoop() client = echolib.Client(name="appstart") loop.add_handler(client) control = AppCommandPublisher(client, "apps.control") loop.wait(100) message = AppCommand() message.type = AppCommandType.EXECUTE message.arguments.append(app) control.send(message) loop.wait(100)
def __init__(self, stdscreen): self.screen = stdscreen curses.curs_set(0) self.screen.clear() loop = echolib.IOLoop() client = echolib.Client(loop, "/tmp/echo.sock") state = ManipulatorStateSubscriber(client, "manipulator0.state", self.on_state) commands = TrajectorySubscriber(client, "manipulator0.trajectory", self.on_trajectory) while loop.wait(30): pass
def __init__(self): self.active_application = None self.applications = {} self.loop = echolib.IOLoop() self.client = echolib.Client(name="apps") self.loop.add_handler(self.client) self.control = AppCommandSubscriber(self.client, "apps.control", lambda x: self.control_callback(x)) self.announce = AppEventPublisher(self.client, "apps.announce") self.listing = AppListingPublisher(self.client, "apps.list") self.output = AppStreamDataPublisher(self.client, "apps.output") self.input = AppStreamDataSubscriber(self.client, "apps.input", lambda x: self.input_callback(x))
def main(): def message(message): reader = echolib.MessageReader(message) name = reader.readString() message = reader.readString() print(name + ": " + message) def write(client, pub, name): while client.isConnected(): try: message = input() writer = echolib.MessageWriter() writer.writeString(name) writer.writeString(message) pub.send(writer) except EOFError: break loop = echolib.IOLoop() client = echolib.Client() loop.add_handler(client) name = input("Please enter your name:") sub = echolib.Subscriber(client, "chat", "string pair", message) pub = echolib.Publisher(client, "chat", "string pair") thread = threading.Thread(target=write, args=( client, pub, name, )) thread.start() try: while loop.wait(10) and thread.is_alive(): # We have to give the write thread some space time.sleep(0.001) except KeyboardInterrupt: pass sys.exit(1)
def main(): loop = echolib.IOLoop() client = echolib.Client() loop.add_handler(client) output = FramePublisher(client, "camera") #count = echolib.SubscriptionWatcher(client, "camera") camera = cv2.VideoCapture(0) if not camera.isOpened(): print("Camera not available") camera = DummyCamera() try: while loop.wait(100): _, image = camera.read() output.send(Frame(image=image)) except Exception as e: traceback.print_exception(e)
return batch = ConfigBatch() for key, value in self.store.items(): batch.entries.append(ConfigEntry(key, value)) self._notify.send(batch) if __name__ == '__main__': if len(sys.argv) > 1: storefile = sys.argv[1] else: storefile = None loop = echolib.IOLoop() client = echolib.Client(name="config") loop.add_handler(client) manager = ConfigManager(client) if storefile is not None and os.path.isfile(storefile): manager.read_config(storefile) def shutdown_handler(signum, frame): if storefile is not None: manager.write_config(storefile) sys.exit(0) signal.signal(signal.SIGTERM, shutdown_handler)