FreeCalypso > hg > freecalypso-tools
comparison rvinterf/tmsh/rftablewr.c @ 138:3803f838e1f3
RF table writing code implemented, linked into fc-tmsh
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 26 Feb 2017 22:37:47 +0000 |
parents | |
children | 6b01d4ef85c3 |
comparison
equal
deleted
inserted
replaced
137:79e71354ba7b | 138:3803f838e1f3 |
---|---|
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 fprintf(outf, " 0x%04X", get_u16(p)); | |
69 p += 2; | |
70 } | |
71 putc('\n', outf); | |
72 } | |
73 } | |
74 | |
75 void | |
76 write_agcglobals_table(bin, outf) | |
77 u_char *bin; | |
78 FILE *outf; | |
79 { | |
80 fputs("rf_table agc-global-params\n\n", outf); | |
81 fprintf(outf, "%5u\t# low_agc_noise_thr\n", get_u16(bin)); | |
82 fprintf(outf, "%5u\t# high_agc_sat_thr\n", get_u16(bin + 2)); | |
83 fprintf(outf, "%5u\t# low_agc\n", get_u16(bin + 4)); | |
84 fprintf(outf, "%5u\t# high_agc\n", get_u16(bin + 6)); | |
85 } | |
86 | |
87 void | |
88 write_il2agc_table(bin, outf) | |
89 u_char *bin; | |
90 FILE *outf; | |
91 { | |
92 int idx; | |
93 | |
94 fputs("rf_table il2agc\n\n", outf); | |
95 for (idx = 0; idx < 121; idx++) | |
96 fprintf(outf, "%3u\t# IL=%d\n", get_u16(bin + idx), -idx); | |
97 } | |
98 | |
99 void | |
100 write_tx_levels_table(bin, outf) | |
101 u_char *bin; | |
102 FILE *outf; | |
103 { | |
104 int i; | |
105 u_char *p = bin; | |
106 | |
107 fputs("rf_table tx-levels\n\n", outf); | |
108 fputs("# Fields in each entry: apc, ramp_index, chan_cal_index\n\n", | |
109 outf); | |
110 for (i = 0; i < 32; i++) { | |
111 fprintf(outf, "%5u %3u %3u\t# entry %d\n", | |
112 get_u16(p), p[2], p[3], i); | |
113 p += 4; | |
114 } | |
115 } | |
116 | |
117 void | |
118 write_tx_calchan_table(bin, outf) | |
119 u_char *bin; | |
120 FILE *outf; | |
121 { | |
122 int i, j; | |
123 u_char *p = bin; | |
124 | |
125 fputs("rf_table tx-calchan\n\n", outf); | |
126 for (i = 0; i < 4; i++) { | |
127 fprintf(outf, "# Channel calibration table %d:\n\n", i); | |
128 for (j = 0; j < 8; j++) { | |
129 fprintf(outf, "%5u %6d\n", get_u16(p), get_s16(p + 2)); | |
130 p += 4; | |
131 } | |
132 } | |
133 } | |
134 | |
135 void | |
136 write_tx_caltemp_table(bin, outf) | |
137 u_char *bin; | |
138 FILE *outf; | |
139 { | |
140 int i; | |
141 u_char *p = bin; | |
142 | |
143 fputs("rf_table tx-caltemp\n\n", outf); | |
144 for (i = 0; i < 5; i++) { | |
145 fprintf(outf, "%6d %6d %6d %6d\n", get_s16(p), get_s16(p + 2), | |
146 get_s16(p + 4), get_s16(p + 6)); | |
147 p += 8; | |
148 } | |
149 } | |
150 | |
151 void | |
152 write_rx_calchan_table(bin, outf) | |
153 u_char *bin; | |
154 FILE *outf; | |
155 { | |
156 int i; | |
157 u_char *p = bin; | |
158 | |
159 fputs("rf_table rx-calchan\n\n", outf); | |
160 for (i = 0; i < 10; i++) { | |
161 fprintf(outf, "%5u %6d\n", get_u16(p), get_s16(p + 2)); | |
162 p += 4; | |
163 } | |
164 } | |
165 | |
166 void | |
167 write_rx_caltemp_table(bin, outf) | |
168 u_char *bin; | |
169 FILE *outf; | |
170 { | |
171 int i; | |
172 u_char *p = bin; | |
173 | |
174 fputs("rf_table rx-caltemp\n\n", outf); | |
175 for (i = 0; i < 11; i++) { | |
176 fprintf(outf, "%6d %6d\n", get_s16(p), get_s16(p + 2)); | |
177 p += 4; | |
178 } | |
179 } | |
180 | |
181 void | |
182 write_rx_agcparams_table(bin, outf) | |
183 u_char *bin; | |
184 FILE *outf; | |
185 { | |
186 fputs("rf_table rx-agc-params\n\n", outf); | |
187 fprintf(outf, "%5u\t# g_magic\n", get_u16(bin)); | |
188 fprintf(outf, "%5u\t# lna_att\n", get_u16(bin + 2)); | |
189 fprintf(outf, "%5u\t# lna_switch_thr_low\n", get_u16(bin + 4)); | |
190 fprintf(outf, "%5u\t# lna_switch_thr_high\n", get_u16(bin + 6)); | |
191 } |