view autocal/vcxomeas.c @ 100:7ad5836d3b87

fc-rfcal-vcxo: added check for final freq offset being within 70 Hz
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 11 Aug 2017 02:45:10 +0000
parents b06532c9642f
children 7ad0495991ed
line wrap: on
line source

/*
 * This module contains the frequency measurement code for fc-rfcal-vcxo.
 */

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <rvinterf/l1tm.h>
#include <rvinterf/exitcodes.h>

extern char tsid_response[];

float
vcxo_freq_meas(dac, hint)
	int dac;
	char *hint;
{
	char cmd[80];
	double meas;

	printf("Performing frequency measurement at DAC=%d (%s)\n", dac, hint);
	do_rfpw(AFC_DAC_VALUE, dac);
	usleep(80000);
	sprintf(cmd, "freq-meas %s\n", hint);
	tsid_command(cmd);
	meas = atof(tsid_response + 1);
	printf("Measured frequency offset %.2f Hz\n", meas);
	if (isnan(meas)) {
		printf("Error: got NaN response, aborting\n");
		do_rfe(STOP_ALL);
		exit(ERROR_TARGET);
	}
	return(meas);
}