annotate duart28/main.c @ 27:2413a54a1bfc

fc-duart28-conf started
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 09 Sep 2023 17:53:21 +0000
parents
children a7393d00996a
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>
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern struct usb_device *find_duart28_usbdev();
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 oper_find()
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 struct usb_device *dev;
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 dev = find_duart28_usbdev();
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (!dev)
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 printf("No DUART28 adapter found\n");
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 return 0;
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 }
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 oper_check_eeprom()
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 fprintf(stderr, "error: check-eeprom command not yet implemented\n");
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 exit(1);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 oper_program(newconf)
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 fprintf(stderr, "error: set command not yet implemented\n");
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 exit(1);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 main(argc, argv)
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 char **argv;
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (argc < 2)
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return oper_find();
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (!strcmp(argv[1], "find")) {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (argc != 2) {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 fprintf(stderr,
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 "error: %s find command takes no arguments\n",
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 argv[0]);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 exit(1);
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 return oper_find();
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (!strcmp(argv[1], "check-eeprom")) {
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 fprintf(stderr,
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 "error: %s check-eeprom command takes no arguments\n",
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 argv[0]);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 exit(1);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 return oper_check_eeprom();
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 if (!strcmp(argv[1], "set")) {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (argc != 3) {
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 fprintf(stderr,
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 "error: %s set command takes 1 argument\n",
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 argv[0]);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 exit(1);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 if (!strcmp(argv[2], "C") || !strcmp(argv[2], "S"))
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 return oper_program(argv[2][0]);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (!strcmp(argv[2], "c") || !strcmp(argv[2], "s"))
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return oper_program(toupper(argv[2][0]));
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 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
71 argv[0]);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 exit(1);
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 fprintf(stderr, "%s error: non-understood command \"%s\"\n", argv[0],
2413a54a1bfc fc-duart28-conf started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 argv[1]);
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 }