X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=blobdiff_plain;f=examples%2Fstream_test.c;h=43abea9506c1d93b175c86600dbe1c641a1bcf44;hp=2c552e6018048278141c06f9fc7f64d7af72af40;hb=19f1452cde9bfe9da0e2830af128fae958ae877a;hpb=705f012d7f828e212986c21f30abb2c12cb8068a diff --git a/examples/stream_test.c b/examples/stream_test.c index 2c552e6..43abea9 100644 --- a/examples/stream_test.c +++ b/examples/stream_test.c @@ -46,10 +46,10 @@ static void usage(const char *argv0) { fprintf(stderr, - "Usage: %s [tions...] \n" + "Usage: %s [options...] \n" "Test streaming read from FT2232H\n" - "[-P string] only look for product with given string" - "[-n] don't check for special block structure" + "[-P string] only look for product with given string\n" + "[-n] don't check for special block structure\n" "\n" "If some filename is given, write data read to that file\n" "Progess information is printed each second\n" @@ -57,7 +57,7 @@ usage(const char *argv0) "\n" "Options:\n" "\n" - "Copyright (C) 2009 Micah Dowty \n", + "Copyright (C) 2009 Micah Dowty \n" "Adapted for use with libftdi (C) 2010 Uwe Bonnes \n", argv0); exit(1); @@ -83,8 +83,8 @@ readCallback(uint8_t *buffer, int length, FTDIProgressInfo *progress, void *user if (start && (num != start +0x4000)) { uint32_t delta = ((num-start)/0x4000)-1; - fprintf(stderr, "Skip %7d blocks from 0x%08x to 0x%08x at blocks %10ld \n", - delta, start -0x4000, num, blocks); + fprintf(stderr, "Skip %7d blocks from 0x%08x to 0x%08x at blocks %10llu\n", + delta, start -0x4000, num, (unsigned long long)blocks); n_err++; skips += delta; } @@ -98,8 +98,8 @@ readCallback(uint8_t *buffer, int length, FTDIProgressInfo *progress, void *user if (start && (num != start +0x4000)) { uint32_t delta = ((num-start)/0x4000)-1; - fprintf(stderr, "Skip %7d blocks from 0x%08x to 0x%08x at blocks %10ld \n", - delta, start -0x4000, num, blocks); + fprintf(stderr, "Skip %7d blocks from 0x%08x to 0x%08x at blocks %10llu\n", + delta, start -0x4000, num, (unsigned long long) blocks); n_err++; skips += delta; } @@ -107,7 +107,7 @@ readCallback(uint8_t *buffer, int length, FTDIProgressInfo *progress, void *user } else if (rem) start += 0x4000; - if (rem != 0); + if (rem != 0) { blocks ++; offset = 16-rem; @@ -136,7 +136,7 @@ readCallback(uint8_t *buffer, int length, FTDIProgressInfo *progress, void *user int main(int argc, char **argv) { - struct ftdi_context ftdic; + struct ftdi_context *ftdi; int err, c; FILE *of = NULL; char const *outfile = 0; @@ -172,34 +172,38 @@ int main(int argc, char **argv) usage(argv[0]); } - if (ftdi_init(&ftdic) < 0) + if ((ftdi = ftdi_new()) == 0) { - fprintf(stderr, "ftdi_init failed\n"); + fprintf(stderr, "ftdi_new failed\n"); return EXIT_FAILURE; } - if (ftdi_set_interface(&ftdic, INTERFACE_A) < 0) + if (ftdi_set_interface(ftdi, INTERFACE_A) < 0) { fprintf(stderr, "ftdi_set_interface failed\n"); + ftdi_free(ftdi); return EXIT_FAILURE; } - if (ftdi_usb_open_desc(&ftdic, 0x0403, 0x6010, descstring, NULL) < 0) + if (ftdi_usb_open_desc(ftdi, 0x0403, 0x6010, descstring, NULL) < 0) { - fprintf(stderr,"Can't open ftdi device: %s\n",ftdi_get_error_string(&ftdic)); + fprintf(stderr,"Can't open ftdi device: %s\n",ftdi_get_error_string(ftdi)); + ftdi_free(ftdi); return EXIT_FAILURE; } /* A timeout value of 1 results in may skipped blocks */ - if(ftdi_set_latency_timer(&ftdic, 2)) + if(ftdi_set_latency_timer(ftdi, 2)) { - fprintf(stderr,"Can't set latency, Error %s\n",ftdi_get_error_string(&ftdic)); + fprintf(stderr,"Can't set latency, Error %s\n",ftdi_get_error_string(ftdi)); + ftdi_usb_close(ftdi); + ftdi_free(ftdi); return EXIT_FAILURE; } -/* if(ftdi_usb_purge_rx_buffer(&ftdic) < 0) +/* if(ftdi_usb_purge_rx_buffer(ftdi) < 0) { - fprintf(stderr,"Can't rx purge\n",ftdi_get_error_string(&ftdic)); + fprintf(stderr,"Can't rx purge\n",ftdi_get_error_string(ftdi)); return EXIT_FAILURE; }*/ if (outfile) @@ -210,7 +214,7 @@ int main(int argc, char **argv) outputFile = of; signal(SIGINT, sigintHandler); - err = ftdi_readstream(&ftdic, readCallback, NULL, 8, 256); + err = ftdi_readstream(ftdi, readCallback, NULL, 8, 256); if (err < 0 && !exitRequested) exit(1); @@ -220,27 +224,31 @@ int main(int argc, char **argv) } fprintf(stderr, "Capture ended.\n"); - if (ftdi_set_bitmode(&ftdic, 0xff, BITMODE_RESET) < 0) + if (ftdi_set_bitmode(ftdi, 0xff, BITMODE_RESET) < 0) { - fprintf(stderr,"Can't set synchronous fifo mode, Error %s\n",ftdi_get_error_string(&ftdic)); + fprintf(stderr,"Can't set synchronous fifo mode, Error %s\n",ftdi_get_error_string(ftdi)); + ftdi_usb_close(ftdi); + ftdi_free(ftdi); return EXIT_FAILURE; } - ftdi_usb_close(&ftdic); - ftdi_deinit(&ftdic); + ftdi_usb_close(ftdi); + ftdi_free(ftdi); signal(SIGINT, SIG_DFL); if (check && outfile) { if ((outputFile = fopen(outfile,"r")) == 0) { fprintf(stderr,"Can't open logfile %s, Error %s\n", outfile, strerror(errno)); + ftdi_usb_close(ftdi); + ftdi_free(ftdi); return EXIT_FAILURE; } check_outfile(descstring); fclose(outputFile); } else if (check) - fprintf(stderr,"%d errors of %ld blocks (%Le), %d (%Le) blocks skipped\n", - n_err, blocks, (long double)n_err/(long double) blocks, + fprintf(stderr,"%d errors of %llu blocks (%Le), %d (%Le) blocks skipped\n", + n_err, (unsigned long long) blocks, (long double)n_err/(long double) blocks, skips, (long double)skips/(long double) blocks); exit (0); } @@ -328,8 +336,8 @@ void check_outfile(char *descstring) { if(n_shown < 30) { - fprintf(stderr, "Skip %7d blocks from 0x%08x to 0x%08x at blocks %10ld \n", - (nread-start)/0x4000, start -0x4000, nread, blocks); + fprintf(stderr, "Skip %7d blocks from 0x%08x to 0x%08x at blocks %10llu \n", + (nread-start)/0x4000, start -0x4000, nread, (unsigned long long) blocks); n_shown ++; } n_errors++; @@ -342,9 +350,9 @@ void check_outfile(char *descstring) pc = pa; } if(n_errors) - fprintf(stderr, "%d blocks wrong from %ld blocks read\n", - n_errors, blocks); + fprintf(stderr, "%d blocks wrong from %llu blocks read\n", + n_errors, (unsigned long long) blocks); else - fprintf(stderr, "%ld blocks all fine\n",blocks); + fprintf(stderr, "%llu blocks all fine\n", (unsigned long long) blocks); } }