Esempio n. 1
1
ftdi_device_t* ftdi_context_match_name(const ftdi_context_t* context,
    const char* name) {
  struct stat stat_buffer;
  struct udev* udev = 0;
  struct udev_device* dev = 0;
  int bus = 0;
  int address = 0;
  int i;
  
  if (!stat(name, &stat_buffer) && S_ISCHR(stat_buffer.st_mode)) {
    udev = udev_new();
    dev = udev_device_new_from_devnum(udev, 'c', stat_buffer.st_rdev);

    if (dev) {
      string_scanf(udev_device_get_sysattr_value(dev, "busnum"),
        "%d", &bus);
      string_scanf(udev_device_get_sysattr_value(dev, "devnum"),
        "%d", &address);
    }

    udev_unref(udev);
  }

  for (i = 0; i < context->num_devices; ++i) {
    if ((context->devices[i].bus == bus) &&
        (context->devices[i].address == address))
      return &context->devices[i];
  }
  
  return 0;
}
Esempio n. 2
0
void ftdi_device_init(ftdi_device_t* dev, struct ftdi_context* libftdi_context,
    struct usb_bus* libusb_bus, struct usb_device* libusb_device) {
  dev->libftdi_context = libftdi_context;
  dev->libusb_device = libusb_device;

  dev->bus = libusb_bus->location;
  string_scanf(libusb_device->filename, "%d", &dev->address);

  dev->product_id = libusb_device->descriptor.idProduct;
  
  switch (libusb_device->descriptor.bcdDevice) {
    case 0x0400:
      dev->chip = ftdi_chip_bm;
      break;
    case 0x0200:
      if (!libusb_device->descriptor.iSerialNumber)
        dev->chip = ftdi_chip_bm;
      else
        dev->chip = ftdi_chip_am;
      break;
    case 0x0500:
      dev->chip = ftdi_chip_2232c;
      break;
    case 0x0600:
      dev->chip = ftdi_chip_r;
      break;
    case 0x0700:
      dev->chip = ftdi_chip_2232h;
      break;
    case 0x0800:
      dev->chip = ftdi_chip_4232h;
      break;
    case 0x0900:
      dev->chip = ftdi_chip_232h;
      break;
    default:
      dev->chip = ftdi_chip_unkown;
  }
  dev->interface = ftdi_interface_any;
  
  dev->baud_rate = 0;
  dev->data_bits = 0;
  dev->stop_bits = 0;
  dev->parity= ftdi_parity_none;
  dev->flow_ctrl = ftdi_flow_ctrl_off;
  dev->break_type = ftdi_break_off;

  dev->timeout = 0.0;
  dev->latency = 0.0;
  
  dev->num_read = 0;
  dev->num_written = 0;
  
  error_init(&dev->error, ftdi_errors);
}
Esempio n. 3
0
/* Fills the 'prop' array with all the 'property' fields read from
 * 'data' before encoutering another 'element' field (or a
 * 'end_header'). Returns 0 upons success and a negative value if a
 * failure occurs. */
static int read_properties(struct file_data *data, struct ply_prop **prop) 
{
  int c;
  char stmp[MAX_WORD_LEN+1];
  int n_prop=0;
  int rcode=0;
  do {
    skip_ws_comm(data);
    c = getc(data);
    if (c == 'p') {
      c = ungetc(c, data);
      if (string_scanf(data, stmp) == 1 && strcmp(stmp, "property") == 0) {
        *prop = realloc(*prop, (n_prop+1)*sizeof(struct ply_prop));
        memset(*prop+n_prop, 0, sizeof(struct ply_prop));
        if (skip_ws_str_scanf(data, stmp) == 1) {
          if (strcmp(stmp, "list") == 0) { /* do we have a list ? */
            (*prop)[n_prop].is_list = 1;
            if (skip_ws_str_scanf(data, stmp) == 1) {/* if yes, we need to
                                                        read an additional
                                                        field */
              (*prop)[n_prop].type_list = get_type(stmp);
              if (skip_ws_str_scanf(data, stmp) != 1)
                rcode = MESH_CORRUPTED;
            }
            else
              rcode = MESH_CORRUPTED;
          }
          (*prop)[n_prop].type_prop = get_type(stmp);

          
          /* Get the property name */
          if (skip_ws_str_scanf(data, stmp) == 1) {
            (*prop)[n_prop++].prop = get_prop_name(stmp);
            skip_ws_comm(data);
          } else
            rcode = MESH_CORRUPTED;
        } else
          rcode = MESH_CORRUPTED;
      } else
        rcode = MESH_CORRUPTED;
    }
  } while (rcode >= 0 && c == 'p');
  c = ungetc(c, data);
  return (rcode < 0) ? rcode : n_prop;
}
Esempio n. 4
0
/* Just a small wrapper : skip all whitespace chars and read the
 * string that follows. Returns 1 upon success */
static int skip_ws_str_scanf(struct file_data *data, char *out) 
{
  skip_ws_comm(data);
  return string_scanf(data, out);
}