annotate cmu200/rfanalyzer.c @ 70:e35da125c937

fc-cmu200d: CMU200 external att setting implemented in RF analyzer mode
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 14 Jul 2017 05:03:10 +0000
parents 3f4221ef916a
children fbfbd813c9b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
40
2fb9768fc1e2 fc-cmu200d: VCXO calibration mode generalized into RF analyzer mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
2 * This module implements the RF analyzer functionality
2fb9768fc1e2 fc-cmu200d: VCXO calibration mode generalized into RF analyzer mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
3 * for VCXO and Tx power level calibration support.
7
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <string.h>
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <strings.h>
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "mode.h"
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "band.h"
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
39
34c6fbe38daa fc-cmu200d: implemented RF1/RF2 port selection
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
13 extern int cmu200_rf_port;
34c6fbe38daa fc-cmu200d: implemented RF1/RF2 port selection
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
14
7
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern char *client_cmd_fields[];
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 extern int client_cmd_nfields;
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 extern int current_mode;
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 extern struct band *current_band;
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
8
c873a36a16e6 fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
21 extern char instrument_response[];
c873a36a16e6 fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
22
40
2fb9768fc1e2 fc-cmu200d: VCXO calibration mode generalized into RF analyzer mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
23 cmd_rfan_setup()
7
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 {
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 int rc;
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 unsigned arfcn;
70
e35da125c937 fc-cmu200d: CMU200 external att setting implemented in RF analyzer mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
27 char cmdstr[80];
7
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (client_cmd_nfields != 3) {
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 send_socket_response("-Wrong number of arguments\n");
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return(0);
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 stop_signal_gen();
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 current_mode = OP_MODE_UNDEF;
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 rc = find_named_band(client_cmd_fields[1]);
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (rc < 0) {
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 send_socket_response("-Invalid band argument\n");
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 return(0);
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 arfcn = atoi(client_cmd_fields[2]);
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (verify_arfcn(arfcn, 0, 0) < 0) {
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 send_socket_response("-Invalid ARFCN\n");
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 return(0);
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 }
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 sprintf(cmdstr, "*SEC %d\n", current_band->secaddr);
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 send_scpi_cmd(cmdstr);
39
34c6fbe38daa fc-cmu200d: implemented RF1/RF2 port selection
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
47 sprintf(cmdstr, "INP RF%d\n", cmu200_rf_port);
34c6fbe38daa fc-cmu200d: implemented RF1/RF2 port selection
Mychaela Falconia <falcon@freecalypso.org>
parents: 11
diff changeset
48 send_scpi_cmd(cmdstr);
70
e35da125c937 fc-cmu200d: CMU200 external att setting implemented in RF analyzer mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
49 sprintf(cmdstr, "CORR:LOSS:INP%d %u.%u\n", cmu200_rf_port,
e35da125c937 fc-cmu200d: CMU200 external att setting implemented in RF analyzer mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
50 current_band->ul_cable_loss / 10,
e35da125c937 fc-cmu200d: CMU200 external att setting implemented in RF analyzer mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
51 current_band->ul_cable_loss % 10);
e35da125c937 fc-cmu200d: CMU200 external att setting implemented in RF analyzer mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 41
diff changeset
52 send_scpi_cmd(cmdstr);
7
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 sprintf(cmdstr, "RFAN:CHAN %uCH\n", arfcn);
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 send_scpi_cmd(cmdstr);
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 send_scpi_cmd("RFAN:TSEQ GSM5\n");
40
2fb9768fc1e2 fc-cmu200d: VCXO calibration mode generalized into RF analyzer mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
56 current_mode = OP_MODE_GSM_RFAN;
7
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 send_socket_response("+OK\n");
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 return(0);
948031e6de50 fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 }
8
c873a36a16e6 fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
60
c873a36a16e6 fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
61 cmd_freq_meas()
c873a36a16e6 fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
62 {
11
aeffe53e110d fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
63 char *resp_fields[11];
aeffe53e110d fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
64 char client_resp[128];
aeffe53e110d fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
65
40
2fb9768fc1e2 fc-cmu200d: VCXO calibration mode generalized into RF analyzer mode
Mychaela Falconia <falcon@freecalypso.org>
parents: 39
diff changeset
66 if (current_mode != OP_MODE_GSM_RFAN) {
8
c873a36a16e6 fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
67 send_socket_response("-Wrong mode\n");
c873a36a16e6 fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
68 return(0);
c873a36a16e6 fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
69 }
c873a36a16e6 fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
70 send_scpi_cmd("READ:MOD?\n");
c873a36a16e6 fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
71 collect_instr_response();
11
aeffe53e110d fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
72 if (parse_commasep_response(resp_fields, 11) < 0) {
aeffe53e110d fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
73 send_socket_response
aeffe53e110d fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
74 ("-CMU200 response has wrong number of fields\n");
aeffe53e110d fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
75 return(0);
aeffe53e110d fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
76 }
aeffe53e110d fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
77 sprintf(client_resp, "+ %s\n", resp_fields[7]);
aeffe53e110d fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents: 8
diff changeset
78 send_socket_response(client_resp);
8
c873a36a16e6 fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
79 return(0);
c873a36a16e6 fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 7
diff changeset
80 }
41
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
81
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
82 cmd_power_meas()
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
83 {
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
84 char *resp_fields[5];
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
85 char client_resp[128];
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
86
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
87 if (current_mode != OP_MODE_GSM_RFAN) {
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
88 send_socket_response("-Wrong mode\n");
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
89 return(0);
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
90 }
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
91 send_scpi_cmd("READ:POW?\n");
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
92 collect_instr_response();
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
93 if (parse_commasep_response(resp_fields, 5) < 0) {
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
94 send_socket_response
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
95 ("-CMU200 response has wrong number of fields\n");
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
96 return(0);
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
97 }
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
98 sprintf(client_resp, "+ %s\n", resp_fields[4]);
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
99 send_socket_response(client_resp);
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
100 return(0);
3f4221ef916a fc-cmu200d: power-meas implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 40
diff changeset
101 }