annotate ffstools/caltools/c1xx-calextr.c @ 297:b1ac1bd1dbbf

c1xx-calextr: table conversion implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 18 Nov 2017 17:45:10 +0000
parents 77d561735b07
children 734b38f634db
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
294
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This program parses Compal's proprietary data structure that contains
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * the factory RF calibration values among other data, locates those RF
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * calibration records, extracts their essential content (Rx GMagic and
296
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
5 * Tx APC values), converts this distilled content into TCS211 RF calibration
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
6 * tables (Rx agcparams and Tx levels) and writes these tables out in either
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
7 * FreeCalypso ASCII or FFS binary format.
294
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 */
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <sys/types.h>
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <sys/file.h>
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <string.h>
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <strings.h>
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <stdio.h>
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include <stdlib.h>
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include <unistd.h>
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #define COMPAL_SECTOR_LENGTH 0x2000
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 u_char sector[COMPAL_SECTOR_LENGTH];
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 u_char endmarker[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 u_char record_magic[4] = {0xAA, 0x00, 0x00, 0x00};
296
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
23 char *ascii_output_dir, *bin_output_dir;
294
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 struct band {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 char *name;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 unsigned compal_record_id;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 unsigned record_length;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 unsigned magic2_offset;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 unsigned start_plnum;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 unsigned end_plnum;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 } bands[] = {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 {"900", 0x00, 0x94, 0x54, 5, 19},
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 {"1800", 0x01, 0xC8, 0x74, 0, 15},
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {"1900", 0x02, 0xB4, 0x68, 0, 15},
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 {"850", 0x18, 0x88, 0x4C, 5, 19},
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 };
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 read_binfile(filename, offset_arg)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 char *filename, *offset_arg;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 int fd, cc;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 u_long offset;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 char *endp;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 fd = open(filename, O_RDONLY);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (fd < 0) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 perror(filename);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 exit(1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 offset = strtoul(offset_arg, &endp, 0);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (*endp) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 fprintf(stderr, "error: invalid offset argument \"%s\"\n",
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 offset_arg);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 exit(1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 lseek(fd, offset, SEEK_SET);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 cc = read(fd, sector, COMPAL_SECTOR_LENGTH);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 if (cc != COMPAL_SECTOR_LENGTH) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 fprintf(stderr,
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 "error: unable to read Compal sector of %d bytes from %s at offset %s\n",
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 COMPAL_SECTOR_LENGTH, filename, offset_arg);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 exit(1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 close(fd);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67
297
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
68 do_rx_agcparams(band, compal_data)
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
69 struct band *band;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
70 u_char *compal_data;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
71 {
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
72 u_char rx_agcparams_table[8];
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
73
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
74 bcopy(compal_data, rx_agcparams_table, 2);
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
75 /* the remaining fields are constants unchanged from TI */
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
76 rx_agcparams_table[2] = 40;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
77 rx_agcparams_table[3] = 0;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
78 rx_agcparams_table[4] = 40;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
79 rx_agcparams_table[5] = 0;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
80 rx_agcparams_table[6] = 44;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
81 rx_agcparams_table[7] = 0;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
82 /* ASCII and binary write-out to be implemented */
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
83 }
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
84
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
85 do_tx_levels(band, compal_data)
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
86 struct band *band;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
87 u_char *compal_data;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
88 {
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
89 u_char tx_levels_table[128], *sp, *dp;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
90 unsigned num_levels, n;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
91
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
92 bzero(tx_levels_table, sizeof tx_levels_table);
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
93 num_levels = band->end_plnum - band->start_plnum;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
94 sp = compal_data;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
95 dp = tx_levels_table + band->start_plnum * 4;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
96 for (n = 0; n < num_levels; n++) {
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
97 *dp++ = *sp++;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
98 *dp++ = *sp++;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
99 *dp++ = n;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
100 *dp++ = 0;
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
101 }
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
102 /* ASCII and binary write-out to be implemented */
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
103 }
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
104
294
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 process_band_record(band, offset)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 struct band *band;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 unsigned offset;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 u_char *record;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 record = sector + offset + 8;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 if (bcmp(record, record_magic, 4)) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 printf("bad magic1, skipping\n");
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 return(-1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 if (bcmp(record + band->magic2_offset, record_magic, 4)) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 printf("bad magic2, skipping\n");
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 return(-1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 if (bcmp(record + band->magic2_offset + 8, record_magic, 4)) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 printf("bad magic3, skipping\n");
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 return(-1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 }
297
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
124 do_rx_agcparams(band, record + 4);
b1ac1bd1dbbf c1xx-calextr: table conversion implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 296
diff changeset
125 do_tx_levels(band, record + band->magic2_offset + 12);
294
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 return(0);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128
296
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
129 process_sector_data()
294
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 unsigned offset, next_offset;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 u_char *header;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 unsigned hdr_words[4];
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 struct band *band;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 int i;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 for (offset = 0; ; offset = next_offset) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 if (offset > COMPAL_SECTOR_LENGTH - 12)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 break;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 header = sector + offset;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 if (!bcmp(header, endmarker, 8))
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 break;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 for (i = 0; i < 4; i++)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 hdr_words[i] = header[i*2] | (header[i*2+1] << 8);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 if (!hdr_words[3]) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 fprintf(stderr,
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 "error at offset 0x%X: rounded record length word is 0\n",
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 offset);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 exit(1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 if (hdr_words[3] & 3) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 fprintf(stderr,
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 "error at offset 0x%X: rounded record length word is not aligned to 4\n",
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 offset);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 exit(1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 if (hdr_words[3] > COMPAL_SECTOR_LENGTH - offset - 8) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 fprintf(stderr,
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 "error at offset 0x%X: rounded record length spills past end of sector\n",
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 offset);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 exit(1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 if (hdr_words[2] > hdr_words[3]) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 fprintf(stderr,
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 "error at offset 0x%X: native record length is greater than rounded\n",
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 offset);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 exit(1);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 next_offset = offset + 8 + hdr_words[3];
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 if (hdr_words[0] != 0x000C)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 continue;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 for (band = bands; band->name; band++)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 if (hdr_words[1] == band->compal_record_id)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 break;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 if (!band->name)
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 continue;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 printf("Found %s MHz calibration record at offset 0x%X\n",
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 band->name, offset);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 if (hdr_words[2] != band->record_length) {
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 printf("Oops, wrong length, skipping\n");
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 continue;
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 }
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 process_band_record(band, offset);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 }
296
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
185 }
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
186
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
187 main(argc, argv)
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
188 char **argv;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
189 {
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
190 int c;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
191 extern char *optarg;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
192 extern int optind;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
193
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
194 while ((c = getopt(argc, argv, "a:b:")) != EOF)
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
195 switch (c) {
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
196 case 'a':
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
197 ascii_output_dir = optarg;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
198 continue;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
199 case 'b':
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
200 bin_output_dir = optarg;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
201 continue;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
202 case '?':
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
203 default:
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
204 usage: fprintf(stderr,
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
205 "usage: %s [-a ascii_outdir] [-b bin_outdir] c1xx-binfile offset\n",
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
206 argv[0]);
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
207 exit(1);
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
208 }
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
209 if (argc - optind != 2)
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
210 goto usage;
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
211 read_binfile(argv[optind], argv[optind+1]);
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
212 if (ascii_output_dir)
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
213 mkdir_existok(ascii_output_dir);
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
214 if (bin_output_dir)
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
215 mkdir_existok(bin_output_dir);
77d561735b07 c1xx-calextr: preparations for both ASCII and binary output
Mychaela Falconia <falcon@freecalypso.org>
parents: 294
diff changeset
216 process_sector_data();
294
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 exit(0);
1416fe200069 c1xx-calextr started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 }