FreeCalypso > hg > fc-rfcal-tools
annotate cmu200/signalgen.c @ 105:44c6a2b4d40a
INSTALL: we need fc-host-tools-r6 or later for ERROR_RFFAIL
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 09 Dec 2017 07:07:19 +0000 |
parents | 4e263849b064 |
children |
rev | line source |
---|---|
4
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the signal generator functionality. |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdlib.h> |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <string.h> |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <strings.h> |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "mode.h" |
69
4e263849b064
fc-cmu200d: CMU200 external attenuation setting implemented in signal gen mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
39
diff
changeset
|
10 #include "band.h" |
4
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "secaddr.h" |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
38
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
13 extern char *cmu200_tx_name; |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
14 extern int cmu200_rf_port; |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
15 |
4
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern char *client_cmd_fields[]; |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 extern int client_cmd_nfields; |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 extern int current_mode; |
69
4e263849b064
fc-cmu200d: CMU200 external attenuation setting implemented in signal gen mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
39
diff
changeset
|
20 extern struct band *current_band; |
4
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
38
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
22 stop_signal_gen() |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
23 { |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
24 char cmdstr[80]; |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
25 |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
26 if (current_mode == OP_MODE_SIGNAL_GEN) { |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
27 sprintf(cmdstr, "ABORT:RFG:%s\n", cmu200_tx_name); |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
28 send_scpi_cmd(cmdstr); |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
29 } |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
30 } |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
31 |
4
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 cmd_signal_gen_setup() |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 { |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 int rc; |
69
4e263849b064
fc-cmu200d: CMU200 external attenuation setting implemented in signal gen mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
39
diff
changeset
|
35 char cmdstr[80]; |
4
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 if (client_cmd_nfields != 2) { |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 send_socket_response("-Wrong number of arguments\n"); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 return(0); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 stop_signal_gen(); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 current_mode = OP_MODE_UNDEF; |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 rc = find_named_band(client_cmd_fields[1]); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (rc < 0) { |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 send_socket_response("-Invalid band argument\n"); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 return(0); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 sprintf(cmdstr, "*SEC %d\n", SECADDR_RF_NSIG); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 send_scpi_cmd(cmdstr); |
39
34c6fbe38daa
fc-cmu200d: implemented RF1/RF2 port selection
Mychaela Falconia <falcon@freecalypso.org>
parents:
38
diff
changeset
|
50 sprintf(cmdstr, "OUTP:%s RF%d\n", cmu200_tx_name, cmu200_rf_port); |
34c6fbe38daa
fc-cmu200d: implemented RF1/RF2 port selection
Mychaela Falconia <falcon@freecalypso.org>
parents:
38
diff
changeset
|
51 send_scpi_cmd(cmdstr); |
69
4e263849b064
fc-cmu200d: CMU200 external attenuation setting implemented in signal gen mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
39
diff
changeset
|
52 sprintf(cmdstr, "CORR:LOSS:OUTP%d:%s %u.%u\n", cmu200_rf_port, |
4e263849b064
fc-cmu200d: CMU200 external attenuation setting implemented in signal gen mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
39
diff
changeset
|
53 cmu200_tx_name, current_band->dl_cable_loss / 10, |
4e263849b064
fc-cmu200d: CMU200 external attenuation setting implemented in signal gen mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
39
diff
changeset
|
54 current_band->dl_cable_loss % 10); |
4e263849b064
fc-cmu200d: CMU200 external attenuation setting implemented in signal gen mode
Mychaela Falconia <falcon@freecalypso.org>
parents:
39
diff
changeset
|
55 send_scpi_cmd(cmdstr); |
4
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 current_mode = OP_MODE_SIGNAL_GEN; |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 send_socket_response("+OK\n"); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 return(0); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
5
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
60 |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
61 cmd_signal_gen_sine() |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
62 { |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
63 unsigned arfcn, freq_khz; |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
64 int offset; |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
65 char cmdstr[128]; |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
66 |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
67 if (current_mode != OP_MODE_SIGNAL_GEN) { |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
68 send_socket_response("-Wrong mode\n"); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
69 return(0); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
70 } |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
71 if (client_cmd_nfields != 4) { |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
72 send_socket_response("-Wrong number of arguments\n"); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
73 return(0); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
74 } |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
75 arfcn = atoi(client_cmd_fields[1]); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
76 if (verify_arfcn(arfcn, 0, &freq_khz) < 0) { |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
77 send_socket_response("-Invalid ARFCN\n"); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
78 return(0); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
79 } |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
80 offset = atoi(client_cmd_fields[2]); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
81 freq_khz += offset; |
38
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
82 sprintf(cmdstr, "SOUR:RFG:%s:LEV %s\n", cmu200_tx_name, |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
83 client_cmd_fields[3]); |
5
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
84 send_scpi_cmd(cmdstr); |
38
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
85 sprintf(cmdstr, "SOUR:RFG:%s:FREQ %u000\n", cmu200_tx_name, freq_khz); |
5
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
86 send_scpi_cmd(cmdstr); |
38
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
87 sprintf(cmdstr, "INIT:RFG:%s\n", cmu200_tx_name); |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
88 send_scpi_cmd(cmdstr); |
5
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
89 send_scpi_cmd("*OPC?\n"); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
90 collect_staropc_response(); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
91 send_socket_response("+OK\n"); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
92 return(0); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
93 } |
6
d8cbc7a383eb
fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
94 |
d8cbc7a383eb
fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
95 cmd_signal_gen_off() |
d8cbc7a383eb
fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
96 { |
d8cbc7a383eb
fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
97 stop_signal_gen(); |
d8cbc7a383eb
fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
98 send_socket_response("+OK\n"); |
d8cbc7a383eb
fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
99 return(0); |
d8cbc7a383eb
fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
100 } |