comparison FXAnalyse.c @ 0:d9aae7d7f2c6

Import
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Tue, 03 Jul 2012 10:38:59 +0200
parents
children a6fb5d3d0ec0
comparison
equal deleted inserted replaced
-1:000000000000 0:d9aae7d7f2c6
1 #include <utility.h>
2 #include <ansi_c.h>
3 #include <cvirte.h>
4 #include <userint.h>
5 #include <formatio.h>
6 #include <string.h>
7
8 #include "YLCStuff.h"
9 #include "FXAnalyse.h"
10 #include "Plot.h"
11 #include "Allan.h"
12 #include "DDSBes.h"
13 #include "DDS4xAD9912.h"
14 #include "DDS_Fox.h"
15 #include "muParserDLL.h"
16
17
18 #define FXLINELENGTH 123
19 #define DDSBESCLOCK (200.e6) // 200MHz de clock pour la DDS de Besancon...
20
21
22 #define LOGFILEPATH "C:\\Femto\\Software\\FXQE80"
23 #define FREP_NORMAL_FORMULA "(0-15M+DDS-Ch1/200)/12+2M/3"
24 #define NUOL_NORMAL_FORMULA "(N*250M-194400G)+N*Math1-8*DDS1"
25 #define NUHG_NORMAL_FORMULA "(N*250M-282143G)+N*Math1-(DDS1-Ch2)"
26 #define NUSR_NORMAL_FORMULA "(N*250M-429228G)+N*Math1+(DDS2-Ch3)"
27 #define NU813_NORMAL_FORMULA "(N*766M-368554G)+N*Math1+000.000M"
28 #define NU1064_NORMAL_FORMULA "(N*766M-281630G)+(DDS_1064-Ch4)"
29
30 #define FACTORDDSBES 36*(8/770000)
31
32 //==============================================================================
33 // Static global variables
34
35 /* multi threading stuff */ // to be used when I will replace timer by thread for counder readout
36 //static int ghPool;
37 //static volatile int vgExiting = 0;
38
39 /* panel handling stuff */
40 static PanelHandle MainPanel ;
41 static PanelHandle CalcN1Panel ;
42 static PanelHandle CalcN2Panel ;
43 static PanelHandle CalcN3Panel ;
44
45 //==============================================================================
46 // Static functions
47
48 //static int CVICALLBACK ReadCounterThread(void *functionData); // to be used when I will replace timer by thread for counder readout
49
50 //==============================================================================
51 // Global variables
52
53 char * LogFileName ;
54 char ExtraMathFileName[MAX_PATHNAME_LEN] ;
55
56 double utc = 0 ;
57 double mjd =0 ;
58
59 double Ch1, Ch2, Ch3, Ch4 ; // le type long double est identique au double (8 octets) sous CVI !!!
60 double Math1, Math2, Math3, Math4, Math5; // N est en fait un entier en pratique...
61 double N1, N2, N3,N4 ;
62
63 Plot_Data PlotCh1, PlotCh2, PlotCh3, PlotCh4, PlotMath1, PlotMath2, PlotMath3, PlotMath4, PlotMath5 ;
64 Allan_Data AllanCh1, AllanCh2, AllanCh3, AllanCh4, AllanMath1, AllanMath2, AllanMath3, AllanMath4, AllanMath5 ;
65
66 DDSBes_Data DDSBes ;
67 DDS4xAD9912_Data DDS4xAD9912 ;
68
69 muParserHandle_t MathParser1, MathParser2, MathParser3, MathParser4, MathParser5 ;
70
71 volatile bool Acquiring = FALSE ;
72
73 long OldLogFilePtr = 0 ;
74
75 double NuOpt=0.0;
76 double Ndiv=8.0;
77
78 ///////////////////
79 //Pour les calculs des N
80
81 volatile bool Measuring_1 = FALSE,Step1_1 = FALSE,Step2_1 = FALSE,Step3_1 = FALSE, Measuring_2 = FALSE,Step1_2 = FALSE,Step2_2 = FALSE,Step3_2 = FALSE;
82 volatile bool Measuring_3 = FALSE,Step1_3 = FALSE,Step2_3 = FALSE,Step3_3 = FALSE;
83 volatile bool TimetoBegin=FALSE;
84
85 double FrequDDS1=110000000.0,FrequDDS2=15300000.0,FrequDDS3=150400000.000000;
86 double Slope_1=0.0,Slope_2=0.0,Slope_3=0.0,Beatslope_2=0.0;
87 double SlopeTime1=60.0,SlopeTime2=60.0;
88
89 double N_1=0.0,N_2=0.0,N_3=0.0;
90 double DeltaT_1=8.0,DeltakHz_1=1800.0,t1_1=0.0,t2_1=0.0,t3_1=0.0, Frepplus_1=0.0, Frepminus_1=0.0;
91 double DeltaT_2=8.0,DeltakHz_2=1500.0,t1_2=0.0,t2_2=0.0,t3_2=0.0, Frepplus_2=0.0, Frepminus_2=0.0;
92 double DeltaT_3=20.0,DeltakHz_3=100.0,t1_3=0.0,t2_3=0.0,t3_3=0.0, Frepplus_3=0.0, Frepminus_3=0.0;
93
94
95 int DeltaTMoy_1=3,n_1=0,DeltaTMoy_2=3,n_2=0,DeltaTMoy_3=3,n_3=0;
96 double Tmoy_1_1=0.0,Tmoy_2_1=0.0,Tmoy_1_2=0.0,Tmoy_2_2=0.0,Tmoy_1_3=0.0,Tmoy_2_3=0.0;
97 double Frequ_slope_1=0.0,Moy_slope_1=0.0,Slope_slope_1=0.0,Frequ_slope_2=0.0,Moy_slope_2=0.0,Slope_slope_2=0.0,Frequ_slope_3=0.0,Moy_slope_3=0.0,Slope_slope_3=0.0;
98 int N_slope_1=0,N_slope_2=0,N_slope_3=0;
99 double Beat_slope_2=0.0 ,Moy_Beatslope_2=0.0,Slope_Beatslope_2=0.0;
100 double Ch4_slope=0.0,Moy_Ch4slope_1=0.0,Slope_Ch4slope_1=0.0,Ch4Slope=0.0;
101
102 double FrequencyDDSBes=0.0,FrequencyDDSBesInit=0.0;
103 double FrequencyDDS3=0.0,FrequencyDDS3Init=0.0;
104 double DeltaFrep275=0.0,DeltaFrep10=0.0; ;
105 double DDSBesChanged1=FALSE,DDSBesChanged2=FALSE;
106
107 double DeltaDDS3=0.0,Delta10K_Plus=0.0,Delta10K_Minus=0.0;
108 double Nu1=0.0, Nu2= 200000-147000+282143746.557455e6;
109
110 double Step1=800000.0,Step2=800000.0;
111
112 double Ch4Plus=0.0,Ch4Minus=0.0;
113
114 int NDEJAPASSE=0, nDDSChange=0, nstabilization=0 ;
115
116 //////
117 //Pour les signes de fb
118
119 double Frequencystep1=10000.0,tbegin1=0.0,Frepbefore1=0.0,Frequency1=0.0,Frequencystep2=10.0,tbegin2=0.0,Frepbefore2=0.0,Ch2before=0.0,Frequency2=0.0,Frequencystep3=100000.0,tbegin3=0.0,Frepbefore3=0.0,Frequency3=0.0;
120 volatile bool Getsign1=FALSE,Getsign2=FALSE,Getsign3=FALSE;
121 double Signe1=1.0,Signe2=1.0,Signe3=0.0;
122
123
124
125
126
127 /////////////////////////
128 // Slope Cancelling Variables
129
130 volatile bool SlopeMeasuring=FALSE;
131 volatile bool AutoStopSlopeCancellingIfDelock=TRUE;
132 volatile bool OnSlopeCancelling =FALSE;
133 double SlopeMath2=0.0;
134 double TimetoSlope=60.0;
135 double SlopeMeasuringTimeBegin=0.0;
136 char * OnOffMessage="OFF" ;
137
138 char DDSFoxName[255] = "DDS Fox Control" ;
139 double DDSFoxClock=200000000;
140 int DDSFoxSweepSign=0;
141 double DDSFoxFrequency=70000000.0;
142 char DDSFoxip[255]="145.238.205.58";
143 int DDSFoxPort=6665 ;
144 unsigned int DDSFoxProfil=7;
145 double DDSFoxSweeprate=0.0;// numéro de profil de la DDS : single freq=0, sweep=7 ;
146 double DDSFoxDeltaT=0.01;
147
148 double Slope_Math2slope=0.0,Math2_slope=0.0,Moy_Math2slope=0.0;
149 int N_Math2slope=0.0,nstabilisationSlopeMeasuring=0;
150
151 double LimitToDelock=5.0;
152 double SlopeCorrection=0.0;
153
154 int ratio=10; //Recentre la frequence tous les ratios
155
156 volatile bool FrequCorrec=FALSE,KeepFrequ=TRUE, KeepSlope=TRUE ;
157 int Nratio=-1;
158 double MoyMath2=0.0,CenterFrequencyCh2=0.0;
159 volatile bool CenterFrequencyCh2ToDetermine=FALSE;
160
161 double limitotakoff=70.0;
162
163
164
165
166 //////////////////////////////////
167 // Keep Centered Variables
168
169 volatile bool KeepCentering=FALSE;
170 double Timetorecenter275K=3600.0*10;
171 double Timetorecenter10K=3600.0*3;
172 double CenteringTimeBegin275K=0.0;
173 double CenteringTimeBegin10K=0.0;
174
175
176
177 //==============================================================================
178 // Functions
179 int LaunchDDSFOX (char *Name,char *ip,int Port,unsigned int Profil,double Clock,double DeltaT,double Frequency,double Sweeprate,int mode) ;
180 double ReadDDSFOX (char *Name,char *ip,int Port,unsigned int Profil,double Clock,double DeltaT,double Frequency,double Sweeprate) ;
181
182
183
184
185
186 void initMathParser(muParserHandle_t * pMathParser)
187 {
188 (* pMathParser) = mupCreate() ; // Math parser number 1, normally used for frep
189 mupDefineOprtChars( * pMathParser, "abcdefghijklmnopqrstuvwxyzµ"
190 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
191 "+-*^/?<>=#!$%&|~'_");
192 mupDefineVar( * pMathParser, "UTC", &utc);
193 mupDefineVar( * pMathParser, "MJD", &mjd);
194 mupDefineVar( * pMathParser, "Ch1", &Ch1);
195 mupDefineVar( * pMathParser, "Ch2", &Ch2);
196 mupDefineVar( * pMathParser, "Ch3", &Ch3);
197 mupDefineVar( * pMathParser, "Ch4", &Ch4);
198 mupDefineVar( * pMathParser, "DDS_Frep", &(DDSBes.Frequency));
199 mupDefineVar( * pMathParser, "DDS1", &(DDS4xAD9912.Frequency1));
200 mupDefineVar( * pMathParser, "DDS2", &(DDS4xAD9912.Frequency2));
201 mupDefineVar( * pMathParser, "DDS3", &(DDS4xAD9912.Frequency3));
202 mupDefineVar( * pMathParser, "DDS4", &(DDS4xAD9912.Frequency4));
203 mupDefineVar( * pMathParser, "N1", &N1);
204 mupDefineVar( * pMathParser, "N2", &N2);
205 mupDefineVar( * pMathParser, "N3", &N3);
206 mupDefineVar( * pMathParser, "Nu1", &Nu1);
207 mupDefineVar( * pMathParser, "Nu2", &Nu2);
208 mupDefineVar( * pMathParser, "DeltaDDS3", &DeltaDDS3);
209 mupDefineVar( * pMathParser, "Signe1", &Signe1);
210 mupDefineVar( * pMathParser, "Signe2", &Signe2);
211 mupDefineVar( * pMathParser, "Ndiv", &Ndiv);
212 mupDefinePostfixOprt( * pMathParser, "P", &Peta , 1);
213 mupDefinePostfixOprt( * pMathParser, "T", &Tera , 1);
214 mupDefinePostfixOprt( * pMathParser, "G", &Giga , 1);
215 mupDefinePostfixOprt( * pMathParser, "M", &Mega , 1);
216 mupDefinePostfixOprt( * pMathParser, "k", &kilo , 1);
217 mupDefinePostfixOprt( * pMathParser, "m", &milli, 1);
218 mupDefinePostfixOprt( * pMathParser, "u", &micro, 1);
219 mupDefinePostfixOprt( * pMathParser, "µ", &micro, 1);
220 mupDefinePostfixOprt( * pMathParser, "n_1", &nano, 1);
221 mupDefinePostfixOprt( * pMathParser, "p", &pico, 1);
222 mupDefinePostfixOprt( * pMathParser, "f", &femto, 1);
223 }
224
225 int main (int argc, char *argv[])
226 {
227 //int ThreadId ; // to be used when I will replace timer by thread for counder readout
228
229 char FileNamePrototype[MAX_PATHNAME_LEN] ;
230 double initfreqDDS ;
231 char * MathString1 = " " ;
232 char * MathString2 = " " ;
233 char * MathString3 = " " ;
234 char * MathString4 = " " ;
235 char * MathString5 = " " ;
236
237 if (InitCVIRTE (0, argv, 0) == 0)
238 return -1; /* out of memory */
239 if ((MainPanel = LoadPanel (0, "FXAnalyse.uir", PANEL)) < 0)
240 return -1;
241 if ((CalcN1Panel = LoadPanel (0, "FXAnalyse.uir", CALCN1)) < 0)
242 return -1;
243 if ((CalcN2Panel = LoadPanel (0, "FXAnalyse.uir", CALCN2)) < 0)
244 return -1;
245 if ((CalcN3Panel = LoadPanel (0, "FXAnalyse.uir", CALCN3)) < 0)
246 return -1;
247 SetPanelAttribute(MainPanel, ATTR_TITLE, "Femto Soft") ;
248
249 DisplayPanel (MainPanel);
250
251 // Initialize LogFileName pointer
252
253 LogFileName = FileNamePrototype ;
254
255 // Initialyze the DDS Besancon Output
256
257 DDSBes_Initialize(&DDSBes) ;
258 DDSBes_SetClockFrequency(&DDSBes, DDSBESCLOCK) ; // Peut etre passer tout ca dans DDSBes-Initialize ?
259 DDSBes_SetAmplitude(&DDSBes, 4095) ;
260 GetCtrlVal(MainPanel, PANEL_DDSFREPOUT,&initfreqDDS) ;
261 DDSBes_SetFrequency(&DDSBes, initfreqDDS) ;
262
263 // Initialize the quadruple AD9959 DDS (Fox board interface)
264
265 DDS4xAD9912_Reset(&DDS4xAD9912) ;
266 GetCtrlVal(MainPanel, PANEL_DDS1, &initfreqDDS) ;
267 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, initfreqDDS) ;
268 GetCtrlVal(MainPanel, PANEL_DDS2, &initfreqDDS) ;
269 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, initfreqDDS) ;
270 GetCtrlVal(MainPanel, PANEL_DDS3, &initfreqDDS) ;
271 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, initfreqDDS) ;
272 GetCtrlVal(MainPanel, PANEL_DDS4, &initfreqDDS) ;
273 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, initfreqDDS) ;
274
275
276 // Initialyze the DDSFOX Output
277 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate,1);
278
279 // Initialize the 5 (separate) math parsers for frep, Nu_Hg, Nu_Sr, N3 and ExtraMath
280
281 Ch1=0.0 ; Ch2=0.0 ; Ch3=0.0 ; Ch4=0.0 ;
282 GetCtrlVal(MainPanel, PANEL_N1CHOICE, &N1) ;
283 GetCtrlVal(MainPanel, PANEL_N2CHOICE, &N2) ;
284
285 GetCtrlVal(MainPanel, PANEL_N3CHOICE, &N3) ;
286
287 initMathParser(&MathParser1) ;
288 mupDefineVar(MathParser1, "DDS", &(DDSBes.Frequency));
289 GetCtrlVal(MainPanel, PANEL_MATHSTRING1, MathString1) ;
290 mupSetExpr(MathParser1, MathString1);
291
292 initMathParser(&MathParser2) ;
293 mupDefineVar( MathParser2, "Math1", &Math1);
294 mupDefineVar( MathParser2, "DDS", &(DDS4xAD9912.Frequency1));
295 GetCtrlVal(MainPanel, PANEL_MATHSTRING2, MathString2) ;
296 mupSetExpr(MathParser2, MathString2);
297
298 initMathParser(&MathParser3) ;
299 mupDefineVar( MathParser3, "Math1", &Math1);
300 mupDefineVar( MathParser3, "Math2", &Math2);
301 mupDefineVar( MathParser3, "DDS", &(DDS4xAD9912.Frequency2));
302 GetCtrlVal(MainPanel, PANEL_MATHSTRING3, MathString3) ;
303 mupSetExpr(MathParser3, MathString3);
304
305 initMathParser(&MathParser4) ;
306 mupDefineVar( MathParser4, "Math1", &Math1);
307 mupDefineVar( MathParser4, "Math2", &Math2);
308 mupDefineVar( MathParser4, "Math3", &Math3);
309 GetCtrlVal(MainPanel, PANEL_MATHSTRING4, MathString4) ;
310 mupSetExpr(MathParser4, MathString4);
311
312 initMathParser(&MathParser5) ;
313 mupDefineVar( MathParser5, "Math1", &Math1);
314 mupDefineVar( MathParser5, "Math2", &Math2);
315 mupDefineVar( MathParser5, "Math3", &Math3);
316 mupDefineVar( MathParser5, "Math4", &Math4);
317 GetCtrlVal(MainPanel, PANEL_MATHSTRING5, MathString5) ;
318 mupSetExpr(MathParser5, MathString5);
319
320
321 RunUserInterface ();
322
323 // Stops everything at the end
324
325 DiscardPanel (MainPanel);
326 return 0;
327 }
328
329
330 void OnCloseViewPanel(int panel){
331
332 if (panel==PlotCh1.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ1PLOT, FALSE) ; } ;
333 if (panel==PlotCh2.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ2PLOT, FALSE) ; } ;
334 if (panel==PlotCh3.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ3PLOT, FALSE) ; } ;
335 if (panel==PlotCh4.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ4PLOT, FALSE) ; } ;
336 if (panel==PlotMath1.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH1PLOT, FALSE) ; } ;
337 if (panel==PlotMath2.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH2PLOT, FALSE) ; } ;
338 if (panel==PlotMath3.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH3PLOT, FALSE) ; } ;
339 if (panel==PlotMath4.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH4PLOT, FALSE) ; } ;
340 if (panel==PlotMath5.PlotPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH5PLOT, FALSE) ; } ;
341
342 if (panel==AllanCh1.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ1ALLAN, FALSE) ; } ;
343 if (panel==AllanCh2.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ2ALLAN, FALSE) ; } ;
344 if (panel==AllanCh3.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ3ALLAN, FALSE) ; } ;
345 if (panel==AllanCh4.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_FREQ4ALLAN, FALSE) ; } ;
346 if (panel==AllanMath1.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH1ALLAN, FALSE) ; } ;
347 if (panel==AllanMath2.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH2ALLAN, FALSE) ; } ;
348 if (panel==AllanMath3.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH3ALLAN, FALSE) ; } ;
349 if (panel==AllanMath4.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH4ALLAN, FALSE) ; } ;
350 if (panel==AllanMath5.AllanPanel) { SetCtrlVal(MainPanel,PANEL_CHECKBOX_MATH5ALLAN, FALSE) ; } ;
351
352 return ;
353 }
354
355
356
357
358
359 int CVICALLBACK QuitCallback (int panel, int control, int event,
360 void *callbackData, int eventData1, int eventData2)
361 {
362 switch (event)
363 {
364 case EVENT_COMMIT:
365 QuitUserInterface (0);
366 DDSBes_Close(&DDSBes);
367 mupRelease(MathParser1);
368 mupRelease(MathParser2);
369 mupRelease(MathParser3);
370 mupRelease(MathParser4);
371 mupRelease(MathParser5);
372 break;
373 case EVENT_RIGHT_CLICK:
374
375 break;
376 }
377 return 0;
378 }
379
380 int CVICALLBACK CB_OnEventMain(int panel, int event, void *callbackData, int eventData1, int eventData2)
381 {
382 int VirtualKeyCode ;
383 int ActiveControl ;
384 int StepIndex ;
385 double Step ;
386
387 switch (event) {
388 case EVENT_CLOSE:
389 QuitUserInterface (0);
390 DDSBes_Close(&DDSBes);
391 mupRelease(MathParser1);
392 mupRelease(MathParser2);
393 mupRelease(MathParser3);
394 break;
395 case EVENT_KEYPRESS:
396 switch (eventData1) // ie the code of the key which has been stroke
397 {
398 case VAL_RIGHT_ARROW_VKEY :
399 ActiveControl = GetActiveCtrl(panel);
400 if (ActiveControl==PANEL_DDSFREPOUT || ActiveControl==PANEL_DDSFREPSTEP) {
401 GetCtrlIndex(MainPanel, PANEL_DDSFREPSTEP, &StepIndex);
402 if (StepIndex<14){
403 SetCtrlIndex(MainPanel, PANEL_DDSFREPSTEP, ++StepIndex) ;
404 GetCtrlVal(MainPanel, PANEL_DDSFREPSTEP, &Step);
405 SetCtrlAttribute(MainPanel, PANEL_DDSFREPOUT, ATTR_INCR_VALUE, Step) ;
406 };
407 };
408 if (ActiveControl==PANEL_DDS1 || ActiveControl==PANEL_DDS1STEP) {
409 GetCtrlIndex(MainPanel, PANEL_DDS1STEP, &StepIndex);
410 if (StepIndex<14){
411 SetCtrlIndex(MainPanel, PANEL_DDS1STEP, ++StepIndex) ;
412 GetCtrlVal(MainPanel, PANEL_DDS1STEP, &Step);
413 SetCtrlAttribute(MainPanel, PANEL_DDS1, ATTR_INCR_VALUE, Step) ;
414 };
415 };
416 if (ActiveControl==PANEL_DDS2 || ActiveControl==PANEL_DDS2STEP) {
417 GetCtrlIndex(MainPanel, PANEL_DDS2STEP, &StepIndex);
418 if (StepIndex<14){
419 SetCtrlIndex(MainPanel, PANEL_DDS2STEP, ++StepIndex) ;
420 GetCtrlVal(MainPanel, PANEL_DDS2STEP, &Step);
421 SetCtrlAttribute(MainPanel, PANEL_DDS2, ATTR_INCR_VALUE, Step) ;
422 };
423 };
424 if (ActiveControl==PANEL_DDS3|| ActiveControl==PANEL_DDS3STEP) {
425 GetCtrlIndex(MainPanel, PANEL_DDS3STEP, &StepIndex);
426 if (StepIndex<14){
427 SetCtrlIndex(MainPanel, PANEL_DDS3STEP, ++StepIndex) ;
428 GetCtrlVal(MainPanel, PANEL_DDS3STEP, &Step);
429 SetCtrlAttribute(MainPanel, PANEL_DDS3, ATTR_INCR_VALUE, Step) ;
430 };
431 };
432 if (ActiveControl==PANEL_DDS4|| ActiveControl==PANEL_DDS4STEP) {
433 GetCtrlIndex(MainPanel, PANEL_DDS4STEP, &StepIndex);
434 if (StepIndex<14){
435 SetCtrlIndex(MainPanel, PANEL_DDS4STEP, ++StepIndex) ;
436 GetCtrlVal(MainPanel, PANEL_DDS4STEP, &Step);
437 SetCtrlAttribute(MainPanel, PANEL_DDS4, ATTR_INCR_VALUE, Step) ;
438 };
439 };
440 break;
441 case VAL_LEFT_ARROW_VKEY :
442 ActiveControl = GetActiveCtrl(panel);
443 if (ActiveControl==PANEL_DDSFREPOUT || ActiveControl==PANEL_DDSFREPSTEP) {
444 GetCtrlIndex(MainPanel, PANEL_DDSFREPSTEP, &StepIndex);
445 if (StepIndex>0){
446 SetCtrlIndex(MainPanel, PANEL_DDSFREPSTEP, --StepIndex) ;
447 GetCtrlVal(MainPanel, PANEL_DDSFREPSTEP, &Step);
448 SetCtrlAttribute(MainPanel, PANEL_DDSFREPOUT, ATTR_INCR_VALUE, Step) ;
449 };
450 };
451 if (ActiveControl==PANEL_DDS1 || ActiveControl==PANEL_DDS1STEP) {
452 GetCtrlIndex(MainPanel, PANEL_DDS1STEP, &StepIndex);
453 if (StepIndex>0){
454 SetCtrlIndex(MainPanel, PANEL_DDS1STEP, --StepIndex) ;
455 GetCtrlVal(MainPanel, PANEL_DDS1STEP, &Step);
456 SetCtrlAttribute(MainPanel, PANEL_DDS1, ATTR_INCR_VALUE, Step) ;
457 };
458 };
459 if (ActiveControl==PANEL_DDS2 || ActiveControl==PANEL_DDS2STEP) {
460 GetCtrlIndex(MainPanel, PANEL_DDS2STEP, &StepIndex);
461 if (StepIndex>0){
462 SetCtrlIndex(MainPanel, PANEL_DDS2STEP, --StepIndex) ;
463 GetCtrlVal(MainPanel, PANEL_DDS2STEP, &Step);
464 SetCtrlAttribute(MainPanel, PANEL_DDS2, ATTR_INCR_VALUE, Step) ;
465 };
466 };
467 if (ActiveControl==PANEL_DDS3 || ActiveControl==PANEL_DDS3STEP) {
468 GetCtrlIndex(MainPanel, PANEL_DDS3STEP, &StepIndex);
469 if (StepIndex>0){
470 SetCtrlIndex(MainPanel, PANEL_DDS3STEP, --StepIndex) ;
471 GetCtrlVal(MainPanel, PANEL_DDS3STEP, &Step);
472 SetCtrlAttribute(MainPanel, PANEL_DDS3, ATTR_INCR_VALUE, Step) ;
473 };
474 };
475 if (ActiveControl==PANEL_DDS4 || ActiveControl==PANEL_DDS4STEP) {
476 GetCtrlIndex(MainPanel, PANEL_DDS4STEP, &StepIndex);
477 if (StepIndex>0){
478 SetCtrlIndex(MainPanel, PANEL_DDS4STEP, --StepIndex) ;
479 GetCtrlVal(MainPanel, PANEL_DDS4STEP, &Step);
480 SetCtrlAttribute(MainPanel, PANEL_DDS4, ATTR_INCR_VALUE, Step) ;
481 };
482 };
483 break;
484 case VAL_F1_VKEY :
485 SetActiveCtrl(MainPanel, PANEL_DDSFREPOUT);
486 break;
487 case VAL_F2_VKEY :
488 SetActiveCtrl(MainPanel, PANEL_DDS1);
489 break;
490 case VAL_F3_VKEY :
491 SetActiveCtrl(MainPanel, PANEL_DDS2);
492 break;
493 case VAL_F4_VKEY :
494 SetActiveCtrl(MainPanel, PANEL_DDS3);
495 break;
496 case VAL_F5_VKEY :
497 SetActiveCtrl(MainPanel, PANEL_DDS4);
498 break;
499 };
500 break;
501
502 }
503 return 0;
504 }
505
506 void FindCurrentFileName(void)
507 {
508 char * date, day[3], month[3], year[3]; // DD ; MM ; 20YY plus one space for NULL termination character
509
510 date = DateStr();
511 Scan(date, "%s>%s[w2]-%s[w2]-20%s[w2]", month, day, year);
512 Fmt(LogFileName, "%s<%s\\%s%s%s_Frequ.txt", LOGFILEPATH, year, month, day);
513 return ;
514 }
515
516
517
518 int CVICALLBACK CB_OnStart (int panel, int control, int event,
519 void *callbackData, int eventData1, int eventData2)
520 {
521 int LogFile ;
522 char CharacterBuffer[]="\r" ;
523 char LineBuffer[FXLINELENGTH+10] = "\r\n_1 ";
524
525
526 switch (event)
527 {
528 case EVENT_COMMIT:
529 if (Acquiring) {
530 PlotCh1.IndexPoint = 0 ;
531 PlotCh2.IndexPoint = 0 ;
532 PlotCh3.IndexPoint = 0 ;
533 PlotCh4.IndexPoint = 0 ;
534 PlotMath1.IndexPoint = 0 ;
535 PlotMath2.IndexPoint = 0 ;
536 PlotMath3.IndexPoint = 0 ;
537 PlotMath4.IndexPoint = 0 ;
538 PlotMath5.IndexPoint = 0 ;
539 Allan_Reset(&AllanCh1) ;
540 Allan_Reset(&AllanCh2) ;
541 Allan_Reset(&AllanCh3) ;
542 Allan_Reset(&AllanCh4) ;
543 Allan_Reset(&AllanMath1) ;
544 Allan_Reset(&AllanMath2) ;
545 Allan_Reset(&AllanMath3) ;
546 Allan_Reset(&AllanMath4) ;
547 Allan_Reset(&AllanMath5) ;
548 } ;
549 Acquiring = TRUE ;
550 SetCtrlAttribute(MainPanel, PANEL_STARTBUTTON, ATTR_LABEL_TEXT, "__RESET");
551
552 FindCurrentFileName() ; // LogFileName is the one corresponding to the date of today...
553 GetFileInfo(LogFileName, &OldLogFilePtr) ;
554 OldLogFilePtr -= OldLogFilePtr%FXLINELENGTH + FXLINELENGTH - 2;
555 break;
556 case EVENT_RIGHT_CLICK:
557
558 break;
559 }
560 return 0;
561 }
562
563 int CVICALLBACK CB_OnStop (int panel, int control, int event,
564 void *callbackData, int eventData1, int eventData2)
565 {
566 switch (event)
567 {
568 case EVENT_COMMIT:
569 Acquiring = FALSE ;
570 SetCtrlAttribute(MainPanel, PANEL_STARTBUTTON, ATTR_LABEL_TEXT, "__START");
571 break;
572 case EVENT_RIGHT_CLICK:
573
574 break;
575 }
576 return 0;
577 }
578
579 int CVICALLBACK CB_OnTimer (int panel, int control, int event,
580 void *callbackData, int eventData1, int eventData2)
581 {
582 int LogFile, FileOpt, FileHg, FileSr, FileExtraMath ;
583 long LogFileSize ;
584 char CharacterBuffer[]="\r" ;
585 char LineBuffer[FXLINELENGTH+10] = "\r\n_1 ";
586
587 char * dateNow, * timeNow, day[4], month[4], year[4] ;
588 char TimeTag[] = "100103 000000.000" ; // K+K time tag meaning here 2010 january the 3rd at 00:00:00.000
589 char Date[] = "03/01/2010" ;
590 char Time[] = "00:00:00.000" ;
591 char Year[] = "2010";
592 char ShortYear[] = "10"; // the last 2 digits of calendar year only
593 char Month[] = "01";
594 char Day[] = "03";
595 char Hour[] = "00";
596 char Min[] = "00" ;
597 char Sec[] = "00.000";
598 struct tm LocalTime ;
599 time_t utcTime ;
600 char * ReportString = "dd.mm.yy\t00:00:00\t3481610838.000\t0000000000000.00000000" ;
601
602 int NotCare = 0 ;
603 bool BoxChecked = FALSE;
604
605 double Target, NCalc ;
606
607 double FoxFrequ=0.0;
608 int Div = 1 ;
609
610 double FrequencyToChange=0.0;
611 double DeltaCh2=0.0;
612 double DeltaCh4=0.0;
613
614 double ActualFrequ=0.0;
615 double ActualSlope=0.0;
616
617 double DDS3Bize ;
618 double DDS2Bize ;
619 int N2Bize ;
620 int Signe2Bize;
621 double Math3Bize;
622 double Math1Bize;
623
624
625
626 switch (event)
627 {
628 case EVENT_TIMER_TICK:
629 switch(Acquiring)
630 {
631 case TRUE:
632
633 GetFileInfo(LogFileName, &LogFileSize) ;
634
635 if (LogFileSize > OldLogFilePtr+2*FXLINELENGTH-2) { // if a complete newline has been written
636
637 SuspendTimerCallbacks ;
638
639 // Open Log file and get to the beginning of newly completed line
640 LogFile = OpenFile(LogFileName, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII) ;
641 OldLogFilePtr += FXLINELENGTH;
642 SetFilePtr(LogFile, OldLogFilePtr, 0) ;
643
644 // return the last complete string from the log file and scan it for date and time information
645
646 // first, the time tag, and store it in various formats
647 ReadFile(LogFile, TimeTag, 17);
648
649 CopyBytes(Date,0,TimeTag,4,2);
650 CopyBytes(Date,3,TimeTag,2,2);
651 CopyBytes(Date,8,TimeTag,0,2);
652 CopyBytes(Time,0,TimeTag,7,2);
653 CopyBytes(Time,3,TimeTag,9,2);
654 CopyBytes(Time,6,TimeTag,11,6);
655 SetCtrlVal(MainPanel, PANEL_DATE, Date) ;
656 SetCtrlVal(MainPanel, PANEL_TIME, Time) ;
657
658 CopyBytes(Year,2,TimeTag,0,2); // first 2 bytes of year string remains "20"
659 CopyBytes(ShortYear,0,TimeTag,0,2);
660 CopyBytes(Month,0,TimeTag,2,2);
661 CopyBytes(Day,0,TimeTag,4,2);
662 CopyBytes(Hour,0,TimeTag,7,2);
663 CopyBytes(Min,0,TimeTag,9,2);
664 CopyBytes(Sec,0,TimeTag,11,6);
665 Fmt(&LocalTime.tm_year, "%d<%s", Year);
666 Fmt(&LocalTime.tm_mon, "%d<%s", Month);
667 Fmt(&LocalTime.tm_mday, "%d<%s", Day);
668 Fmt(&LocalTime.tm_hour, "%d<%s", Hour);
669 Fmt(&LocalTime.tm_min, "%d<%s", Min);
670 Fmt(&LocalTime.tm_sec, "%d<%s", "00"); // special case to handle non integer number of UTC seconds
671 LocalTime.tm_hour += 0;
672 LocalTime.tm_min -= 0;
673 LocalTime.tm_sec -= 0;
674 LocalTime.tm_mon -= 1 ; // january is month 0 for tm struct
675 LocalTime.tm_year -= 1900 ; // year is number of years since 1900 for tm struct
676 LocalTime.tm_isdst = -1; // daylight saving flag MUST be set to -1 (unallocated is bugging and +1 is making 1 hour error in summer)
677 utcTime = mktime (&LocalTime);
678 utc = (double) utcTime + strtod(Sec,NULL) ;
679 mjd=utc/86400.; //nb de jours depuis l'origine d'UTC (01/01/1900 à 00h00 GMT)
680 mjd+=15020; //date MJD de la date origine d'UTC
681 SetCtrlVal(MainPanel, PANEL_UTC, utc);
682 SetCtrlVal(MainPanel, PANEL_MJD, mjd);
683
684 // scan the line for counters's channels information
685
686 ReadLine(LogFile, LineBuffer, FXLINELENGTH+9) ;
687 CloseFile(LogFile);
688
689 Scan(LineBuffer, "%f%f%f%f", &Ch1, &Ch2, &Ch3, &Ch4) ;
690 Ch1 = 1000*Ch1;
691 Ch2 = 1000*Ch2;
692 Ch3 = 1000*Ch3;
693 Ch4 = 1000*Ch4;
694
695 NuOpt=N1*(250000000+Math1)-Signe1*8*FrequDDS1 ;
696
697 SetCtrlVal(MainPanel, PANEL_FREQ1, Ch1) ;
698 SetCtrlVal(MainPanel, PANEL_FREQ2, Ch2) ;
699 SetCtrlVal(MainPanel, PANEL_FREQ3, Ch3) ;
700 SetCtrlVal(MainPanel, PANEL_FREQ4, Ch4) ;
701 SetCtrlVal(MainPanel, PANEL_SIGN1, Signe1);
702 SetCtrlVal(MainPanel, PANEL_SIGN2, Signe2);
703 SetCtrlVal(MainPanel, PANEL_SIGN3, Signe3);
704 SetCtrlVal(CalcN1Panel, CALCN1_N_1, N_1) ;
705 SetCtrlVal(CalcN1Panel, CALCN1_SLOPE, Slope_1) ;
706 SetCtrlVal(CalcN2Panel, CALCN2_N_2, N_2) ;
707 SetCtrlVal(CalcN2Panel, CALCN2_SLOPE, Beatslope_2) ;
708 SetCtrlVal(CalcN3Panel, CALCN3_N_3, N_3) ;
709 SetCtrlVal(CalcN3Panel, CALCN3_SLOPE, Slope_3) ;
710 SetCtrlVal(MainPanel, PANEL_SLOPETOCANCEL, SlopeMath2);
711 /*SetCtrlVal(MainPanel, PANEL_SLOPECANCELONOFF, OnOffMessage); */
712 SetCtrlVal(MainPanel, PANEL_CENTERFREQUENCY, CenterFrequencyCh2);
713 SetCtrlVal(MainPanel, PANEL_LED1, SlopeMeasuring);
714 SetCtrlVal(MainPanel, PANEL_LED2, OnSlopeCancelling);
715 // Treat data
716
717 Math1 = mupEval(MathParser1) ;
718 SetCtrlVal(MainPanel,PANEL_MATH1, Math1) ;
719
720 Math2 = mupEval(MathParser2) ;
721 //Math2=NuOpt;
722 SetCtrlVal(MainPanel,PANEL_MATH2, Math2) ;
723
724 Math3 = mupEval(MathParser3) ;
725 SetCtrlVal(MainPanel,PANEL_MATH3, Math3) ;
726
727 Math4 = mupEval(MathParser4) ;
728 SetCtrlVal(MainPanel,PANEL_MATH4, Math4) ;
729
730 Math5 = mupEval(MathParser5) ;
731 SetCtrlVal(MainPanel,PANEL_MATH5, Math5) ;
732
733 // Plot Data and calculus if required
734
735 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ1PLOT, &BoxChecked) ;
736 if (BoxChecked) {
737 Plot_AddFrequency(&PlotCh1, Ch1) ;
738 }
739 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ1ALLAN, &BoxChecked) ;
740 if (BoxChecked) {
741 Allan_AddFrequency(&AllanCh1, Ch1) ;
742 }
743
744 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ2PLOT, &BoxChecked) ;
745 if (BoxChecked) {
746 Plot_AddFrequency(&PlotCh2, Ch2) ;
747 }
748 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ2ALLAN, &BoxChecked) ;
749 if (BoxChecked) {
750 Allan_AddFrequency(&AllanCh2, Ch2) ;
751 }
752
753 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ3PLOT, &BoxChecked) ;
754 if (BoxChecked) {
755 Plot_AddFrequency(&PlotCh3, Ch3) ;
756 }
757 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ3ALLAN, &BoxChecked) ;
758 if (BoxChecked) {
759 Allan_AddFrequency(&AllanCh3, Ch3) ;
760 }
761
762 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ4PLOT, &BoxChecked) ;
763 if (BoxChecked) {
764 Plot_AddFrequency(&PlotCh4, Ch4) ;
765 }
766 GetCtrlVal(MainPanel, PANEL_CHECKBOX_FREQ4ALLAN, &BoxChecked) ;
767 if (BoxChecked) {
768 Allan_AddFrequency(&AllanCh4, Ch4) ;
769 }
770
771 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH1PLOT, &BoxChecked) ;
772 if (BoxChecked) {
773 Plot_AddFrequency(&PlotMath1, Math1) ;
774 }
775 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH1ALLAN, &BoxChecked) ;
776 if (BoxChecked) {
777 Allan_AddFrequency(&AllanMath1, Math1) ;
778 }
779
780 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2PLOT, &BoxChecked) ;
781 if (BoxChecked) {
782 Plot_AddFrequency(&PlotMath2, Math2) ;
783 }
784 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2ALLAN, &BoxChecked) ;
785 if (BoxChecked) {
786 Allan_AddFrequency(&AllanMath2, Math2) ;
787 }
788
789 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3PLOT, &BoxChecked) ;
790 if (BoxChecked) {
791 Plot_AddFrequency(&PlotMath3, Math3) ;
792 }
793 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3ALLAN, &BoxChecked) ;
794 if (BoxChecked) {
795 Allan_AddFrequency(&AllanMath3, Math3) ;
796 }
797
798 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH4PLOT, &BoxChecked) ;
799 if (BoxChecked) {
800 Plot_AddFrequency(&PlotMath4, Math4) ;
801 }
802 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH4ALLAN, &BoxChecked) ;
803 if (BoxChecked) {
804 Allan_AddFrequency(&AllanMath4, Math4) ;
805 }
806
807 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5PLOT, &BoxChecked) ;
808 if (BoxChecked) {
809 Plot_AddFrequency(&PlotMath5, Math5) ;
810 }
811 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5ALLAN, &BoxChecked) ;
812 if (BoxChecked) {
813 Allan_AddFrequency(&AllanMath5, Math5) ;
814 }
815 // Calcul de N
816
817 if (Measuring_1==TRUE)
818 {
819 if (Step1_1==FALSE) {
820 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ;
821 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1);
822
823 GetCtrlVal(MainPanel, PANEL_DDS2, &FrequencyDDSBesInit) ;
824 t1_1=utc;
825 Frequ_slope_1=Math1;
826 Moy_slope_1= Frequ_slope_1;
827 Ch4_slope=Ch4;
828 Moy_Ch4slope_1= Ch4_slope;
829 N_slope_1=1;
830 Step1_1=TRUE ;
831 }
832 else {
833 if(Step2_1==FALSE){
834 N_slope_1=N_slope_1+1;
835 Frequ_slope_1=Math1;
836 Ch4_slope=Ch4;
837 Moy_slope_1=((N_slope_1-1)*Moy_slope_1 + Frequ_slope_1)/N_slope_1;
838 Moy_Ch4slope_1=((N_slope_1-1)*Moy_Ch4slope_1 + Ch4_slope)/N_slope_1;
839 Slope_slope_1 = (Slope_slope_1*(N_slope_1-2) + 6*(Frequ_slope_1-Moy_slope_1)/N_slope_1)/(N_slope_1+1) ;
840 Slope_Ch4slope_1 = (Slope_Ch4slope_1*(N_slope_1-2) + 6*(Ch4_slope-Moy_Ch4slope_1)/N_slope_1)/(N_slope_1+1) ;
841 if (utc-t1_1>SlopeTime1) {
842 Slope_1 = Slope_slope_1;
843 Ch4Slope = Slope_Ch4slope_1;
844 Step2_1=TRUE ;
845 N_slope_1=0;
846 Frequ_slope_1=0.0;
847 Moy_slope_1=0.0;
848 Slope_slope_1 =0.0;
849 Ch4_slope=0.0;
850 Moy_Ch4slope_1=0.0;
851 Slope_Ch4slope_1=0.0;
852
853 DDS4xAD9912_FrequencyRampe (&DDS4xAD9912,1, FrequDDS1,(FrequDDS1+DeltakHz_1*1000), Step1/Ndiv ) ;
854 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1+DeltakHz_1*1000)) ;
855 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, (FrequDDS1+DeltakHz_1*1000));
856
857 }
858 }
859 else {
860 if (DDSBesChanged1==FALSE){
861
862 if (nDDSChange<3)
863 { nDDSChange=nDDSChange+1;}
864
865 else
866 {
867 nDDSChange=0;
868
869 DeltaFrep275=275000-Ch4;
870 FrequencyDDSBes=FrequencyDDSBesInit+(DeltaFrep275);
871 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBes) ;
872 DDS4xAD9912_SetFrequency(&DDS4xAD9912,2,FrequencyDDSBes);
873 DDSBesChanged1=TRUE;
874 t2_1=utc;
875
876 }
877
878 }
879 else{
880
881 if(Step3_1==FALSE){
882 if (nstabilization<3)
883 {nstabilization= nstabilization+1;
884 TimetoBegin=TRUE;}
885 else
886 {
887 if (utc-t2_1<DeltaT_1) {
888 if (TimetoBegin==TRUE)
889 {
890 t2_1=utc;
891 TimetoBegin=FALSE;
892 }
893 Frepplus_1=Frepplus_1 +Math1-Slope_1*(utc-t2_1);
894 Ch4Plus=Ch4Plus + Ch4 -Ch4Slope*(utc-t2_1);
895 n_1=n_1+1;
896 }
897 else{
898 Frepplus_1=Frepplus_1/n_1;
899 Ch4Plus=Ch4Plus/n_1;
900 n_1=0;
901 Step3_1=TRUE ;
902 nstabilization=0;
903 DDS4xAD9912_FrequencyRampe ( &DDS4xAD9912,1, (FrequDDS1+DeltakHz_1*1000),(FrequDDS1-DeltakHz_1*1000), Step1/Ndiv ) ;
904 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1-DeltakHz_1*1000)) ;
905 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, (FrequDDS1-DeltakHz_1*1000));
906 }
907 }
908 }
909
910 else {
911 if (DDSBesChanged2==FALSE){
912
913 if (nDDSChange<3)
914 { nDDSChange=nDDSChange+1;}
915
916 else
917 {
918 nDDSChange=0;
919
920
921 DeltaFrep275=275000-Ch4;
922 FrequencyDDSBes=FrequencyDDSBes+(DeltaFrep275) ;
923 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBes) ;
924 DDS4xAD9912_SetFrequency(&DDS4xAD9912,2,FrequencyDDSBes);
925 DDSBesChanged2=TRUE;
926 t3_1=utc;
927
928
929 }
930 }
931
932 else{
933 if (nstabilization<3)
934 { nstabilization=nstabilization+1;
935 TimetoBegin=TRUE;}
936 else
937 {
938 if (utc-t3_1<DeltaT_1) {
939 if (TimetoBegin==TRUE)
940 {
941 t3_1=utc;
942 TimetoBegin=FALSE;
943 }
944
945 Frepminus_1=Frepminus_1 +Math1-Slope_1*(utc-t3_1);
946 Ch4Minus=Ch4Minus+Ch4-Ch4Slope*(utc-t3_1);
947 n_1=n_1+1;
948 }
949 else{
950 Frepminus_1=Frepminus_1/(n_1);
951 Ch4Minus=Ch4Minus/(n_1);
952 N_1 = Signe1*(2*Ndiv*DeltakHz_1*1000 /*-(Ch4Plus-Ch4Minus)-Ch4Slope*(t3_1-t2_1)*/)/(Frepminus_1-Frepplus_1-Slope_1*(t3_1-t2_1));
953 n_1=0;
954 Frepminus_1=0.0;
955 Frepplus_1=0.0;
956 DDS4xAD9912_FrequencyRampe (&DDS4xAD9912, 1, FrequDDS1-DeltakHz_1*1000,FrequDDS1, Step1/Ndiv ) ;
957 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ;
958 DDS4xAD9912_SetFrequency(&DDS4xAD9912,1,FrequDDS1);
959 DDS4xAD9912_SetFrequency(&DDS4xAD9912,2,FrequencyDDSBesInit);
960 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit) ;
961 Measuring_1=FALSE ;
962 Step1_1=FALSE ;
963 Step2_1=FALSE ;
964 Step3_1=FALSE ;
965 t1_1=0.0;
966 t2_1=0.0;
967 t3_1=0.0;
968 DDSBesChanged1=FALSE;
969 DDSBesChanged2=FALSE;
970 FrequencyDDSBes=0.0;
971 nstabilization=0;
972
973 }
974 }
975 }
976 }
977 }
978 }
979 }
980 }
981
982
983
984
985
986
987 if (Measuring_2==TRUE)
988 {
989 if (Step1_2==FALSE) {
990 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ;
991 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1);
992
993 GetCtrlVal(MainPanel, PANEL_DDS2, &FrequencyDDSBesInit) ;
994 GetCtrlVal(MainPanel, PANEL_DDS3, &FrequencyDDS3Init) ;
995 t1_2=utc;
996 Frequ_slope_2=Math1;
997 Beat_slope_2=Ch2;
998 Moy_slope_2= Frequ_slope_2;
999 Moy_Beatslope_2= Beat_slope_2;
1000 N_slope_2=1;
1001 Step1_2=TRUE ;
1002 Nu1=(250000000+Math1)*N1;
1003 }
1004 else {
1005 if(Step2_2==FALSE){
1006 N_slope_2=N_slope_2+1;
1007 Frequ_slope_2=Math1;
1008 Beat_slope_2=Ch2;
1009 Moy_slope_2=((N_slope_2-1)*Moy_slope_2 + Frequ_slope_2)/N_slope_2;
1010 Moy_Beatslope_2=((N_slope_2-1)*Moy_Beatslope_2 + Beat_slope_2)/N_slope_2;
1011 Slope_slope_2 = (Slope_slope_2*(N_slope_2-2) + 6*(Frequ_slope_2-Moy_slope_2)/N_slope_2)/(N_slope_2+1) ;
1012 Slope_Beatslope_2 = (Slope_Beatslope_2*(N_slope_2-2) + 6*(Beat_slope_2-Moy_Beatslope_2)/N_slope_2)/(N_slope_2+1) ;
1013 if (utc-t1_2>SlopeTime2) {
1014 Slope_2 = Slope_slope_2;
1015 Beatslope_2 = Slope_Beatslope_2;
1016 Step2_2=TRUE ;
1017 N_slope_2=0;
1018 Frequ_slope_2=0.0;
1019 Moy_slope_2=0.0;
1020 Slope_slope_2 =0.0;
1021 Moy_Beatslope_2=0.0;
1022 Slope_Beatslope_2 =0.0;
1023 Beat_slope_2=0.0;
1024
1025 DDS4xAD9912_FrequencyRampe (&DDS4xAD9912,1, FrequDDS1,(FrequDDS1+DeltakHz_2*1000), Step2/Ndiv ) ;
1026 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1+DeltakHz_2*1000)) ;
1027 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, (FrequDDS1+DeltakHz_2*1000));
1028 Delay(0.1);
1029 DeltaDDS3 = -DeltakHz_2*1000*(-Signe1/Signe2)*Ndiv*(Nu2)/(Nu1) - Beatslope_2*(utc-t1_2);
1030 SetCtrlVal(MainPanel, PANEL_DDS3, (FrequencyDDS3Init+DeltaDDS3)) ;
1031 DDS4xAD9912_SetFrequency (&DDS4xAD9912,3,(FrequencyDDS3Init+DeltaDDS3)) ;
1032
1033 }
1034 }
1035 else {
1036 if (DDSBesChanged1==FALSE){
1037
1038 if (nDDSChange<3)
1039 { nDDSChange=nDDSChange+1;}
1040
1041 else
1042 {
1043 nDDSChange=0;
1044
1045 DeltaFrep275=275000-Ch4;
1046 DeltaFrep10=10000-Ch2;
1047 DeltaDDS3= DeltaDDS3 +(DeltaFrep10);
1048 FrequencyDDSBes=FrequencyDDSBesInit+(DeltaFrep275);
1049 FrequencyDDS3=FrequencyDDS3Init+DeltaDDS3;
1050
1051 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBes) ;
1052 DDS4xAD9912_SetFrequency(&DDS4xAD9912,2,FrequencyDDSBes);
1053
1054 Delay(0.1);
1055 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3) ;
1056 DDS4xAD9912_SetFrequency(&DDS4xAD9912,3,FrequencyDDS3);
1057
1058 DDSBesChanged1=TRUE;
1059 t2_2=utc;
1060
1061 }
1062
1063 }
1064 else{
1065
1066 if(Step3_2==FALSE){
1067 if (nstabilization<3)
1068 {nstabilization= nstabilization+1;}
1069 else
1070 {
1071 if (utc-t2_2<DeltaT_2) {
1072 Frepplus_2=Frepplus_2 +Math1+250000000-Slope_2*(utc-t2_2);
1073 Delta10K_Plus= Delta10K_Plus + 10000 - (Ch2 -Beatslope_2*(utc-t2_2));
1074 n_2=n_2+1;
1075 }
1076 else{
1077 Frepplus_2=Frepplus_2/n_2;
1078 Delta10K_Plus=Delta10K_Plus/n_2;
1079 n_2=0;
1080 Step3_2=TRUE ;
1081 nstabilization=0;
1082 DDS4xAD9912_FrequencyRampe ( &DDS4xAD9912,1, (FrequDDS1+DeltakHz_2*1000),(FrequDDS1-DeltakHz_2*1000), Step2/Ndiv ) ;
1083 SetCtrlVal(MainPanel, PANEL_DDS1, (FrequDDS1-DeltakHz_2*1000)) ;
1084 DDS4xAD9912_SetFrequency (&DDS4xAD9912,1, (FrequDDS1-DeltakHz_2*1000) ) ;
1085
1086 Delay(0.1);
1087 DeltaDDS3 = (FrequencyDDS3Init+DeltakHz_2*1000*(-Signe1/Signe2)*Ndiv*(Nu2)/(Nu1)) - FrequencyDDS3;
1088 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3+DeltaDDS3) ;
1089 DDS4xAD9912_SetFrequency (&DDS4xAD9912,3, FrequencyDDS3+DeltaDDS3 ) ;
1090
1091 }
1092 }
1093 }
1094
1095 else {
1096 if (DDSBesChanged2==FALSE){
1097
1098 if (nDDSChange<3)
1099 { nDDSChange=nDDSChange+1;}
1100
1101 else
1102 {
1103 nDDSChange=0;
1104
1105
1106 DeltaFrep275=275000-Ch4;
1107 DeltaFrep10=10000-Ch2;
1108 DeltaDDS3 = DeltaDDS3+(DeltaFrep10) ;
1109 FrequencyDDSBes=FrequencyDDSBes+(DeltaFrep275) ;
1110 FrequencyDDS3=FrequencyDDS3+DeltaDDS3 ;
1111 DDS4xAD9912_SetFrequency(&DDS4xAD9912,2,FrequencyDDSBes);
1112 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBes);
1113
1114 Delay(0.1);
1115 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3) ;
1116 DDS4xAD9912_SetFrequency(&DDS4xAD9912,3,FrequencyDDS3);
1117
1118 DDSBesChanged2=TRUE;
1119 t3_2=utc;
1120
1121
1122 }
1123 }
1124
1125 else{
1126 if (nstabilization<3)
1127 { nstabilization=nstabilization+1;}
1128 else
1129 {
1130 if (utc-t3_2<DeltaT_2) {
1131 Frepminus_2=Frepminus_2 +Math1+250000000-Slope_2*(utc-t3_2);
1132 Delta10K_Minus= Delta10K_Minus +10000 - ( Ch2 -Beatslope_2*(utc-t3_2));
1133 n_2=n_2+1;
1134 }
1135 else{
1136 Frepminus_2=Frepminus_2/(n_2);
1137 Delta10K_Minus= Delta10K_Minus/n_2;
1138 N_2 = (Signe2)*(-DeltaDDS3+Delta10K_Plus-Delta10K_Minus-Beatslope_2*(t3_2-t2_2) )/(Frepminus_2-Frepplus_2-Slope_2*(t3_2-t2_2));
1139 n_2=0;
1140 Frepminus_2=0.0;
1141 Frepplus_2=0.0;
1142 Delta10K_Minus=0.0;
1143 Delta10K_Plus=0.0;
1144 DDS4xAD9912_FrequencyRampe (&DDS4xAD9912, 1, FrequDDS1-DeltakHz_2*1000,FrequDDS1, Step2/Ndiv ) ;
1145 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ;
1146 DDS4xAD9912_SetFrequency(&DDS4xAD9912,1,FrequDDS1);
1147
1148 Delay(0.1);
1149
1150 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit) ;
1151 DDS4xAD9912_SetFrequency (&DDS4xAD9912, 2, FrequencyDDSBesInit ) ;
1152
1153 Delay(0.1);
1154
1155 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init-Beatslope_2*(utc-t1_2)) ;
1156 DDS4xAD9912_SetFrequency (&DDS4xAD9912, 3, FrequencyDDS3Init-Beatslope_2*(utc-t1_2) ) ;
1157
1158 Measuring_2=FALSE ;
1159 Step1_2=FALSE ;
1160 Step2_2=FALSE ;
1161 Step3_2=FALSE ;
1162 t1_2=0.0;
1163 t2_2=0.0;
1164 t3_2=0.0;
1165 DDSBesChanged1=FALSE;
1166 DDSBesChanged2=FALSE;
1167 FrequencyDDSBes=0.0;
1168 nstabilization=0;
1169
1170 }
1171 }
1172 }
1173 }
1174 }
1175 }
1176 }
1177 }
1178
1179
1180
1181 /* if (Measuring_3==TRUE)
1182 {
1183 if (Step1_3==FALSE) {
1184 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequDDS3);
1185 t1_3=utc;
1186 Frequ_slope_3=Math1;
1187 Moy_slope_3= Frequ_slope_3;
1188 N_slope_3=1;
1189 Step1_3=TRUE ;
1190 }
1191 else {
1192 if(Step2_3==FALSE){
1193 N_slope_3=N_slope_3+1;
1194 Frequ_slope_3=Math1;
1195 Moy_slope_3=((N_slope_3-1)*Moy_slope_3 + Frequ_slope_3)/N_slope_3;
1196 Slope_slope_3 = (Slope_slope_3*(N_slope_3-2) + 6*(Frequ_slope_3-Moy_slope_3)/N_slope_3)/(N_slope_3+1) ;
1197 if (utc-t1_3>DeltaT_3) {
1198 Slope_3 = Slope_slope_3;
1199 GetCtrlVal(MainPanel, PANEL_DDSFREPOUT, &FrequencyDDSBes) ;
1200 DDSBes_SetFrequency(&DDSBes, FrequencyDDSBes+(FACTORDDSBES*DeltakHz_3*1000));
1201 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequDDS3+DeltakHz_3*1000);
1202 t2_3=utc;
1203 Step2_3=TRUE ;
1204 N_slope_3=0;
1205 Frequ_slope_3=0.0;
1206 Moy_slope_3=0.0;
1207 Slope_slope_3 =0.0;
1208 }
1209 }
1210 else {
1211 if(Step2_3==FALSE){
1212 if (utc-t2_3<DeltaT_3) {
1213 Frepplus_3=Frepplus_3 +Math1+250000000-Slope_3*(utc-t2_3);
1214 n_3=n_3+1;
1215 }
1216 else{
1217 Frepplus_3=Frepplus_3/n_3;
1218 DDSBes_SetFrequency(&DDSBes, FrequencyDDSBes-(FACTORDDSBES*DeltakHz_3*1000));
1219 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequDDS3-DeltakHz_3*1000);
1220 n_3=0;
1221 t3_3=utc;
1222 Step3_3=TRUE ;
1223 }
1224 }
1225 else {
1226 if (utc-t3_3<DeltaT_3) {
1227 Frepminus_3=Frepminus_3 +Math1+250000000-Slope_3*(utc-t3_3);
1228 n_3=n_3+1;
1229 }
1230 else{
1231 Frepminus_3=Frepminus_3/(n_3);
1232 N_3 = (16*DeltakHz_3*1000 -Slope_3*(t3_3-t2_3))/(Frepplus_3-Frepminus_3);
1233 n_3=0;
1234 Frepminus_3=0.0;
1235 Frepplus_3=0.0;
1236 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequDDS3);
1237 Measuring_2=FALSE ;
1238 Step1_3=FALSE ;
1239 Step2_3=FALSE ;
1240 Step3_3=FALSE ;
1241 t1_3=0.0;
1242 t2_3=0.0;
1243 t3_3=0.0;
1244 }
1245 }
1246 }
1247 }
1248 } */
1249
1250
1251
1252
1253
1254 // Calcul du signe de fb
1255
1256 if (Getsign1 ==TRUE) {
1257 if (utc> tbegin1+2){
1258 if (Math1> Frepbefore1) { Signe1=-1.0;}
1259 else {Signe1=1.0;}
1260 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency1) ;
1261 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency1);
1262 Getsign1=FALSE;
1263 }
1264 }
1265 if (Getsign2 ==TRUE) {
1266 if (utc> tbegin2+2){
1267 if (Math1> Frepbefore2) {
1268 if (Ch2>Ch2before) {Signe2=+1.0;}
1269 else {Signe2=-1.0;}
1270 }
1271 else {
1272 if (Ch2>Ch2before) {Signe2=-1.0;}
1273 else {Signe2=+1.0;}
1274 }
1275 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency2) ;
1276 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency2);
1277 Getsign2=FALSE;
1278 }
1279 }
1280 if (Getsign3 ==TRUE) {
1281 if (utc> tbegin3+2){
1282 if (Ch1> Frepbefore3) { Signe3=-1.0;}
1283 else {Signe3=1.0;}
1284 SetCtrlVal(MainPanel, PANEL_DDS3, Frequency3) ;
1285 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, Frequency3);
1286 Getsign3=FALSE;
1287 }
1288 }
1289
1290
1291
1292
1293 //Pour le Slope Cancelling
1294
1295 if (SlopeMeasuring==TRUE)
1296 {
1297 if (utc-SlopeMeasuringTimeBegin>TimetoSlope)
1298 {
1299 Nratio=Nratio+1;
1300
1301 if (Nratio>=1)
1302 {
1303 MoyMath2= MoyMath2+Moy_Math2slope;
1304 }
1305 SlopeMath2=SlopeMath2+Slope_Math2slope;
1306 N_Math2slope=0.0;
1307 Math2_slope=0.0;
1308 Moy_Math2slope=0.0;
1309 Slope_Math2slope=0.0;
1310
1311
1312
1313 if (Nratio==1 && CenterFrequencyCh2ToDetermine==TRUE) {
1314 CenterFrequencyCh2= MoyMath2;
1315 CenterFrequencyCh2ToDetermine=FALSE;
1316 }
1317
1318 OnOffMessage="ON " ;
1319 OnSlopeCancelling =TRUE;
1320
1321 // S'occupe du slope
1322 // SweepSign =0 fait un slope +
1323 // SweepSign =1 fait un slope -
1324
1325 /* if (SlopeMath2<0)
1326 {
1327 DDSFoxSweepSign=0;
1328 SlopeMath2= -SlopeMath2;
1329 }
1330 else
1331 { DDSFoxSweepSign=1; } */
1332
1333 FoxFrequ=ReadDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate);
1334
1335 if (Nratio==ratio) {
1336
1337 if (FrequCorrec==TRUE) {
1338 SlopeCorrection= (MoyMath2/ratio-CenterFrequencyCh2)/TimetoSlope;
1339 SlopeMath2=SlopeMath2+ SlopeCorrection;
1340 }
1341 Nratio=0;
1342 MoyMath2=0.0;
1343
1344 }
1345
1346 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,FoxFrequ,SlopeMath2,0);
1347
1348 nstabilisationSlopeMeasuring=0;
1349 SlopeMeasuringTimeBegin=utc;
1350
1351
1352
1353 }
1354 else
1355 {
1356 if (nstabilisationSlopeMeasuring<5)
1357 {
1358 nstabilisationSlopeMeasuring= nstabilisationSlopeMeasuring+1;
1359 Math2_slope=Math2;
1360 }
1361 else
1362 {
1363 if ((Math2-Math2_slope)<limitotakoff && (Math2-Math2_slope)>-limitotakoff )
1364 {
1365 N_Math2slope=N_Math2slope+1;
1366 Math2_slope=Math2;
1367 Moy_Math2slope=((N_Math2slope-1)*Moy_Math2slope + Math2_slope)/N_Math2slope;
1368 Slope_Math2slope= (Slope_Math2slope*(N_Math2slope-2) + 6*(Math2_slope-Moy_Math2slope)/N_Math2slope)/(N_Math2slope+1) ;
1369 }
1370
1371 else
1372 {
1373
1374 if (AutoStopSlopeCancellingIfDelock)
1375 {
1376 // S'occupe d'arreter le slope en cas de delockage
1377
1378 if (KeepFrequ==TRUE) {ActualFrequ=ReadDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate);}
1379 else { ActualFrequ= DDSFoxFrequency;}
1380 if (KeepSlope==TRUE) {ActualSlope= SlopeMath2;
1381 }
1382 else { ActualSlope= DDSFoxSweeprate;
1383 OnSlopeCancelling =FALSE;}
1384 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,ActualFrequ,ActualSlope,0);
1385 SlopeMeasuring=FALSE;
1386 OnOffMessage="OFF " ;
1387 N_Math2slope=0.0;
1388 Math2_slope=0.0;
1389 MoyMath2=0.0;
1390 Moy_Math2slope=0.0;
1391 Slope_Math2slope=0.0;
1392 CenterFrequencyCh2= 0.0;
1393 CenterFrequencyCh2ToDetermine=TRUE;
1394 Nratio=-1;
1395 nstabilisationSlopeMeasuring=0;
1396 SetCtrlVal(MainPanel, PANEL_STARTCANCEL, 0) ;
1397
1398 }
1399 }
1400
1401 }
1402
1403 }
1404
1405 }
1406
1407
1408 //// For re-centering
1409
1410 if (KeepCentering)
1411 {
1412
1413 DeltaCh4=275000-Ch4;
1414 DeltaCh2=10000-Ch2;
1415
1416 if (utc- CenteringTimeBegin275K > Timetorecenter275K && CenteringTimeBegin275K>10)
1417 {
1418 GetCtrlVal(MainPanel, PANEL_DDS2, &FrequencyToChange) ;
1419 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyToChange+DeltaCh4) ;
1420 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyToChange+DeltaCh4);
1421 CenteringTimeBegin275K=utc;
1422
1423
1424 }
1425
1426 if (utc- CenteringTimeBegin10K > Timetorecenter10K && CenteringTimeBegin10K>10)
1427 {
1428 GetCtrlVal(MainPanel, PANEL_DDS3, &FrequencyToChange) ;
1429 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyToChange+DeltaCh2) ;
1430 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyToChange+DeltaCh2);
1431 CenteringTimeBegin10K=utc;
1432
1433
1434 }
1435
1436
1437 }
1438
1439
1440
1441
1442 // Now, some special extra functions for some math value which have special 'default' meaning (like nu_Hg and nu_Sr)
1443
1444 /*GetPanelAttribute(CalcNHgPanel, ATTR_VISIBLE, &BoxChecked) ; // correct name for answer would be more
1445 if (BoxChecked) { // something like "&PanelOpened" here
1446 N_1 = 0; // evaluate Math2 for N=0 gives 282143G-/+320M
1447 GetCtrlVal(CalcNHgPanel, CALCNHG_TARGET, &Target) ;
1448 NCalc = (Target-mupEval(MathParser2))/(Math1+766e6) ;
1449 SetCtrlVal(CalcNHgPanel, CALCNHG_NHGCALC, (double) RoundRealToNearestInteger (NCalc) ) ;
1450 SetCtrlVal(CalcNHgPanel, CALCNHG_ERROR, NCalc-RoundRealToNearestInteger (NCalc) ) ;
1451 GetCtrlVal(MainPanel, PANEL_N_HG, &N_1) ; // Set N_1 back to value user defined in main panel
1452 }
1453
1454 GetPanelAttribute(CalcNSrPanel, ATTR_VISIBLE, &BoxChecked) ; // correct name for answer would be more
1455 if (BoxChecked) { // something like "&PanelOpened" here, but I reuse variable name for concision
1456 N2 = 0; // evaluate Math3 for N=0 gives 429228G-/+DDS2-/+Ch3
1457 GetCtrlVal(CalcNSrPanel, CALCN2_TARGET, &Target) ;
1458 NCalc = (Target-mupEval(MathParser3))/(Math1+766e6) ;
1459 SetCtrlVal(CalcNSrPanel, CALCN2_NSRCALC, (double) RoundRealToNearestInteger (NCalc) ) ;
1460 SetCtrlVal(CalcNSrPanel, CALCNSR_ERROR, NCalc-RoundRealToNearestInteger (NCalc) ) ;
1461 GetCtrlVal(MainPanel, PANEL_N_SR, &N2) ; // Set N_2 back to value user defined in main panel
1462 }
1463
1464 GetPanelAttribute(CalcN813Panel, ATTR_VISIBLE, &BoxChecked) ; // correct name for answer would be more
1465 if (BoxChecked) { // something like "&PanelOpened" here, but I reuse variable name for concision
1466 N3 = 0; // evaluate Math4 for N=0 gives ??????G-/+DDS_813-/+Ch4
1467 GetCtrlVal(CalcN813Panel, CALCN83_TARGET, &Target) ;
1468 NCalc = (Target-mupEval(MathParser4))/(Math1+766e6) ;
1469 SetCtrlVal(CalcN813Panel, CALCN813_N813CALC, (double) RoundRealToNearestInteger (NCalc) ) ;
1470 SetCtrlVal(CalcN813Panel, CALCN813_ERROR, NCalc-RoundRealToNearestInteger (NCalc) ) ;
1471 GetCtrlVal(MainPanel, PANEL_N_813, &N3) ; // Set N3 back to value user defined in main panel
1472 }*/
1473
1474 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2AUTOSAV, &BoxChecked) ; // AutoSave OL
1475 if (BoxChecked) {
1476 SetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, TRUE) ; // so that it will try to write it (at next block) if it seems reasonnable, even though it was off before
1477 }
1478
1479 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, &BoxChecked) ; // Save OL (Math2)
1480 if (BoxChecked) {
1481 /*GetCtrlVal(CalcNHgPanel, CALCNHG_TARGET, &Target) ;
1482 if (abs(Math2-Target)>1e4) { // write it only if it's vaguely plausible (here outlier>10kHz ie approx 10000sigma but not dedrift applied !!!)
1483 SetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH2SAVE, FALSE) ;
1484 break ;
1485 } ;*/
1486 FileOpt = OpenFile("z:\\MeasuresFifi1\\OptCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ;
1487 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math2);
1488 WriteLine(FileOpt, ReportString, -1) ;
1489 CloseFile(FileOpt) ;
1490 FileOpt = OpenFile("C:\\Femto\\Results\\OptCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ; // a local backup for debugging
1491 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math2);
1492 WriteLine(FileOpt, ReportString, -1) ;
1493 CloseFile(FileOpt) ;
1494 }
1495
1496 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3AUTOSAV, &BoxChecked) ; // AutoSave Hg (Math3)
1497 if (BoxChecked) {
1498 SetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, TRUE) ; // so that it will try to write it (at next block) if it seems reasonnable, even though it was off before
1499 }
1500
1501 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, &BoxChecked) ; // Save Hg
1502
1503 if (BoxChecked) {
1504 /*GetCtrlVal(CalcNSrPanel, CALCN3_TARGET, &Target) ;
1505 if (abs(Math3-Target)>1.0e4) { // write it only if it's vaguely plausible (here outlier>10kHz ie approx 10000sigma but not dedrift applied !!!)
1506 SetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH3SAVE, FALSE) ; // otherwise uncheck the save box
1507 break ;
1508 } ;*/
1509 FileHg = OpenFile("z:\\MeasuresFifi1\\HgCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ;
1510 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math3);
1511 WriteLine(FileHg, ReportString, -1) ;
1512 CloseFile(FileHg) ;
1513 FileHg = OpenFile("C:\\Femto\\Results\\HgCavity.txt", VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ;
1514 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p3]", Date, Time, utc, Math3);
1515 WriteLine(FileHg, ReportString, -1) ;
1516 CloseFile(FileHg) ;
1517
1518 }
1519
1520 GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5SAVE, &BoxChecked) ; // Save ExtraMath (Math5)
1521 if (BoxChecked) {
1522 FileExtraMath = OpenFile(ExtraMathFileName, VAL_WRITE_ONLY, VAL_APPEND, VAL_ASCII) ;
1523 Fmt(ReportString, "%s\t%s\t%f[p3]\t%f[p7]", Date, Time, utc, Math5);
1524 WriteLine(FileExtraMath, ReportString, -1) ;
1525 CloseFile(FileExtraMath) ;
1526 }
1527
1528 // Special case to handle change of day at next second
1529 //if ( LocalTime.tm_hour==23 && LocalTime.tm_min==59 && strtod(Sec,NULL)>59 ) {
1530 if ( LocalTime.tm_hour==23 && LocalTime.tm_min==59 && strtod(Sec,NULL)>=58 ) {
1531 printf("Entering change of date substructure\r\n");
1532 printf("old file : %s %s %s \r\n",Date, Time, LogFileName);
1533 Acquiring = FALSE ;
1534 do {
1535 Delay(5.1);
1536 FindCurrentFileName() ;
1537 }
1538 while (!GetFileInfo(LogFileName, &OldLogFilePtr)) ;
1539 printf("new file : %s \r\n\r\n",Date, Time, LogFileName);
1540 Acquiring = TRUE ;
1541 OldLogFilePtr = 2;
1542 }
1543
1544 ResumeTimerCallbacks ;
1545
1546 } ;
1547
1548 break;
1549 case FALSE:
1550 break;
1551 }
1552 break;
1553 }
1554 return 0;
1555 }
1556
1557
1558
1559
1560 int CVICALLBACK CB_OnFreqPlot (int panel, int control, int event,
1561 void *callbackData, int eventData1, int eventData2)
1562 {
1563 int BoxChecked ;
1564 Plot_Data * pPlot = NULL;
1565 char PlotTitle[] = "Ch? Frequency Plot" ;
1566 double PlotMin = 10e6 ;
1567 double PlotMax = 65e6 ;
1568
1569 switch (event)
1570 {
1571 case EVENT_COMMIT:
1572
1573 GetCtrlVal(MainPanel, control, &BoxChecked);
1574 switch (control) {
1575 case PANEL_CHECKBOX_FREQ1PLOT :
1576 pPlot = &PlotCh1 ;
1577 Fmt(PlotTitle, "Ch1 Frequency Plot") ;
1578 PlotMin = 54.999e6 ; PlotMax = 55.001e6 ;
1579 break ;
1580 case PANEL_CHECKBOX_FREQ2PLOT :
1581 pPlot = &PlotCh2 ;
1582 Fmt(PlotTitle, "Ch2 Frequency Plot") ;
1583 PlotMin = 8.0e3 ; PlotMax = 12.0e3 ;
1584 break ;
1585 case PANEL_CHECKBOX_FREQ3PLOT :
1586 pPlot = &PlotCh3 ;
1587 Fmt(PlotTitle, "Ch3 Frequency Plot") ;
1588 PlotMin = 8.0e3 ; PlotMax = 12.0e3 ;
1589 break ;
1590 case PANEL_CHECKBOX_FREQ4PLOT :
1591 pPlot = &PlotCh4 ;
1592 Fmt(PlotTitle, "Ch4 Frequency Plot") ;
1593 break ;
1594 case PANEL_CHECKBOX_MATH1PLOT :
1595 pPlot = &PlotMath1 ;
1596 Fmt(PlotTitle, "Math1 Plot") ;
1597 PlotMin = 765.0e6 ; PlotMax = 775.0e6 ;
1598 break ;
1599 case PANEL_CHECKBOX_MATH2PLOT :
1600 pPlot = &PlotMath2 ;
1601 Fmt(PlotTitle, "Math2 Plot") ;
1602 PlotMin = -1.0e9 ; PlotMax = 1.0e9 ;
1603 break ;
1604 case PANEL_CHECKBOX_MATH3PLOT :
1605 pPlot = &PlotMath3 ;
1606 Fmt(PlotTitle, "Math3 Plot") ;
1607 PlotMin = -1.0e9 ; PlotMax = 1.0e9 ;
1608 break ;
1609 case PANEL_CHECKBOX_MATH4PLOT :
1610 pPlot = &PlotMath4 ;
1611 Fmt(PlotTitle, "Math4 Plot") ;
1612 PlotMin = -1.0e9 ; PlotMax = 1.0e9 ;
1613 break ;
1614 case PANEL_CHECKBOX_MATH5PLOT :
1615 pPlot = &PlotMath5 ;
1616 Fmt(PlotTitle, "Math5 Plot") ;
1617 PlotMin = -1.0e9 ; PlotMax = 1.0e9 ;
1618 break ;
1619 }
1620
1621 if (BoxChecked) {
1622 Plot_InitPanel(pPlot, PlotTitle, PlotMin, PlotMax, &OnCloseViewPanel) ;
1623 }
1624 else {
1625 Plot_ClosePanel(pPlot) ;
1626 } ;
1627 break;
1628
1629 case EVENT_RIGHT_CLICK:
1630
1631 break;
1632
1633 }
1634 return 0;
1635 }
1636
1637
1638 int CVICALLBACK CB_OnAllanPlot (int panel, int control, int event,
1639 void *callbackData, int eventData1, int eventData2)
1640 {
1641 int BoxChecked ;
1642 Allan_Data * pAllan = NULL;
1643 char AllanTitle[] = "Ch? Allan Deviation " ;
1644 double Normalizer = 300e12 ;
1645
1646 switch (event)
1647 {
1648 case EVENT_COMMIT:
1649
1650 GetCtrlVal(MainPanel, control, &BoxChecked);
1651 switch (control) {
1652 case PANEL_CHECKBOX_FREQ1ALLAN :
1653 pAllan = &AllanCh1 ;
1654 Fmt(AllanTitle, "Ch1 Allan Deviation") ;
1655 Normalizer = 1.84e12 ;
1656 break ;
1657 case PANEL_CHECKBOX_FREQ2ALLAN :
1658 pAllan = &AllanCh2 ;
1659 Fmt(AllanTitle, "Ch2 Allan Deviation") ;
1660 Normalizer = 10.e3 ;
1661 break ;
1662 case PANEL_CHECKBOX_FREQ3ALLAN :
1663 pAllan = &AllanCh3 ;
1664 Fmt(AllanTitle, "Ch3 Allan Deviation") ;
1665 Normalizer = 429.228e12 ;
1666 break ;
1667 case PANEL_CHECKBOX_FREQ4ALLAN :
1668 pAllan = &AllanCh4 ;
1669 Fmt(AllanTitle, "Ch4 Allan Deviation") ;
1670 Normalizer = 275.0e3 ;
1671 break ;
1672 case PANEL_CHECKBOX_MATH1ALLAN :
1673 pAllan = &AllanMath1 ;
1674 Fmt(AllanTitle, "Math1 Allan Deviation") ;
1675 Normalizer = 250.0e6 ;
1676 break ;
1677 case PANEL_CHECKBOX_MATH2ALLAN :
1678 pAllan = &AllanMath2 ;
1679 Fmt(AllanTitle, "Math2 Allan Deviation") ;
1680 Normalizer = 194.395e12 ;
1681 break ;
1682 case PANEL_CHECKBOX_MATH3ALLAN :
1683 pAllan = &AllanMath3 ;
1684 Fmt(AllanTitle, "Math3 Allan Deviation") ;
1685 Normalizer = 282.143e12 ;
1686 break ;
1687 case PANEL_CHECKBOX_MATH4ALLAN :
1688 pAllan = &AllanMath4 ;
1689 Fmt(AllanTitle, "Math4 Allan Deviation") ;
1690 Normalizer = 429.228e12 ;
1691 break ;
1692 case PANEL_CHECKBOX_MATH5ALLAN :
1693 pAllan = &AllanMath5 ;
1694 Fmt(AllanTitle, "Math5 Allan Deviation") ;
1695 Normalizer = 429.228e12 ;
1696 break ;
1697 }
1698
1699 if (BoxChecked) {
1700 Allan_InitPanel(pAllan, AllanTitle, Normalizer, &OnCloseViewPanel) ;
1701 }
1702 else {
1703 Allan_ClosePanel(pAllan) ;
1704 } ;
1705 break;
1706
1707 case EVENT_RIGHT_CLICK:
1708
1709 break;
1710
1711 }
1712 return 0;
1713 }
1714
1715 int CVICALLBACK CB_ChangeDDSOut (int panel, int control, int event,
1716 void *callbackData, int eventData1, int eventData2)
1717 {
1718 double Frequency ;
1719
1720 switch (event)
1721 {
1722 case EVENT_COMMIT:
1723 GetCtrlVal(MainPanel, control, &Frequency) ;
1724 if (control==PANEL_DDSFREPOUT) { DDSBes_SetFrequency(&DDSBes, Frequency) ;}
1725 if (control==PANEL_DDS1) { DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency);}
1726 if (control==PANEL_DDS2) { DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, Frequency);}
1727 if (control==PANEL_DDS3) { DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, Frequency);}
1728 if (control==PANEL_DDS4) { DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, Frequency);}
1729 case EVENT_RIGHT_CLICK:
1730
1731 break;
1732
1733 }
1734 return 0;
1735 }
1736
1737 int CVICALLBACK CB_ChangeDDSStep (int panel, int control, int event,
1738 void *callbackData, int eventData1, int eventData2)
1739 {
1740 double Step ;
1741
1742 switch (event)
1743 {
1744 case EVENT_COMMIT:
1745 GetCtrlVal(MainPanel, control, &Step) ;
1746 if (control==PANEL_DDSFREPSTEP) { SetCtrlAttribute(panel, PANEL_DDSFREPOUT, ATTR_INCR_VALUE, Step) ;}
1747 if (control==PANEL_DDS1STEP) { SetCtrlAttribute(panel, PANEL_DDS1, ATTR_INCR_VALUE, Step) ;}
1748 if (control==PANEL_DDS2STEP) { SetCtrlAttribute(panel, PANEL_DDS2, ATTR_INCR_VALUE, Step) ;}
1749 if (control==PANEL_DDS3STEP) { SetCtrlAttribute(panel, PANEL_DDS3, ATTR_INCR_VALUE, Step) ;}
1750 if (control==PANEL_DDS4STEP) { SetCtrlAttribute(panel, PANEL_DDS4, ATTR_INCR_VALUE, Step) ;}
1751 break;
1752 case EVENT_RIGHT_CLICK:
1753
1754 break;
1755
1756 }
1757 return 0;
1758 }
1759
1760 int CVICALLBACK CB_ChangeDDSAmpli (int panel, int control, int event,
1761 void *callbackData, int eventData1, int eventData2)
1762 {
1763 unsigned short int Amplitude ;
1764
1765 switch (event)
1766 {
1767 case EVENT_COMMIT:
1768 GetCtrlVal(MainPanel, control, &Amplitude) ;
1769 if (control==PANEL_DDSFREPAMP) { DDSBes_SetAmplitude(&DDSBes, Amplitude) ;}
1770 case EVENT_RIGHT_CLICK:
1771
1772 break;
1773
1774 }
1775 return 0;
1776 }
1777
1778 int CVICALLBACK CB_ChangeMath (int panel, int control, int event,
1779 void *callbackData, int eventData1, int eventData2)
1780 {
1781
1782 char * MathString = " " ;
1783 // should be long enough for any reasonnable math expression...
1784
1785 switch (event)
1786 {
1787 case EVENT_COMMIT:
1788 GetCtrlVal(panel, control, MathString) ;
1789 if (control==PANEL_MATHSTRING1) { mupSetExpr(MathParser1, MathString) ; }
1790 if (control==PANEL_MATHSTRING2) { mupSetExpr(MathParser2, MathString) ; }
1791 if (control==PANEL_MATHSTRING3) { mupSetExpr(MathParser3, MathString) ; }
1792 if (control==PANEL_MATHSTRING4) { mupSetExpr(MathParser4, MathString) ; }
1793 if (control==PANEL_MATHSTRING5) { mupSetExpr(MathParser5, MathString) ; }
1794 break;
1795 }
1796 return 0;
1797 }
1798
1799 int CVICALLBACK CB_ChangeN (int panel, int control, int event,
1800 void *callbackData, int eventData1, int eventData2)
1801 {
1802
1803 switch (event)
1804 {
1805 case EVENT_COMMIT:
1806 if (control==PANEL_N1CHOICE) GetCtrlVal(MainPanel, control, &N1) ;
1807 if (control==PANEL_N2CHOICE) GetCtrlVal(MainPanel, control, &N2) ;
1808 if (control==PANEL_N3CHOICE) GetCtrlVal(MainPanel, control, &N3) ;
1809 break;
1810 }
1811 return 0;
1812 }
1813
1814 int CVICALLBACK CB_OnPlus275k (int panel, int control, int event,
1815 void *callbackData, int eventData1, int eventData2)
1816 {
1817 double Frequency ;
1818
1819 switch (event)
1820 {
1821 case EVENT_COMMIT:
1822 GetCtrlVal(MainPanel, PANEL_DDSFREPOUT, &Frequency) ;
1823 Frequency += 275000.0 ;
1824 DDSBes_SetFrequency(&DDSBes, Frequency) ;
1825 SetCtrlVal(MainPanel, PANEL_DDSFREPOUT, Frequency) ;
1826 /*SetCtrlVal(MainPanel, PANEL_MATHSTRING1, FREP_NORMAL_FORMULA) ;
1827 mupSetExpr(MathParser1, FREP_NORMAL_FORMULA) ;
1828 SetCtrlVal(MainPanel, PANEL_MATHSTRING2, NUHG_NORMAL_FORMULA) ;
1829 mupSetExpr(MathParser2, NUHG_NORMAL_FORMULA) ;
1830 SetCtrlVal(MainPanel, PANEL_MATHSTRING4, NU813_NORMAL_FORMULA) ;
1831 mupSetExpr(MathParser4, NU813_NORMAL_FORMULA) ;
1832 */
1833 break;
1834 }
1835 return 0;
1836 }
1837
1838 int CVICALLBACK CB_OnMinus275k (int panel, int control, int event,
1839 void *callbackData, int eventData1, int eventData2)
1840 {
1841 double Frequency ;
1842
1843 switch (event)
1844 {
1845 case EVENT_COMMIT:
1846 GetCtrlVal(MainPanel, PANEL_DDSFREPOUT, &Frequency) ;
1847 Frequency -= 275000.0 ;
1848 DDSBes_SetFrequency(&DDSBes, Frequency) ;
1849 SetCtrlVal(MainPanel, PANEL_DDSFREPOUT, Frequency) ;
1850 /*SetCtrlVal(MainPanel, PANEL_MATHSTRING1, "0") ;
1851 mupSetExpr(MathParser1, "0") ;
1852 SetCtrlVal(MainPanel, PANEL_MATHSTRING2, "0") ;
1853 mupSetExpr(MathParser2, "0") ;
1854 SetCtrlVal(MainPanel, PANEL_MATHSTRING4, "0") ;
1855 mupSetExpr(MathParser4, "0") ;
1856 */
1857 break;
1858 }
1859 return 0;
1860 }
1861
1862 int CVICALLBACK CB_OnPlus10k (int panel, int control, int event,
1863 void *callbackData, int eventData1, int eventData2)
1864 {
1865 double Frequency ;
1866
1867 switch (event)
1868 {
1869 case EVENT_COMMIT:
1870 if (control==PANEL_PLUS10KDDS1) {
1871 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency) ;
1872 Frequency += 10000.0 ;
1873 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency);
1874 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency) ;
1875 /*SetCtrlVal(MainPanel, PANEL_MATHSTRING3, NUHG_NORMAL_FORMULA) ;
1876 mupSetExpr(MathParser3, NUHG_NORMAL_FORMULA) ;
1877 */
1878 }
1879 if (control==PANEL_PLUS10KDDS2) {
1880 GetCtrlVal(MainPanel, PANEL_DDS2, &Frequency) ;
1881 Frequency += 10000.0 ;
1882 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, Frequency);
1883 SetCtrlVal(MainPanel, PANEL_DDS2, Frequency) ;
1884 /*SetCtrlVal(MainPanel, PANEL_MATHSTRING3, NUSR_NORMAL_FORMULA) ;
1885 mupSetExpr(MathParser3, NUSR_NORMAL_FORMULA) ;
1886 */
1887 }
1888 if (control==PANEL_PLUS10KDDS3) {
1889 GetCtrlVal(MainPanel, PANEL_DDS3, &Frequency) ;
1890 Frequency += 10000.0 ;
1891 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, Frequency);
1892 SetCtrlVal(MainPanel, PANEL_DDS3, Frequency) ;
1893 }
1894 if (control==PANEL_PLUS10KDDS4) {
1895 GetCtrlVal(MainPanel, PANEL_DDS4, &Frequency) ;
1896 Frequency += 10000.0 ;
1897 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, Frequency);
1898 SetCtrlVal(MainPanel, PANEL_DDS4, Frequency) ;
1899 }
1900 break;
1901 }
1902 return 0;
1903 }
1904
1905 int CVICALLBACK CB_OnMinus10k (int panel, int control, int event,
1906 void *callbackData, int eventData1, int eventData2)
1907 {
1908 double Frequency ;
1909
1910 switch (event)
1911 {
1912 case EVENT_COMMIT:
1913 if (control==PANEL_MINUS10KDDS1) {
1914 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency) ;
1915 Frequency -= 10000.0 ;
1916 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency);
1917 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency) ;
1918 /*SetCtrlVal(MainPanel, PANEL_MATHSTRING3, NUHG_NORMAL_FORMULA) ;
1919 mupSetExpr(MathParser3, NUHG_NORMAL_FORMULA) ;
1920 */
1921 }
1922 if (control==PANEL_MINUS10KDDS2) {
1923 GetCtrlVal(MainPanel, PANEL_DDS2, &Frequency) ;
1924 Frequency -= 10000.0 ;
1925 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, Frequency);
1926 SetCtrlVal(MainPanel, PANEL_DDS2, Frequency) ;
1927 /*SetCtrlVal(MainPanel, PANEL_MATHSTRING3, NUSR_NORMAL_FORMULA) ;
1928 mupSetExpr(MathParser3, NUSR_NORMAL_FORMULA) ;
1929 */
1930 }
1931 if (control==PANEL_MINUS10KDDS3) {
1932 GetCtrlVal(MainPanel, PANEL_DDS3, &Frequency) ;
1933 Frequency -= 10000.0 ;
1934 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, Frequency);
1935 SetCtrlVal(MainPanel, PANEL_DDS3, Frequency) ;
1936 }
1937 if (control==PANEL_MINUS10KDDS4) {
1938 GetCtrlVal(MainPanel, PANEL_DDS4, &Frequency) ;
1939 Frequency -= 10000.0 ;
1940 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, Frequency);
1941 SetCtrlVal(MainPanel, PANEL_DDS4, Frequency) ;
1942 }
1943 break;
1944 }
1945 return 0;
1946 }
1947
1948
1949
1950
1951 int CVICALLBACK CB_OnSaveOpt (int panel, int control, int event,
1952 void *callbackData, int eventData1, int eventData2)
1953 {
1954 bool BoxChecked = FALSE ;
1955
1956 switch (event)
1957 {
1958 case EVENT_COMMIT:
1959
1960 GetCtrlVal(MainPanel, control, &BoxChecked);
1961
1962 if (BoxChecked) {
1963 SetCtrlAttribute(MainPanel, PANEL_CHECKBOX_MATH2AUTOSAV, ATTR_DIMMED, FALSE) ;
1964 }
1965
1966 if (!BoxChecked) {
1967 SetCtrlAttribute(MainPanel, PANEL_CHECKBOX_MATH2AUTOSAV, ATTR_DIMMED, TRUE) ;
1968 }
1969
1970 break;
1971 }
1972 return 0;
1973 }
1974
1975
1976
1977
1978 int CVICALLBACK CB_OnSaveHg (int panel, int control, int event,
1979 void *callbackData, int eventData1, int eventData2)
1980 {
1981 bool BoxChecked = FALSE ;
1982
1983 switch (event)
1984 {
1985 case EVENT_COMMIT:
1986
1987 GetCtrlVal(MainPanel, control, &BoxChecked);
1988
1989 if (BoxChecked) {
1990 SetCtrlAttribute(MainPanel, PANEL_CHECKBOX_MATH3AUTOSAV, ATTR_DIMMED, FALSE) ;
1991 }
1992
1993 if (!BoxChecked) {
1994 SetCtrlAttribute(MainPanel, PANEL_CHECKBOX_MATH3AUTOSAV, ATTR_DIMMED, TRUE) ;
1995 }
1996
1997 break;
1998 }
1999 return 0;
2000 }
2001
2002 int CVICALLBACK CB_OnAutoSaveHg (int panel, int control, int event,
2003 void *callbackData, int eventData1, int eventData2)
2004 {
2005 bool BoxChecked = FALSE ;
2006
2007 switch (event)
2008 {
2009 case EVENT_COMMIT:
2010
2011 GetCtrlVal(MainPanel, control, &BoxChecked);
2012
2013 if (BoxChecked) {
2014 SetCtrlAttribute(MainPanel, PANEL_CHECKBOX_MATH2SAVE, ATTR_DIMMED, TRUE) ;
2015 }
2016
2017 if (!BoxChecked) {
2018 SetCtrlAttribute(MainPanel, PANEL_CHECKBOX_MATH2SAVE, ATTR_DIMMED, FALSE) ;
2019 }
2020
2021 break;
2022 }
2023 return 0;
2024 }
2025
2026 int CVICALLBACK CB_OnSaveSr (int panel, int control, int event,
2027 void *callbackData, int eventData1, int eventData2)
2028 {
2029 bool BoxChecked = FALSE ;
2030
2031 switch (event)
2032 {
2033 case EVENT_COMMIT:
2034
2035 GetCtrlVal(MainPanel, control, &BoxChecked);
2036
2037 if (BoxChecked) {
2038 SetCtrlAttribute(MainPanel, PANEL_CHECKBOX_MATH3AUTOSAV, ATTR_DIMMED, FALSE) ;
2039 }
2040
2041 if (!BoxChecked) {
2042 SetCtrlAttribute(MainPanel, PANEL_CHECKBOX_MATH3AUTOSAV, ATTR_DIMMED, TRUE) ;
2043 }
2044 break;
2045 }
2046 return 0;
2047 }
2048
2049 int CVICALLBACK CB_OnAutoSaveSr (int panel, int control, int event,
2050 void *callbackData, int eventData1, int eventData2)
2051 {
2052 bool BoxChecked = FALSE ;
2053
2054 switch (event)
2055 {
2056 case EVENT_COMMIT:
2057
2058 GetCtrlVal(MainPanel, control, &BoxChecked);
2059
2060 if (BoxChecked) {
2061 SetCtrlAttribute(MainPanel, PANEL_CHECKBOX_MATH3SAVE, ATTR_DIMMED, TRUE) ;
2062 }
2063
2064 if (!BoxChecked) {
2065 SetCtrlAttribute(MainPanel, PANEL_CHECKBOX_MATH3SAVE, ATTR_DIMMED, FALSE) ;
2066 }
2067
2068 break;
2069 }
2070 return 0;
2071 }
2072
2073
2074 int CVICALLBACK OnAcceptN (int panel, int control, int event,
2075 void *callbackData, int eventData1, int eventData2)
2076 {
2077 double N;
2078
2079 switch (event)
2080 {
2081 case EVENT_COMMIT:
2082 if (panel == CalcN1Panel) {
2083 N = floor(N_1);
2084 if (N_1-N<0.5)
2085 {
2086 N1=N;
2087 }
2088 else
2089 {
2090 N1=N+1;
2091 }
2092 SetCtrlVal(MainPanel, PANEL_N1CHOICE, N1) ;
2093 }
2094
2095 if (panel == CalcN2Panel) {
2096 N = floor(N_2);
2097 if (N_2-N<0.5)
2098 {
2099 N2=N;
2100 }
2101 else
2102 {
2103 N2=N+1;
2104 }
2105 SetCtrlVal(MainPanel, PANEL_N2CHOICE, N2) ;
2106 }
2107
2108 if (panel == CalcN3Panel) {
2109 GetCtrlVal(CalcN3Panel, CALCN3_N_3, &N) ;
2110 SetCtrlVal(MainPanel, PANEL_N3CHOICE, N) ;
2111 N3=N;
2112 }
2113 break;
2114 }
2115 return 0;
2116 }
2117
2118 /*int CVICALLBACK OnFSRStep (int panel, int control, int event,
2119 void *callbackData, int eventData1, int eventData2)
2120 {
2121 double Target, FSR ;
2122
2123 switch (event)
2124 {
2125 case EVENT_COMMIT:
2126 if (panel==CalcNHgPanel) {
2127 if (control==CALCNHG_MINUSFSR) {
2128 GetCtrlVal(CalcNHgPanel, CALCNHG_FSR, &FSR) ;
2129 GetCtrlVal(CalcNHgPanel, CALCNHG_TARGET, &Target) ;
2130 Target -= FSR ;
2131 SetCtrlVal(CalcNHgPanel, CALCNHG_TARGET, Target) ;
2132 }
2133 if (control==CALCNHG_PLUSFSR) {
2134 GetCtrlVal(CalcNHgPanel, CALCNHG_FSR, &FSR) ;
2135 GetCtrlVal(CalcNHgPanel, CALCNHG_TARGET, &Target) ;
2136 Target += FSR ;
2137 SetCtrlVal(CalcNHgPanel, CALCNHG_TARGET, Target) ;
2138 }
2139 }
2140 if (panel==CalcNSrPanel) {
2141 if (control==CALCNSR_MINUSFSR) {
2142 GetCtrlVal(CalcNSrPanel, CALCNSR_FSR, &FSR) ;
2143 GetCtrlVal(CalcNSrPanel, CALCNSR_TARGET, &Target) ;
2144 Target -= FSR ;
2145 SetCtrlVal(CalcNSrPanel, CALCNSR_TARGET, Target) ;
2146 }
2147 if (control==CALCNSR_PLUSFSR) {
2148 GetCtrlVal(CalcNSrPanel, CALCNSR_FSR, &FSR) ;
2149 GetCtrlVal(CalcNSrPanel, CALCNSR_TARGET, &Target) ;
2150 Target += FSR ;
2151 SetCtrlVal(CalcNSrPanel, CALCNSR_TARGET, Target) ;
2152 }
2153 }
2154 break;
2155 }
2156 return 0;
2157 } */
2158
2159 /*int CVICALLBACK OnExtrapolateTarget (int panel, int control, int event,
2160 void *callbackData, int eventData1, int eventData2)
2161 {
2162 bool BoxChecked = FALSE ;
2163 double extrapolFreq = 745967614;
2164 time_t utcTime ;
2165 double utc ;
2166
2167 switch (event)
2168 {
2169 case EVENT_COMMIT:
2170 GetCtrlVal(CalcNHgPanel, CALCNHG_EXTRAPOLATE, &BoxChecked) ;
2171 if (BoxChecked) {
2172 SetCtrlAttribute(CalcNHgPanel, CALCNHG_TARGET, ATTR_DIMMED, TRUE) ;
2173 SetCtrlAttribute(CalcNHgPanel, CALCNHG_OFFSETFREQ, ATTR_DIMMED, TRUE) ;
2174 SetCtrlAttribute(CalcNHgPanel, CALCNHG_PLUSFSR, ATTR_DIMMED, TRUE) ;
2175 SetCtrlAttribute(CalcNHgPanel, CALCNHG_MINUSFSR, ATTR_DIMMED, TRUE) ;
2176 utc = time(&utcTime) ;
2177 //extrapolFreq = 746127081 + 0.032*(utc-3491304000) ; // linear data extrapolation with slope from 18/08/2010-12/08/2010
2178 extrapolFreq = 746108328.707542 + 3.144737e-002 * (utc-3490779388.183) - 9.527612e-010 * (utc-3490779388.183) ; // quad extrapol from fit of data in HgCavity.txt 5/10/2010
2179
2180
2181 SetCtrlVal(CalcNHgPanel, CALCNHG_TARGET, extrapolFreq) ;
2182 }
2183 else {
2184 SetCtrlAttribute(CalcNHgPanel, CALCNHG_TARGET, ATTR_DIMMED, FALSE) ;
2185 SetCtrlAttribute(CalcNHgPanel, CALCNHG_OFFSETFREQ, ATTR_DIMMED, FALSE) ;
2186 SetCtrlAttribute(CalcNHgPanel, CALCNHG_PLUSFSR, ATTR_DIMMED, FALSE) ;
2187 SetCtrlAttribute(CalcNHgPanel, CALCNHG_MINUSFSR, ATTR_DIMMED, FALSE) ;
2188 }
2189 break;
2190 }
2191 return 0;
2192 } */
2193
2194
2195 int CVICALLBACK OnChooseSaveFile (int panel, int control, int event,
2196 void *callbackData, int eventData1, int eventData2)
2197 {
2198 switch (event)
2199 {
2200 case EVENT_COMMIT:
2201
2202 FileSelectPopup("D:\\Manip Femto", "*.txt", "*.txt", "Selection of the ExtraMath saving file", VAL_SAVE_BUTTON, 0, 0, 0, FALSE, ExtraMathFileName) ;
2203 SetCtrlAttribute(MainPanel, PANEL_CHECKBOX_MATH5SAVE, ATTR_DIMMED, FALSE) ;
2204
2205 break;
2206 }
2207 return 0;
2208 }
2209
2210
2211 // Changements pour Calcul de N
2212
2213
2214
2215 int CVICALLBACK CB_OnNCalculus (int panel, int control, int event,
2216 void *callbackData, int eventData1, int eventData2)
2217 {
2218
2219 int PanelIsVisible, PanelTop, PanelLeft, PanelWidth ;
2220
2221 switch (event)
2222 {
2223 case EVENT_COMMIT:
2224
2225 if (control==PANEL_N1CALCULUS){
2226 GetPanelAttribute (CalcN1Panel, ATTR_VISIBLE , &PanelIsVisible);
2227 if (PanelIsVisible) {
2228 }
2229 else {
2230 GetPanelAttribute (MainPanel, ATTR_TOP, &PanelTop) ;
2231 GetPanelAttribute (MainPanel, ATTR_LEFT, &PanelLeft) ;
2232 GetPanelAttribute (MainPanel, ATTR_WIDTH, &PanelWidth) ;
2233 SetPanelAttribute (CalcN1Panel, ATTR_TOP, PanelTop+170 ) ;
2234 SetPanelAttribute (CalcN1Panel, ATTR_LEFT, PanelLeft+PanelWidth+4 ) ;
2235 DisplayPanel(CalcN1Panel) ;
2236 }
2237 }
2238 if (control==PANEL_N2CALCULUS){
2239 GetPanelAttribute (CalcN2Panel, ATTR_VISIBLE , &PanelIsVisible);
2240 if (PanelIsVisible) {
2241 }
2242 else {
2243 GetPanelAttribute (MainPanel, ATTR_TOP, &PanelTop) ;
2244 GetPanelAttribute (MainPanel, ATTR_LEFT, &PanelLeft) ;
2245 GetPanelAttribute (MainPanel, ATTR_WIDTH, &PanelWidth) ;
2246 SetPanelAttribute (CalcN2Panel, ATTR_TOP, PanelTop+310 ) ;
2247 SetPanelAttribute (CalcN2Panel, ATTR_LEFT, PanelLeft+PanelWidth+4 ) ;
2248 DisplayPanel(CalcN2Panel) ;
2249 }
2250 }
2251 if (control==PANEL_N3CALCULUS){
2252 GetPanelAttribute (CalcN3Panel, ATTR_VISIBLE , &PanelIsVisible);
2253 if (PanelIsVisible) {
2254 }
2255 else {
2256 GetPanelAttribute (MainPanel, ATTR_TOP, &PanelTop) ;
2257 GetPanelAttribute (MainPanel, ATTR_LEFT, &PanelLeft) ;
2258 GetPanelAttribute (MainPanel, ATTR_WIDTH, &PanelWidth) ;
2259 SetPanelAttribute (CalcN3Panel, ATTR_TOP, PanelTop+480 ) ;
2260 SetPanelAttribute (CalcN3Panel, ATTR_LEFT, PanelLeft+PanelWidth+4 ) ;
2261 DisplayPanel(CalcN3Panel) ;
2262 }
2263 }
2264 break;
2265 }
2266
2267 return 0;
2268 }
2269
2270
2271 int CVICALLBACK CB_OnStartNCalculus (int panel, int control, int event,
2272 void *callbackData, int eventData1, int eventData2)
2273 {
2274
2275 switch (event)
2276 {
2277 case EVENT_COMMIT:
2278 if (control==CALCN1_COMMANDBUTTON)
2279 {
2280 Measuring_1=TRUE;
2281 }
2282 if (control==CALCN2_COMMANDBUTTON)
2283 {
2284 Measuring_2=TRUE;
2285 }
2286 break;
2287 }
2288
2289
2290
2291 return 0;
2292 }
2293
2294 int CVICALLBACK CB_OnStartN3Calculus (int panel, int control, int event,
2295 void *callbackData, int eventData1, int eventData2)
2296 {
2297
2298 switch (event)
2299 {
2300 case EVENT_COMMIT:
2301 Measuring_3=TRUE;
2302 break;
2303 }
2304 return 0;
2305 }
2306
2307
2308 int CVICALLBACK CB_OnNStop (int panel, int control, int event,
2309 void *callbackData, int eventData1, int eventData2)
2310 {
2311 int PanelIsVisible;
2312
2313 switch (event)
2314 {
2315 case EVENT_COMMIT:
2316 //switch (control)
2317 if (control==CALCN1_COMMANDBUTTON_2)
2318 {
2319 GetPanelAttribute (CalcN1Panel, ATTR_VISIBLE , &PanelIsVisible);
2320 if (PanelIsVisible) {
2321 HidePanel(CalcN1Panel) ;
2322 }
2323
2324 Measuring_1=FALSE;
2325 Step1_1=FALSE ;
2326 Step2_1=FALSE ;
2327 Step3_1=FALSE ;
2328 Frepminus_1=0.0;
2329 Frepplus_1=0.0;
2330 t1_1=0.0;
2331 t2_1=0.0;
2332 t3_1=0.0;
2333 N_slope_1=0;
2334 Frequ_slope_1=0.0;
2335 Moy_slope_1=0.0;
2336 Slope_slope_1 =0.0;
2337 Ch4_slope=0.0;
2338 Moy_Ch4slope_1=0.0;
2339 Slope_Ch4slope_1=0.0;
2340 DDSBesChanged1=FALSE;
2341 DDSBesChanged2=FALSE;
2342 nDDSChange=0.0;
2343
2344 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ;
2345 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1);
2346 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit) ;
2347 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit);
2348 nstabilization=0;
2349 }
2350
2351
2352 if (control==CALCN2_STOP2)
2353 {
2354 GetPanelAttribute (CalcN2Panel, ATTR_VISIBLE , &PanelIsVisible);
2355 if (PanelIsVisible) {
2356 HidePanel(CalcN2Panel) ;
2357 }
2358
2359 Measuring_2=FALSE;
2360 Step1_2=FALSE ;
2361 Step2_2=FALSE ;
2362 Step3_2=FALSE ;
2363 Frepminus_2=0.0;
2364 Delta10K_Minus=0.0;
2365 Frepplus_2=0.0;
2366 Delta10K_Plus=0.0;
2367 DeltaDDS3=0.0;
2368 t1_2=0.0;
2369 t2_2=0.0;
2370 t3_2=0.0;
2371 N_slope_2=0;
2372 Frequ_slope_2=0.0;
2373 Moy_slope_2=0.0;
2374 Beat_slope_2=0.0;
2375 Moy_Beatslope_2=0.0;
2376 Slope_Beatslope_2 =0.0;
2377 Slope_slope_2 =0.0;
2378 DDSBesChanged1=FALSE;
2379 DDSBesChanged2=FALSE;
2380 nDDSChange=0.0;
2381 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ;
2382 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1);
2383 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit) ;
2384 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit);
2385 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init) ;
2386 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyDDS3Init);
2387 nstabilization=0;
2388 }
2389
2390
2391 break;
2392 }
2393 return 0;
2394 }
2395
2396 int CVICALLBACK CB_OnN3Stop (int panel, int control, int event,
2397 void *callbackData, int eventData1, int eventData2)
2398 {
2399 int PanelIsVisible;
2400
2401 switch (event)
2402 {
2403 case EVENT_COMMIT:
2404 GetPanelAttribute (CalcN3Panel, ATTR_VISIBLE , &PanelIsVisible);
2405 if (PanelIsVisible) {
2406 HidePanel(CalcN3Panel) ;
2407 }
2408
2409 Measuring_3=FALSE;
2410 Step1_3=FALSE ;
2411 Step2_3=FALSE ;
2412 Step3_3=FALSE ;
2413 Frepminus_3=0.0;
2414 Frepplus_3=0.0;
2415 t1_3=0.0;
2416 t2_3=0.0;
2417 t3_3=0.0;
2418 N_slope_3=0;
2419 Frequ_slope_3=0.0;
2420 Moy_slope_3=0.0;
2421 Slope_slope_3 =0.0;
2422 break;
2423 }
2424 return 0;
2425 }
2426
2427
2428 int CVICALLBACK CB_OnIntegrationTime (int panel, int control, int event,
2429 void *callbackData, int eventData1, int eventData2)
2430 {
2431 double Time ;
2432
2433 switch (event)
2434 {
2435 case EVENT_COMMIT:
2436 if (control==CALCN1_INTEGRATIONTIME){
2437 GetCtrlVal(CalcN1Panel, CALCN1_INTEGRATIONTIME, &Time) ;
2438 DeltaT_1=Time;
2439 }
2440 if (control==CALCN2_INTEGRATIONTIME){
2441 GetCtrlVal(CalcN2Panel, CALCN2_INTEGRATIONTIME, &Time) ;
2442 DeltaT_2=Time;
2443 }
2444 if (control==CALCN3_INTEGRATIONTIME){
2445 GetCtrlVal(CalcN3Panel, CALCN3_INTEGRATIONTIME, &Time) ;
2446 DeltaT_3=Time;
2447 }
2448
2449 break;
2450
2451 }
2452 return 0;
2453 }
2454
2455
2456 int CVICALLBACK CB_OnDeltaFreq (int panel, int control, int event,
2457 void *callbackData, int eventData1, int eventData2)
2458 {
2459 double Frequ ;
2460
2461 switch (event)
2462 {
2463 case EVENT_COMMIT:
2464 if (control==CALCN1_DELTAFREQ){
2465 GetCtrlVal(CalcN1Panel, CALCN1_DELTAFREQ, &Frequ) ;
2466 DeltakHz_1=Frequ;
2467 }
2468 if (control==CALCN2_DELTAFREQ){
2469 GetCtrlVal(CalcN2Panel, CALCN2_DELTAFREQ, &Frequ) ;
2470 DeltakHz_2=Frequ;
2471 }
2472 if (control==CALCN3_DELTAFREQ){
2473 GetCtrlVal(CalcN3Panel, CALCN3_DELTAFREQ, &Frequ) ;
2474 DeltakHz_3=Frequ;
2475 }
2476
2477 break;
2478
2479 }
2480 return 0;
2481 }
2482
2483
2484 int CVICALLBACK CB_OnFindSign (int panel, int control, int event,
2485 void *callbackData, int eventData1, int eventData2)
2486 {
2487
2488 switch (event)
2489 {
2490 case EVENT_COMMIT:
2491 if (control==PANEL_FINDSIGN1){
2492 tbegin1=utc;
2493 Frepbefore1=Math1;
2494 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency1) ;
2495 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency1+Frequencystep1) ;
2496 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency1+Frequencystep1);
2497 Getsign1=TRUE;
2498 }
2499 if (control==PANEL_FINDSIGN2){
2500 tbegin2=utc;
2501 Frepbefore2=Math1;
2502 Ch2before=Ch2;
2503 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency2) ;
2504 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency2+Frequencystep2) ;
2505 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency2+Frequencystep2);
2506 Getsign2=TRUE;
2507 }
2508 if (control==PANEL_FINDSIGN3){
2509 tbegin3=utc;
2510 Frepbefore3=Ch1;
2511 GetCtrlVal(MainPanel, PANEL_DDS3, &Frequency3) ;
2512 SetCtrlVal(MainPanel, PANEL_DDS3, Frequency3+Frequencystep3) ;
2513 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, Frequency3+Frequencystep3);
2514 Getsign3=TRUE;
2515 }
2516
2517
2518 break;
2519
2520 }
2521 return 0;
2522 }
2523
2524
2525
2526 int CVICALLBACK CB_OnFind275K (int panel, int control, int event,
2527 void *callbackData, int eventData1, int eventData2)
2528 {
2529
2530
2531 double FrequencyToChange,DeltaCh4,DeltaCh2;
2532
2533 DeltaCh4=275000-Ch4;
2534 DeltaCh2=10000-Ch2;
2535
2536 switch (event)
2537 {
2538 case EVENT_COMMIT:
2539 if (control==PANEL_FIND275K2){
2540 GetCtrlVal(MainPanel, PANEL_DDS2, &FrequencyToChange) ;
2541 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyToChange+DeltaCh4) ;
2542 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyToChange+DeltaCh4);
2543
2544 }
2545
2546 if (control==PANEL_FIND10K3){
2547 GetCtrlVal(MainPanel, PANEL_DDS3, &FrequencyToChange) ;
2548 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyToChange+DeltaCh2) ;
2549 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyToChange+DeltaCh2);
2550
2551 }
2552
2553 break;
2554
2555 }
2556 return 0;
2557 }
2558
2559
2560 int CVICALLBACK CB_OnSlopeTime (int panel, int control, int event,
2561 void *callbackData, int eventData1, int eventData2)
2562 {
2563 double Time ;
2564
2565 switch (event)
2566 {
2567 case EVENT_COMMIT:
2568 if (control==CALCN1_SLOPETIME){
2569 GetCtrlVal(CalcN1Panel, CALCN1_SLOPETIME, &Time) ;
2570 SlopeTime1=Time;
2571 }
2572
2573 if (control==CALCN2_SLOPETIME){
2574 GetCtrlVal(CalcN2Panel, CALCN2_SLOPETIME, &Time) ;
2575 SlopeTime2=Time;
2576 }
2577
2578 break;
2579
2580 }
2581 return 0;
2582 }
2583
2584
2585 int CVICALLBACK CB_OnChangeNdiv (int panel, int control, int event,
2586 void *callbackData, int eventData1, int eventData2)
2587 {
2588 double NewN ;
2589
2590 switch (event)
2591 {
2592 case EVENT_COMMIT:
2593 if (control==PANEL_CHANGENDIV){
2594 GetCtrlVal(MainPanel, PANEL_CHANGENDIV, &NewN) ;
2595 Ndiv=NewN;
2596 FrequDDS1=880000000.0/Ndiv;
2597 DeltakHz_1=1800.0*8/Ndiv;
2598 DeltakHz_2=1500.0*8/Ndiv;
2599 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ;
2600 DDS4xAD9912_SetFrequency(&DDS4xAD9912,1,FrequDDS1);
2601 SetCtrlVal(CalcN1Panel, CALCN1_DELTAFREQ, DeltakHz_1) ;
2602 SetCtrlVal(CalcN2Panel, CALCN2_DELTAFREQ, DeltakHz_2) ;
2603 }
2604
2605 break;
2606
2607 }
2608 return 0;
2609 }
2610
2611
2612 int CVICALLBACK CB_OnStartSlopeCancelling (int panel, int control, int event,
2613 void *callbackData, int eventData1, int eventData2)
2614 {
2615
2616 double ActualFrequ=0.0;
2617 double ActualSlope=0.0;
2618 int buttonstatu=0;
2619
2620 switch (event)
2621 {
2622 case EVENT_COMMIT:
2623 if (control==PANEL_STARTCANCEL){
2624
2625 GetCtrlVal(MainPanel, PANEL_STARTCANCEL, &buttonstatu) ;
2626
2627 if (buttonstatu==1)
2628 {
2629 SlopeMeasuringTimeBegin=utc;
2630 SlopeMeasuring=TRUE;
2631 ActualFrequ=ReadDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate);
2632 ActualSlope= SlopeMath2;
2633 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,ActualFrequ,ActualSlope,0);
2634 Nratio=-1;
2635 CenterFrequencyCh2ToDetermine=TRUE ;
2636 CenterFrequencyCh2=0.0;
2637
2638 }
2639 else
2640 {
2641 if (KeepFrequ==TRUE) {ActualFrequ=ReadDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate);}
2642 else { ActualFrequ= DDSFoxFrequency;}
2643 if (KeepSlope==TRUE) {ActualSlope= SlopeMath2;
2644 OnSlopeCancelling =TRUE; }
2645 else { ActualSlope= DDSFoxSweeprate;
2646 OnSlopeCancelling =FALSE; }
2647 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,ActualFrequ,ActualSlope,0);
2648 SlopeMeasuring=FALSE;
2649 OnOffMessage="OFF " ;
2650 N_Math2slope=0.0;
2651 Math2_slope=0.0;
2652 Moy_Math2slope=0.0;
2653 Slope_Math2slope=0.0;
2654 MoyMath2=0.0;
2655 Slope_Math2slope=0.0;
2656 CenterFrequencyCh2= 0.0;
2657 Nratio=-1;
2658 nstabilisationSlopeMeasuring=0;
2659 }
2660 }
2661
2662 break;
2663
2664 }
2665 return 0;
2666 }
2667
2668
2669 int CVICALLBACK CB_OnResetSlope (int panel, int control, int event,
2670 void *callbackData, int eventData1, int eventData2)
2671 {
2672
2673 switch (event)
2674 {
2675 case EVENT_COMMIT:
2676 if (control==PANEL_RESETSLOPE){
2677
2678 SlopeMath2=0.0;
2679 CenterFrequencyCh2=0.0;
2680 MoyMath2=0.0;
2681 Nratio=-1;
2682 CenterFrequencyCh2ToDetermine=TRUE ;
2683 OnSlopeCancelling =FALSE;
2684 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate,0);
2685 }
2686
2687 break;
2688
2689 }
2690 return 0;
2691 }
2692
2693
2694 int CVICALLBACK CB_ChangeSlopeTime (int panel, int control, int event,
2695 void *callbackData, int eventData1, int eventData2)
2696 {
2697
2698 switch (event)
2699 {
2700 case EVENT_COMMIT:
2701 if (control==PANEL_SLOPETIME){
2702
2703 GetCtrlVal(MainPanel, PANEL_SLOPETIME, &TimetoSlope);
2704 }
2705
2706 break;
2707
2708 }
2709 return 0;
2710 }
2711
2712
2713 int LaunchDDSFOX (char *Name,char *ip,int Port,unsigned int Profil,double Clock,double DeltaT,double Frequency,double Sweeprate,int mode)
2714 {
2715 //mode =0 pour normal
2716 //mode =1 pour reset
2717 DDSParameter DDSState;
2718 strcpy(DDSState.Name ,Name) ;
2719 DDSState.Profil = Profil ;
2720 strcpy(DDSState.ip,ip) ;
2721 DDSState.Port = Port;
2722 DDSState.Clock = Clock;
2723 DDSState.Delta_T = DeltaT;
2724 DDSState.Frequency = Frequency;
2725 DDSState.SweepRate = Sweeprate ;
2726 if (mode == 1) { DDS_Initialize (&DDSState) ; }
2727 else { DDS_ReInitialize (&DDSState) ; }
2728
2729 return 0;
2730 }
2731
2732 double ReadDDSFOX (char *Name,char *ip,int Port,unsigned int Profil,double Clock,double DeltaT,double Frequency,double Sweeprate)
2733 {
2734
2735 DDSParameter DDSState;
2736 double FrequDDSFox;
2737
2738 strcpy(DDSState.Name ,Name) ;
2739 DDSState.Profil = Profil ;
2740 strcpy(DDSState.ip,ip) ;
2741 DDSState.Port = Port;
2742 DDSState.Clock = Clock;
2743 DDSState.Delta_T = DeltaT;
2744 DDSState.Frequency = Frequency;
2745 DDSState.SweepRate = Sweeprate ;
2746
2747 FrequDDSFox=DDSFox_ReadFreq(&DDSState);
2748
2749
2750 return FrequDDSFox;
2751 }
2752
2753
2754 int CVICALLBACK CB_OnCROX (int panel, int control, int event,
2755 void *callbackData, int eventData1, int eventData2)
2756 {
2757 bool BoxChecked = FALSE;
2758 double ActualFrequ=0.0;
2759
2760 switch (event)
2761 {
2762 case EVENT_COMMIT:
2763
2764 if (control== PANEL_CHECKBOX_CORRFREQU)
2765 {
2766 GetCtrlVal(MainPanel, PANEL_CHECKBOX_CORRFREQU, &BoxChecked) ;
2767 if (BoxChecked) {
2768 FrequCorrec=TRUE ;
2769 }
2770 else {FrequCorrec=FALSE ;}
2771
2772 }
2773
2774 if (control== PANEL_CHECKBOX_KEEP)
2775 {
2776 GetCtrlVal(MainPanel, PANEL_CHECKBOX_KEEP, &BoxChecked) ;
2777 if (BoxChecked) {
2778 KeepFrequ=TRUE ;
2779 }
2780 else {KeepFrequ=FALSE ;}
2781
2782 }
2783
2784
2785 if (control== PANEL_CHECKBOX_KEEPSLOPE)
2786 {
2787 GetCtrlVal(MainPanel, PANEL_CHECKBOX_KEEPSLOPE, &BoxChecked) ;
2788 if (BoxChecked) {
2789 KeepSlope=TRUE ;
2790 if (SlopeMeasuring==FALSE && OnSlopeCancelling==FALSE)
2791 {
2792 ActualFrequ=ReadDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate);
2793 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,ActualFrequ,SlopeMath2,0);
2794 OnSlopeCancelling=TRUE;
2795
2796
2797 }
2798 }
2799 else {KeepSlope=FALSE ;
2800 if (SlopeMeasuring==FALSE && OnSlopeCancelling==TRUE)
2801 {
2802 ActualFrequ=ReadDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,DDSFoxFrequency,DDSFoxSweeprate);
2803 LaunchDDSFOX (DDSFoxName,DDSFoxip,DDSFoxPort,DDSFoxProfil,DDSFoxClock,DDSFoxDeltaT,ActualFrequ,DDSFoxSweeprate,0);
2804 OnSlopeCancelling=FALSE;
2805 }
2806
2807 }
2808
2809 }
2810
2811 break;
2812
2813 }
2814 return 0;
2815 }
2816
2817
2818
2819 int CVICALLBACK CB_OnReCentering (int panel, int control, int event,
2820 void *callbackData, int eventData1, int eventData2)
2821 {
2822 bool BoxChecked = FALSE;
2823
2824 switch (event)
2825 {
2826 case EVENT_COMMIT:
2827
2828 if (control== PANEL_CHECKBOX_RECENTER)
2829 {
2830 GetCtrlVal(MainPanel, PANEL_CHECKBOX_RECENTER, &BoxChecked) ;
2831 if (BoxChecked) {
2832 KeepCentering=TRUE ;
2833 CenteringTimeBegin275K=utc;
2834 CenteringTimeBegin10K=utc;
2835 }
2836 else {KeepCentering=FALSE ;}
2837
2838 }
2839
2840
2841 break;
2842
2843 }
2844 return 0;
2845 }
2846
2847
2848 int CVICALLBACK CB_OnAutoStopSlopeCancellingIfDelock (int panel, int control, int event,
2849 void *callbackData, int eventData1, int eventData2)
2850 {
2851 bool BoxChecked = FALSE;
2852 double ActualFrequ=0.0;
2853
2854 switch (event)
2855 {
2856 case EVENT_COMMIT:
2857
2858 if (control== PANEL_CHECKBOX_STOPIFAUTODE)
2859 {
2860 GetCtrlVal(MainPanel, PANEL_CHECKBOX_STOPIFAUTODE, &BoxChecked) ;
2861 if (BoxChecked) {
2862 AutoStopSlopeCancellingIfDelock=TRUE ;
2863 }
2864 else {AutoStopSlopeCancellingIfDelock=FALSE ;}
2865
2866 }
2867
2868
2869 break;
2870
2871 }
2872 return 0;
2873 }