class Glove(object): def __init__(self, exchange, tty, debug): if not debug: log.info("Glove in Live Mode") self.serial = serial.Serial(tty, 115200) else: log.info("Glove in Debug Mode") self.serial = None self.debug = debug self.kinematics = KinematicsSolver(1) self.connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) self.channel = self.connection.channel() # channel.queue_declare(queue='glove') self.channel.exchange_declare(exchange=exchange, type='direct') self.glove = self.channel.queue_declare(exclusive=True) self.glove_queue_name = self.glove.method.queue self.channel.queue_bind(exchange=exchange, routing_key="glove-in", queue=self.glove_queue_name) self.channel.basic_consume(self.glove_callback, queue=self.glove_queue_name, no_ack=True) # self.channel.basic_consume(partial(self.glove_callback, kin=self.kinematics), queue=self.glove_queue_name, no_ack=True) def start(self): log.info("Starting Glove Thread") self.thread = threading.Thread(target=read_from_serial, args=(self.serial, self.connection, self.channel, self.kinematics, self.debug)) self.thread.daemon = True self.thread.start() log.info("Glove Up and Running") def stop(self): self.thread.join(0) self.connection.close() def glove_callback(self, ch, method, properties, body): log.warn("Resetting Kinematics...") self.kinematics.reset() log.info("Kinematics Reset Complete")
def __init__(self, exchange, tty, debug): if not debug: log.info("Glove in Live Mode") self.serial = serial.Serial(tty, 115200) else: log.info("Glove in Debug Mode") self.serial = None self.debug = debug self.kinematics = KinematicsSolver(1) self.connection = pika.BlockingConnection(pika.ConnectionParameters('localhost')) self.channel = self.connection.channel() # channel.queue_declare(queue='glove') self.channel.exchange_declare(exchange=exchange, type='direct') self.glove = self.channel.queue_declare(exclusive=True) self.glove_queue_name = self.glove.method.queue self.channel.queue_bind(exchange=exchange, routing_key="glove-in", queue=self.glove_queue_name) self.channel.basic_consume(self.glove_callback, queue=self.glove_queue_name, no_ack=True)