annotate cmu200/signalgen.c @ 22:e8bcead3aa9b

autocal: started linking fc-rfcal-vcxo
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 22 May 2017 21:01:29 +0000
parents d8cbc7a383eb
children 8877634feba5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 extern char *client_cmd_fields[];
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern int client_cmd_nfields;
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern int current_mode;
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 cmd_signal_gen_setup()
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 int rc;
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 char cmdstr[32];
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (client_cmd_nfields != 2) {
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 send_socket_response("-Wrong number of arguments\n");
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 return(0);
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 }
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 stop_signal_gen();
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 current_mode = OP_MODE_UNDEF;
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 rc = find_named_band(client_cmd_fields[1]);
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (rc < 0) {
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 send_socket_response("-Invalid band argument\n");
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return(0);
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 sprintf(cmdstr, "*SEC %d\n", SECADDR_RF_NSIG);
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 send_scpi_cmd(cmdstr);
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 current_mode = OP_MODE_SIGNAL_GEN;
504d3cbb95b5 fc-cmu200d: signal-gen-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 send_socket_response("+OK\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 }
5
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
39
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
40 cmd_signal_gen_sine()
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
41 {
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
42 unsigned arfcn, freq_khz;
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
43 int offset;
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
44 char cmdstr[128];
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
45
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
46 if (current_mode != OP_MODE_SIGNAL_GEN) {
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
47 send_socket_response("-Wrong mode\n");
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
48 return(0);
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
49 }
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
50 if (client_cmd_nfields != 4) {
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
51 send_socket_response("-Wrong number of arguments\n");
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
52 return(0);
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
53 }
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
54 arfcn = atoi(client_cmd_fields[1]);
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
55 if (verify_arfcn(arfcn, 0, &freq_khz) < 0) {
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
56 send_socket_response("-Invalid ARFCN\n");
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
57 return(0);
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
58 }
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
59 offset = atoi(client_cmd_fields[2]);
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
60 freq_khz += offset;
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
61 sprintf(cmdstr, "SOUR:RFG:LEV %s\n", client_cmd_fields[3]);
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
62 send_scpi_cmd(cmdstr);
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
63 sprintf(cmdstr, "SOUR:RFG:FREQ %u000\n", freq_khz);
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
64 send_scpi_cmd(cmdstr);
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
65 send_scpi_cmd("INIT:RFG\n");
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
66 send_scpi_cmd("*OPC?\n");
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
67 collect_staropc_response();
493987a4527e fc-cmu200d: signal-gen-sine implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 4
diff changeset
68 send_socket_response("+OK\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 }
6
d8cbc7a383eb fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
71
d8cbc7a383eb fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
72 cmd_signal_gen_off()
d8cbc7a383eb fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
73 {
d8cbc7a383eb fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
74 stop_signal_gen();
d8cbc7a383eb fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
75 send_socket_response("+OK\n");
d8cbc7a383eb fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
76 return(0);
d8cbc7a383eb fc-cmu200d: signal-gen-off implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 5
diff changeset
77 }