view cmu200/rfanalyzer.c @ 132:94e8a410d6bd

fc-rfcal-txcheck: pass PCL to tester (txpwr-cal-pcl)
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 20 Dec 2021 03:52:01 +0000
parents 634995d55601
children
line wrap: on
line source

/*
 * This module implements the RF analyzer functionality
 * for VCXO and Tx power level calibration support.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "mode.h"
#include "band.h"

extern int cmu200_rf_port;

extern char *client_cmd_fields[];
extern int client_cmd_nfields;

extern int current_mode;
extern struct band *current_band;

extern char instrument_response[];

cmd_rfan_setup()
{
	int rc;
	unsigned arfcn;
	char cmdstr[80];

	if (client_cmd_nfields != 3) {
		send_socket_response("-Wrong number of arguments\n");
		return(0);
	}
	stop_signal_gen();
	current_mode = OP_MODE_UNDEF;
	rc = find_named_band(client_cmd_fields[1]);
	if (rc < 0) {
		send_socket_response("-Invalid band argument\n");
		return(0);
	}
	arfcn = atoi(client_cmd_fields[2]);
	if (verify_arfcn(arfcn, 0, 0) < 0) {
		send_socket_response("-Invalid ARFCN\n");
		return(0);
	}
	sprintf(cmdstr, "*SEC %d\n", current_band->secaddr);
	send_scpi_cmd(cmdstr);
	sprintf(cmdstr, "INP RF%d\n", cmu200_rf_port);
	send_scpi_cmd(cmdstr);
	sprintf(cmdstr, "CORR:LOSS:INP%d %u.%u\n", cmu200_rf_port,
		current_band->ul_cable_loss / 10,
		current_band->ul_cable_loss % 10);
	send_scpi_cmd(cmdstr);
	sprintf(cmdstr, "RFAN:CHAN %uCH\n", arfcn);
	send_scpi_cmd(cmdstr);
	send_scpi_cmd("RFAN:TSEQ GSM5\n");
	current_mode = OP_MODE_GSM_RFAN;
	send_socket_response("+OK\n");
	return(0);
}

cmd_rfan_channel()
{
	unsigned arfcn;
	char cmdstr[80];

	if (current_mode != OP_MODE_GSM_RFAN) {
		send_socket_response("-Wrong mode\n");
		return(0);
	}
	if (client_cmd_nfields != 2) {
		send_socket_response("-Wrong number of arguments\n");
		return(0);
	}
	arfcn = atoi(client_cmd_fields[1]);
	if (verify_arfcn(arfcn, 0, 0) < 0) {
		send_socket_response("-Invalid ARFCN\n");
		return(0);
	}
	sprintf(cmdstr, "RFAN:CHAN %uCH\n", arfcn);
	send_scpi_cmd(cmdstr);
	send_socket_response("+OK\n");
	return(0);
}

cmd_rfan_tpcl()
{
	unsigned pcl;
	char cmdstr[80];

	if (current_mode != OP_MODE_GSM_RFAN) {
		send_socket_response("-Wrong mode\n");
		return(0);
	}
	if (client_cmd_nfields != 2) {
		send_socket_response("-Wrong number of arguments\n");
		return(0);
	}
	pcl = atoi(client_cmd_fields[1]);
	if (pcl > 31) {
		send_socket_response("-Invalid PCL\n");
		return(0);
	}
	sprintf(cmdstr, "CONF:RFAN:TPCL %u\n", pcl);
	send_scpi_cmd(cmdstr);
	send_socket_response("+OK\n");
	return(0);
}

cmd_freq_meas()
{
	char *resp_fields[11];
	char client_resp[128];

	if (current_mode != OP_MODE_GSM_RFAN) {
		send_socket_response("-Wrong mode\n");
		return(0);
	}
	send_scpi_cmd("READ:MOD?\n");
	collect_instr_response();
	if (parse_commasep_response(resp_fields, 11) < 0) {
		send_socket_response
			("-CMU200 response has wrong number of fields\n");
		return(0);
	}
	sprintf(client_resp, "+ %s\n", resp_fields[7]);
	send_socket_response(client_resp);
	return(0);
}

cmd_power_meas()
{
	char *resp_fields[5], *ramp_status;
	char client_resp[128];

	if (current_mode != OP_MODE_GSM_RFAN) {
		send_socket_response("-Wrong mode\n");
		return(0);
	}
	send_scpi_cmd("READ:POW?\n");
	collect_instr_response();
	if (parse_commasep_response(resp_fields, 5) < 0) {
		send_socket_response
			("-CMU200 response has wrong number of fields\n");
		return(0);
	}
	if (!strcasecmp(resp_fields[3], "MATC"))
		ramp_status = "OK";
	else if (!strcasecmp(resp_fields[3], "NMAT"))
		ramp_status = "BAD";
	else
		ramp_status = resp_fields[3];
	sprintf(client_resp, "+ %s %s\n", resp_fields[4], ramp_status);
	send_socket_response(client_resp);
	return(0);
}