Mercurial > hg > fxanalyse
comparison DDS4xAD9912.c @ 0:d9aae7d7f2c6
Import
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Tue, 03 Jul 2012 10:38:59 +0200 |
parents | |
children | 0e9f95525a8f |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d9aae7d7f2c6 |
---|---|
1 #include <utility.h> | |
2 | |
3 //============================================================================== | |
4 // | |
5 // Title: DDS4xAD9912.c | |
6 // Purpose: | |
7 // | |
8 // Created on: by Volodimer Laurent, modified by YLC | |
9 // Copyright: syrte. All Rights Reserved. | |
10 // | |
11 //============================================================================== | |
12 | |
13 //============================================================================== | |
14 // Include files | |
15 | |
16 #include "DDS4xAD9912.h" | |
17 #include <userint.h> | |
18 #include <tcpsupp.h> | |
19 #include <ansi_c.h> | |
20 | |
21 //============================================================================== | |
22 // Global functions | |
23 | |
24 static int OnTCPEvent(unsigned handle, int xType, int errCode, void *callbackData) | |
25 { | |
26 switch(xType) | |
27 { | |
28 case TCP_DISCONNECT : | |
29 break; | |
30 case TCP_DATAREADY : | |
31 ClientTCPRead (handle, Response, sizeof(Response), 0); | |
32 break; | |
33 } | |
34 return 0; | |
35 } | |
36 | |
37 | |
38 //============================================================================== | |
39 // DDS4xAD9912_SendCmd | |
40 // | |
41 // FUNC : envoie une chaine de caracteres sur un port du serveur TCP/IP de la foxboard | |
42 // PARAM : DDSNum contient le numero de la DDS (1,2,3 ou 4) | |
43 // PARAM : Buffer contenant la chaîne de caractères à envoyer | |
44 // RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK | |
45 //============================================================================== | |
46 | |
47 | |
48 static int DDS4xAD9912_SendCmd(int DDSNum, char * Buffer) // essentially a private function | |
49 { | |
50 int res_1,res_2; | |
51 | |
52 switch(DDSNum) | |
53 { | |
54 case 1: | |
55 res_1=ConnectToTCPServer (&hConv, Port1, Adress, OnTCPEvent, 0, 0); | |
56 if(res_1 <0) MessagePopup("DDS4xAD9912_1 Serveur", "Connection to server failed !"); | |
57 break; | |
58 case 2: | |
59 res_1=ConnectToTCPServer (&hConv, Port2, Adress, OnTCPEvent, 0, 0); | |
60 if(res_1 <0) MessagePopup("DDS4xAD9912_2 Serveur", "Connection to server failed !"); | |
61 break; | |
62 | |
63 case 3: | |
64 res_1=ConnectToTCPServer (&hConv, Port3, Adress, OnTCPEvent, 0, 0); | |
65 if(res_1 <0) MessagePopup("DDS4xAD9912_3 Serveur", "Connection to server failed !"); | |
66 break; | |
67 | |
68 case 4: | |
69 res_1=ConnectToTCPServer (&hConv, Port4, Adress, OnTCPEvent, 0, 0); | |
70 if(res_1 <0) MessagePopup("DDS4xAD9912_4 Serveur", "Connection to server failed !"); | |
71 break; | |
72 | |
73 } | |
74 | |
75 res_2=ClientTCPWrite (hConv, Buffer, strlen(Buffer)+1, 0); | |
76 if(res_2 <0) MessagePopup("DDS Serveur", "Write to server failed !"); | |
77 DisconnectFromTCPServer (hConv); | |
78 return (res_1+res_2) ; | |
79 } | |
80 | |
81 | |
82 //============================================================================== | |
83 // DDS4xAD9912_Reset | |
84 // | |
85 // FUNC : reset des 4 DDS | |
86 // PARAM : | |
87 // RETURN : 0 si le reset de la DDS 1 , DDS 2, DDS3 et DDS4 est OK | |
88 //============================================================================== | |
89 | |
90 int DDS4xAD9912_Reset(DDS4xAD9912_Data * Instance) | |
91 { | |
92 int res_1,res_2; | |
93 | |
94 sprintf(Request,"set;%i;%i",1,17); | |
95 res_1 = DDS4xAD9912_SendCmd(1,Request) ; | |
96 if(res_1 <0) { | |
97 MessagePopup("DDS Serveur", "DDS4xAD9912_1 Reset failed !") ; | |
98 } | |
99 else Instance->Frequency1 = 0.0 ; | |
100 | |
101 sprintf(Request,"set;%i;%i",1,17); | |
102 res_2 = DDS4xAD9912_SendCmd(2,Request) ; | |
103 if(res_2 <0) { | |
104 MessagePopup("DDS Serveur", "DDS4xAD9912_2 Reset failed !") ; | |
105 } | |
106 else Instance->Frequency2 = 0.0; | |
107 | |
108 sprintf(Request,"set;%i;%i",1,17); | |
109 res_2 = DDS4xAD9912_SendCmd(3,Request) ; | |
110 if(res_2 <0) { | |
111 MessagePopup("DDS Serveur", "DDS4xAD9912_3 Reset failed !") ; | |
112 } | |
113 else Instance->Frequency3 = 0.0; | |
114 | |
115 sprintf(Request,"set;%i;%i",1,17); | |
116 res_2 = DDS4xAD9912_SendCmd(4,Request) ; | |
117 if(res_2 <0) { | |
118 MessagePopup("DDS Serveur", "DDS4xAD9912_4 Reset failed !") ; | |
119 } | |
120 else Instance->Frequency4 = 0.0; | |
121 | |
122 | |
123 return (res_1+res_2); | |
124 } | |
125 | |
126 | |
127 //============================================================================== | |
128 // DDS4xAD9912_SetFreq | |
129 // | |
130 // FUNC : sort une fréquence sur la DDS1 ,DDS2, DDS3 ou DDS4 | |
131 // PARAM : DDSNum contient le numero de la DDS (1, 2 , 3 ou 4) | |
132 // RETURN : 0 si la connexion et l'ecriture sur le serveur TCP/IP sont OK | |
133 //============================================================================== | |
134 int DDS4xAD9912_SetFrequency(DDS4xAD9912_Data * Instance, int DDSNum, double Freq) | |
135 { | |
136 | |
137 double Word=WORD(Freq,Clk) ; | |
138 double reste ; | |
139 int res_0 ; | |
140 unsigned char b5,b4,b3,b2,b1,b0 ; | |
141 | |
142 b5=(unsigned char)(Word/E40); | |
143 b4=(unsigned char)((Word - E40*b5)/E32); | |
144 b3=(unsigned char)((Word - E40*b5 - E32*b4)/E24); | |
145 b2=(unsigned char)((Word - E40*b5 - E32*b4 - E24*b3)/E16); | |
146 b1=(unsigned char)((Word - E40*b5 - E32*b4 - E24*b3 - E16*b2)/E8); | |
147 b0=(unsigned char)((Word - E40*b5 - E32*b4 - E24*b3 - E16*b2 - E8*b1)/1.0); | |
148 reste = (Word - E40*b5 -E32*b4 -E24*b3 -E16*b2 -E8*b1-1.0*b0) ; | |
149 | |
150 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",0,10,b5,b4,b3,b2,b1,b0); | |
151 res_0 = DDS4xAD9912_SendCmd(DDSNum, Request) ; | |
152 if (res_0 <0) { | |
153 MessagePopup("DDS Serveur", "SetFrequency function failed !") ; | |
154 } | |
155 else { | |
156 if (DDSNum==1) Instance->Frequency1 = Freq - reste*Clk/E48 ; | |
157 if (DDSNum==2) Instance->Frequency2 = Freq - reste*Clk/E48 ; | |
158 if (DDSNum==3) Instance->Frequency3 = Freq - reste*Clk/E48 ; | |
159 if (DDSNum==4) Instance->Frequency4 = Freq - reste*Clk/E48 ; | |
160 } ; | |
161 | |
162 sprintf(Request,"set;%i;%i",0,18); // IO_Update logiciel | |
163 res_0 = DDS4xAD9912_SendCmd(DDSNum, Request) ; | |
164 if (res_0 <0) { | |
165 MessagePopup("DDS Serveur", "IO_Update function failed !") ; | |
166 } | |
167 return(res_0) ; | |
168 | |
169 } | |
170 | |
171 | |
172 | |
173 int DDS4xAD9912_FrequencyRampe ( DDS4xAD9912_Data * Instance, int DDSNum, double Frequin,double Frequout, double Step ) | |
174 { | |
175 int i=0,imax=0; | |
176 double Frequactu=0; | |
177 time_t Time ; | |
178 double delaysecond=0.01; | |
179 | |
180 | |
181 if ( (Frequout - Frequin)>0) | |
182 { | |
183 if ((Frequout-Frequin) > Step) | |
184 { | |
185 imax= (Frequout-Frequin)/Step ; | |
186 for (i=0; i<imax;i++) | |
187 { | |
188 Delay(delaysecond); | |
189 Frequactu= Frequin+i*Step; | |
190 DDS4xAD9912_SetFrequency(Instance, DDSNum, Frequactu); | |
191 | |
192 } | |
193 } | |
194 } | |
195 | |
196 else | |
197 { | |
198 if ((Frequin-Frequout) > Step) | |
199 { | |
200 imax= (Frequin-Frequout)/Step ; | |
201 for (i=0; i<imax;i++) | |
202 { | |
203 Delay(delaysecond); | |
204 Frequactu= Frequin-i*Step; | |
205 DDS4xAD9912_SetFrequency(Instance, DDSNum, Frequactu); | |
206 } | |
207 } | |
208 | |
209 } | |
210 | |
211 DDS4xAD9912_SetFrequency(Instance, DDSNum, Frequout); | |
212 return(0); | |
213 | |
214 } | |
215 | |
216 /*Word=WORD(Frequactu,Clk); | |
217 b5=(unsigned char)(Word/E48); | |
218 b4=(unsigned char)((Word - E48*b5)/E32); | |
219 b3=(unsigned char)((Word - E48*b5 -E32*b4)/E24); | |
220 b2=(unsigned char)((Word - E48*b5 -E32*b4 -E24*b3)/E16); | |
221 b1=(unsigned char)((Word - E48*b5 -E32*b4 -E24*b3 -E16*b2)/E8); | |
222 b0=(unsigned char)((Word - E48*b5 -E32*b4 -E24*b3 -E16*b2 -E8*b1)/1.0); | |
223 reste = (Word - E48*b5 -E32*b4 -E24*b3 -E16*b2 -E8*b1-1.0*b0) ; | |
224 sprintf(Request,"set;%i;%i;%i;%i;%i;%i;%i;%i",0,10,b5,b4,b3,b2,b1,b0); | |
225 res_0 = DDS4xAD9912_SendCmd(DDSNum, Request) ; | |
226 if (DDSNum==1) Instance->Frequency1 = Frequactu - reste*Clk/E48 ; | |
227 if (DDSNum==2) Instance->Frequency2 = Frequactu - reste*Clk/E48 ; | |
228 if (DDSNum==3) Instance->Frequency3 = Frequactu - reste*Clk/E48 ; | |
229 if (DDSNum==4) Instance->Frequency4 = Frequactu - reste*Clk/E48 ; | |
230 sprintf(Request,"set;%i;%i",0,18); | |
231 res_0 = DDS4xAD9912_SendCmd(DDSNum, Request) ; */ | |
232 |