FreeCalypso > hg > fc-usbser-tools
comparison cp2102/read_eeprom_main.c @ 98:1cacc1ae56f0
cp2102 tools: convert to -d option for non-default device
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Thu, 28 Sep 2023 04:45:13 +0000 |
| parents | 8d35346f1d46 |
| children |
comparison
equal
deleted
inserted
replaced
| 97:8d35346f1d46 | 98:1cacc1ae56f0 |
|---|---|
| 16 #include "cp210x_defs.h" | 16 #include "cp210x_defs.h" |
| 17 | 17 |
| 18 extern struct usb_device *find_cp2102_device(); | 18 extern struct usb_device *find_cp2102_device(); |
| 19 | 19 |
| 20 u_char eeprom[SIZE_EEPROM]; | 20 u_char eeprom[SIZE_EEPROM]; |
| 21 char *device_selector, *outfilename; | |
| 22 | |
| 23 process_cmdline(argc, argv) | |
| 24 char **argv; | |
| 25 { | |
| 26 int c; | |
| 27 extern int optind; | |
| 28 extern char *optarg; | |
| 29 | |
| 30 while ((c = getopt(argc, argv, "d:")) != EOF) { | |
| 31 switch (c) { | |
| 32 case 'd': | |
| 33 device_selector = optarg; | |
| 34 continue; | |
| 35 default: | |
| 36 usage: | |
| 37 fprintf(stderr, | |
| 38 "usage: %s [-d device-selector] output-hex-file\n", | |
| 39 argv[0]); | |
| 40 exit(1); | |
| 41 } | |
| 42 } | |
| 43 if (argc != optind + 1) | |
| 44 goto usage; | |
| 45 outfilename = argv[optind]; | |
| 46 } | |
| 21 | 47 |
| 22 main(argc, argv) | 48 main(argc, argv) |
| 23 char **argv; | 49 char **argv; |
| 24 { | 50 { |
| 25 struct usb_device *dev; | 51 struct usb_device *dev; |
| 26 usb_dev_handle *usbh; | 52 usb_dev_handle *usbh; |
| 27 FILE *outf; | 53 FILE *outf; |
| 28 | 54 |
| 29 if (argc != 3) { | 55 process_cmdline(argc, argv); |
| 30 fprintf(stderr, "usage: %s device-selector output-hex-file\n", | 56 dev = find_cp2102_device(device_selector); |
| 31 argv[0]); | |
| 32 exit(1); | |
| 33 } | |
| 34 dev = find_cp2102_device(argv[1]); | |
| 35 usbh = usb_open(dev); | 57 usbh = usb_open(dev); |
| 36 if (!usbh) { | 58 if (!usbh) { |
| 37 fprintf(stderr, "error: usb_open() failed\n"); | 59 fprintf(stderr, "error: usb_open() failed\n"); |
| 38 exit(1); | 60 exit(1); |
| 39 } | 61 } |
| 40 read_eeprom(usbh); | 62 read_eeprom(usbh); |
| 41 usb_close(usbh); | 63 usb_close(usbh); |
| 42 outf = fopen(argv[2], "w"); | 64 outf = fopen(outfilename, "w"); |
| 43 if (!outf) { | 65 if (!outf) { |
| 44 perror(argv[2]); | 66 perror(outfilename); |
| 45 exit(1); | 67 exit(1); |
| 46 } | 68 } |
| 47 intel_hex_out(eeprom, outf); | 69 intel_hex_out(eeprom, outf); |
| 48 fclose(outf); | 70 fclose(outf); |
| 49 exit(0); | 71 exit(0); |
