annotate DDS_Fox.c @ 63:2320f5fc66aa

Fix varargs handling in DDS Fox driver error function
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Mon, 29 Oct 2012 14:43:48 +0100
parents 7ab3fb870ef8
children 64a7a1d3d75c
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;
63
2320f5fc66aa Fix varargs handling in DDS Fox driver error function
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 50
diff changeset
50 va_start(args, frmt);
13
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 unsigned char octets[6];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
142 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
143 convert_double_6char(pow(2,48)/2,octets); // borne sup : clock / 2
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
144 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_SUP,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
145 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
146 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
147 DDSFox_SetSweepSign (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
148 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
149 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
150
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
151 void DDSFox_SetFreqMin (DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
152 unsigned char octets[6];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
153 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
154 convert_double_6char(1,octets); // borne inf : ~0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
155 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_INF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
156 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
157 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
158 DDSFox_SetSweepSign (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
159 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
160 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
161
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
162 void DDSFox_SetFreq (DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
163 double word ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
164 unsigned char octets[6];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
165 int SweepSign = -1 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
166 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
167 if (Param->Profil == 0) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
168 word = pow(2,48)*(Param->Frequency/Param->Clock);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
169 convert_double_6char(word, octets); // borne inf : la freq voulu
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
170 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_INF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
171 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
172 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
173 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
174 else if(Param->Profil == 7) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
175 SweepSign = DDSFox_GetSweepSign(Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
176 if(SweepSign == 0){ // sweep positif
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
177 word = pow(2,48)*(Param->Frequency/Param->Clock);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
178 convert_double_6char(word, octets); // borne inf : la freq voulu
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
179 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_INF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
180 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
181 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
182 DDSFox_SetFreqMax (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
183 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
184 else { // sweep neg
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
185 word = pow(2,48)*(Param->Frequency/Param->Clock);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
186 convert_double_6char(word, octets); // borne sup : la freq voulue
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
187 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_FREQ_SUP,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
188 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
189 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
190 DDSFox_SetFreqMin (Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
191 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
192 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
193 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
194 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
195
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
196
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
197 // Change le signe de sweep en frequence. Argument: struct de param de la DDS
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
198 void DDSFox_SetSweepSign(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
199 char Request[255] ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
200 int SweepSign ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
201 SweepSign = DDSFox_GetSweepSign(Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
202 sprintf(Request,"set;%i;%i;%i",1,CMD_SWEEP_SIGN, SweepSign) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
203 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
204 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
205 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
206
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
207 /*void DDSFox_SetSweepSign(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
208 char Request[255] ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
209 int SweepSign ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
210 if (Param->Profil == 7)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
211 Param->Frequency = DDSFox_ReadFreq(Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
212 DDSFox_SetFreq (Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
213 SweepSign = DDSFox_GetSweepSign(Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
214 sprintf(Request,"set;%i;%i;%i",1,CMD_SWEEP_SIGN, SweepSign) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
215 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
216 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
217 }*/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
218
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
219
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
220 // 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
221 void DDSFox_SetDT(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
222 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
223 int dt= 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
224 char FTW0[255]="0"; /**** sinon le fichier inf.xx est faux ***/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
225 dt = ((Param->Delta_T)/BASE_TIME) - 1 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
226 sprintf(FTW0,"%ims",dt);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
227 sprintf(Request,"set;%i;%i;%i;%s",1,CMD_DT, dt ,FTW0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
228 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
229 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
230 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
231
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
232
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
233 // Change le facteur de division de la clock. Argument: facteur de div, retourne rien
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
234 void DDSFox_SetDiv(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
235 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
236 int Div = DIV ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
237 Command Rd;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
238 char temp;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
239 init_command(&Rd);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
240 sprintf(Request,"get;%i;%i",1,CMD_CONFIG_REG2);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
241 if (RecvCmd(&Rd, Request, Param) < 0)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
242 return;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
243 temp = atoi(Rd.value2) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
244 temp = temp & 0x9F ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
245 temp = temp | Div << 5 ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
246 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
247 atoi(Rd.value1),temp,atoi(Rd.value3),atoi(Rd.value4)) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
248 SendCmd(Request, Param) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
249 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
250 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
251
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 void DDSFox_SetDf(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
255 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
256 double word ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
257 unsigned char *octets;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
258 word = pow(2,48)*(fabs(Param->SweepRate)*Param->Delta_T/Param->Clock);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
259 octets=malloc(6*sizeof(unsigned char));
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
260 convert_double_6char(word, octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
261 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",1,CMD_DF,
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
262 *(octets+5),*(octets+4),*(octets+3),*(octets+2),*(octets+1),*octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
263 SendCmd(Request, Param);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
264 free(octets);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
265 return ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
266 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
267
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
268 int DDSFox_GetSweepSign(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
269 if (Param->SweepRate >= 0) return(0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
270 else return(1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
271 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
272
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
273
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
274 double DDSFox_ReadFreq(DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
275 char Request[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
276 unsigned int OctetA, OctetB, OctetC, OctetD, OctetE, OctetF ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
277 double FreqRead ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
278 Command Rd;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
279 init_command(&Rd);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
280 sprintf(Request,"get;%i;%i",1,CMD_GET_FREQ);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
281 if (RecvCmd(&Rd, Request, Param) == -1)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
282 return -1.;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
283 OctetA=atoi(Rd.value0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
284 OctetB=atoi(Rd.value1);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
285 OctetC=atoi(Rd.value2);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
286 OctetD=atoi(Rd.value3);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
287 OctetE=atoi(Rd.value4);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
288 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
289 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
290 FreqRead = FreqRead * Param->Clock / pow(2,48);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
291 return(FreqRead);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
292 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
293
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
294
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
295 /************************ Fonction de communications TCP ******************/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
296 static const double timeout = 0.5;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
297
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
298
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
299 int SendCmd(char *Buffer, DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
300 unsigned int hConv=0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
301 char Response[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
302 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
303 error("Connect failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
304 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
305 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
306 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
307 error("Write 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 sprintf(Response," ");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
311 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
312 error("Read failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
313 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
314 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
315 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
316 error("Response failed %s %s", Buffer, Response);
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 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
320 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
321
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
322
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
323 int RecvCmd(Command *Rd, char * Buffer, DDSParameter *Param) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
324 unsigned int hConv=0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
325 char parsebuf[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
326 char Response[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
327 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
328 error("Connect failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
329 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
330 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
331 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
332 error("Write 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 sprintf(Response," ");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
336 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
337 error("Read failed");
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
338 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
339 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
340
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
341 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
342 error("Response failed %s %s", Buffer, Response);
0
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
343 return -1;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
344 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
345
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
346 sprintf(parsebuf,"%s",Response) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
347 parse_command(Rd, parsebuf) ;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
348 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
349 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
350
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
351
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
352 int OnTCPEvent(unsigned handle, int xType, int errCode, void *callbackData) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
353 //char* Response = (char*)(callbackData);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
354 //char Response[255];
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
355 //switch(xType) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
356 // case TCP_DISCONNECT :
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
357 //printf("Server disconnected\n");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
358 // break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
359 // case TCP_DATAREADY :
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
360 //printf("Server data ready\n");
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
361 //ClientTCPRead (handle, Response, 255, 5);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
362 // break;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
363 //}
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
364 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
365 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
366
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
367 /************************ Fonction de mise en forme des données pour le transfert ******************/
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
368
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
369 void parse_command2(int* cmd, char* buf)
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
370 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
371 char* pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
372 int c = 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
373
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
374 pointer = strtok( buf, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
375 while( pointer ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
376 if ((c > 2) && ( c < 19 ))
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
377 {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
378 cmd[c-3] = atoi(pointer);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
379 printf("%i", cmd[c-3]);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
380 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
381
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
382
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
383 pointer = strtok( NULL, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
384 c++;
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
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
388
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
389 int parse_command(Command *cmd1, char *buf){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
390 char* pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
391 int c = 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
392
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
393 pointer = strtok( buf, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
394 while( pointer ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
395 if( c == 0 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
396 cmd1->action = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
397 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
398 else if( c == 1 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
399 cmd1->canal = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
400 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
401 else if( c == 2 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
402 cmd1->command = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
403 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
404 else if( c == 3 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
405 cmd1->value0 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
406 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
407 else if( c == 4 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
408 cmd1->value1 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
409 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
410 else if( c == 5 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
411 cmd1->value2 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
412 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
413 else if( c == 6 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
414 cmd1->value3 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
415 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
416 else if( c == 7 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
417 cmd1->value4 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
418 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
419 else if( c == 8 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
420 cmd1->value5 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
421 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
422 else if( c == 9 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
423 cmd1->value6 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
424 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
425 else if( c == 10 ){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
426 cmd1->value7 = pointer;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
427 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
428 pointer = strtok( NULL, CMD_SEP );
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
429 c++;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
430 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
431 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
432 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
433
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
434
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
435 int init_command(Command *cmd1){
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
436 cmd1->action = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
437 cmd1->canal = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
438 cmd1->command = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
439 cmd1->value0 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
440 cmd1->value1 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
441 cmd1->value2 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
442 cmd1->value3 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
443 cmd1->value4 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
444 cmd1->value5 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
445 cmd1->value6 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
446 cmd1->value7 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
447 cmd1->value8 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
448 cmd1->value9 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
449 cmd1->value10 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
450 cmd1->value11 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
451 cmd1->value12 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
452 cmd1->value13 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
453 cmd1->value14 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
454 cmd1->value15 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
455 cmd1->value16 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
456 cmd1->value17 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
457 cmd1->value18 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
458 cmd1->value19 = NULL;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
459 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
460 }
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
461
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
462
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
463 //Convert double into 6 bytes sent back by an unsigned char pointer
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
464 int convert_double_6char (double fraction, unsigned char* octets) {
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
465 double bita, bitb, bitc, bitd, bite, bitf;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
466 bitf= fraction/(1099511627776.0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
467 *(octets+5)=(unsigned char)bitf;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
468 bite= (fraction-1099511627776.0*(*(octets+5)))/(4294967296.0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
469 *(octets+4)=(unsigned char)bite;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
470 bitd=(fraction-1099511627776.0*(*(octets+5))- 4294967296.0*(*(octets+4)))/( 16777216.0);
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
471 *(octets+3)=(unsigned char)bitd;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
472 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
473 *(octets+2)=(unsigned char)bitc;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
474 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
475 *(octets+1)=(unsigned char)bitb;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
476 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
477 *(octets)=(unsigned char)bita;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
478 return 0;
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
479 }