annotate DDS_Fox.c @ 45:b47b97cfd050

Fix output frequency read back in DDS Fox driver The FTW registry value was read back wrong due to an integer overflow in the conversion from bytes string to double. This should fix the "jumps" seen in the application of the frequency dedrifting.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Wed, 10 Oct 2012 12:14:01 +0200
parents e45d6e9544f5
children 7ab3fb870ef8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
1 #include <tcpsupp.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
2 #include <ansi_c.h>
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
3 #include "DDS_Fox.h"
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
4
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
5 //#define DDS_IP "192.168.0.3"
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
6 //#define TCP_PORT 6665
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
7
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
8 #define DIV 0 // divided by 1
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
9 #define CMD_SEP ";"
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
10 #define BASE_TIME 0.01
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
11
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
12 #define CMD_CONFIG_REG1 1 // cmd d'acces direct au rergistre 1 de config de la DDS (voir datasheet)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
13 #define CMD_CONFIG_REG2 2 // cmd d'acces direct au rergistre 1 de config de la DDS (voir datasheet)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
14 #define CMD_SINGLE_FREQ_PROF0 7
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
15 #define CMD_PROFILE 15 // cmd de choix du profile de fonctionnement de la DDS (voir datasheet)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
16 #define CMD_ATTENUATION 16
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
17 #define CMD_RESET_DDS 17
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
18 #define CMD_NOP 20
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
19 #define CMD_FREQ_INF 21
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
20 #define CMD_FREQ_SUP 22
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
21 #define CMD_DF 23
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
22 #define CMD_DT 24
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
23 #define CMD_START_SWEEP 25
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
24 #define CMD_STOP_SWEEP 26
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
25 #define CMD_GET_FREQ 28
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
26 #define CMD_SWEEP_SIGN 29
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
27
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
28
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
29 /************************* Global variables ***********************************/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
30 //static char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
31
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
32 /************************* My own functions ***********************************/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
33 /*DDSParameter DDSGetParam (int panel, int control) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
34 DDSParameter Parameter ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
35
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
36 GetCtrlVal (panel, CONTROL_DDS_IP, Parameter->ip) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
37 GetCtrlVal (panel, CONTROL_DDS_PORT, &(Parameter->Port)) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
38 GetCtrlVal (panel, CONTROL_DDS_CLOCK, &(Parameter->Clock)) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
39 GetCtrlVal (panel, CONTROL_DDS_RATE, &(Parameter->SweepRate)) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
40 GetCtrlVal (panel, CONTROL_DDS_DELTA_T, &(Parameter->Delta_T)) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
41 return(Parameter);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
42 }*/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
43
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
44
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
45 #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
46
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
47 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
48 {
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
49 va_list args;
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
50 va_start(args, line);
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
51 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
52 vfprintf(stderr, frmt, args);
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
53 fprintf(stderr, "\n");
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
54 va_end(args);
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
55 }
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
56
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
57
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
58 void DDS_Initialize (DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
59 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
60 //send NOP command
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
61 sprintf(Request,"set;%i;%i",1,CMD_NOP);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
62 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
63 //reset the DDS
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
64 DDSFox_Reset(Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
65
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
66 //Set Profile Number 0 (only one used for soft frequecy sweep)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
67 // sprintf(Request,"set;%i;%i;%i",1,CMD_PROFILE,0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
68 // SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
69
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
70 //Set Profile Number 7 (only one used for soft frequecy sweep)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
71 sprintf(Request,"set;%i;%i;%i",1,CMD_PROFILE,7);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
72 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
73
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
74
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
75 //Set Clock Divider to 00b (which means 1)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
76 DDSFox_SetDiv(Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
77 //Set sweep rate at 0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
78 DDSFox_SetFreqMax (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
79 DDSFox_SetFreq (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
80 DDSFox_SetDT (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
81 DDSFox_SetDf (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
82 DDSFox_StartSweep (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
83 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
84 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
85
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
86 void DDS_ReInitialize (DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
87 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
88 //send NOP command
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
89 sprintf(Request,"set;%i;%i",1,CMD_NOP);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
90 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
91 //reset the DDS
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
92 //DDSFox_Reset(Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
93
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
94 //Set Profile Number 0 (only one used for soft frequecy sweep)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
95 // sprintf(Request,"set;%i;%i;%i",1,CMD_PROFILE,0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
96 // SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
97
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
98 //Set Profile Number 7 (only one used for soft frequecy sweep)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
99 sprintf(Request,"set;%i;%i;%i",1,CMD_PROFILE,7);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
100 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
101
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
102
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
103 //Set Clock Divider to 00b (which means 1)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
104 DDSFox_SetDiv(Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
105 //Set sweep rate at 0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
106 DDSFox_SetFreqMax (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
107 DDSFox_SetFreq (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
108 DDSFox_SetDT (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
109 DDSFox_SetDf (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
110 DDSFox_StartSweep (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
111 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
112 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
113
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
114
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
115 void DDSFox_Reset(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
116 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
117 sprintf(Request,"set;%i;%i",1,CMD_NOP);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
118 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
119 sprintf(Request,"set;%i;%i",1,CMD_RESET_DDS);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
120 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
121 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
122 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
123
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
124
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
125 void DDSFox_StopSweep(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
126 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
127 sprintf(Request,"set;%i;%i;%i",1,CMD_STOP_SWEEP,1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
128 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
129 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
130 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
131
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
132
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
133 void DDSFox_StartSweep(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
134 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
135 sprintf(Request,"set;%i;%i;%i",1,CMD_START_SWEEP,1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
136 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
137 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
138 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
139
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
140 void DDSFox_SetFreqMax (DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
141 double word ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
142 unsigned char octets[6];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
143 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
144 convert_double_6char(pow(2,48)/2,octets); // borne sup : clock / 2
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
145 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_SUP,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
146 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
147 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
148 DDSFox_SetSweepSign (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
149 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
150 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
151
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
152 void DDSFox_SetFreqMin (DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
153 double word ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
154 unsigned char octets[6];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
155 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
156 convert_double_6char(1,octets); // borne inf : ~0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
157 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_INF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
158 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
159 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
160 DDSFox_SetSweepSign (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
161 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
162 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
163
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
164 void DDSFox_SetFreq (DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
165 double word ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
166 unsigned char octets[6];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
167 int SweepSign = -1 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
168 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
169 if (Param->Profil == 0) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
170 word = pow(2,48)*(Param->Frequency/Param->Clock);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
171 convert_double_6char(word, octets); // borne inf : la freq voulu
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
172 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_INF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
173 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
174 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
175 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
176 else if(Param->Profil == 7) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
177 SweepSign = DDSFox_GetSweepSign(Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
178 if(SweepSign == 0){ // sweep positif
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
179 word = pow(2,48)*(Param->Frequency/Param->Clock);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
180 convert_double_6char(word, octets); // borne inf : la freq voulu
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
181 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_INF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
182 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
183 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
184 DDSFox_SetFreqMax (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
185 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
186 else { // sweep neg
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
187 word = pow(2,48)*(Param->Frequency/Param->Clock);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
188 convert_double_6char(word, octets); // borne sup : la freq voulue
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
189 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_SUP,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
190 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
191 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
192 DDSFox_SetFreqMin (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
193 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
194 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
195 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
196 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
197
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
198
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
199 // Change le signe de sweep en frequence. Argument: struct de param de la DDS
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
200 void DDSFox_SetSweepSign(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
201 char Request[255] ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
202 int SweepSign ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
203 SweepSign = DDSFox_GetSweepSign(Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
204 sprintf(Request,"set;%i;%i;%i",1,CMD_SWEEP_SIGN, SweepSign) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
205 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
206 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
207 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
208
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
209 /*void DDSFox_SetSweepSign(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
210 char Request[255] ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
211 int SweepSign ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
212 if (Param->Profil == 7)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
213 Param->Frequency = DDSFox_ReadFreq(Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
214 DDSFox_SetFreq (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
215 SweepSign = DDSFox_GetSweepSign(Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
216 sprintf(Request,"set;%i;%i;%i",1,CMD_SWEEP_SIGN, SweepSign) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
217 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
218 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
219 }*/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
220
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
221
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
222 // Change la valeur de la base pour 'lincrement de frequence (sweep). Argument: delta T x 10ms, retourne rien.
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
223 void DDSFox_SetDT(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
224 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
225 int dt= 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
226 char FTW0[255]="0"; /**** sinon le fichier inf.xx est faux ***/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
227 dt = ((Param->Delta_T)/BASE_TIME) - 1 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
228 sprintf(FTW0,"%ims",dt);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
229 sprintf(Request,"set;%i;%i;%i;%s",1,CMD_DT, dt ,FTW0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
230 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
231 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
232 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
233
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
234
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
235 // Change le facteur de division de la clock. Argument: facteur de div, retourne rien
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
236 void DDSFox_SetDiv(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
237 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
238 int Div = DIV ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
239 Command Rd;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
240 char temp;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
241 init_command(&Rd);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
242 sprintf(Request,"get;%i;%i",1,CMD_CONFIG_REG2);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
243 if (RecvCmd(&Rd, Request, Param) < 0)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
244 return;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
245 temp = atoi(Rd.value2) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
246 temp = temp & 0x9F ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
247 temp = temp | Div << 5 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
248 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i",1,CMD_CONFIG_REG2,atoi(Rd.value0),
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
249 atoi(Rd.value1),temp,atoi(Rd.value3),atoi(Rd.value4)) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
250 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
251 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
252 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
253
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
254
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
255
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
256 void DDSFox_SetDf(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
257 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
258 double word ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
259 unsigned char *octets;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
260 word = pow(2,48)*(fabs(Param->SweepRate)*Param->Delta_T/Param->Clock);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
261 octets=malloc(6*sizeof(unsigned char));
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
262 convert_double_6char(word, octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
263 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_DF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
264 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
265 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
266 free(octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
267 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
268 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
269
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
270 int DDSFox_GetSweepSign(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
271 if (Param->SweepRate >= 0) return(0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
272 else return(1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
273 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
274
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
275
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
276 double DDSFox_ReadFreq(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
277 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
278 unsigned int OctetA, OctetB, OctetC, OctetD, OctetE, OctetF ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
279 double FreqRead ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
280 int cmd[20];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
281 Command Rd;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
282 init_command(&Rd);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
283 sprintf(Request,"get;%i;%i",1,CMD_GET_FREQ);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
284 if (RecvCmd(&Rd, Request, Param) == -1)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
285 return -1.;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
286 OctetA=atoi(Rd.value0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
287 OctetB=atoi(Rd.value1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
288 OctetC=atoi(Rd.value2);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
289 OctetD=atoi(Rd.value3);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
290 OctetE=atoi(Rd.value4);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
291 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
292 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
293 FreqRead = FreqRead * Param->Clock / pow(2,48);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
294 return(FreqRead);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
295 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
296
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
297
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
298 /************************ Fonction de communications TCP ******************/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
299 static const double timeout = 0.5;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
300
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
301
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
302 int SendCmd(char *Buffer, DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
303 unsigned int hConv=0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
304 char Response[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
305 char parsebuf[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
306 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, 0) < 0) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
307 error("Connect failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
308 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
309 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
310 if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0) < 0) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
311 error("Write failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
312 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
313 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
314 sprintf(Response," ");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
315 if (ClientTCPRead (hConv, Response, 255, 0) < 0) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
316 error("Read failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
317 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
318 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
319 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
320 error("Response failed %s %s", Buffer, Response);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
321 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
322 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
323 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
324 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
325
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
326
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
327 int RecvCmd(Command *Rd, char * Buffer, DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
328 unsigned int hConv=0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
329 char parsebuf[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
330 char Response[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
331 if (ConnectToTCPServer (&hConv, Param->Port, Param->ip, OnTCPEvent, Response, 0) < 0) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
332 error("Connect failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
333 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
334 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
335 if (ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0) < 0) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
336 error("Write failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
337 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
338 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
339 sprintf(Response," ");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
340 if (ClientTCPRead (hConv, Response, 255, 0) < 0) {
13
e45d6e9544f5 Log file name and line number on error
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 3
diff changeset
341 error("Read failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
342 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
343 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
344
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
345 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
346 error("Response failed %s %s", Buffer, Response);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
347 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
348 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
349
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
350 sprintf(parsebuf,"%s",Response) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
351 parse_command(Rd, parsebuf) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
352 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
353 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
354
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
355
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
356 int OnTCPEvent(unsigned handle, int xType, int errCode, void *callbackData) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
357 //char* Response = (char*)(callbackData);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
358 //char Response[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
359 //switch(xType) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
360 // case TCP_DISCONNECT :
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
361 //printf("Server disconnected\n");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
362 // break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
363 // case TCP_DATAREADY :
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
364 //printf("Server data ready\n");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
365 //ClientTCPRead (handle, Response, 255, 5);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
366 // break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
367 //}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
368 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
369 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
370
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
371 /************************ Fonction de mise en forme des données pour le transfert ******************/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
372
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
373 void parse_command2(int* cmd, char* buf)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
374 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
375 char* pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
376 int c = 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
377
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
378 pointer = strtok( buf, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
379 while( pointer ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
380 if ((c > 2) && ( c < 19 ))
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
381 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
382 cmd[c-3] = atoi(pointer);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
383 printf("%i", cmd[c-3]);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
384 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
385
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
386
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
387 pointer = strtok( NULL, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
388 c++;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
389 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
390 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
391
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
392
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
393 int parse_command(Command *cmd1, char *buf){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
394 char* pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
395 int c = 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
396
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
397 pointer = strtok( buf, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
398 while( pointer ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
399 if( c == 0 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
400 cmd1->action = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
401 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
402 else if( c == 1 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
403 cmd1->canal = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
404 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
405 else if( c == 2 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
406 cmd1->command = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
407 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
408 else if( c == 3 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
409 cmd1->value0 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
410 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
411 else if( c == 4 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
412 cmd1->value1 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
413 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
414 else if( c == 5 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
415 cmd1->value2 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
416 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
417 else if( c == 6 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
418 cmd1->value3 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
419 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
420 else if( c == 7 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
421 cmd1->value4 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
422 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
423 else if( c == 8 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
424 cmd1->value5 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
425 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
426 else if( c == 9 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
427 cmd1->value6 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
428 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
429 else if( c == 10 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
430 cmd1->value7 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
431 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
432 pointer = strtok( NULL, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
433 c++;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
434 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
435 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
436 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
437
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
438
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
439 int init_command(Command *cmd1){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
440 cmd1->action = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
441 cmd1->canal = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
442 cmd1->command = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
443 cmd1->value0 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
444 cmd1->value1 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
445 cmd1->value2 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
446 cmd1->value3 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
447 cmd1->value4 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
448 cmd1->value5 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
449 cmd1->value6 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
450 cmd1->value7 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
451 cmd1->value8 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
452 cmd1->value9 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
453 cmd1->value10 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
454 cmd1->value11 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
455 cmd1->value12 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
456 cmd1->value13 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
457 cmd1->value14 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
458 cmd1->value15 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
459 cmd1->value16 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
460 cmd1->value17 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
461 cmd1->value18 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
462 cmd1->value19 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
463 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
464 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
465
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
466
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
467 //Convert double into 6 bytes sent back by an unsigned char pointer
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
468 int convert_double_6char (double fraction, unsigned char* octets) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
469 double bita, bitb, bitc, bitd, bite, bitf;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
470 bitf= fraction/(1099511627776.0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
471 *(octets+5)=(unsigned char)bitf;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
472 bite= (fraction-1099511627776.0*(*(octets+5)))/(4294967296.0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
473 *(octets+4)=(unsigned char)bite;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
474 bitd=(fraction-1099511627776.0*(*(octets+5))- 4294967296.0*(*(octets+4)))/( 16777216.0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
475 *(octets+3)=(unsigned char)bitd;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
476 bitc=(fraction-1099511627776.0*(*(octets+5))- 4294967296.0*(*(octets+4))-16777216.0*(*(octets+3)))/( 65536.0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
477 *(octets+2)=(unsigned char)bitc;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
478 bitb= (fraction-1099511627776.0*(*(octets+5))- 4294967296.0*(*(octets+4))-16777216.0*(*(octets+3))-65536*(*(octets+2)))/ 256.0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
479 *(octets+1)=(unsigned char)bitb;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
480 bita= (fraction-1099511627776.0*(*(octets+5))- 4294967296.0*(*(octets+4))-16777216.0*(*(octets+3))-65536*(*(octets+2))-256.0*(*(octets+1)))/ 1.0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
481 *(octets)=(unsigned char)bita;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
482 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
483 }