annotate duart28/main.c @ 29:a7393d00996a

fc-duart28-conf: implement check-eeprom
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 09 Sep 2023 19:13:35 +0000
parents 2413a54a1bfc
children 530ec3792de8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Main module for fc-duart28-conf utility.
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <ctype.h>
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <string.h>
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <strings.h>
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <usb.h>
29
a7393d00996a fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
11 #include "../libuwrap/open_close.h"
27
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern struct usb_device *find_duart28_usbdev();
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 oper_find()
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 struct usb_device *dev;
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 dev = find_duart28_usbdev();
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (!dev)
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 printf("No DUART28 adapter found\n");
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 return 0;
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 oper_check_eeprom()
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 {
29
a7393d00996a fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
27 struct usb_device *dev;
a7393d00996a fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
28 usb_dev_handle *usbh;
a7393d00996a fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
29
a7393d00996a fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
30 dev = find_duart28_usbdev();
a7393d00996a fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
31 if (!dev) {
a7393d00996a fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
32 fprintf(stderr, "error: no DUART28 adapter found\n");
a7393d00996a fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
33 exit(1);
a7393d00996a fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
34 }
a7393d00996a fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
35 usbh = usbwrap_open_dev(dev, 1);
a7393d00996a fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
36 read_eeprom(usbh);
a7393d00996a fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
37 usbwrap_close_dev(usbh);
a7393d00996a fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
38 analyze_eeprom();
a7393d00996a fc-duart28-conf: implement check-eeprom
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
39 return 0;
27
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 oper_program(newconf)
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 fprintf(stderr, "error: set command not yet implemented\n");
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 exit(1);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 main(argc, argv)
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 char **argv;
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (argc < 2)
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 return oper_find();
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 if (!strcmp(argv[1], "find")) {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (argc != 2) {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 fprintf(stderr,
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 "error: %s find command takes no arguments\n",
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 argv[0]);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 exit(1);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return oper_find();
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 if (!strcmp(argv[1], "check-eeprom")) {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (argc != 2) {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 fprintf(stderr,
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 "error: %s check-eeprom command takes no arguments\n",
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 argv[0]);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 exit(1);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return oper_check_eeprom();
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (!strcmp(argv[1], "set")) {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (argc != 3) {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 fprintf(stderr,
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 "error: %s set command takes 1 argument\n",
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 argv[0]);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 exit(1);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if (!strcmp(argv[2], "C") || !strcmp(argv[2], "S"))
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 return oper_program(argv[2][0]);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 if (!strcmp(argv[2], "c") || !strcmp(argv[2], "s"))
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 return oper_program(toupper(argv[2][0]));
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 fprintf(stderr, "error: %s set argument must be C or S\n",
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 argv[0]);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 exit(1);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 fprintf(stderr, "%s error: non-understood command \"%s\"\n", argv[0],
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 argv[1]);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 exit(1);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }