Example #1
0
void
usb_dump_entries(void)
{
	struct usb_blob *pub;
	struct usb_device_id *id;
	uint32_t x;

	id = malloc(usb_blob_count * sizeof(*id));
	if (id == NULL)
		errx(EX_SOFTWARE, "Out of memory");

	/* make linear array of all USB blobs */
	x = 0;
	TAILQ_FOREACH(pub, &usb_blob_head, entry)
	    id[x++] = pub->temp;

	usb_sort_entries(id, usb_blob_count);

	for (x = 0; x != usb_blob_count;)
		x += usb_dump(id + x, usb_blob_count - x);

	free(id);

	printf("# %d USB entries processed\n\n", usb_blob_count);
}
Example #2
0
/*=========================================================================
| MAIN PROGRAM ENTRY POINT
 ========================================================================*/
int main (int argc, char *argv[])
{
    int port       = 0;   // open port 0 by default
    int samplerate = 0;   // in kHz (query)
    int timeout    = 500; // in milliseconds
    int latency    = 200; // in milliseconds
    int num        = 0;

    if (argc < 2) {
        print_usage();
        return 1;
    }

    num = atoi(argv[1]);

    // Open the device
    beagle = bg_open(port);
    if (beagle <= 0) {
        printf("Unable to open Beagle device on port %d\n", port);
        printf("Error code = %d\n", beagle);
        return 1;
    }
    printf("Opened Beagle device on port %d\n", port);

    // Query the samplerate since Beagle USB 480 has a fixed sampling rate
    samplerate = bg_samplerate(beagle, samplerate);
    if (samplerate < 0) {
        printf("error: %s\n", bg_status_string(samplerate));
        return 1;
    }
    printf("Sampling rate set to %d KHz.\n", samplerate);

    // Set the idle timeout.
    // The Beagle read functions will return in the specified time
    // if there is no data available on the bus.
    bg_timeout(beagle, timeout);
    printf("Idle timeout set to %d ms.\n", timeout);

    // Set the latency.
    // The latency parameter allows the programmer to balance the
    // tradeoff between host side buffering and the latency to
    // receive a packet when calling one of the Beagle read
    // functions.
    bg_latency(beagle, latency);
    printf("Latency set to %d ms.\n", latency);

    printf("Host interface is %s.\n",
           (bg_host_ifce_speed(beagle)) ? "high speed" : "full speed");

    // Set up the digital input and output lines
    setup_digital_lines();

    printf("\n");
    fflush(stdout);

    // Capture the USB packets
    usb_dump(num);

    // Close the device
    bg_close(beagle);

    return 0;
}