FreeCalypso > hg > freecalypso-tools
comparison rvinterf/etmsync/readcal.c @ 278:31d056f37647
fc-readcal written, compiles
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 17 Nov 2017 01:22:06 +0000 |
| parents | |
| children | 36ae854536e8 |
comparison
equal
deleted
inserted
replaced
| 277:4469d73bbc60 | 278:31d056f37647 |
|---|---|
| 1 /* | |
| 2 * This utility reads the RF calibration data out of a TI-based GSM device | |
| 3 * using the L1TM protocol over RVTMUX. Warning: invasive tms 1 and rfpw 7 | |
| 4 * commands are issued to the target in order to select the band of interest! | |
| 5 */ | |
| 6 | |
| 7 #include <sys/types.h> | |
| 8 #include <sys/file.h> | |
| 9 #include <stdio.h> | |
| 10 #include <stdlib.h> | |
| 11 #include <string.h> | |
| 12 #include <strings.h> | |
| 13 #include <unistd.h> | |
| 14 #include "tm3.h" | |
| 15 #include "l1tm.h" | |
| 16 #include "localtypes.h" | |
| 17 #include "exitcodes.h" | |
| 18 | |
| 19 int compal_mode; | |
| 20 | |
| 21 extern char *socket_pathname; | |
| 22 extern char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt; | |
| 23 | |
| 24 /* macro for encoding std and band in rfpw 7 command */ | |
| 25 #define RFPW_STD_BAND(std,band) ((std) | ((band) << 8)) | |
| 26 | |
| 27 static struct band { | |
| 28 char *argname; | |
| 29 char *filename; | |
| 30 unsigned rfpw_std_band; | |
| 31 } bands[] = { | |
| 32 {"900", "900", RFPW_STD_BAND(6, 0)}, | |
| 33 {"1800", "1800", RFPW_STD_BAND(6, 1)}, | |
| 34 {"1900", "1900", RFPW_STD_BAND(8, 1)}, | |
| 35 {"850", "850", RFPW_STD_BAND(8, 0)}, | |
| 36 {"1900s", "1900", RFPW_STD_BAND(3, 0)}, | |
| 37 {"850s", "850", RFPW_STD_BAND(7, 0)}, | |
| 38 {0, 0, 0} | |
| 39 }; | |
| 40 | |
| 41 static void | |
| 42 write_out_file(filename, data, size) | |
| 43 char *filename; | |
| 44 u_char *data; | |
| 45 { | |
| 46 int fd; | |
| 47 | |
| 48 fd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0666); | |
| 49 if (fd < 0) { | |
| 50 perror(filename); | |
| 51 exit(ERROR_UNIX); | |
| 52 } | |
| 53 write(fd, data, size); | |
| 54 close(fd); | |
| 55 } | |
| 56 | |
| 57 copy_afcdac() | |
| 58 { | |
| 59 u16 datum; | |
| 60 u_char bytes[2]; | |
| 61 int rc; | |
| 62 | |
| 63 rc = do_rfpr(INITIAL_AFC_DAC, &datum); | |
| 64 if (rc) | |
| 65 exit(rc); | |
| 66 datum << 3; | |
| 67 bytes[0] = datum; | |
| 68 bytes[1] = datum >> 8; | |
| 69 write_out_file("afcdac", bytes, 2); | |
| 70 } | |
| 71 | |
| 72 copy_afcparams() | |
| 73 { | |
| 74 u_char table[24]; | |
| 75 int rc; | |
| 76 | |
| 77 rc = do_rftr(AFC_PARAMS, table, sizeof table); | |
| 78 if (rc) | |
| 79 exit(rc); | |
| 80 write_out_file("afcparams", table, sizeof table); | |
| 81 } | |
| 82 | |
| 83 copy_rx_agcparams(bandname) | |
| 84 char *bandname; | |
| 85 { | |
| 86 u_char table[8]; | |
| 87 char filename[32]; | |
| 88 int rc; | |
| 89 | |
| 90 rc = do_rftr(RX_AGC_PARAMS, table, sizeof table); | |
| 91 if (rc) | |
| 92 exit(rc); | |
| 93 sprintf(filename, "rx/agcparams.%s", bandname); | |
| 94 write_out_file(filename, table, sizeof table); | |
| 95 } | |
| 96 | |
| 97 copy_rx_calchan(bandname) | |
| 98 char *bandname; | |
| 99 { | |
| 100 u_char table[40]; | |
| 101 char filename[32]; | |
| 102 int rc; | |
| 103 | |
| 104 rc = do_rftr(RX_CAL_CHAN, table, sizeof table); | |
| 105 if (rc) | |
| 106 exit(rc); | |
| 107 sprintf(filename, "rx/calchan.%s", bandname); | |
| 108 write_out_file(filename, table, sizeof table); | |
| 109 } | |
| 110 | |
| 111 copy_tx_levels(bandname) | |
| 112 char *bandname; | |
| 113 { | |
| 114 u_char table[128]; | |
| 115 char filename[32]; | |
| 116 int rc; | |
| 117 | |
| 118 rc = do_rftr(TX_LEVELS, table, sizeof table); | |
| 119 if (rc) | |
| 120 exit(rc); | |
| 121 sprintf(filename, "tx/levels.%s", bandname); | |
| 122 write_out_file(filename, table, sizeof table); | |
| 123 } | |
| 124 | |
| 125 copy_tx_calchan(bandname) | |
| 126 char *bandname; | |
| 127 { | |
| 128 u_char table[128]; | |
| 129 char filename[32]; | |
| 130 int rc; | |
| 131 | |
| 132 rc = do_rftr(TX_CAL_CHAN, table, sizeof table); | |
| 133 if (rc) | |
| 134 exit(rc); | |
| 135 sprintf(filename, "tx/calchan.%s", bandname); | |
| 136 write_out_file(filename, table, sizeof table); | |
| 137 } | |
| 138 | |
| 139 copy_tx_ramps(bandname) | |
| 140 char *bandname; | |
| 141 { | |
| 142 u_char table[512]; | |
| 143 char filename[32]; | |
| 144 int rc, i; | |
| 145 | |
| 146 for (i = 0; i < 16; i++) { | |
| 147 rc = do_ttr(i, table + i * 32); | |
| 148 if (rc) | |
| 149 exit(rc); | |
| 150 } | |
| 151 sprintf(filename, "tx/ramps.%s", bandname); | |
| 152 write_out_file(filename, table, sizeof table); | |
| 153 } | |
| 154 | |
| 155 process_band(bandname) | |
| 156 char *bandname; | |
| 157 { | |
| 158 int rc; | |
| 159 | |
| 160 rc = host_mkdir("rx"); | |
| 161 if (rc) | |
| 162 exit(rc); | |
| 163 copy_rx_agcparams(bandname); | |
| 164 if (!compal_mode) | |
| 165 copy_rx_calchan(bandname); | |
| 166 rc = host_mkdir("tx"); | |
| 167 if (rc) | |
| 168 exit(rc); | |
| 169 copy_tx_levels(bandname); | |
| 170 if (!compal_mode) | |
| 171 copy_tx_calchan(bandname); | |
| 172 copy_tx_ramps(bandname); | |
| 173 } | |
| 174 | |
| 175 single_op_main(argc, argv) | |
| 176 char **argv; | |
| 177 { | |
| 178 int rc; | |
| 179 char **ap; | |
| 180 struct band *tp; | |
| 181 | |
| 182 if (argc < 2) { | |
| 183 fprintf(stderr, | |
| 184 "usage: fc-readcal [options] output-dir band...\n"); | |
| 185 exit(ERROR_USAGE); | |
| 186 } | |
| 187 if (chdir(argv[0]) < 0) { | |
| 188 perror(argv[0]); | |
| 189 exit(ERROR_UNIX); | |
| 190 } | |
| 191 rc = do_tms(1); | |
| 192 if (rc) | |
| 193 exit(rc); | |
| 194 for (ap = argv + 1; *ap; ap++) { | |
| 195 if (!strcmp(*ap, "afc")) { | |
| 196 copy_afcdac(); | |
| 197 copy_afcparams(); | |
| 198 continue; | |
| 199 } | |
| 200 for (tp = bands; tp->argname; tp++) | |
| 201 if (!strcmp(*ap, tp->argname)) | |
| 202 break; | |
| 203 if (!tp->argname) { | |
| 204 fprintf(stderr, "error: unknown band name \"%s\"\n", | |
| 205 *ap); | |
| 206 exit(ERROR_USAGE); | |
| 207 } | |
| 208 rc = do_rfpw(STD_BAND_FLAG, tp->rfpw_std_band); | |
| 209 if (rc) | |
| 210 exit(rc); | |
| 211 process_band(tp->filename); | |
| 212 } | |
| 213 exit(0); | |
| 214 } | |
| 215 | |
| 216 main(argc, argv) | |
| 217 char **argv; | |
| 218 { | |
| 219 extern int optind; | |
| 220 extern char *optarg; | |
| 221 int c, sopt = 0; | |
| 222 | |
| 223 while ((c = getopt(argc, argv, "B:cl:p:s:w:")) != EOF) | |
| 224 switch (c) { | |
| 225 case 'B': | |
| 226 rvinterf_Bopt = optarg; | |
| 227 continue; | |
| 228 case 'c': | |
| 229 compal_mode++; | |
| 230 continue; | |
| 231 case 'l': | |
| 232 rvinterf_lopt = optarg; | |
| 233 continue; | |
| 234 case 'p': | |
| 235 rvinterf_ttyport = optarg; | |
| 236 continue; | |
| 237 case 's': | |
| 238 socket_pathname = optarg; | |
| 239 sopt++; | |
| 240 continue; | |
| 241 case 'w': | |
| 242 rvinterf_wopt = optarg; | |
| 243 continue; | |
| 244 case '?': | |
| 245 default: | |
| 246 /* error msg already printed */ | |
| 247 exit(ERROR_USAGE); | |
| 248 } | |
| 249 if (rvinterf_ttyport) { | |
| 250 if (sopt) { | |
| 251 fprintf(stderr, | |
| 252 "%s error: -p and -s options are mutually exclusive\n", | |
| 253 argv[0]); | |
| 254 exit(ERROR_USAGE); | |
| 255 } | |
| 256 if (compal_mode && !rvinterf_Bopt) | |
| 257 rvinterf_Bopt = "57600"; | |
| 258 launch_rvinterf(); | |
| 259 } else { | |
| 260 if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) { | |
| 261 fprintf(stderr, | |
| 262 "%s error: -B, -l and -w options are meaningful only when launching rvinterf\n", | |
| 263 argv[0]); | |
| 264 exit(ERROR_USAGE); | |
| 265 } | |
| 266 connect_local_socket(); | |
| 267 } | |
| 268 | |
| 269 return single_op_main(argc - optind, argv + optind); | |
| 270 } |
