comparison ffstools/caltools/fc-bin2rftab.c @ 484:68c7e4edc4da

fc-bin2rftab utility written
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 15 Mar 2019 05:47:06 +0000
parents
children a58a38cae51c
comparison
equal deleted inserted replaced
483:e76cb6994508 484:68c7e4edc4da
1 /*
2 * This utility reads a binary RF table or extracts it out of some larger
3 * binary file such as an alien fw image (the user must specify the offset
4 * in the binary file and the expected RF table type), and emits it in our
5 * FreeCalypso ASCII format.
6 */
7
8 #include <sys/types.h>
9 #include <sys/file.h>
10 #include <ctype.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <strings.h>
15 #include <unistd.h>
16
17 extern void write_afcparams_table();
18 extern void write_agcwords_table();
19 extern void write_agcglobals_table();
20 extern void write_il2agc_table();
21 extern void write_tx_ramps_table();
22 extern void write_tx_levels_table();
23 extern void write_tx_calchan_table();
24 extern void write_tx_caltemp_table();
25 extern void write_rx_calchan_table();
26 extern void write_rx_caltemp_table();
27 extern void write_rx_agcparams_table();
28
29 static struct table_map {
30 char *type;
31 int size;
32 void (*func)();
33 } table_map[] = {
34 {"afcparams", 24, write_afcparams_table},
35 {"agc-table", 40, write_agcwords_table},
36 {"agc-global-params", 8, write_agcglobals_table},
37 {"il2agc", 121, write_il2agc_table},
38 {"tx-ramps", 512, write_tx_ramps_table},
39 {"tx-levels", 128, write_tx_levels_table},
40 {"tx-calchan", 128, write_tx_calchan_table},
41 {"tx-caltemp", 40, write_tx_caltemp_table},
42 {"rx-calchan", 40, write_rx_calchan_table},
43 {"rx-caltemp", 44, write_rx_caltemp_table},
44 {"rx-agc-params", 8, write_rx_agcparams_table},
45 {0, 0, 0}
46 };
47
48 main(argc, argv)
49 char **argv;
50 {
51 struct table_map *tp;
52 u_char buf[512];
53 int ifd, cc;
54 u_long offset;
55 char *endp;
56 FILE *outf;
57
58 if (argc < 4 || argc > 5) {
59 fprintf(stderr, "usage: %s binfile offset type [outfile]\n",
60 argv[0]);
61 exit(1);
62 }
63 ifd = open(argv[1], O_RDONLY);
64 if (ifd < 0) {
65 perror(argv[1]);
66 exit(1);
67 }
68 if (!isdigit(argv[2][0])) {
69 inv_offset: fprintf(stderr, "error: specified offset \"%s\" is invalid\n",
70 argv[2]);
71 exit(1);
72 }
73 offset = strtoul(argv[2], &endp, 0);
74 if (*endp)
75 goto inv_offset;
76 lseek(ifd, offset, SEEK_SET);
77 for (tp = table_map; tp->type; tp++)
78 if (!strcmp(tp->type, argv[3]))
79 break;
80 if (!tp->type) {
81 fprintf(stderr, "error: RF table type \"%s\" not known\n",
82 argv[3]);
83 exit(1);
84 }
85 cc = read(ifd, buf, tp->size);
86 if (cc < 0) {
87 perror("error reading from file");
88 exit(1);
89 }
90 if (cc != tp->size) {
91 fprintf(stderr, "error: short read\n");
92 exit(1);
93 }
94 close(ifd);
95 if (argc >= 5) {
96 outf = fopen(argv[4], "w");
97 if (!outf) {
98 perror(argv[4]);
99 exit(1);
100 }
101 tp->func(buf, outf);
102 fclose(outf);
103 } else
104 tp->func(buf, stdout);
105 exit(0);
106 }