# HG changeset patch # User Mychaela Falconia # Date 1491979545 0 # Node ID dcab0be3f67a05517f5fb583a7a53d2166749f98 # Parent e50c3aa1152aa7ad5185222bdc264b1bdf62b2d7 started manual VCXO calibration code: fc-vcxo-linear utility written diff -r e50c3aa1152a -r dcab0be3f67a .hgignore --- a/.hgignore Mon Mar 27 21:38:45 2017 +0000 +++ b/.hgignore Wed Apr 12 06:45:45 2017 +0000 @@ -27,6 +27,8 @@ ^miscutil/fc-vm2hex$ ^miscutil/imei-luhn$ +^rfcal/vcxo-manual/fc-vcxo-linear$ + ^ringtools/fc-e1decode$ ^ringtools/fc-e1gen$ diff -r e50c3aa1152a -r dcab0be3f67a rfcal/vcxo-manual/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rfcal/vcxo-manual/Makefile Wed Apr 12 06:45:45 2017 +0000 @@ -0,0 +1,18 @@ +CC= gcc +CFLAGS= -O2 +PROGS= fc-vcxo-linear +INSTBIN=/opt/freecalypso/bin + +LINEAR_OBJS= linear.o readmeas.o + +all: ${PROGS} + +fc-vcxo-linear: ${LINEAR_OBJS} + ${CC} ${CFLAGS} -o $@ ${LINEAR_OBJS} + +install: + mkdir -p ${INSTBIN} + install -c ${PROGS} ${INSTBIN} + +clean: + rm -f *.o *.out *errs ${PROGS} diff -r e50c3aa1152a -r dcab0be3f67a rfcal/vcxo-manual/linear.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rfcal/vcxo-manual/linear.c Wed Apr 12 06:45:45 2017 +0000 @@ -0,0 +1,27 @@ +#include +#include +#include "meas.h" + +struct meas meas[2]; +float lin_a, lin_b, target_off; +int target_dac; + +main(argc, argv) + char **argv; +{ + if (argc < 2 || argc > 3) { + fprintf(stderr, "usage: %s meas-file [target]\n", argv[0]); + exit(1); + } + read_meas_file(argv[1], meas, 2); + if (argc > 2) + target_off = atof(argv[2]); + else + target_off = 0; + lin_a = (float)(meas[1].freq_offset - meas[0].freq_offset) / + (float)(meas[1].dac_value - meas[0].dac_value); + lin_b = (float)meas[1].freq_offset - lin_a * meas[1].dac_value; + target_dac = (target_off - lin_b) / lin_a; + printf("%d\n", target_dac); + exit(0); +} diff -r e50c3aa1152a -r dcab0be3f67a rfcal/vcxo-manual/meas.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rfcal/vcxo-manual/meas.h Wed Apr 12 06:45:45 2017 +0000 @@ -0,0 +1,4 @@ +struct meas { + int dac_value; + int freq_offset; +}; diff -r e50c3aa1152a -r dcab0be3f67a rfcal/vcxo-manual/readmeas.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rfcal/vcxo-manual/readmeas.c Wed Apr 12 06:45:45 2017 +0000 @@ -0,0 +1,61 @@ +#include +#include +#include +#include "meas.h" + +read_meas_file(filename, meas_table, nmeas) + char *filename; + struct meas *meas_table; +{ + FILE *f; + char linebuf[256], *cp, *np; + int lineno; + struct meas *mtp; + int got_meas; + + f = fopen(filename, "r"); + if (!f) { + perror(filename); + exit(1); + } + mtp = meas_table; + got_meas = 0; + for (lineno = 1; fgets(linebuf, sizeof linebuf, f); lineno++) { + for (cp = linebuf; isspace(*cp); cp++) + ; + if (*cp == '\0' || *cp == '#') + continue; + if (!isdigit(*cp) && *cp != '-' && *cp != '+') { +inv: fprintf(stderr, "%s line %d: invalid syntax\n", + filename, lineno); + exit(1); + } + np = cp++; + while (isdigit(*cp)) + cp++; + if (!isspace(*cp)) + goto inv; + mtp->dac_value = atoi(np); + while (isspace(*cp)) + cp++; + if (!isdigit(*cp) && *cp != '-' && *cp != '+') + goto inv; + np = cp++; + while (isdigit(*cp)) + cp++; + if (*cp && !isspace(*cp)) + goto inv; + mtp->freq_offset = atoi(np); + mtp++; + got_meas++; + if (got_meas >= nmeas) + break; + } + fclose(f); + if (got_meas < nmeas) { + fprintf(stderr, "error: need %d measurements, got %d in %s\n", + nmeas, got_meas, filename); + exit(1); + } + return 0; +}