annotate rfcal/vcxo-manual/readmeas.c @ 203:f2dde45ba378

target-utils/Makefile: flash-boot-wa added
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 01 May 2017 21:21:13 +0000
parents dcab0be3f67a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
181
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <ctype.h>
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdio.h>
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdlib.h>
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include "meas.h"
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 read_meas_file(filename, meas_table, nmeas)
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 char *filename;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 struct meas *meas_table;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 {
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 FILE *f;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 char linebuf[256], *cp, *np;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 int lineno;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 struct meas *mtp;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 int got_meas;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 f = fopen(filename, "r");
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 if (!f) {
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 perror(filename);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 exit(1);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 }
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 mtp = meas_table;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 got_meas = 0;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) {
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 for (cp = linebuf; isspace(*cp); cp++)
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 ;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (*cp == '\0' || *cp == '#')
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 continue;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (!isdigit(*cp) && *cp != '-' && *cp != '+') {
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 inv: fprintf(stderr, "%s line %d: invalid syntax\n",
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 filename, lineno);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 exit(1);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 np = cp++;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 while (isdigit(*cp))
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 cp++;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (!isspace(*cp))
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 goto inv;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 mtp->dac_value = atoi(np);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 while (isspace(*cp))
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 cp++;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (!isdigit(*cp) && *cp != '-' && *cp != '+')
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 goto inv;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 np = cp++;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 while (isdigit(*cp))
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 cp++;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (*cp && !isspace(*cp))
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 goto inv;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 mtp->freq_offset = atoi(np);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 mtp++;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 got_meas++;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (got_meas >= nmeas)
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 break;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 fclose(f);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 if (got_meas < nmeas) {
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 fprintf(stderr, "error: need %d measurements, got %d in %s\n",
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 nmeas, got_meas, filename);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 exit(1);
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return 0;
dcab0be3f67a started manual VCXO calibration code: fc-vcxo-linear utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }