Ejemplo n.º 1
0
/*
 * Helper function to usbobex_find_interfaces
 */
static int find_obex_data_interface(unsigned char *buffer, int buflen, struct usb_config_descriptor config, struct obex_usb_intf_transport_t *intf)
{
	struct cdc_union_desc *union_header = NULL;
	int i, a;
	int found_active = 0;
	int found_idle = 0;

	if (!buffer) {
		DEBUG(2,"Weird descriptor references");
		return -EINVAL;
	}

	while (buflen > 0) {
		if (buffer [1] != USB_DT_CS_INTERFACE) {
			DEBUG(2,"skipping garbage");
			goto next_desc;
		}
		switch (buffer [2]) {
		case CDC_UNION_TYPE: /* we've found it */
			if (union_header) {
				DEBUG(2,"More than one union descriptor, skiping ...");
				goto next_desc;
			}
			union_header = (struct cdc_union_desc *)buffer;
			break;
		case CDC_OBEX_TYPE: /* maybe check version */
		case CDC_OBEX_SERVICE_ID_TYPE: /* This one is handled later */
		case CDC_HEADER_TYPE:
			break; /* for now we ignore it */
		default:
			DEBUG(2, "Ignoring extra header, type %d, length %d", buffer[2], buffer[0]);
			break;
		}
next_desc:
		buflen -= buffer[0];
		buffer += buffer[0];
	}

	if (!union_header) {
		DEBUG(2,"No union descriptor, giving up\n");
		return -ENODEV;
	}
	/* Found the slave interface, now find active/idle settings and endpoints */
	intf->data_interface = union_header->bSlaveInterface0;
	/* Loop through all of the interfaces */
	for (i = 0; i < config.bNumInterfaces; i++) {
		/* Loop through all of the alternate settings */
		for (a = 0; a < config.interface[i].num_altsetting; a++) {
			/* Check if this interface is OBEX data interface*/
			/* and find endpoints */
			if (config.interface[i].altsetting[a].bInterfaceNumber == intf->data_interface)
				find_eps(intf, config.interface[i].altsetting[a], &found_active, &found_idle);
		}
	}
	if (!found_idle) {
		DEBUG(2,"No idle setting\n");
		return -ENODEV;
	}
	if (!found_active) {
		DEBUG(2,"No active setting\n");
		return -ENODEV;
	}

	return 0;
}
Ejemplo n.º 2
0
strategy_profile_t *descent(polymatrix_t *game, strategy_profile_t *xs, int *scount, double delta)
{
    double *eps_i = calloc(game->players, sizeof(double));
    double eps = compute_eps(game, xs, eps_i);
    g_eps = eps;
    int *K_x = calloc(game->players, sizeof(double));
    strategy_profile_t *x = xs;
    gx = x;
    double Df;
    double e1;
    double e = delta / (delta + 2);
    pivcount = 0;
    int m = get_K_x(eps, eps_i, game->players, K_x);

    //while(eps > 0.5 + delta) {
    while(1) {
        ++pivcount;
        //printf("-------------------------\n");
        //int m = get_K_x(eps, eps_i, game->players, K_x);
        //printf("SKx %d\n", m);
        strategy_profile_t *xp = solve_descent_lp(game, x, scount, delta, K_x, m, &Df);
        Df -= eps;

        strategy_profile_t *np;
        if (line_search > 0) {
            double dist = find_eps(game, x, xp, e, scount);
            np = new_point(x, xp, dist);
        } else {
            np = new_point(x, xp, e);
        }
        //printf("x\n");
        //matrix_print(matrix_trans(x->strategies[0]));
        //matrix_print(matrix_trans(x->strategies[1]));
        //printf("xp\n");
        //matrix_print(matrix_trans(xp->strategies[0]));
        //matrix_print(matrix_trans(xp->strategies[1]));
        //printf("np\n");
        //matrix_print(matrix_trans(np->strategies[0]));
        //matrix_print(matrix_trans(np->strategies[1]));
        //printf("Df %lf ", Df);
        //Df = delta_Df(game, x, xp, delta, eps, K_x, m);
        //printf("Eps %lf %lf\n", eps, Df);
        e1 = compute_eps(game, np, eps_i);
        //printf("Np %lf %lf\n", eps, e1);
        //e = delta / (delta + 2);
        if (err_le(eps, e1) && !err_eq(e1, eps)) {
            printf("Exiting %lf %lf\n", eps, e1);
            exit(1);
        }
        eps = e1;
        g_eps = eps;
        if (x != xs)
            strategy_free(x);
        strategy_free(xp);
        x = np;
        gx = x;
        if (Df >= -delta)
            break;
    }
    free(eps_i);
    free(K_x);
    return x;
}
Ejemplo n.º 3
0
int
main (int argc, char **argv)
{
  TestFlags flags;
  cube_t *ctx;
  cube_h5_t fd;
  char *filename;
  double eps;
  Test  *test;
  int    fcount;
  int    tcount;
  int    c;
  int    gpu;

  flags = 0;
  gpu = 1;

  opterr = 0;

  while ((c = getopt (argc, argv, "dvH")) != -1)
    switch (c)
      {
      case 'd':
	flags |= TestFlag_Debug;
	break;

      case 'v':
	flags |= TestFlag_Verbose;
	break;

      case 'H':
        gpu = 0;
        break;

      case '?':
      default:
	usage (argv[0]);
	return 0;
      }

  if (!(optind < argc))
    {
      usage (argv[0]);
      return -1;
    }

  eps = find_eps ();
  max_math_dev = eps * 10;
  max_iter_dev = eps;
  max_pinv_dev = eps * 1000;

  printf ("Machine epsilon: %e\n", eps);

  filename = argv[optind];

  ctx = cube_context_new (gpu);

  if (! cube_context_check (ctx))
    {
      fprintf (stderr, "Could not create cube context!\n");
      cube_context_destroy (&ctx);
      return -1;
    }

  fd = cube_h5_open (filename, 0);

  fcount = 0;
  for (test = tests; test->name; test++)
    {
      int failed;
      double ct;
      struct timespec tic, toc;

      printf ("\n** \033[34m%s\033[39m: \n", test->name);

      get_current_time (&tic);
      failed = ! cube_context_check (ctx) || test->func (ctx, fd, flags);
      get_current_time (&toc);

      if (failed)
        fcount++;

      ct = ((toc.tv_sec - tic.tv_sec)  + (double) (toc.tv_nsec - tic.tv_nsec) / 1000000000.0) * 1000.0;
      printf (" * DONE:%s [%f ms]\n", (!failed) ? "\033[32m pass\033[39m" : "\033[31m FAILED\033[39m", ct);
    }

  tcount = (sizeof (tests) / sizeof (Test)) -1;

  printf ("\n** result:");
  if (fcount > 0)
    printf ("\033[31m FAIL\033[39m");
  else
    printf ("\033[32m ok\033[39m");

  printf (" [%d tests, %d passed, %s%d\033[39m failed]\n",
	  tcount,
	  tcount - fcount,
	  fcount > 0 ? "\033[31m" : "",
	  fcount);

  cube_h5_close (fd);
  cube_context_destroy (&ctx);

  return 0;
}