Exemplo n.º 1
0
def main():
    # Parse CLI args
    args = setup_cli_args(cli.grpc_host, cli.log_level)

    # Setup logging
    setup_logging(level=args[LOG_LEVEL])

    http = Flask(__name__)

    @http.route("/count")
    def val_count():
        global count
        return "Read {0} values".format(count)

    def read_values():
        global count
        while True:
            print("Got location: {0}".format(client.get_xy()))
            count += 1

    # Start client
    with LocationClient(args[GRPC_HOST]) as client:

        # Run read_values in a thread
        count = 0
        Thread(target=read_values).start()

        # Run HTTP server in a thread
        Thread(target=http.run, kwargs={"port": 8080}).start()

        sleep()
def main():
    # Parse CLI args
    args = setup_cli_args(ImageServer.args, cli.camera_name_optional,
                          fifo_name_option, fifo_verbose, cli.log_level)

    # Setup logging
    setup_logging(level=args[LOG_LEVEL])

    image_server = ImageServer(template_file=args[TEMPLATE_FILE],
                               image_x=args[IMAGE_X],
                               image_y=args[IMAGE_Y],
                               camera_name=args[CAMERA_NAME],
                               http_port=args[HTTP_PORT],
                               http_delay_secs=args[HTTP_DELAY_SECS],
                               http_verbose=args[HTTP_VERBOSE])
    fifo_reader = FifoReader(image_server=image_server,
                             fifo_name=args[FIFO_NAME],
                             fifo_verbose=args[FIFO_VERBOSE])

    try:
        image_server.start()
        fifo_reader.start()
        sleep()
    except KeyboardInterrupt:
        pass
    finally:
        image_server.stop()
        fifo_reader.stop()

    logger.info("Exiting")
    sys.exit(1)
Exemplo n.º 3
0
    userdata = {
        SHORT_LIDAR_PUB: pub,
        SHORT_LIDAR_RATE: rate,
        HEALTH_PUB: health_pub,
        HEALTH_RATE: health_rate,
        COMMAND: "lidar/{0}/command".format(args[DEVICE]),
        ENABLED: True,
        MOVING_AVERAGE: MovingAverage(size=3),
        #OOR_VALUES: OutOfRangeValues(size=args[OOR_SIZE]),
        #OOR_TIME: args[OOR_TIME],
        #OOR_UPPER: args[OOR_UPPER],
    }

    logger.info("Opened serial port: " +
                SerialReader.lookup_port(args[DEVICE_ID]))

    with SerialReader(func=fetch_data,
                      userdata=userdata,
                      port=SerialReader.lookup_port(args[DEVICE_ID])
                      if args.get(DEVICE_ID) else args[SERIAL_PORT],
                      baudrate=args[BAUD_RATE],
                      debug=True):
        try:
            sleep()
        except KeyboardInterrupt:
            pass
        finally:
            stopped = True

    logger.info("Exiting...")