view cmu200/signalgen.c @ 87:34a1e06a8587

checking in cableconf and txlevels config files
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 17 Jul 2017 00:03:27 +0000
parents 4e263849b064
children
line wrap: on
line source

/*
 * This module implements the signal generator functionality.
 */

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

extern char *cmu200_tx_name;
extern int cmu200_rf_port;

extern char *client_cmd_fields[];
extern int client_cmd_nfields;

extern int current_mode;
extern struct band *current_band;

stop_signal_gen()
{
	char cmdstr[80];

	if (current_mode == OP_MODE_SIGNAL_GEN) {
		sprintf(cmdstr, "ABORT:RFG:%s\n", cmu200_tx_name);
		send_scpi_cmd(cmdstr);
	}
}

cmd_signal_gen_setup()
{
	int rc;
	char cmdstr[80];

	if (client_cmd_nfields != 2) {
		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);
	}
	sprintf(cmdstr, "*SEC %d\n", SECADDR_RF_NSIG);
	send_scpi_cmd(cmdstr);
	sprintf(cmdstr, "OUTP:%s RF%d\n", cmu200_tx_name, cmu200_rf_port);
	send_scpi_cmd(cmdstr);
	sprintf(cmdstr, "CORR:LOSS:OUTP%d:%s %u.%u\n", cmu200_rf_port,
		cmu200_tx_name, current_band->dl_cable_loss / 10,
		current_band->dl_cable_loss % 10);
	send_scpi_cmd(cmdstr);
	current_mode = OP_MODE_SIGNAL_GEN;
	send_socket_response("+OK\n");
	return(0);
}

cmd_signal_gen_sine()
{
	unsigned arfcn, freq_khz;
	int offset;
	char cmdstr[128];

	if (current_mode != OP_MODE_SIGNAL_GEN) {
		send_socket_response("-Wrong mode\n");
		return(0);
	}
	if (client_cmd_nfields != 4) {
		send_socket_response("-Wrong number of arguments\n");
		return(0);
	}
	arfcn = atoi(client_cmd_fields[1]);
	if (verify_arfcn(arfcn, 0, &freq_khz) < 0) {
		send_socket_response("-Invalid ARFCN\n");
		return(0);
	}
	offset = atoi(client_cmd_fields[2]);
	freq_khz += offset;
	sprintf(cmdstr, "SOUR:RFG:%s:LEV %s\n", cmu200_tx_name,
		client_cmd_fields[3]);
	send_scpi_cmd(cmdstr);
	sprintf(cmdstr, "SOUR:RFG:%s:FREQ %u000\n", cmu200_tx_name, freq_khz);
	send_scpi_cmd(cmdstr);
	sprintf(cmdstr, "INIT:RFG:%s\n", cmu200_tx_name);
	send_scpi_cmd(cmdstr);
	send_scpi_cmd("*OPC?\n");
	collect_staropc_response();
	send_socket_response("+OK\n");
	return(0);
}

cmd_signal_gen_off()
{
	stop_signal_gen();
	send_socket_response("+OK\n");
	return(0);
}