Mercurial > hg > fxanalyse
annotate DDS_Fox.c @ 171:7d0c8319c496
Add new parameters to default condiguration file
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Fri, 14 Feb 2014 16:58:19 +0100 |
parents | 8e6a2ec85169 |
children | e5ad3ed47d2c |
rev | line source |
---|---|
0 | 1 #include <tcpsupp.h> |
2 #include <ansi_c.h> | |
3 #include "DDS_Fox.h" | |
4 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
5 // #define DEBUG 1 |
0 | 6 #define CMD_SEP ";" |
7 #define BASE_TIME 0.01 | |
8 | |
9 #define CMD_CONFIG_REG1 1 // cmd d'acces direct au rergistre 1 de config de la DDS (voir datasheet) | |
10 #define CMD_CONFIG_REG2 2 // cmd d'acces direct au rergistre 1 de config de la DDS (voir datasheet) | |
11 #define CMD_SINGLE_FREQ_PROF0 7 | |
12 #define CMD_PROFILE 15 // cmd de choix du profile de fonctionnement de la DDS (voir datasheet) | |
13 #define CMD_ATTENUATION 16 | |
14 #define CMD_RESET_DDS 17 | |
15 #define CMD_NOP 20 | |
16 #define CMD_FREQ_INF 21 | |
17 #define CMD_FREQ_SUP 22 | |
18 #define CMD_DF 23 | |
19 #define CMD_DT 24 | |
20 #define CMD_START_SWEEP 25 | |
21 #define CMD_STOP_SWEEP 26 | |
22 #define CMD_GET_FREQ 28 | |
23 #define CMD_SWEEP_SIGN 29 | |
24 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
25 typedef struct { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
26 char* action; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
27 char* canal; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
28 char* command; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
29 char* value0; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
30 char* value1; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
31 char* value2; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
32 char* value3; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
33 char* value4; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
34 char* value5; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
35 char* value6; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
36 char* value7; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
37 char* value8; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
38 char* value9; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
39 char* value10; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
40 char* value11; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
41 char* value12; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
42 char* value13; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
43 char* value14; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
44 char* value15; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
45 char* value16; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
46 char* value17; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
47 char* value18; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
48 char* value19; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
49 } Command; |
0 | 50 |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
51 static int SendCmd(char *Buffer, DDSParameter *Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
52 static int RecvCmd(Command *Rd, char * Buffer, DDSParameter *Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
53 static void init_command(Command *cmd); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
54 static int parse_command(Command *cmd1, char *buf); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
55 static void convert_double_6char (double fraction, unsigned char* octets); |
0 | 56 |
13
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
57 #define error(...) _error(__FILE__, __LINE__, __func__, __VA_ARGS__) |
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
58 |
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
59 void _error(const char *file, int line, const char *func, const char *frmt, ...) |
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
60 { |
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
61 va_list args; |
63
2320f5fc66aa
Fix varargs handling in DDS Fox driver error function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
50
diff
changeset
|
62 va_start(args, frmt); |
13
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
63 fprintf(stderr, "ERROR: %s:%d:%s: ", file, line, func); |
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
64 vfprintf(stderr, frmt, args); |
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
65 fprintf(stderr, "\n"); |
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
66 va_end(args); |
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
67 } |
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
68 |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
69 void DDSFox_Initialize(DDSParameter *Param, char *ip, int port, double frequency) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
70 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
71 strcpy(Param->ip, ip); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
72 Param->Port = 6665; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
73 Param->Profil = 7; // configuration profile: single freq=0, sweep=7 |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
74 Param->Clock = 200000000; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
75 Param->Delta_T = 0.01; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
76 Param->SweepRate = 0.0; |
0 | 77 |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
78 // reset the DDS |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
79 //DDSFox_Nop(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
80 DDSFox_Reset(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
81 // set profile number 7 soft frequecy sweep |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
82 DDSFox_SetProfile(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
83 // set clock divider to 1 |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
84 DDSFox_SetDiv(Param, 1); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
85 // set frequency |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
86 DDSFox_SetFreqInf(Param, frequency); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
87 // set frequency upper bound to max value |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
88 DDSFox_SetFreqMax(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
89 // set sweep rate to 0 |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
90 DDSFox_SetDT(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
91 DDSFox_SetDf(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
92 DDSFox_SetSweepSign(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
93 // start sweep |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
94 DDSFox_StartSweep(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
95 // set frequency lower bound to min value |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
96 DDSFox_SetFreqMin(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
97 |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
98 return; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
99 } |
0 | 100 |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
101 void DDSFox_SetSweepRate(DDSParameter *Param, double sweepRate) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
102 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
103 Param->SweepRate = sweepRate; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
104 DDSFox_SetDf(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
105 DDSFox_SetSweepSign(Param); |
0 | 106 } |
107 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
108 void DDSFox_Set(DDSParameter *Param, double frequency, double sweepRate) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
109 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
110 // set desired frequency |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
111 DDSFox_SetFreqInf(Param, frequency); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
112 // set frequency upper bound to max value |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
113 DDSFox_SetFreqMax(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
114 // set sweep rate to 0 |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
115 Param->SweepRate = 0.0; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
116 DDSFox_SetDT(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
117 DDSFox_SetDf(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
118 DDSFox_SetSweepSign(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
119 // start sweep |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
120 DDSFox_StartSweep(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
121 // set frequency lower bound to min value |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
122 DDSFox_SetFreqMin(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
123 // set desired sweep rate |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
124 Param->SweepRate = sweepRate; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
125 DDSFox_SetDf(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
126 DDSFox_SetSweepSign(Param); |
0 | 127 } |
128 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
129 void DDSFox_Nop (DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
130 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
131 // send NOP command |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
132 char request[255]; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
133 sprintf(request, "set;%i;%i", 1, CMD_NOP); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
134 SendCmd(request, Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
135 } |
0 | 136 |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
137 void DDSFox_SetProfile (DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
138 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
139 char request[255]; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
140 sprintf(request, "set;%i;%i;%i", 1, CMD_PROFILE, Param->Profil); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
141 SendCmd(request, Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
142 } |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
143 |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
144 void DDSFox_Reset(DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
145 { |
0 | 146 char Request[255]; |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
147 //sprintf(Request,"set;%i;%i",1,CMD_NOP); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
148 //SendCmd(Request, Param) ; |
0 | 149 sprintf(Request,"set;%i;%i",1,CMD_RESET_DDS); |
150 SendCmd(Request, Param) ; | |
151 return ; | |
152 } | |
153 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
154 void DDSFox_StopSweep(DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
155 { |
0 | 156 char Request[255]; |
157 sprintf(Request,"set;%i;%i;%i",1,CMD_STOP_SWEEP,1); | |
158 SendCmd(Request, Param); | |
159 return ; | |
160 } | |
161 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
162 void DDSFox_StartSweep(DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
163 { |
0 | 164 char Request[255]; |
165 sprintf(Request,"set;%i;%i;%i",1,CMD_START_SWEEP,1); | |
166 SendCmd(Request, Param); | |
167 return ; | |
168 } | |
169 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
170 void DDSFox_SetFreqMax (DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
171 { |
0 | 172 unsigned char octets[6]; |
173 char Request[255]; | |
174 convert_double_6char(pow(2,48)/2,octets); // borne sup : clock / 2 | |
175 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_SUP, | |
176 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets); | |
177 SendCmd(Request, Param); | |
178 DDSFox_SetSweepSign (Param); | |
179 return ; | |
180 } | |
181 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
182 void DDSFox_SetFreqMin (DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
183 { |
0 | 184 unsigned char octets[6]; |
185 char Request[255]; | |
186 convert_double_6char(1,octets); // borne inf : ~0 | |
187 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_INF, | |
188 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets); | |
189 SendCmd(Request, Param); | |
190 DDSFox_SetSweepSign (Param); | |
191 return ; | |
192 } | |
193 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
194 void DDSFox_SetFreqInf (DDSParameter *Param, double frequency) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
195 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
196 double word ; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
197 unsigned char octets[6]; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
198 char Request[255]; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
199 word = pow(2,48)*(frequency / Param->Clock); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
200 convert_double_6char(word, octets); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
201 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_INF, |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
202 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
203 SendCmd(Request, Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
204 } |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
205 |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
206 void DDSFox_SetFreqSup (DDSParameter *Param, double frequency) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
207 { |
0 | 208 double word ; |
209 unsigned char octets[6]; | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
210 char Request[255]; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
211 word = pow(2,48)*(frequency / Param->Clock); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
212 convert_double_6char(word, octets); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
213 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_SUP, |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
214 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
215 SendCmd(Request, Param); |
0 | 216 } |
217 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
218 static int GetSweepSign(DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
219 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
220 if (Param->SweepRate >= 0.0) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
221 return 0; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
222 return 1; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
223 } |
0 | 224 |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
225 void DDSFox_SetSweepSign(DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
226 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
227 char Request[255] ; |
0 | 228 int SweepSign ; |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
229 SweepSign = GetSweepSign(Param) ; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
230 sprintf(Request, "set;%i;%i;%i", 1, CMD_SWEEP_SIGN, SweepSign); |
0 | 231 SendCmd(Request, Param) ; |
232 return ; | |
233 } | |
234 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
235 void DDSFox_SetDT(DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
236 { |
0 | 237 char Request[255]; |
238 int dt= 0; | |
239 char FTW0[255]="0"; /**** sinon le fichier inf.xx est faux ***/ | |
240 dt = ((Param->Delta_T)/BASE_TIME) - 1 ; | |
241 sprintf(FTW0,"%ims",dt); | |
242 sprintf(Request,"set;%i;%i;%i;%s",1,CMD_DT, dt ,FTW0); | |
243 SendCmd(Request, Param) ; | |
244 return ; | |
245 } | |
246 | |
247 // Change le facteur de division de la clock. Argument: facteur de div, retourne rien | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
248 void DDSFox_SetDiv(DDSParameter *Param, int div) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
249 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
250 char Request[255]; |
0 | 251 Command Rd; |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
252 char temp; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
253 |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
254 int Div = 0; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
255 // Div = log2(div) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
256 while ((div >>= 1) > 1) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
257 Div++; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
258 |
0 | 259 init_command(&Rd); |
260 sprintf(Request,"get;%i;%i",1,CMD_CONFIG_REG2); | |
261 if (RecvCmd(&Rd, Request, Param) < 0) | |
262 return; | |
263 temp = atoi(Rd.value2) ; | |
264 temp = temp & 0x9F ; | |
265 temp = temp | Div << 5 ; | |
266 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i",1,CMD_CONFIG_REG2,atoi(Rd.value0), | |
267 atoi(Rd.value1),temp,atoi(Rd.value3),atoi(Rd.value4)) ; | |
268 SendCmd(Request, Param) ; | |
269 return ; | |
270 } | |
271 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
272 void DDSFox_SetDf(DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
273 { |
0 | 274 char Request[255]; |
275 double word ; | |
276 unsigned char *octets; | |
277 word = pow(2,48)*(fabs(Param->SweepRate)*Param->Delta_T/Param->Clock); | |
278 octets=malloc(6*sizeof(unsigned char)); | |
279 convert_double_6char(word, octets); | |
280 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_DF, | |
281 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets); | |
282 SendCmd(Request, Param); | |
283 free(octets); | |
284 return ; | |
285 } | |
286 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
287 double DDSFox_ReadFreq(DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
288 { |
0 | 289 char Request[255]; |
290 unsigned int OctetA, OctetB, OctetC, OctetD, OctetE, OctetF ; | |
291 double FreqRead ; | |
292 Command Rd; | |
293 init_command(&Rd); | |
294 sprintf(Request,"get;%i;%i",1,CMD_GET_FREQ); | |
295 if (RecvCmd(&Rd, Request, Param) == -1) | |
296 return -1.; | |
297 OctetA=atoi(Rd.value0); | |
298 OctetB=atoi(Rd.value1); | |
299 OctetC=atoi(Rd.value2); | |
300 OctetD=atoi(Rd.value3); | |
301 OctetE=atoi(Rd.value4); | |
302 OctetF=atoi(Rd.value5); | |
45
b47b97cfd050
Fix output frequency read back in DDS Fox driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
13
diff
changeset
|
303 FreqRead = 1099511627776.0 * OctetA + 4294967296.0 * OctetB + 16777216.0 * OctetC + 65536.0 * OctetD + 256.0 * OctetE + 1.0 * OctetF; |
b47b97cfd050
Fix output frequency read back in DDS Fox driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
13
diff
changeset
|
304 FreqRead = FreqRead * Param->Clock / pow(2,48); |
0 | 305 return(FreqRead); |
306 } | |
307 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
308 // TCP communication |
0 | 309 |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
310 static unsigned int timeout = 0; // milliseconds |
0 | 311 |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
312 int OnTCPEvent(unsigned handle, int xType, int errCode, void *callbackData) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
313 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
314 return 0; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
315 } |
0 | 316 |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
317 static int SendCmd(char *Buffer, DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
318 { |
0 | 319 unsigned int hConv=0; |
320 char Response[255]; | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
321 #ifdef DEBUG |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
322 fprintf(stderr, "> %s\n", Buffer); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
323 #endif |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
324 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, timeout) < 0) { |
13
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
325 error("Connect failed"); |
0 | 326 return -1; |
327 } | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
328 if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, timeout) < 0) { |
13
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
329 error("Write failed"); |
0 | 330 return -1; |
331 } | |
332 sprintf(Response," "); | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
333 if (ClientTCPRead (hConv, Response, 255, timeout) < 0) { |
13
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
334 error("Read failed"); |
0 | 335 return -1; |
336 } | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
337 #ifdef DEBUG |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
338 fprintf(stderr, "< %s\n", Response); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
339 #endif |
0 | 340 if (strncmp("OK",Response,2)) { |
13
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
341 error("Response failed %s %s", Buffer, Response); |
0 | 342 return -1; |
343 } | |
344 return 0; | |
345 } | |
346 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
347 static int RecvCmd(Command *Rd, char * Buffer, DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
348 { |
0 | 349 unsigned int hConv=0; |
350 char parsebuf[255]; | |
351 char Response[255]; | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
352 #ifdef DEBUG |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
353 fprintf(stderr, "> %s\n", Buffer); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
354 #endif |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
355 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, timeout) < 0) { |
13
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
356 error("Connect failed"); |
0 | 357 return -1; |
358 } | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
359 if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, timeout) < 0) { |
13
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
360 error("Write failed"); |
0 | 361 return -1; |
362 } | |
363 sprintf(Response," "); | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
364 if (ClientTCPRead (hConv, Response, 255, timeout) < 0) { |
13
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
365 error("Read failed"); |
0 | 366 return -1; |
367 } | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
368 #ifdef DEBUG |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
369 fprintf(stderr, "< %s\n", Response); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
370 #endif |
0 | 371 if (strncmp(Buffer,Response,strlen(Buffer))) { |
13
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
372 error("Response failed %s %s", Buffer, Response); |
0 | 373 return -1; |
374 } | |
375 | |
376 sprintf(parsebuf,"%s",Response) ; | |
377 parse_command(Rd, parsebuf) ; | |
378 return 0; | |
379 } | |
380 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
381 static void init_command(Command *cmd) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
382 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
383 memset(cmd, 0, sizeof(Command)); |
0 | 384 } |
385 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
386 static int parse_command(Command *cmd1, char *buf) |
0 | 387 { |
388 char* pointer; | |
389 int c = 0; | |
390 | |
391 pointer = strtok( buf, CMD_SEP ); | |
392 while( pointer ){ | |
393 if( c == 0 ){ | |
394 cmd1->action = pointer; | |
395 } | |
396 else if( c == 1 ){ | |
397 cmd1->canal = pointer; | |
398 } | |
399 else if( c == 2 ){ | |
400 cmd1->command = pointer; | |
401 } | |
402 else if( c == 3 ){ | |
403 cmd1->value0 = pointer; | |
404 } | |
405 else if( c == 4 ){ | |
406 cmd1->value1 = pointer; | |
407 } | |
408 else if( c == 5 ){ | |
409 cmd1->value2 = pointer; | |
410 } | |
411 else if( c == 6 ){ | |
412 cmd1->value3 = pointer; | |
413 } | |
414 else if( c == 7 ){ | |
415 cmd1->value4 = pointer; | |
416 } | |
417 else if( c == 8 ){ | |
418 cmd1->value5 = pointer; | |
419 } | |
420 else if( c == 9 ){ | |
421 cmd1->value6 = pointer; | |
422 } | |
423 else if( c == 10 ){ | |
424 cmd1->value7 = pointer; | |
425 } | |
426 pointer = strtok( NULL, CMD_SEP ); | |
427 c++; | |
428 } | |
429 return 0; | |
430 } | |
431 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
432 // convert double into 6 bytes sent back by an unsigned char pointer |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
433 static void convert_double_6char (double fraction, unsigned char* octets) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
434 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
435 // 64 bits integer |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
436 unsigned long long x = fraction; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
437 for (int i = 0; i < 6; i++) |
72
8e6a2ec85169
Fix byte order in AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
68
diff
changeset
|
438 octets[i] = (unsigned char)((x >> (i * 8)) & 0xFF); |
0 | 439 } |