FreeCalypso > hg > fc-usbser-tools
comparison cp2102/read_partno.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 |
|---|---|
| 13 #include <usb.h> | 13 #include <usb.h> |
| 14 #include "../libuwrap/find_dev.h" | 14 #include "../libuwrap/find_dev.h" |
| 15 #include "cp210x_defs.h" | 15 #include "cp210x_defs.h" |
| 16 | 16 |
| 17 extern struct usb_device *find_cp2102_device(); | 17 extern struct usb_device *find_cp2102_device(); |
| 18 char *device_selector; | |
| 19 | |
| 20 process_cmdline(argc, argv) | |
| 21 char **argv; | |
| 22 { | |
| 23 int c; | |
| 24 extern int optind; | |
| 25 extern char *optarg; | |
| 26 | |
| 27 while ((c = getopt(argc, argv, "d:")) != EOF) { | |
| 28 switch (c) { | |
| 29 case 'd': | |
| 30 device_selector = optarg; | |
| 31 continue; | |
| 32 default: | |
| 33 usage: | |
| 34 fprintf(stderr, "usage: %s [-d device-selector]\n", | |
| 35 argv[0]); | |
| 36 exit(1); | |
| 37 } | |
| 38 } | |
| 39 if (argc != optind) | |
| 40 goto usage; | |
| 41 } | |
| 18 | 42 |
| 19 main(argc, argv) | 43 main(argc, argv) |
| 20 char **argv; | 44 char **argv; |
| 21 { | 45 { |
| 22 struct usb_device *dev; | 46 struct usb_device *dev; |
| 23 usb_dev_handle *usbh; | 47 usb_dev_handle *usbh; |
| 24 u_char partno; | 48 u_char partno; |
| 25 int rc; | 49 int rc; |
| 26 | 50 |
| 27 if (argc != 2) { | 51 process_cmdline(argc, argv); |
| 28 fprintf(stderr, "usage: %s device-selector\n", argv[0]); | 52 dev = find_cp2102_device(device_selector); |
| 29 exit(1); | |
| 30 } | |
| 31 dev = find_cp2102_device(argv[1]); | |
| 32 usbh = usb_open(dev); | 53 usbh = usb_open(dev); |
| 33 if (!usbh) { | 54 if (!usbh) { |
| 34 fprintf(stderr, "error: usb_open() failed\n"); | 55 fprintf(stderr, "error: usb_open() failed\n"); |
| 35 exit(1); | 56 exit(1); |
| 36 } | 57 } |
