コード例 #1
0
ファイル: drmdevice.c プロジェクト: grate-driver/libdrm
int
main(void)
{
    drmDevicePtr *devices;
    drmDevicePtr device;
    int fd, ret, max_devices;

    printf("--- Checking the number of DRM device available ---\n");
    max_devices = drmGetDevices2(0, NULL, 0);

    if (max_devices <= 0) {
        printf("drmGetDevices2() has not found any devices (errno=%d)\n",
               -max_devices);
        return 77;
    }
    printf("--- Devices reported %d ---\n", max_devices);


    devices = calloc(max_devices, sizeof(drmDevicePtr));
    if (devices == NULL) {
        printf("Failed to allocate memory for the drmDevicePtr array\n");
        return -1;
    }

    printf("--- Retrieving devices information (PCI device revision is ignored) ---\n");
    ret = drmGetDevices2(0, devices, max_devices);
    if (ret < 0) {
        printf("drmGetDevices2() returned an error %d\n", ret);
        free(devices);
        return -1;
    }

    for (int i = 0; i < ret; i++) {
        print_device_info(devices[i], i, false);

        for (int j = 0; j < DRM_NODE_MAX; j++) {
            if (devices[i]->available_nodes & 1 << j) {
                printf("--- Opening device node %s ---\n", devices[i]->nodes[j]);
                fd = open(devices[i]->nodes[j], O_RDONLY | O_CLOEXEC, 0);
                if (fd < 0) {
                    printf("Failed - %s (%d)\n", strerror(errno), errno);
                    continue;
                }

                printf("--- Retrieving device info, for node %s ---\n", devices[i]->nodes[j]);
                if (drmGetDevice2(fd, DRM_DEVICE_GET_PCI_REVISION, &device) == 0) {
                    print_device_info(device, i, true);
                    drmFreeDevice(&device);
                }
                close(fd);
            }
        }
    }

    drmFreeDevices(devices, ret);
    free(devices);
    return 0;
}
コード例 #2
0
ファイル: drmdevice.c プロジェクト: jonathangray/drm
int
main(void)
{
    drmDevicePtr *devices;
    drmDevicePtr device;
    int fd, ret, max_devices;

    max_devices = drmGetDevices(NULL, 0);

    if (max_devices <= 0) {
        printf("drmGetDevices() has returned %d\n", max_devices);
        return -1;
    }

    devices = calloc(max_devices, sizeof(drmDevicePtr));
    if (devices == NULL) {
        printf("Failed to allocate memory for the drmDevicePtr array\n");
        return -1;
    }

    ret = drmGetDevices(devices, max_devices);
    if (ret < 0) {
        printf("drmGetDevices() returned an error %d\n", ret);
        free(devices);
        return -1;
    }

    for (int i = 0; i < ret; i++) {
        print_device_info(devices[i], i);

        for (int j = 0; j < DRM_NODE_MAX; j++) {
            if (devices[i]->available_nodes & 1 << j) {
                printf("Opening device %d node %s\n", i, devices[i]->nodes[j]);
                fd = open(devices[i]->nodes[j], O_RDONLY | O_CLOEXEC, 0);
                if (fd < 0) {
                    printf("Failed - %s (%d)\n", strerror(errno), errno);
                    continue;
                }

                if (drmGetDevice(fd, &device) == 0) {
                    print_device_info(device, i);
                    drmFreeDevice(&device);
                }
                close(fd);
            }
        }
    }

    drmFreeDevices(devices, ret);
    free(devices);
    return 0;
}
コード例 #3
0
ファイル: compass.c プロジェクト: nishantP-10/WSNS15IRFence
uint8_t init_compass(uint8_t priority)
{
    uint8_t num_tasks = 0;
    int8_t rc;

    LOG("init: prio "); LOGP("%u\r\n", priority);

    // 1 sample per reading and 15Hz frequency
    rc = twi_write(COMPASS_ADDR, REG_CTRL_A, 0x10);
    if (rc == NRK_OK) {
        have_compass = true;
        print_device_info();
    } else {
        have_compass = false;
        WARN("device init failed\r\n");
        /* continue (heading RPC needs to be supported) */
    }


#if ENABLE_COMPASS_RPC
    rpc_init_endpoint(&compass_endpoint);
#endif

    ASSERT(num_tasks == NUM_TASKS(COMPASS));
    return num_tasks;
}
コード例 #4
0
ファイル: cl-helper.c プロジェクト: kristofe/OpenCLFluids
void print_device_info_from_queue(cl_command_queue queue)
{
  cl_device_id dev;
  CALL_CL_GUARDED(clGetCommandQueueInfo,
      (queue, CL_QUEUE_DEVICE, sizeof dev, &dev, NULL));

  print_device_info(dev);
}
コード例 #5
0
ファイル: videohubctrl.c プロジェクト: gfto/videohubctrl
static void print_device_full(struct videohub_data *d) {
	print_device_info(d);
	print_device_video_inputs(d);
	print_device_video_outputs(d);
	print_device_monitoring_outputs(d);
	print_device_serial_ports(d);
	print_device_processing_units(d);
	print_device_frame_buffers(d);
	fflush(stdout);
}
コード例 #6
0
static void print_memory_info (GLenum queryType, NVQRQueryData_t *data)
{
    int num_devices = nvqr_get_num_devices(data);
    int i;

    for (i = 0; i < num_devices; i++) {
        NVQRQueryDeviceInfo *device = nvqr_get_device(data, i);
        printf("  Device %d: ", i);
        print_device_info(queryType, device);
        free(device);
    }
}
コード例 #7
0
ファイル: main.c プロジェクト: fstab/music-box
void print(const char *dev) {
    int fd = open(dev, O_RDONLY);
    if ( fd == -1 ) {
        fprintf(stderr, "Failed to open %s: %s\n", dev, strerror(errno));
        exit(-1);
    }
    printf("\n%s\n", dev);
    print_driver_version(fd);
    print_device_info(fd);
    print_device_name(fd);
    print_device_port(fd);
    close(fd);
}
コード例 #8
0
void print_platform_info(cl_platform_id platform) {
  print_platform_param(platform, CL_PLATFORM_NAME, "Name");
  print_platform_param(platform, CL_PLATFORM_VENDOR, "Vendor");

  cl_uint num_devices;
  CHECK_STATUS(clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices));

  cl_device_id* devices = (cl_device_id*)malloc(sizeof(cl_device_id) * num_devices);
  CHECK_STATUS(clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, num_devices, devices, NULL));

  printf("\nFound %u device(s)\n", num_devices);
  for (int i = 0; i < num_devices; ++i) {
    printf("\nDevice %d\n", i);
    print_device_info(devices[i]);
  }
}
コード例 #9
0
ファイル: timer_resolution.c プロジェクト: ssrg-vt/aira
int main(int argc, char** argv)
{
	cl_device_id dev;
	int i, j;
	unsigned long res;
	cl_runtime rt = new_cl_runtime(false);

	for(i = 0; i < get_num_platforms(); i++)
	{
		for(j = 0; j < get_num_devices(i); j++)
		{
			dev = get_device(rt, i, j);
			print_device_info(dev, false);
			clGetDeviceInfo(dev, CL_DEVICE_PROFILING_TIMER_RESOLUTION, sizeof(cl_ulong), &res, NULL);
			printf("---\nTimer resolution: %lu\n---\n", res);
		}
	}
	delete_cl_runtime(rt);
	return 0;
}
コード例 #10
0
int main () {
	int fd, grabbed;
	char *filename;

	if (getuid() != 0) {
		fprintf(stderr, "Not running as root, no devices may be available.\n");
	}

	filename = scan_devices();
	if (!filename) {
		fprintf(stderr, "Device not found\n");
		return EXIT_FAILURE;
	}

	if ((fd = open(filename, O_RDONLY)) < 0) {
		perror("");
		if (errno == EACCES && getuid() != 0) {
			fprintf(stderr, "You do not have access to %s. Try "
					"running as root instead.\n", filename);
		}
		return EXIT_FAILURE;
	}

	free(filename);

	if (print_device_info(fd)) {
		return EXIT_FAILURE;
	}

	grabbed = ioctl(fd, EVIOCGRAB, (void *) 1);
	ioctl(fd, EVIOCGRAB, (void *) 0);
	if (grabbed) {
		printf("This device is grabbed by another process. Try switching VT.\n");
		return EXIT_FAILURE;
	}

	return print_events(fd);
}
コード例 #11
0
ファイル: util.c プロジェクト: EricTing/geauxdock_cs_v2
cl_device_id
opencl_choose_device (cl_device_type dev_type)
{
#define MAX_PLATFORMS 10
#define MAX_DEVICES 10

    cl_platform_id platforms[MAX_PLATFORMS];
    cl_uint platforms_n = 0;
    cl_device_id devices[MAX_DEVICES];
    cl_uint devices_n = 0;  // devices per platform


    CL_ERR (clGetPlatformIDs (MAX_PLATFORMS, platforms, &platforms_n));
    if (platforms_n < 1) {
        printf ("Error: no platforms found while looking for a platform.\n");
        exit (EXIT_FAILURE);
    }

    cl_uint p;
    for (p = 0; p < platforms_n; ++p) {
        print_platform_info (platforms[p]);
        CL_ERR (clGetDeviceIDs (platforms[p], CL_DEVICE_TYPE_ALL, MAX_DEVICES, devices, &devices_n));
        //CL_ERR (clGetDeviceIDs (platforms[p], dev_type, MAX_DEVICES, devices, &devices_n));

        cl_uint d;
        for (d = 0; d < devices_n; ++d) {
            print_device_info (devices[d]);
            if (dev_type == opencl_device_type (devices[d])) {
                printf ("Choose device %i\n", devices[d]);
                return devices[d];
            }
        }
    }

    printf ("No requested type of device found in the system\n");
    exit (EXIT_FAILURE);
}
コード例 #12
0
ファイル: gauss.c プロジェクト: sifrrich/ocl-examples
int main(int argc, char **argv) {
  cl_int status;

  const char *platform_name = "NVIDIA";

  if (!find_platform(platform_name, &platform)) {
    fprintf(stderr,"Error: Platform \"%s\" not found\n", platform_name);
    print_platforms();
    teardown(-1);
  }

  status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 1, &device, NULL);
  checkError (status, "Error: could not query devices");

  context = clCreateContext(NULL, 1, &device, NULL, NULL, &status);
  checkError(status, "could not create context");

  const char name[] = KERNELDIR "/gauss.cl";

  unsigned char *source;
  size_t size;
  if (!load_file(name, &source, &size)) {
    teardown(-1);
  }

  program = clCreateProgramWithSource(context, 1, (const char **) &source, &size, &status);
  checkError(status, "Error: failed to create program %s: ", name);

  status = clBuildProgram(program, 1, &device, "-I.", NULL, NULL);
  if (status != CL_SUCCESS) {
    print_build_log(program, device);
    checkError(status, "Error: failed to create build %s: ", name);
  }

  free(source);

  print_device_info(device, 0);

  queue = clCreateCommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE, &status);
  checkError(status, "could not create command queue");

  cl_ulong start, end;
  cl_event event;

  unsigned char *data;
  size_t datasize;

  if (!load_file("lena.dat", &data, &datasize)) {
    teardown(-1);
  }

  size_t width  = 512;
  size_t height = 512;
  size_t buf_size = width*height*sizeof(cl_float);

  float *data_out = malloc(buf_size);
  if (!data_out) {
    fprintf(stderr,"\nError: malloc failed\n");
    teardown(-1);
  }

  kernel = clCreateKernel(program, "gauss", &status);
  checkError(status, "could not create kernel");

  cl_image_format format = { CL_R, CL_UNORM_INT8};
  buffer_in = clCreateImage2D (context, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, &format,
    width, height, 0,
    data,
    &status);
  checkError(status, "Error: could not create image");

  buffer_out = clCreateBuffer(context, CL_MEM_READ_WRITE, buf_size, NULL, &status);
  checkError(status, "Error: could not create buffer_out");

  // execute kernel
  int arg = 0;
  status  = clSetKernelArg(kernel, arg++, sizeof(cl_mem), &buffer_in);
  status  = clSetKernelArg(kernel, arg++, sizeof(cl_mem), &buffer_out);
  checkError(status, "Error: could not set args");

  size_t work_size[] = {width, height};
  size_t local_size[] = {1, 1};

  status = clEnqueueNDRangeKernel(queue, kernel, 2, NULL, work_size, local_size, 0, NULL, &event);
  checkError(status, "Error: could not enqueue kernel");

  status = clWaitForEvents(1, &event);
  checkError(status, "Error: could not wait for event");

  status  = clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &start, NULL);
  checkError(status, "Error: could not get start profile information");

  status = clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &end, NULL);
  checkError(status, "Error: could not get end profile information");

  status = clReleaseEvent(event);
  checkError(status, "Error: could not release event");

  // read results back
  status = clEnqueueReadBuffer(queue, buffer_out, CL_FALSE, 0, buf_size, data_out, 0, NULL, NULL);
  checkError(status, "Error: could not copy data into device");

  status  = clFinish(queue);
  checkError(status, "Error: could not finish successfully");

  double elapsed = (end - start) * 1e-9f;
  printf("time: %f\n", elapsed);

  write_bmp("gauss.bmp", data_out, width, height, NORMAL);

  free(data);
  free(data_out);
  teardown(0);
}
コード例 #13
0
int
main(int argc, char **argv)
{
	char	*name, *p;
	mode_t	 mode;
	dev_t	 dev;
	pack_t	*pack;
	u_long	 numbers[MAXARGS];
	int	 n, ch, fifo, hasformat;
	int	 r_flag = 0;		/* force: delete existing entry */
#ifdef KERN_DRIVERS
	int	 l_flag = 0;		/* list device names and numbers */
	int	 major;
#endif
	void	*modes = 0;
	uid_t	 uid = -1;
	gid_t	 gid = -1;
	int	 rval;

	dev = 0;
	fifo = hasformat = 0;
	pack = pack_native;

#ifdef KERN_DRIVERS
	while ((ch = getopt(argc, argv, "lrRF:g:m:u:")) != -1) {
#else
	while ((ch = getopt(argc, argv, "rRF:g:m:u:")) != -1) {
#endif
		switch (ch) {

#ifdef KERN_DRIVERS
		case 'l':
			l_flag = 1;
			break;
#endif

		case 'r':
			r_flag = 1;
			break;

		case 'R':
			r_flag = 2;
			break;

		case 'F':
			pack = pack_find(optarg);
			if (pack == NULL)
				errx(1, "invalid format: %s", optarg);
			hasformat++;
			break;

		case 'g':
			if (optarg[0] == '#') {
				gid = strtol(optarg + 1, &p, 10);
				if (*p == 0)
					break;
			}
			if (gid_name(optarg, &gid) == 0)
				break;
			gid = strtol(optarg, &p, 10);
			if (*p == 0)
				break;
			errx(1, "%s: invalid group name", optarg);

		case 'm':
			modes = setmode(optarg);
			if (modes == NULL)
				err(1, "Cannot set file mode `%s'", optarg);
			break;

		case 'u':
			if (optarg[0] == '#') {
				uid = strtol(optarg + 1, &p, 10);
				if (*p == 0)
					break;
			}
			if (uid_from_user(optarg, &uid) == 0)
				break;
			uid = strtol(optarg, &p, 10);
			if (*p == 0)
				break;
			errx(1, "%s: invalid user name", optarg);

		default:
		case '?':
			usage();
		}
	}
	argc -= optind;
	argv += optind;

#ifdef KERN_DRIVERS
	if (l_flag) {
		print_device_info(argv);
		return 0;
	}
#endif

	if (argc < 2 || argc > 10)
		usage();

	name = *argv;
	argc--;
	argv++;

	umask(mode = umask(0));
	mode = (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) & ~mode;

	if (argv[0][1] != '\0')
		goto badtype;
	switch (*argv[0]) {
	case 'c':
		mode |= S_IFCHR;
		break;

	case 'b':
		mode |= S_IFBLK;
		break;

	case 'p':
		if (hasformat)
			errx(1, "format is meaningless for fifos");
		mode |= S_IFIFO;
		fifo = 1;
		break;

	default:
 badtype:
		errx(1, "node type must be 'b', 'c' or 'p'.");
	}
	argc--;
	argv++;

	if (fifo) {
		if (argc != 0)
			usage();
	} else {
		if (argc < 1 || argc > MAXARGS)
			usage();
	}

	for (n = 0; n < argc; n++) {
		errno = 0;
		numbers[n] = strtoul(argv[n], &p, 0);
		if (*p == 0 && errno == 0)
			continue;
#ifdef KERN_DRIVERS
		if (argc == 2 && n == 0) {
			major = major_from_name(argv[0], mode);
			if (major != -1) {
				numbers[0] = major;
				continue;
			}
			if (!isdigit(*(unsigned char *)argv[0]))
				errx(1, "unknown driver: %s", argv[0]);
		}
#endif
		errx(1, "invalid number: %s", argv[n]);
	}

	switch (argc) {
	case 0:
		dev = 0;
		break;

	case 1:
		dev = numbers[0];
		break;

	default:
		dev = callPack(pack, argc, numbers);
		break;
	}

	if (modes != NULL)
		mode = getmode(modes, mode);
	umask(0);
	rval = fifo ? mkfifo(name, mode) : mknod(name, mode, dev);
	if (rval < 0 && errno == EEXIST && r_flag) {
		struct stat sb;
		if (lstat(name, &sb) != 0 || (!fifo && sb.st_rdev != dev))
			sb.st_mode = 0;

		if ((sb.st_mode & S_IFMT) == (mode & S_IFMT)) {
			if (r_flag == 1)
				/* Ignore permissions and user/group */
				return 0;
			if (sb.st_mode != mode)
				rval = chmod(name, mode);
			else
				rval = 0;
		} else {
			unlink(name);
			rval = fifo ? mkfifo(name, mode)
				    : mknod(name, mode, dev);
		}
	}
	if (rval < 0)
		err(1, "%s", name);
	if ((uid != (uid_t)-1 || gid != (uid_t)-1) && chown(name, uid, gid) == -1)
		/* XXX Should we unlink the files here? */
		warn("%s: uid/gid not changed", name);

	return 0;
}

static void
usage(void)
{
	const char *progname = getprogname();

	(void)fprintf(stderr,
	    "usage: %s [-rR] [-F format] [-m mode] [-u user] [-g group]\n",
	    progname);
	(void)fprintf(stderr,
#ifdef KERN_DRIVERS
	    "                   [ name [b | c] [major | driver] minor\n"
#else
	    "                   [ name [b | c] major minor\n"
#endif
	    "                   | name [b | c] major unit subunit\n"
	    "                   | name [b | c] number\n"
	    "                   | name p ]\n");
#ifdef KERN_DRIVERS
	(void)fprintf(stderr, "       %s -l [driver] ...\n", progname);
#endif
	exit(1);
}

static int
gid_name(const char *name, gid_t *gid)
{
	struct group *g;

	g = getgrnam(name);
	if (!g)
		return -1;
	*gid = g->gr_gid;
	return 0;
}

static dev_t
callPack(pack_t *f, int n, u_long *numbers)
{
	dev_t d;
	const char *error = NULL;

	d = (*f)(n, numbers, &error);
	if (error != NULL)
		errx(1, "%s", error);
	return d;
}
コード例 #14
0
int main()
{
    rs2_error* e = 0;

    // Create a context object. This object owns the handles to all connected realsense devices.
    // The returned object should be released with rs2_delete_context(...)
    rs2_context* ctx = rs2_create_context(RS2_API_VERSION, &e);
    check_error(e);

    /* Get a list of all the connected devices. */
    // The returned object should be released with rs2_delete_device_list(...)
    rs2_device_list* device_list = rs2_query_devices(ctx, &e);
    check_error(e);

    int dev_count = rs2_get_device_count(device_list, &e);
    check_error(e);
    printf("There are %d connected RealSense devices.\n", dev_count);
    if (0 == dev_count)
        return EXIT_FAILURE;

    // Get the first connected device
    // The returned object should be released with rs2_delete_device(...)
    rs2_device* dev = rs2_create_device(device_list, 0, &e);
    check_error(e);

    print_device_info(dev);

    /* Determine depth value corresponding to one meter */
    uint16_t one_meter = (uint16_t)(1.0f / get_depth_unit_value(dev));

    // Create a pipeline to configure, start and stop camera streaming
    // The returned object should be released with rs2_delete_pipeline(...)
    rs2_pipeline* pipeline =  rs2_create_pipeline(ctx, &e);
    check_error(e);

    // Create a config instance, used to specify hardware configuration
    // The retunred object should be released with rs2_delete_config(...)
    rs2_config* config = rs2_create_config(&e);
    check_error(e);

    // Request a specific configuration
    rs2_config_enable_stream(config, STREAM, STREAM_INDEX, WIDTH, HEIGHT, FORMAT, FPS, &e);
    check_error(e);

    // Start the pipeline streaming
    // The retunred object should be released with rs2_delete_pipeline_profile(...)
    rs2_pipeline_profile* pipeline_profile = rs2_pipeline_start_with_config(pipeline, config, &e);
    if (e)
    {
        printf("The connected device doesn't support depth streaming!\n");
        exit(EXIT_FAILURE);
    }

    char buffer[BUFFER_SIZE];
    char* out = NULL;
    while (1)
    {
        // This call waits until a new composite_frame is available
        // composite_frame holds a set of frames. It is used to prevent frame drops
        // The retunred object should be released with rs2_release_frame(...)
        rs2_frame* frames = rs2_pipeline_wait_for_frames(pipeline, 5000, &e);
        check_error(e);

        // Returns the number of frames embedded within the composite frame
        int num_of_frames = rs2_embedded_frames_count(frames, &e);
        check_error(e);

        int i;
        for (i = 0; i < num_of_frames; ++i)
        {
            // The retunred object should be released with rs2_release_frame(...)
            rs2_frame* frame = rs2_extract_frame(frames, i, &e);
            check_error(e);

            // Check if the given frame can be extended to depth frame interface
            // Accept only depth frames and skip other frames
            if (0 == rs2_is_frame_extendable_to(frame, RS2_EXTENSION_DEPTH_FRAME, &e))
                continue;

            /* Retrieve depth data, configured as 16-bit depth values */
            const uint16_t* depth_frame_data = (const uint16_t*)(rs2_get_frame_data(frame, &e));
            check_error(e);

            /* Print a simple text-based representation of the image, by breaking it into 10x5 pixel regions and approximating the coverage of pixels within one meter */
            out = buffer;
            int coverage[ROW_LENGTH] = { 0 }, x, y, i;
            for (y = 0; y < HEIGHT; ++y)
            {
                for (x = 0; x < WIDTH; ++x)
                {
                    // Create a depth histogram to each row
                    int coverage_index = x / WIDTH_RATIO;
                    int depth = *depth_frame_data++;
                    if (depth > 0 && depth < one_meter)
                        ++coverage[coverage_index];
                }

                if ((y % HEIGHT_RATIO) == (HEIGHT_RATIO-1))
                {
                    for (i = 0; i < (ROW_LENGTH); ++i)
                    {
                        static const char* pixels = " .:nhBXWW";
                        int pixel_index = (coverage[i] / (HEIGHT_RATIO * WIDTH_RATIO / sizeof(pixels)));
                        *out++ = pixels[pixel_index];
                        coverage[i] = 0;
                    }
                    *out++ = '\n';
                }
            }
            *out++ = 0;
            printf("\n%s", buffer);

            rs2_release_frame(frame);
        }

        rs2_release_frame(frames);
    }

    // Stop the pipeline streaming
    rs2_pipeline_stop(pipeline, &e);
    check_error(e);

    // Release resources
    rs2_delete_pipeline_profile(pipeline_profile);
    rs2_delete_config(config);
    rs2_delete_pipeline(pipeline);
    rs2_delete_device(dev);
    rs2_delete_device_list(device_list);
    rs2_delete_context(ctx);

    return EXIT_SUCCESS;
}
コード例 #15
0
ファイル: list-caps.c プロジェクト: nickdannenberg/v4l4j
int main(int argc, char** argv) {
	struct capture_device *c;
	struct control_list *l;
	struct v4l2_queryctrl *qc;
	struct video_device *v;
	int std=0, channel=0, i, j;

	if(argc!=2 && argc!=4) {
		printf("This program requires the path to the video device file to be tested.\n");
		printf("The optional second and third arguments are a video standard and channel.\n");
		printf("Usage: %s <video_device_file> [standard channel]\n", argv[0]);
		printf("Video standards: webcam:0 - PAL:1 - SECAM:2 - NTSC:3\n");
		return -1;
	}


	if (argc==4){
		std = atoi(argv[2]);
		channel = atoi(argv[3]);
		printf("Using standard %d, channel %d\n",std, channel);
	}

	v = open_device(argv[1]);
	if(v==NULL){
		printf("Error opening device\n");
		return -1;
	}
	c = init_capture_device(v,MAX_WIDTH,MAX_HEIGHT,channel,std,3);
	c->actions->list_cap(v->fd);
	free_capture_device(v);
	l = get_control_list(v);
	printf("Listing available controls (%d)\n", l->count);
	for(i=0;i<l->count; i++){
		qc = l->controls[i].v4l2_ctrl;
		printf("Control: id: 0x%x - name: %s - min: %d -max: %d - step: %d - type: %d(%s) - flags: %d (%s%s%s%s%s%s)\n",
				qc->id, (char *) &qc->name, qc->minimum, qc->maximum, qc->step, qc->type,
				qc->type == V4L2_CTRL_TYPE_INTEGER ? "Integer" :
				qc->type == V4L2_CTRL_TYPE_BOOLEAN ? "Boolean" :
				qc->type == V4L2_CTRL_TYPE_MENU ? "Menu" :
				qc->type == V4L2_CTRL_TYPE_BUTTON ? "Button" :
				qc->type == V4L2_CTRL_TYPE_INTEGER64 ? "Integer64" :
				qc->type == V4L2_CTRL_TYPE_CTRL_CLASS ? "Class" :
				qc->type == V4L2_CTRL_TYPE_STRING ? "String" :
				qc->type == V4L2_CTRL_TYPE_BITMASK ? "Bitmask" : "",
				qc->flags,
				qc->flags & V4L2_CTRL_FLAG_DISABLED ? "Disabled " : "",
				qc->flags & V4L2_CTRL_FLAG_GRABBED ? "Grabbed " : "",
				qc->flags & V4L2_CTRL_FLAG_READ_ONLY ? "ReadOnly " : "",
				qc->flags & V4L2_CTRL_FLAG_UPDATE ? "Update " : "",
				qc->flags & V4L2_CTRL_FLAG_INACTIVE ? "Inactive " : "",
				qc->flags & V4L2_CTRL_FLAG_SLIDER ? "slider " : "",
				qc->flags & V4L2_CTRL_FLAG_WRITE_ONLY ? "Write only" : "");

		if(l->controls[i].count_menu!=0){
			printf("Menu items (%d) %s\n", l->controls[i].count_menu, l->controls[i].v4l2_ctrl->step==1?"contiguous":"non-contiguous");
			for(j=0; j<l->controls[i].count_menu; j++)
				printf("\tMenu item: %s - %d\n", l->controls[i].v4l2_menu[j].name, l->controls[i].v4l2_menu[j].index);

		}
	}

	get_device_info(v);
	print_device_info(v);
	release_device_info(v);

	release_control_list(v);

	close_device(v);

	return 0;
}
コード例 #16
0
ファイル: videohubctrl.c プロジェクト: gfto/videohubctrl
int main(int argc, char **argv) {
	struct videohub_data *data = &maindata;

	parse_options(data, argc, argv);
	set_log_io_errors(0);

	if (!test_data) {
		data->dev_fd = connect_client(SOCK_STREAM, data->dev_host, data->dev_port);
		if (data->dev_fd < 0)
			exit(EXIT_FAILURE);
	}

	reset_routed_to(&data->inputs);
	reset_routed_to(&data->outputs);
	reset_routed_to(&data->serial);
	reset_routed_to(&data->proc_units);
	reset_routed_to(&data->frames);
	read_device_command_stream(data);

	if (test_data)
		parse_text_buffer(data, test_data);

	if (!strlen(data->device.protocol_ver) || !strlen(data->device.model_name))
		die("The device does not respond correctly. Is it Videohub?");

	if (strstr(data->device.protocol_ver, "2.") != data->device.protocol_ver)
		q("WARNING: Device protocol is %s but this program is tested with 2.x only.\n",
			data->device.protocol_ver);

	if (!data->device.dev_present) {
		if (data->device.needs_fw_update) {
			die("Device reports that it needs firmware update.");
		}
		die("Device reports that it is not present.");
	}

	check_number_of_ports(&data->inputs);
	check_number_of_ports(&data->outputs);
	check_number_of_ports(&data->mon_outputs);
	check_number_of_ports(&data->serial);
	check_number_of_ports(&data->proc_units);
	check_number_of_ports(&data->frames);

	if (num_parsed_cmds) {
		unsigned int i;
		for (i = 0; i < ARRAY_SIZE(parsed_cmds.entry); i++) {
			struct vcmd_entry *ve = &parsed_cmds.entry[i];
			if (!ve->p1.param)
				continue;
			prepare_cmd_entry(data, &parsed_cmds.entry[i]);
		}

		for (i = 0; i < ARRAY_SIZE(parsed_cmds.entry); i++) {
			char cmd_buffer[1024];
			struct vcmd_entry *ve = &parsed_cmds.entry[i];
			if (!ve->p1.param)
				continue;
			format_cmd_text(ve, cmd_buffer, sizeof(cmd_buffer));
			if (strlen(cmd_buffer)) {
				show_cmd(data, ve);
				send_device_command(data, cmd_buffer);
				read_device_command_stream(data);
			}
		}
		// Show the result after commands
		if (test_data)
			print_device_full(data);
	} else if (show_monitor) {
		while (1) {
			int sleeps = 0;
			printf("\e[2J\e[H"); // Clear screen
			time_t now = time(NULL);
			struct tm *tm = localtime(&now);
			printf("Last update: %s\n", asctime(tm));
			print_device_info(data);
			print_device_video_inputs(data);
			print_device_video_outputs(data);
			fflush(stdout);
			do {
				usleep(500000);
				if (++sleeps >= 20)
					send_device_command(data, "PING:\n\n");
			} while (read_device_command_stream(data) == 0);
		}
	} else if (show_list) {
コード例 #17
0
ファイル: reduce.c プロジェクト: sifrrich/ocl-examples
int main(int argc, char **argv) {
  cl_int status;

  const char *platform_name = "NVIDIA";

  if (!find_platform(platform_name, &platform)) {
    fprintf(stderr,"Error: Platform \"%s\" not found\n", platform_name);
    print_platforms();
    teardown(-1);
  }

  status = clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 1, &device, NULL);
  checkError (status, "Error: could not query devices");

  context = clCreateContext(NULL, 1, &device, NULL, NULL, &status);
  checkError(status, "could not create context");

  const char name[] = KERNELDIR "/reduce.cl";

  unsigned char *source;
  size_t size;
  if (!load_file(name, &source, &size)) {
    teardown(-1);
  }

  program = clCreateProgramWithSource(context, 1, (const char **) &source, &size, &status);
  checkError(status, "Error: failed to create program %s: ", name);

  status = clBuildProgram(program, 1, &device, "-I.", NULL, NULL);

  if (status != CL_SUCCESS) {
    print_build_log(program, device);
    checkError(status, "Error: failed to create build %s: ", name);
  }

  free(source);

  print_device_info(device, 0);

  queue = clCreateCommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE, &status);
  checkError(status, "could not create command queue");

  cl_ulong start, end;
  cl_event event;

  size_t width  = 1024+1024;
  size_t buf_size = width*sizeof(cl_float);

  kernel = clCreateKernel(program, "reduce", &status);
  checkError(status, "could not create kernel");

  size_t work_size = width;
  size_t local_size = 64;
  size_t local_buf_size = local_size * sizeof(cl_float);
  size_t groups = width / local_size;
  size_t res_buf_size = groups * sizeof(cl_float);

  float *data_in  = malloc(buf_size);
  float *data_out = malloc(res_buf_size);
  if (!data_in || !data_out) {
    fprintf(stderr,"\nError: malloc failed\n");
    teardown(-1);
  }

  for (unsigned int i = 0; i < width; ++i) {
    data_in[i] = (float) (i % 16);
  }

  buffer_in = clCreateBuffer(context, CL_MEM_READ_WRITE, buf_size, NULL, &status);
  checkError(status, "Error: could not create buffer_in");

  buffer_out = clCreateBuffer(context, CL_MEM_READ_WRITE, res_buf_size, NULL, &status);
  checkError(status, "Error: could not create buffer_out");

  status = clEnqueueWriteBuffer(queue, buffer_in, CL_FALSE, 0, buf_size, data_in, 0, NULL, NULL);
  checkError(status, "Error: could not copy data into device");

  // execute kernel
  int arg = 0;
  status  = clSetKernelArg(kernel, arg++, sizeof(cl_mem), &buffer_in);
  status  = clSetKernelArg(kernel, arg++, sizeof(cl_mem), &buffer_out);
  status  = clSetKernelArg(kernel, arg++, local_buf_size, NULL);
  status  = clSetKernelArg(kernel, arg++, sizeof(cl_int), &width);
  checkError(status, "Error: could not set args");

  status = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &work_size, &local_size, 0, NULL, &event);
  checkError(status, "Error: could not enqueue kernel");

  status = clWaitForEvents(1, &event);
  checkError(status, "Error: could not wait for event");

  status  = clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_START, sizeof(cl_ulong), &start, NULL);
  checkError(status, "Error: could not get start profile information");

  status = clGetEventProfilingInfo(event, CL_PROFILING_COMMAND_END, sizeof(cl_ulong), &end, NULL);
  checkError(status, "Error: could not get end profile information");

  status = clReleaseEvent(event);
  checkError(status, "Error: could not release event");

  // read results back
  status = clEnqueueReadBuffer(queue, buffer_out, CL_TRUE, 0, res_buf_size, data_out, 0, NULL, NULL);
  checkError(status, "Error: could not copy data into device");

  status  = clFinish(queue);
  checkError(status, "Error: could not finish successfully");

  float clsum = 0;
  for (unsigned int i = 0; i < groups; ++i) {
    clsum += data_out[i];
  }

