Mercurial > hg > fxanalyse
annotate DDS_Fox.c @ 184:12df3a2b18de
Do not reset dedrift DDS at program initialization
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Fri, 21 Feb 2014 18:42:30 +0100 |
parents | e5ad3ed47d2c |
children |
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 |
184
12df3a2b18de
Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
175
diff
changeset
|
69 void DDSFox_Init(DDSParameter *Param, char *ip, int port) |
68
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; |
184
12df3a2b18de
Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
175
diff
changeset
|
77 } |
12df3a2b18de
Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
175
diff
changeset
|
78 |
12df3a2b18de
Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
175
diff
changeset
|
79 void DDSFox_Reset(DDSParameter *Param, double frequency) |
12df3a2b18de
Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
175
diff
changeset
|
80 { |
12df3a2b18de
Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
175
diff
changeset
|
81 // set sweep rate to 0 |
12df3a2b18de
Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
175
diff
changeset
|
82 Param->SweepRate = 0.0; |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
83 // reset the DDS |
184
12df3a2b18de
Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
175
diff
changeset
|
84 DDSFox_DeviceReset(Param); |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
85 // set profile number 7 soft frequecy sweep |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
86 DDSFox_SetProfile(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
87 // set clock divider to 1 |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
88 DDSFox_SetDiv(Param, 1); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
89 // set frequency |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
90 DDSFox_SetFreqInf(Param, frequency); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
91 // set frequency upper bound to max value |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
92 DDSFox_SetFreqMax(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
93 // set sweep rate to 0 |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
94 DDSFox_SetDT(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
95 DDSFox_SetDf(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
96 DDSFox_SetSweepSign(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
97 // start sweep |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
98 DDSFox_StartSweep(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
99 // set frequency lower bound to min value |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
100 DDSFox_SetFreqMin(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
101 |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
102 return; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
103 } |
0 | 104 |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
105 void DDSFox_SetSweepRate(DDSParameter *Param, double sweepRate) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
106 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
107 Param->SweepRate = sweepRate; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
108 DDSFox_SetDf(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
109 DDSFox_SetSweepSign(Param); |
0 | 110 } |
111 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
112 void DDSFox_Set(DDSParameter *Param, double frequency, double sweepRate) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
113 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
114 // set desired frequency |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
115 DDSFox_SetFreqInf(Param, frequency); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
116 // set frequency upper bound to max value |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
117 DDSFox_SetFreqMax(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
118 // set sweep rate to 0 |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
119 Param->SweepRate = 0.0; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
120 DDSFox_SetDT(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
121 DDSFox_SetDf(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
122 DDSFox_SetSweepSign(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
123 // start sweep |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
124 DDSFox_StartSweep(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
125 // set frequency lower bound to min value |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
126 DDSFox_SetFreqMin(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
127 // set desired sweep rate |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
128 Param->SweepRate = sweepRate; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
129 DDSFox_SetDf(Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
130 DDSFox_SetSweepSign(Param); |
0 | 131 } |
132 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
133 void DDSFox_Nop (DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
134 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
135 // send NOP command |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
136 char request[255]; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
137 sprintf(request, "set;%i;%i", 1, CMD_NOP); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
138 SendCmd(request, Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
139 } |
0 | 140 |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
141 void DDSFox_SetProfile (DDSParameter *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 char request[255]; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
144 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
|
145 SendCmd(request, Param); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
146 } |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
147 |
184
12df3a2b18de
Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
175
diff
changeset
|
148 void DDSFox_DeviceReset(DDSParameter *Param) |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
149 { |
184
12df3a2b18de
Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
175
diff
changeset
|
150 char request[255]; |
12df3a2b18de
Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
175
diff
changeset
|
151 sprintf(request, "set;%i;%i", 1, CMD_RESET_DDS); |
12df3a2b18de
Do not reset dedrift DDS at program initialization
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
175
diff
changeset
|
152 SendCmd(request, Param); |
0 | 153 } |
154 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
155 void DDSFox_StopSweep(DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
156 { |
0 | 157 char Request[255]; |
158 sprintf(Request,"set;%i;%i;%i",1,CMD_STOP_SWEEP,1); | |
159 SendCmd(Request, Param); | |
160 return ; | |
161 } | |
162 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
163 void DDSFox_StartSweep(DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
164 { |
0 | 165 char Request[255]; |
166 sprintf(Request,"set;%i;%i;%i",1,CMD_START_SWEEP,1); | |
167 SendCmd(Request, Param); | |
168 return ; | |
169 } | |
170 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
171 void DDSFox_SetFreqMax (DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
172 { |
0 | 173 unsigned char octets[6]; |
174 char Request[255]; | |
175 convert_double_6char(pow(2,48)/2,octets); // borne sup : clock / 2 | |
176 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_SUP, | |
177 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets); | |
178 SendCmd(Request, Param); | |
179 DDSFox_SetSweepSign (Param); | |
180 return ; | |
181 } | |
182 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
183 void DDSFox_SetFreqMin (DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
184 { |
0 | 185 unsigned char octets[6]; |
186 char Request[255]; | |
187 convert_double_6char(1,octets); // borne inf : ~0 | |
188 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_INF, | |
189 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets); | |
190 SendCmd(Request, Param); | |
191 DDSFox_SetSweepSign (Param); | |
192 return ; | |
193 } | |
194 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
195 void DDSFox_SetFreqInf (DDSParameter *Param, double frequency) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
196 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
197 double word ; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
198 unsigned char octets[6]; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
199 char Request[255]; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
200 word = pow(2,48)*(frequency / Param->Clock); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
201 convert_double_6char(word, octets); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
202 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
|
203 *(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
|
204 SendCmd(Request, Param); |
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 |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
207 void DDSFox_SetFreqSup (DDSParameter *Param, double frequency) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
208 { |
0 | 209 double word ; |
210 unsigned char octets[6]; | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
211 char Request[255]; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
212 word = pow(2,48)*(frequency / Param->Clock); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
213 convert_double_6char(word, octets); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
214 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
|
215 *(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
|
216 SendCmd(Request, Param); |
0 | 217 } |
218 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
219 static int GetSweepSign(DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
220 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
221 if (Param->SweepRate >= 0.0) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
222 return 0; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
223 return 1; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
224 } |
0 | 225 |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
226 void DDSFox_SetSweepSign(DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
227 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
228 char Request[255] ; |
0 | 229 int SweepSign ; |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
230 SweepSign = GetSweepSign(Param) ; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
231 sprintf(Request, "set;%i;%i;%i", 1, CMD_SWEEP_SIGN, SweepSign); |
0 | 232 SendCmd(Request, Param) ; |
233 return ; | |
234 } | |
235 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
236 void DDSFox_SetDT(DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
237 { |
0 | 238 char Request[255]; |
239 int dt= 0; | |
240 char FTW0[255]="0"; /**** sinon le fichier inf.xx est faux ***/ | |
241 dt = ((Param->Delta_T)/BASE_TIME) - 1 ; | |
242 sprintf(FTW0,"%ims",dt); | |
243 sprintf(Request,"set;%i;%i;%i;%s",1,CMD_DT, dt ,FTW0); | |
244 SendCmd(Request, Param) ; | |
245 return ; | |
246 } | |
247 | |
248 // 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
|
249 void DDSFox_SetDiv(DDSParameter *Param, int div) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
250 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
251 char Request[255]; |
0 | 252 Command Rd; |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
253 char temp; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
254 |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
255 int Div = 0; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
256 // Div = log2(div) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
257 while ((div >>= 1) > 1) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
258 Div++; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
259 |
0 | 260 init_command(&Rd); |
261 sprintf(Request,"get;%i;%i",1,CMD_CONFIG_REG2); | |
262 if (RecvCmd(&Rd, Request, Param) < 0) | |
263 return; | |
264 temp = atoi(Rd.value2) ; | |
265 temp = temp & 0x9F ; | |
266 temp = temp | Div << 5 ; | |
267 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i",1,CMD_CONFIG_REG2,atoi(Rd.value0), | |
268 atoi(Rd.value1),temp,atoi(Rd.value3),atoi(Rd.value4)) ; | |
269 SendCmd(Request, Param) ; | |
270 return ; | |
271 } | |
272 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
273 void DDSFox_SetDf(DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
274 { |
0 | 275 char Request[255]; |
276 double word ; | |
277 unsigned char *octets; | |
278 word = pow(2,48)*(fabs(Param->SweepRate)*Param->Delta_T/Param->Clock); | |
279 octets=malloc(6*sizeof(unsigned char)); | |
280 convert_double_6char(word, octets); | |
281 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_DF, | |
282 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets); | |
283 SendCmd(Request, Param); | |
284 free(octets); | |
285 return ; | |
286 } | |
287 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
288 double DDSFox_ReadFreq(DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
289 { |
0 | 290 char Request[255]; |
291 unsigned int OctetA, OctetB, OctetC, OctetD, OctetE, OctetF ; | |
292 double FreqRead ; | |
293 Command Rd; | |
294 init_command(&Rd); | |
295 sprintf(Request,"get;%i;%i",1,CMD_GET_FREQ); | |
296 if (RecvCmd(&Rd, Request, Param) == -1) | |
297 return -1.; | |
298 OctetA=atoi(Rd.value0); | |
299 OctetB=atoi(Rd.value1); | |
300 OctetC=atoi(Rd.value2); | |
301 OctetD=atoi(Rd.value3); | |
302 OctetE=atoi(Rd.value4); | |
303 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
|
304 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
|
305 FreqRead = FreqRead * Param->Clock / pow(2,48); |
0 | 306 return(FreqRead); |
307 } | |
308 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
309 // TCP communication |
0 | 310 |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
311 static unsigned int timeout = 0; // milliseconds |
0 | 312 |
313 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
314 static int SendCmd(char *Buffer, DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
315 { |
0 | 316 unsigned int hConv=0; |
317 char Response[255]; | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
318 #ifdef DEBUG |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
319 fprintf(stderr, "> %s\n", Buffer); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
320 #endif |
175 | 321 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, NULL, NULL, timeout) < 0) { |
13
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
322 error("Connect failed"); |
0 | 323 return -1; |
324 } | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
325 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
|
326 error("Write failed"); |
0 | 327 return -1; |
328 } | |
329 sprintf(Response," "); | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
330 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
|
331 error("Read failed"); |
0 | 332 return -1; |
333 } | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
334 #ifdef DEBUG |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
335 fprintf(stderr, "< %s\n", Response); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
336 #endif |
0 | 337 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
|
338 error("Response failed %s %s", Buffer, Response); |
0 | 339 return -1; |
340 } | |
341 return 0; | |
342 } | |
343 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
344 static int RecvCmd(Command *Rd, char * Buffer, DDSParameter *Param) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
345 { |
0 | 346 unsigned int hConv=0; |
347 char parsebuf[255]; | |
348 char Response[255]; | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
349 #ifdef DEBUG |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
350 fprintf(stderr, "> %s\n", Buffer); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
351 #endif |
175 | 352 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, NULL, NULL, timeout) < 0) { |
13
e45d6e9544f5
Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
3
diff
changeset
|
353 error("Connect failed"); |
0 | 354 return -1; |
355 } | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
356 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
|
357 error("Write failed"); |
0 | 358 return -1; |
359 } | |
360 sprintf(Response," "); | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
361 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
|
362 error("Read failed"); |
0 | 363 return -1; |
364 } | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
365 #ifdef DEBUG |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
366 fprintf(stderr, "< %s\n", Response); |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
367 #endif |
0 | 368 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
|
369 error("Response failed %s %s", Buffer, Response); |
0 | 370 return -1; |
371 } | |
372 | |
373 sprintf(parsebuf,"%s",Response) ; | |
374 parse_command(Rd, parsebuf) ; | |
375 return 0; | |
376 } | |
377 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
378 static void init_command(Command *cmd) |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
379 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
380 memset(cmd, 0, sizeof(Command)); |
0 | 381 } |
382 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
383 static int parse_command(Command *cmd1, char *buf) |
0 | 384 { |
385 char* pointer; | |
386 int c = 0; | |
387 | |
388 pointer = strtok( buf, CMD_SEP ); | |
389 while( pointer ){ | |
390 if( c == 0 ){ | |
391 cmd1->action = pointer; | |
392 } | |
393 else if( c == 1 ){ | |
394 cmd1->canal = pointer; | |
395 } | |
396 else if( c == 2 ){ | |
397 cmd1->command = pointer; | |
398 } | |
399 else if( c == 3 ){ | |
400 cmd1->value0 = pointer; | |
401 } | |
402 else if( c == 4 ){ | |
403 cmd1->value1 = pointer; | |
404 } | |
405 else if( c == 5 ){ | |
406 cmd1->value2 = pointer; | |
407 } | |
408 else if( c == 6 ){ | |
409 cmd1->value3 = pointer; | |
410 } | |
411 else if( c == 7 ){ | |
412 cmd1->value4 = pointer; | |
413 } | |
414 else if( c == 8 ){ | |
415 cmd1->value5 = pointer; | |
416 } | |
417 else if( c == 9 ){ | |
418 cmd1->value6 = pointer; | |
419 } | |
420 else if( c == 10 ){ | |
421 cmd1->value7 = pointer; | |
422 } | |
423 pointer = strtok( NULL, CMD_SEP ); | |
424 c++; | |
425 } | |
426 return 0; | |
427 } | |
428 | |
68
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
429 // 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
|
430 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
|
431 { |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
432 // 64 bits integer |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
433 unsigned long long x = fraction; |
64a7a1d3d75c
Cleanup AD9956 DDS driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
63
diff
changeset
|
434 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
|
435 octets[i] = (unsigned char)((x >> (i * 8)) & 0xFF); |
0 | 436 } |