FreeCalypso > hg > fc-rfcal-tools
annotate cmu200/vcxocal.c @ 34:99f753d4ccaf
fc-cmu200d: check for errors on serial port write
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 23 May 2017 00:33:10 +0000 |
parents | aeffe53e110d |
children | 34c6fbe38daa |
rev | line source |
---|---|
7
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the VCXO calibration support functionality. |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
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 #include <stdio.h> |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdlib.h> |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <string.h> |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <strings.h> |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "mode.h" |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "band.h" |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 extern char *client_cmd_fields[]; |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern int client_cmd_nfields; |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern int current_mode; |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern struct band *current_band; |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
8
c873a36a16e6
fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
18 extern char instrument_response[]; |
c873a36a16e6
fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
19 |
7
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 cmd_vcxo_cal_setup() |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 { |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int rc; |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 unsigned arfcn; |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 char cmdstr[32]; |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (client_cmd_nfields != 3) { |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 send_socket_response("-Wrong number of arguments\n"); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return(0); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 stop_signal_gen(); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 current_mode = OP_MODE_UNDEF; |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 rc = find_named_band(client_cmd_fields[1]); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 if (rc < 0) { |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 send_socket_response("-Invalid band argument\n"); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return(0); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 arfcn = atoi(client_cmd_fields[2]); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 if (verify_arfcn(arfcn, 0, 0) < 0) { |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 send_socket_response("-Invalid ARFCN\n"); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 return(0); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 } |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 sprintf(cmdstr, "*SEC %d\n", current_band->secaddr); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 send_scpi_cmd(cmdstr); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 sprintf(cmdstr, "RFAN:CHAN %uCH\n", arfcn); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 send_scpi_cmd(cmdstr); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 send_scpi_cmd("RFAN:TSEQ GSM5\n"); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 current_mode = OP_MODE_VCXO_CAL; |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 send_socket_response("+OK\n"); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 return(0); |
948031e6de50
fc-cmu200d: vcxo-cal-setup implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
8
c873a36a16e6
fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
51 |
c873a36a16e6
fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
52 cmd_freq_meas() |
c873a36a16e6
fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
53 { |
11
aeffe53e110d
fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
54 char *resp_fields[11]; |
aeffe53e110d
fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
55 char client_resp[128]; |
aeffe53e110d
fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
56 |
8
c873a36a16e6
fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
57 if (current_mode != OP_MODE_VCXO_CAL) { |
c873a36a16e6
fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
58 send_socket_response("-Wrong mode\n"); |
c873a36a16e6
fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
59 return(0); |
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 send_scpi_cmd("READ:MOD?\n"); |
c873a36a16e6
fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
62 collect_instr_response(); |
11
aeffe53e110d
fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
63 if (parse_commasep_response(resp_fields, 11) < 0) { |
aeffe53e110d
fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
64 send_socket_response |
aeffe53e110d
fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
65 ("-CMU200 response has wrong number of fields\n"); |
aeffe53e110d
fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
66 return(0); |
aeffe53e110d
fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
67 } |
aeffe53e110d
fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
68 sprintf(client_resp, "+ %s\n", resp_fields[7]); |
aeffe53e110d
fc-cmu200d: freq-meas works
Mychaela Falconia <falcon@freecalypso.org>
parents:
8
diff
changeset
|
69 send_socket_response(client_resp); |
8
c873a36a16e6
fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
70 return(0); |
c873a36a16e6
fc-cmu200d: freq-meas implemented without response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents:
7
diff
changeset
|
71 } |