#ifdef DEBUG
  for (int i = 0; i < groups; ++i) {
    printf("%.0f ", data_out[i]);
  }
#endif

  double elapsed = (end - start) * 1e-9f;
  printf("time: %f\n", elapsed);

  float sum = 0;
  for (unsigned int i = 0; i < width; ++i) {
    sum += data_in[i];
  }

  if (sum != clsum)
    fprintf(stderr, "Compare failed: %f != %f\n", clsum, sum);


  free(data_in);
  free(data_out);
  teardown(0);
}
コード例 #18
0
ファイル: rs-distance.c プロジェクト: Andy95800/librealsense
int main()
{
    rs2_error* e = 0;

    // Create a context object. This object owns the handles to all connected realsense devices.
    // The returned object should be released with rs2_delete_context(...)
    rs2_context* ctx = rs2_create_context(RS2_API_VERSION, &e);
    check_error(e);

    /* Get a list of all the connected devices. */
    // The returned object should be released with rs2_delete_device_list(...)
    rs2_device_list* device_list = rs2_query_devices(ctx, &e);
    check_error(e);

    int dev_count = rs2_get_device_count(device_list, &e);
    check_error(e);
    printf("There are %d connected RealSense devices.\n", dev_count);
    if (0 == dev_count)
        return EXIT_FAILURE;

    // Get the first connected device
    // The returned object should be released with rs2_delete_device(...)
    rs2_device* dev = rs2_create_device(device_list, 0, &e);
    check_error(e);

    print_device_info(dev);

    // Create a pipeline to configure, start and stop camera streaming
    // The returned object should be released with rs2_delete_pipeline(...)
    rs2_pipeline* pipeline =  rs2_create_pipeline(ctx, &e);
    check_error(e);

    // Create a config instance, used to specify hardware configuration
    // The retunred object should be released with rs2_delete_config(...)
    rs2_config* config = rs2_create_config(&e);
    check_error(e);

    // Request a specific configuration
    rs2_config_enable_stream(config, STREAM, STREAM_INDEX, WIDTH, HEIGHT, FORMAT, FPS, &e);
    check_error(e);

    // Start the pipeline streaming
    // The retunred object should be released with rs2_delete_pipeline_profile(...)
    rs2_pipeline_profile* pipeline_profile = rs2_pipeline_start_with_config(pipeline, config, &e);
    if (e)
    {
        printf("The connected device doesn't support depth streaming!\n");
        exit(EXIT_FAILURE);
    }

    while (1)
    {
        // This call waits until a new composite_frame is available
        // composite_frame holds a set of frames. It is used to prevent frame drops
        // The retunred object should be released with rs2_release_frame(...)
        rs2_frame* frames = rs2_pipeline_wait_for_frames(pipeline, 5000, &e);
        check_error(e);

        // Returns the number of frames embedded within the composite frame
        int num_of_frames = rs2_embedded_frames_count(frames, &e);
        check_error(e);

        int i;
        for (i = 0; i < num_of_frames; ++i)
        {
            // The retunred object should be released with rs2_release_frame(...)
            rs2_frame* frame = rs2_extract_frame(frames, i, &e);
            check_error(e);

            // Check if the given frame can be extended to depth frame interface
            // Accept only depth frames and skip other frames
            if (0 == rs2_is_frame_extendable_to(frame, RS2_EXTENSION_DEPTH_FRAME, &e))
                continue;

            // Get the depth frame's dimensions
            int width = rs2_get_frame_width(frame, &e);
            check_error(e);
            int height = rs2_get_frame_height(frame, &e);
            check_error(e);

            // Query the distance from the camera to the object in the center of the image
            float dist_to_center = rs2_depth_frame_get_distance(frame, width / 2, height / 2, &e);
            check_error(e);

            // Print the distance
            printf("The camera is facing an object %.3f meters away.\n", dist_to_center);

            rs2_release_frame(frame);
        }

        rs2_release_frame(frames);
    }

    // Stop the pipeline streaming
    rs2_pipeline_stop(pipeline, &e);
    check_error(e);

    // Release resources
    rs2_delete_pipeline_profile(pipeline_profile);
    rs2_delete_config(config);
    rs2_delete_pipeline(pipeline);
    rs2_delete_device(dev);
    rs2_delete_device_list(device_list);
    rs2_delete_context(ctx);

    return EXIT_SUCCESS;
}