FreeCalypso > hg > fc-rfcal-tools
annotate cmu200/signalgen.c @ 65:e7b9a9903f14
doc/Rx-cal-theory: typo fix
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 28 May 2017 05:10:32 +0000 |
parents | 34c6fbe38daa |
children | 4e263849b064 |
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" |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "secaddr.h" |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
38
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
12 extern char *cmu200_tx_name; |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
13 extern int cmu200_rf_port; |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
14 |
4
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern char *client_cmd_fields[]; |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern int client_cmd_nfields; |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 extern int current_mode; |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
38
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
20 stop_signal_gen() |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
21 { |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
22 char cmdstr[80]; |
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 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
|
25 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
|
26 send_scpi_cmd(cmdstr); |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
27 } |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
28 } |
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
29 |
4
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 cmd_signal_gen_setup() |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 { |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 int rc; |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 char cmdstr[32]; |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (client_cmd_nfields != 2) { |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 send_socket_response("-Wrong number of arguments\n"); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 return(0); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 } |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 stop_signal_gen(); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 current_mode = OP_MODE_UNDEF; |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 rc = find_named_band(client_cmd_fields[1]); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 if (rc < 0) { |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 send_socket_response("-Invalid band argument\n"); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 return(0); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 sprintf(cmdstr, "*SEC %d\n", SECADDR_RF_NSIG); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 send_scpi_cmd(cmdstr); |
39
34c6fbe38daa
fc-cmu200d: implemented RF1/RF2 port selection
Mychaela Falconia <falcon@freecalypso.org>
parents:
38
diff
changeset
|
48 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
|
49 send_scpi_cmd(cmdstr); |
4
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 current_mode = OP_MODE_SIGNAL_GEN; |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 send_socket_response("+OK\n"); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 return(0); |
504d3cbb95b5
fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 } |
5
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
54 |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
55 cmd_signal_gen_sine() |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
56 { |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
57 unsigned arfcn, freq_khz; |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
58 int offset; |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
59 char cmdstr[128]; |
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 if (current_mode != OP_MODE_SIGNAL_GEN) { |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
62 send_socket_response("-Wrong mode\n"); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
63 return(0); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
64 } |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
65 if (client_cmd_nfields != 4) { |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
66 send_socket_response("-Wrong number of arguments\n"); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
67 return(0); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
68 } |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
69 arfcn = atoi(client_cmd_fields[1]); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
70 if (verify_arfcn(arfcn, 0, &freq_khz) < 0) { |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
71 send_socket_response("-Invalid ARFCN\n"); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
72 return(0); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
73 } |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
74 offset = atoi(client_cmd_fields[2]); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
75 freq_khz += offset; |
38
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
76 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
|
77 client_cmd_fields[3]); |
5
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
78 send_scpi_cmd(cmdstr); |
38
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
79 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
|
80 send_scpi_cmd(cmdstr); |
38
8877634feba5
fc-cmu200d: use either main or Aux Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
6
diff
changeset
|
81 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
|
82 send_scpi_cmd(cmdstr); |
5
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
83 send_scpi_cmd("*OPC?\n"); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
84 collect_staropc_response(); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
85 send_socket_response("+OK\n"); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
86 return(0); |
493987a4527e
fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
4
diff
changeset
|
87 } |
6
d8cbc7a383eb
fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
88 |
d8cbc7a383eb
fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
89 cmd_signal_gen_off() |
d8cbc7a383eb
fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
90 { |
d8cbc7a383eb
fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
91 stop_signal_gen(); |
d8cbc7a383eb
fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
92 send_socket_response("+OK\n"); |
d8cbc7a383eb
fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
93 return(0); |
d8cbc7a383eb
fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
5
diff
changeset
|
94 } |