comparison librftab/rftablewr.c @ 280:36922911e6bb

librftab started with rftablerd.c and rftablewr.c from rvinterf/tmsh
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 17 Nov 2017 23:43:38 +0000
parents rvinterf/tmsh/rftablewr.c@d2a79b68789b
children 90c475877d34
comparison
equal deleted inserted replaced
279:36ae854536e8 280:36922911e6bb
1 /*
2 * Here we implement the writing of RF tables into ASCII text files
3 * in our defined format. This module will also be linked by the
4 * standalone fc-cal2text utility, hence our code here needs to be
5 * independent of rvinterf and fc-tmsh specifics.
6 */
7
8 #include <sys/types.h>
9 #include <stdio.h>
10 #include <stdint.h>
11 #include <endian.h>
12
13 static unsigned
14 get_u32(bin)
15 u_char *bin;
16 {
17 return le32toh(*(uint32_t *)bin);
18 }
19
20 static unsigned
21 get_u16(bin)
22 u_char *bin;
23 {
24 return le16toh(*(uint16_t *)bin);
25 }
26
27 static int
28 get_s16(bin)
29 u_char *bin;
30 {
31 int i;
32
33 i = le16toh(*(uint16_t *)bin);
34 if (i >= 32768)
35 i -= 65536;
36 return(i);
37 }
38
39 void
40 write_afcparams_table(bin, outf)
41 u_char *bin;
42 FILE *outf;
43 {
44 fputs("rf_table afcparams\n\n", outf);
45 /* 32-bit parameters */
46 fprintf(outf, "%10u\t# psi_sta_inv\n", get_u32(bin));
47 fprintf(outf, "%10u\t# psi_st\n", get_u32(bin + 4));
48 fprintf(outf, "%10u\t# psi_st_32\n", get_u32(bin + 8));
49 fprintf(outf, "%10u\t# psi_st_inv\n\n", get_u32(bin + 12));
50 /* 16-bit parameters */
51 fprintf(outf, "%10d\t# dac_center\n", get_s16(bin + 16));
52 fprintf(outf, "%10d\t# dac_min\n", get_s16(bin + 18));
53 fprintf(outf, "%10d\t# dac_max\n", get_s16(bin + 20));
54 fprintf(outf, "%10d\t# snr_thr\n", get_s16(bin + 22));
55 }
56
57 void
58 write_agcwords_table(bin, outf)
59 u_char *bin;
60 FILE *outf;
61 {
62 int i, j;
63 u_char *p = bin;
64
65 fputs("rf_table agc-table\n\n", outf);
66 for (i = 0; i < 4; i++) {
67 for (j = 0; j < 5; j++) {
68 if (j)
69 putc(' ', outf);
70 fprintf(outf, "0x%04X", get_u16(p));
71 p += 2;
72 }
73 putc('\n', outf);
74 }
75 }
76
77 void
78 write_agcglobals_table(bin, outf)
79 u_char *bin;
80 FILE *outf;
81 {
82 fputs("rf_table agc-global-params\n\n", outf);
83 fprintf(outf, "%5u\t# low_agc_noise_thr\n", get_u16(bin));
84 fprintf(outf, "%5u\t# high_agc_sat_thr\n", get_u16(bin + 2));
85 fprintf(outf, "%5u\t# low_agc\n", get_u16(bin + 4));
86 fprintf(outf, "%5u\t# high_agc\n", get_u16(bin + 6));
87 }
88
89 void
90 write_il2agc_table(bin, outf)
91 u_char *bin;
92 FILE *outf;
93 {
94 int idx;
95
96 fputs("rf_table il2agc\n\n", outf);
97 for (idx = 0; idx < 121; idx++)
98 fprintf(outf, "%3u\t# IL=%d\n", bin[idx], -idx);
99 }
100
101 void
102 write_tx_levels_table(bin, outf)
103 u_char *bin;
104 FILE *outf;
105 {
106 int i;
107 u_char *p = bin;
108
109 fputs("rf_table tx-levels\n\n", outf);
110 fputs("# Fields in each entry: apc, ramp_index, chan_cal_index\n\n",
111 outf);
112 for (i = 0; i < 32; i++) {
113 fprintf(outf, "%5u %3u %3u\t# entry %d\n",
114 get_u16(p), p[2], p[3], i);
115 p += 4;
116 }
117 }
118
119 void
120 write_tx_calchan_table(bin, outf)
121 u_char *bin;
122 FILE *outf;
123 {
124 int i, j;
125 u_char *p = bin;
126
127 fputs("rf_table tx-calchan\n", outf);
128 for (i = 0; i < 4; i++) {
129 fprintf(outf, "\n# Channel calibration table %d:\n\n", i);
130 for (j = 0; j < 8; j++) {
131 fprintf(outf, "%5u %6d\n", get_u16(p), get_s16(p + 2));
132 p += 4;
133 }
134 }
135 }
136
137 void
138 write_tx_caltemp_table(bin, outf)
139 u_char *bin;
140 FILE *outf;
141 {
142 int i;
143 u_char *p = bin;
144
145 fputs("rf_table tx-caltemp\n\n", outf);
146 for (i = 0; i < 5; i++) {
147 fprintf(outf, "%6d %6d %6d %6d\n", get_s16(p), get_s16(p + 2),
148 get_s16(p + 4), get_s16(p + 6));
149 p += 8;
150 }
151 }
152
153 void
154 write_rx_calchan_table(bin, outf)
155 u_char *bin;
156 FILE *outf;
157 {
158 int i;
159 u_char *p = bin;
160
161 fputs("rf_table rx-calchan\n\n", outf);
162 for (i = 0; i < 10; i++) {
163 fprintf(outf, "%5u %6d\n", get_u16(p), get_s16(p + 2));
164 p += 4;
165 }
166 }
167
168 void
169 write_rx_caltemp_table(bin, outf)
170 u_char *bin;
171 FILE *outf;
172 {
173 int i;
174 u_char *p = bin;
175
176 fputs("rf_table rx-caltemp\n\n", outf);
177 for (i = 0; i < 11; i++) {
178 fprintf(outf, "%6d %6d\n", get_s16(p), get_s16(p + 2));
179 p += 4;
180 }
181 }
182
183 void
184 write_rx_agcparams_table(bin, outf)
185 u_char *bin;
186 FILE *outf;
187 {
188 fputs("rf_table rx-agc-params\n\n", outf);
189 fprintf(outf, "%5u\t# g_magic\n", get_u16(bin));
190 fprintf(outf, "%5u\t# lna_att\n", get_u16(bin + 2));
191 fprintf(outf, "%5u\t# lna_switch_thr_low\n", get_u16(bin + 4));
192 fprintf(outf, "%5u\t# lna_switch_thr_high\n", get_u16(bin + 6));
193 }
194
195 void
196 write_tx_ramp(bin, outf)
197 u_char *bin;
198 FILE *outf;
199 {
200 int i;
201
202 fputs("ramp-up ", outf);
203 for (i = 0; i < 16; i++)
204 fprintf(outf, " %3u", bin[i]);
205 putc('\n', outf);
206 fputs("ramp-down", outf);
207 for (i = 0; i < 16; i++)
208 fprintf(outf, " %3u", bin[i+16]);
209 putc('\n', outf);
210 }