comparison FXAnalyse.c @ 17:9cadd12e7722

Implement N3 measurement. Large code cleanup.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Wed, 18 Jul 2012 18:48:36 +0200
parents 783407954cdf
children 3a7f088d4960
comparison
equal deleted inserted replaced
16:9d57d1fcbcd5 17:9cadd12e7722
2 #include <ansi_c.h> 2 #include <ansi_c.h>
3 #include <cvirte.h> 3 #include <cvirte.h>
4 #include <userint.h> 4 #include <userint.h>
5 #include <formatio.h> 5 #include <formatio.h>
6 #include <string.h> 6 #include <string.h>
7 #include <future.h>
7 8
8 #include "YLCStuff.h" 9 #include "YLCStuff.h"
9 #include "FXAnalyse.h" 10 #include "FXAnalyse.h"
10 #include "Plot.h" 11 #include "Plot.h"
11 #include "Allan.h" 12 #include "Allan.h"
39 /* panel handling stuff */ 40 /* panel handling stuff */
40 static PanelHandle MainPanel ; 41 static PanelHandle MainPanel ;
41 static PanelHandle CalcN1Panel ; 42 static PanelHandle CalcN1Panel ;
42 static PanelHandle CalcN2Panel ; 43 static PanelHandle CalcN2Panel ;
43 static PanelHandle CalcN3Panel ; 44 static PanelHandle CalcN3Panel ;
45 static PanelHandle EstimateN3Panel;
44 46
45 //============================================================================== 47 //==============================================================================
46 // Static functions 48 // Static functions
47 49
48 //static int CVICALLBACK ReadCounterThread(void *functionData); // to be used when I will replace timer by thread for counder readout 50 //static int CVICALLBACK ReadCounterThread(void *functionData); // to be used when I will replace timer by thread for counder readout
56 double utc = 0 ; 58 double utc = 0 ;
57 double mjd =0 ; 59 double mjd =0 ;
58 60
59 double Ch1, Ch2, Ch3, Ch4 ; // le type long double est identique au double (8 octets) sous CVI !!! 61 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... 62 double Math1, Math2, Math3, Math4, Math5; // N est en fait un entier en pratique...
61 double N1, N2, N3,N4 ; 63 double N1, N2, N3, N4 ;
62 64
63 Plot_Data PlotCh1, PlotCh2, PlotCh3, PlotCh4, PlotMath1, PlotMath2, PlotMath3, PlotMath4, PlotMath5 ; 65 Plot_Data PlotCh1, PlotCh2, PlotCh3, PlotCh4, PlotMath1, PlotMath2, PlotMath3, PlotMath4, PlotMath5 ;
64 Allan_Data AllanCh1, AllanCh2, AllanCh3, AllanCh4, AllanMath1, AllanMath2, AllanMath3, AllanMath4, AllanMath5 ; 66 Allan_Data AllanCh1, AllanCh2, AllanCh3, AllanCh4, AllanMath1, AllanMath2, AllanMath3, AllanMath4, AllanMath5 ;
65 67
66 DDSBes_Data DDSBes ; 68 DDSBes_Data DDSBes ;
75 double NuOpt=0.0; 77 double NuOpt=0.0;
76 double Ndiv=8.0; 78 double Ndiv=8.0;
77 79
78 /////////////////// 80 ///////////////////
79 //Pour les calculs des N 81 //Pour les calculs des N
82
83 enum {
84 N_MEASUREMENT_STEP_0,
85 N_MEASUREMENT_STEP_1,
86 N_MEASUREMENT_STEP_2,
87 N_MEASUREMENT_STEP_3,
88 N_MEASUREMENT_STEP_4,
89 };
90
91 int settling = 0;
80 92
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; 93 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; 94 volatile bool Measuring_3 = FALSE,Step1_3 = FALSE,Step2_3 = FALSE,Step3_3 = FALSE;
83 volatile bool TimetoBegin=FALSE; 95 volatile bool TimetoBegin=FALSE;
84 96
85 double FrequDDS1=110000000.0,FrequDDS2=15300000.0,FrequDDS3=150400000.000000; 97 double FrequDDS1=110000000.0, FrequDDS2=15300000.0, FrequDDS3=150400000.0, FrequDDS4=110000000.0;
86 double Slope_1=0.0,Slope_2=0.0,Slope_3=0.0,Beatslope_2=0.0; 98 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; 99 double SlopeTime1=40.0, SlopeTime2=40.0; SlopeTime3=40.0;
88 100
89 double N_1=0.0,N_2=0.0,N_3=0.0; 101 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; 102 double DeltaT_1=20.0, DeltakHz_1=500.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; 103 double DeltaT_2=20.0, DeltakHz_2=500.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; 104 double DeltaT_3=20.0, DeltakHz_3=500.0, t1_3=0.0, t2_3=0.0, t3_3=0.0, Frepplus_3=0.0, Frepminus_3=0.0;
93 105
94 106
95 int DeltaTMoy_1=3,n_1=0,DeltaTMoy_2=3,n_2=0,DeltaTMoy_3=3,n_3=0; 107 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; 108 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; 109 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;
109 121
110 double Step1=800000.0,Step2=800000.0; 122 double Step1=800000.0,Step2=800000.0;
111 123
112 double Ch4Plus=0.0,Ch4Minus=0.0; 124 double Ch4Plus=0.0,Ch4Minus=0.0;
113 125
114 int NDEJAPASSE=0, nDDSChange=0, nstabilization=0 ; 126 int NDEJAPASSE=0, nDDSChange=0, nstabilization=0;
115 127
116 ////// 128 //////
117 //Pour les signes de fb 129 //Pour les signes de fb
118 130
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; 131 double Frequencystep1=10000.0, tbegin1=0.0, Frepbefore1=0.0, Frequency1=0.0;
132 double Frequencystep2=10.0, tbegin2=0.0, Frepbefore2=0.0, Ch2before=0.0, Frequency2=0.0;
133 double Frequencystep3=100000.0, tbegin3=0.0, Frepbefore3=0.0, Frequency3=0.0;
134
120 volatile bool Getsign1=FALSE,Getsign2=FALSE,Getsign3=FALSE; 135 volatile bool Getsign1=FALSE,Getsign2=FALSE,Getsign3=FALSE;
121 double Signe1=1.0,Signe2=1.0,Signe3=0.0; 136 double Signe1=1.0,Signe2=1.0,Signe3=0.0;
122 137
123 138
124 139
245 if ((CalcN1Panel = LoadPanel (0, "FXAnalyse.uir", CALCN1)) < 0) 260 if ((CalcN1Panel = LoadPanel (0, "FXAnalyse.uir", CALCN1)) < 0)
246 return -1; 261 return -1;
247 if ((CalcN2Panel = LoadPanel (0, "FXAnalyse.uir", CALCN2)) < 0) 262 if ((CalcN2Panel = LoadPanel (0, "FXAnalyse.uir", CALCN2)) < 0)
248 return -1; 263 return -1;
249 if ((CalcN3Panel = LoadPanel (0, "FXAnalyse.uir", CALCN3)) < 0) 264 if ((CalcN3Panel = LoadPanel (0, "FXAnalyse.uir", CALCN3)) < 0)
265 return -1;
266 if ((EstimateN3Panel = LoadPanel (MainPanel, "FXAnalyse.uir", ESTIMATEN3)) < 0)
250 return -1; 267 return -1;
251 268
252 DisplayPanel (MainPanel); 269 DisplayPanel (MainPanel);
253 270
254 // Initialize LogFileName pointer 271 // Initialize LogFileName pointer
1177 } 1194 }
1178 } 1195 }
1179 } 1196 }
1180 } 1197 }
1181 1198
1182 1199 switch (Measuring_3) {
1200
1201 case N_MEASUREMENT_STEP_0:
1202 // not measuring N3
1203 break;
1183 1204
1184 /* if (Measuring_3==TRUE) 1205 case N_MEASUREMENT_STEP_1: // init
1185 { 1206
1186 if (Step1_3==FALSE) { 1207 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4);
1187 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequDDS3); 1208 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4);
1188 t1_3=utc; 1209 settling = 3;
1189 Frequ_slope_3=Math1; 1210
1190 Moy_slope_3= Frequ_slope_3; 1211 t1_3 = utc;
1191 N_slope_3=1; 1212 N_slope_3 = 0;
1192 Step1_3=TRUE ; 1213 // record current DDS3 frequency
1193 } 1214 GetCtrlVal(MainPanel, PANEL_DDS3, &FrequencyDDS3Init);
1194 else { 1215
1195 if(Step2_3==FALSE){ 1216 // step 1 done
1196 N_slope_3=N_slope_3+1; 1217 Measuring_3 = N_MEASUREMENT_STEP_2;
1197 Frequ_slope_3=Math1; 1218 break;
1198 Moy_slope_3=((N_slope_3-1)*Moy_slope_3 + Frequ_slope_3)/N_slope_3; 1219
1199 Slope_slope_3 = (Slope_slope_3*(N_slope_3-2) + 6*(Frequ_slope_3-Moy_slope_3)/N_slope_3)/(N_slope_3+1) ; 1220 case N_MEASUREMENT_STEP_2: // slope measurement
1200 if (utc-t1_3>DeltaT_3) { 1221
1201 Slope_3 = Slope_slope_3; 1222 if (settling > 0) {
1202 GetCtrlVal(MainPanel, PANEL_DDSFREPOUT, &FrequencyDDSBes) ; 1223 settling--;
1203 DDSBes_SetFrequency(&DDSBes, FrequencyDDSBes+(FACTORDDSBES*DeltakHz_3*1000)); 1224 break;
1204 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequDDS3+DeltakHz_3*1000);
1205 t2_3=utc;
1206 Step2_3=TRUE ;
1207 N_slope_3=0;
1208 Frequ_slope_3=0.0;
1209 Moy_slope_3=0.0;
1210 Slope_slope_3 =0.0;
1211 }
1212 }
1213 else {
1214 if(Step2_3==FALSE){
1215 if (utc-t2_3<DeltaT_3) {
1216 Frepplus_3=Frepplus_3 +Math1+250000000-Slope_3*(utc-t2_3);
1217 n_3=n_3+1;
1218 }
1219 else{
1220 Frepplus_3=Frepplus_3/n_3;
1221 DDSBes_SetFrequency(&DDSBes, FrequencyDDSBes-(FACTORDDSBES*DeltakHz_3*1000));
1222 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequDDS3-DeltakHz_3*1000);
1223 n_3=0;
1224 t3_3=utc;
1225 Step3_3=TRUE ;
1226 }
1227 }
1228 else {
1229 if (utc-t3_3<DeltaT_3) {
1230 Frepminus_3=Frepminus_3 +Math1+250000000-Slope_3*(utc-t3_3);
1231 n_3=n_3+1;
1232 }
1233 else{
1234 Frepminus_3=Frepminus_3/(n_3);
1235 N_3 = (16*DeltakHz_3*1000 -Slope_3*(t3_3-t2_3))/(Frepplus_3-Frepminus_3);
1236 n_3=0;
1237 Frepminus_3=0.0;
1238 Frepplus_3=0.0;
1239 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequDDS3);
1240 Measuring_2=FALSE ;
1241 Step1_3=FALSE ;
1242 Step2_3=FALSE ;
1243 Step3_3=FALSE ;
1244 t1_3=0.0;
1245 t2_3=0.0;
1246 t3_3=0.0;
1247 }
1248 }
1249 }
1250 } 1225 }
1251 } */ 1226
1252 1227 N_slope_3++;
1253 1228 Frequ_slope_3 = Ch2;
1254 1229 Moy_slope_3 = ((N_slope_3-1)*Moy_slope_3 + Frequ_slope_3)/N_slope_3;
1255 1230 Slope_slope_3 = (Slope_slope_3*(N_slope_3-2) + 6*(Frequ_slope_3-Moy_slope_3)/N_slope_3)/(N_slope_3+1) ;
1231
1232 if (utc - t1_3 > SlopeTime3) {
1233 // slope measurement
1234 Slope_3 = Slope_slope_3;
1235
1236 t2_3 = utc;
1237 N_slope_3 = 0;
1238 Frequ_slope_3 = 0.0;
1239 Moy_slope_3 = 0.0;
1240 Slope_slope_3 = 0.0;
1241
1242 // step 2 done
1243 Measuring_3 = N_MEASUREMENT_STEP_3;
1244
1245 // frep positive step
1246 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4 + DeltakHz_3 * 1000);
1247 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4 + DeltakHz_3 * 1000);
1248 // compensate with DDS3 to keep measured beatnote in counter box range
1249 double fDDS3 = FrequencyDDS3Init + N3/N1 * DeltakHz_3;
1250 SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3);
1251 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3);
1252 // allow counter to settle
1253 settling = 3;
1254 }
1255 break;
1256
1257 case N_MEASUREMENT_STEP_3: // frep positive step
1258
1259 if (settling > 0) {
1260 settling--;
1261 break;
1262 }
1263
1264 n_3++;
1265 Frepplus_3 += Ch2 - Slope_3 * (utc - t2_3);
1266
1267 if (utc - t2_3 > DeltaT_3) {
1268 // positive step measurement
1269 Frepplus_3 = Frepplus_3 / n_3;
1270
1271 n_3 = 0;
1272 t3_3 = utc;
1273
1274 // step 3 done
1275 Measuring_3 = N_MEASUREMENT_STEP_4;
1276
1277 // frep negative step
1278 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4 - DeltakHz_3 * 1000);
1279 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4 - DeltakHz_3 * 1000);
1280 // compensate with DDS3 to keep measured beatnote in counter box range
1281 double fDDS3 = FrequencyDDS3Init - N3/N1 * DeltakHz_3;
1282 SetCtrlVal(MainPanel, PANEL_DDS3, fDDS3);
1283 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, fDDS3);
1284 // allow counter to settle
1285 settling = 3;
1286 }
1287 break;
1288
1289
1290 case N_MEASUREMENT_STEP_4: // frep negative step
1291
1292 if (settling > 0) {
1293 settling--;
1294 break;
1295 }
1296
1297 n_3++;
1298 Frepminus_3 += Ch2 - Slope_3 * (utc - t3_3);
1299
1300 if (utc - t3_3 > DeltaT_3) {
1301 // positive step measurement
1302 Frepminus_3 = Frepminus_3 / n_3;
1303
1304 // compute N3
1305 N_3 = 1000.0 * DeltakHz_3 / (Frepplus_3 - Frepminus_3);
1306 SetCtrlVal(CalcN3Panel, CALCN3_N_3, N_3);
1307
1308 t1_3=0.0;
1309 t2_3=0.0;
1310 t3_3=0.0;
1311 n_3 = 0;
1312 Frepminus_3 = 0.0;
1313 Frepplus_3 = 0.0;
1314
1315 // step 4 done
1316 Measuring_3 = N_MEASUREMENT_STEP_0;
1317
1318 // back to nominal frep
1319 SetCtrlVal(MainPanel, PANEL_DDS4, FrequDDS4);
1320 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, FrequDDS4);
1321 }
1322 break;
1323 }
1256 1324
1257 // Calcul du signe de fb 1325 // Calcul du signe de fb
1258 1326
1259 if (Getsign1 ==TRUE) { 1327 if (Getsign1 == TRUE) {
1260 if (utc> tbegin1+2){ 1328 if (utc > tbegin1+2) {
1261 if (Math1> Frepbefore1) { Signe1=-1.0;} 1329 if (Math1 > Frepbefore1)
1262 else {Signe1=1.0;} 1330 Signe1 = -1.0;
1331 else
1332 Signe1 = +1.0;
1263 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency1) ; 1333 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency1) ;
1264 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency1); 1334 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency1);
1265 Getsign1=FALSE; 1335 Getsign1 = FALSE;
1266 } 1336 }
1267 } 1337 }
1268 if (Getsign2 ==TRUE) { 1338 if (Getsign2 == TRUE) {
1269 if (utc> tbegin2+2){ 1339 if (utc > tbegin2+2){
1270 if (Math1> Frepbefore2) { 1340 if (Math1 > Frepbefore2) {
1271 if (Ch2>Ch2before) {Signe2=+1.0;} 1341 if (Ch2 > Ch2before)
1272 else {Signe2=-1.0;} 1342 Signe2 = +1.0;
1273 } 1343 else
1274 else { 1344 Signe2 = -1.0;
1275 if (Ch2>Ch2before) {Signe2=-1.0;} 1345 } else {
1276 else {Signe2=+1.0;} 1346 if (Ch2 > Ch2before)
1347 Signe2 = -1.0;
1348 else
1349 Signe2 = +1.0;
1277 } 1350 }
1278 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency2) ; 1351 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency2) ;
1279 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency2); 1352 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency2);
1280 Getsign2=FALSE; 1353 Getsign2 = FALSE;
1281 } 1354 }
1282 } 1355 }
1283 if (Getsign3 ==TRUE) { 1356 if (Getsign3 == TRUE) {
1284 if (utc> tbegin3+2){ 1357 if (utc > tbegin3+2){
1285 if (Ch1> Frepbefore3) { Signe3=-1.0;} 1358 if (Ch3 > Frepbefore3)
1286 else {Signe3=1.0;} 1359 Signe3 = -1.0;
1360 else
1361 Signe3 = +1.0;
1287 SetCtrlVal(MainPanel, PANEL_DDS3, Frequency3) ; 1362 SetCtrlVal(MainPanel, PANEL_DDS3, Frequency3) ;
1288 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, Frequency3); 1363 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, Frequency3);
1289 Getsign3=FALSE; 1364 Getsign3 = FALSE;
1290 } 1365 }
1291 } 1366 }
1292 1367
1293 1368
1294 1369
1295 1370
1296 /* 1371 /*
2083 } 2158 }
2084 return 0; 2159 return 0;
2085 } 2160 }
2086 2161
2087 2162
2088 int CVICALLBACK OnAcceptN (int panel, int control, int event, 2163 int CVICALLBACK CB_OnAcceptN (int panel, int control, int event,
2089 void *callbackData, int eventData1, int eventData2) 2164 void *callbackData, int eventData1, int eventData2)
2090 { 2165 {
2091 double N; 2166 switch (event)
2092 2167 {
2093 switch (event)
2094 {
2095 case EVENT_COMMIT: 2168 case EVENT_COMMIT:
2096 if (panel == CalcN1Panel) { 2169 if (panel == CalcN1Panel) {
2097 N = floor(N_1); 2170 N1 = round(N_1);
2098 if (N_1-N<0.5) 2171 SetCtrlVal(MainPanel, PANEL_N1CHOICE, N1);
2099 { 2172 }
2100 N1=N;
2101 }
2102 else
2103 {
2104 N1=N+1;
2105 }
2106 SetCtrlVal(MainPanel, PANEL_N1CHOICE, N1) ;
2107 }
2108
2109 if (panel == CalcN2Panel) { 2173 if (panel == CalcN2Panel) {
2110 N = floor(N_2); 2174 N2 = round(N_2);
2111 if (N_2-N<0.5) 2175 SetCtrlVal(MainPanel, PANEL_N2CHOICE, N2);
2112 { 2176 }
2113 N2=N;
2114 }
2115 else
2116 {
2117 N2=N+1;
2118 }
2119 SetCtrlVal(MainPanel, PANEL_N2CHOICE, N2) ;
2120 }
2121
2122 if (panel == CalcN3Panel) { 2177 if (panel == CalcN3Panel) {
2123 GetCtrlVal(CalcN3Panel, CALCN3_N_3, &N) ; 2178 N3 = round(N_3);
2124 SetCtrlVal(MainPanel, PANEL_N3CHOICE, N) ; 2179 SetCtrlVal(MainPanel, PANEL_N3CHOICE, N3);
2125 N3=N; 2180 }
2126 } 2181 break;
2127 break; 2182 }
2128 }
2129 return 0; 2183 return 0;
2130 } 2184 }
2131 2185
2132 /*int CVICALLBACK OnFSRStep (int panel, int control, int event, 2186 /*int CVICALLBACK OnFSRStep (int panel, int control, int event,
2133 void *callbackData, int eventData1, int eventData2) 2187 void *callbackData, int eventData1, int eventData2)
2285 int CVICALLBACK CB_OnStartNCalculus (int panel, int control, int event, 2339 int CVICALLBACK CB_OnStartNCalculus (int panel, int control, int event,
2286 void *callbackData, int eventData1, int eventData2) 2340 void *callbackData, int eventData1, int eventData2)
2287 { 2341 {
2288 2342
2289 switch (event) 2343 switch (event)
2290 { 2344 {
2291 case EVENT_COMMIT: 2345 case EVENT_COMMIT:
2292 if (control==CALCN1_COMMANDBUTTON) 2346 if (panel == CalcN1Panel)
2293 { 2347 Measuring_1 = TRUE;
2294 Measuring_1=TRUE; 2348 if (panel == CalcN2Panel)
2349 Measuring_2 = TRUE;
2350 if (panel == CalcN3Panel)
2351 Measuring_3 = TRUE;
2352 break;
2353 }
2354
2355 return 0;
2356 }
2357
2358
2359
2360 int CVICALLBACK CB_OnNStop (int panel, int control, int event,
2361 void *callbackData, int eventData1, int eventData2)
2362 {
2363 int PanelIsVisible;
2364
2365 switch (event)
2366 {
2367 case EVENT_COMMIT:
2368 if (panel == CalcN1Panel) {
2369 GetPanelAttribute (CalcN1Panel, ATTR_VISIBLE, &PanelIsVisible);
2370 if (PanelIsVisible)
2371 HidePanel(CalcN1Panel);
2372
2373 Measuring_1=FALSE;
2374 Step1_1=FALSE ;
2375 Step2_1=FALSE ;
2376 Step3_1=FALSE ;
2377 Frepminus_1=0.0;
2378 Frepplus_1=0.0;
2379 t1_1=0.0;
2380 t2_1=0.0;
2381 t3_1=0.0;
2382 N_slope_1=0;
2383 Frequ_slope_1=0.0;
2384 Moy_slope_1=0.0;
2385 Slope_slope_1 =0.0;
2386 Ch4_slope=0.0;
2387 Moy_Ch4slope_1=0.0;
2388 Slope_Ch4slope_1=0.0;
2389 DDSBesChanged1=FALSE;
2390 DDSBesChanged2=FALSE;
2391 nDDSChange=0.0;
2392
2393 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ;
2394 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1);
2395 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit) ;
2396 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit);
2397 nstabilization=0;
2398 }
2399 if (panel == CalcN2Panel) {
2400 GetPanelAttribute (CalcN2Panel, ATTR_VISIBLE, &PanelIsVisible);
2401 if (PanelIsVisible)
2402 HidePanel(CalcN2Panel);
2403
2404 Measuring_2=FALSE;
2405 Step1_2=FALSE ;
2406 Step2_2=FALSE ;
2407 Step3_2=FALSE ;
2408 Frepminus_2=0.0;
2409 Delta10K_Minus=0.0;
2410 Frepplus_2=0.0;
2411 Delta10K_Plus=0.0;
2412 DeltaDDS3=0.0;
2413 t1_2=0.0;
2414 t2_2=0.0;
2415 t3_2=0.0;
2416 N_slope_2=0;
2417 Frequ_slope_2=0.0;
2418 Moy_slope_2=0.0;
2419 Beat_slope_2=0.0;
2420 Moy_Beatslope_2=0.0;
2421 Slope_Beatslope_2 =0.0;
2422 Slope_slope_2 =0.0;
2423 DDSBesChanged1=FALSE;
2424 DDSBesChanged2=FALSE;
2425 nDDSChange=0.0;
2426
2427 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ;
2428 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1);
2429 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit) ;
2430 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit);
2431 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init) ;
2432 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyDDS3Init);
2433 nstabilization=0;
2295 } 2434 }
2296 if (control==CALCN2_COMMANDBUTTON) 2435 if (panel == CalcN3Panel) {
2297 { 2436 GetPanelAttribute (CalcN3Panel, ATTR_VISIBLE, &PanelIsVisible);
2298 Measuring_2=TRUE; 2437 if (PanelIsVisible)
2438 HidePanel(CalcN3Panel);
2439
2440 Measuring_3 = FALSE;
2441 Frepminus_3 = 0.0;
2442 Frepplus_3 = 0.0;
2443 t1_3 = 0.0;
2444 t2_3 = 0.0;
2445 t3_3 = 0.0;
2446 N_slope_3 = 0;
2447 Frequ_slope_3 = 0.0;
2448 Moy_slope_3 = 0.0;
2449 Slope_slope_3 = 0.0;
2299 } 2450 }
2300 break; 2451 break;
2301 }
2302
2303
2304
2305 return 0;
2306 }
2307
2308 int CVICALLBACK CB_OnStartN3Calculus (int panel, int control, int event,
2309 void *callbackData, int eventData1, int eventData2)
2310 {
2311
2312 switch (event)
2313 {
2314 case EVENT_COMMIT:
2315 Measuring_3=TRUE;
2316 break;
2317 } 2452 }
2318 return 0;
2319 }
2320
2321
2322 int CVICALLBACK CB_OnNStop (int panel, int control, int event,
2323 void *callbackData, int eventData1, int eventData2)
2324 {
2325 int PanelIsVisible;
2326
2327 switch (event)
2328 {
2329 case EVENT_COMMIT:
2330 //switch (control)
2331 if (control==CALCN1_COMMANDBUTTON_2)
2332 {
2333 GetPanelAttribute (CalcN1Panel, ATTR_VISIBLE , &PanelIsVisible);
2334 if (PanelIsVisible) {
2335 HidePanel(CalcN1Panel) ;
2336 }
2337
2338 Measuring_1=FALSE;
2339 Step1_1=FALSE ;
2340 Step2_1=FALSE ;
2341 Step3_1=FALSE ;
2342 Frepminus_1=0.0;
2343 Frepplus_1=0.0;
2344 t1_1=0.0;
2345 t2_1=0.0;
2346 t3_1=0.0;
2347 N_slope_1=0;
2348 Frequ_slope_1=0.0;
2349 Moy_slope_1=0.0;
2350 Slope_slope_1 =0.0;
2351 Ch4_slope=0.0;
2352 Moy_Ch4slope_1=0.0;
2353 Slope_Ch4slope_1=0.0;
2354 DDSBesChanged1=FALSE;
2355 DDSBesChanged2=FALSE;
2356 nDDSChange=0.0;
2357
2358 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ;
2359 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1);
2360 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit) ;
2361 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit);
2362 nstabilization=0;
2363 }
2364
2365
2366 if (control==CALCN2_STOP2)
2367 {
2368 GetPanelAttribute (CalcN2Panel, ATTR_VISIBLE , &PanelIsVisible);
2369 if (PanelIsVisible) {
2370 HidePanel(CalcN2Panel) ;
2371 }
2372
2373 Measuring_2=FALSE;
2374 Step1_2=FALSE ;
2375 Step2_2=FALSE ;
2376 Step3_2=FALSE ;
2377 Frepminus_2=0.0;
2378 Delta10K_Minus=0.0;
2379 Frepplus_2=0.0;
2380 Delta10K_Plus=0.0;
2381 DeltaDDS3=0.0;
2382 t1_2=0.0;
2383 t2_2=0.0;
2384 t3_2=0.0;
2385 N_slope_2=0;
2386 Frequ_slope_2=0.0;
2387 Moy_slope_2=0.0;
2388 Beat_slope_2=0.0;
2389 Moy_Beatslope_2=0.0;
2390 Slope_Beatslope_2 =0.0;
2391 Slope_slope_2 =0.0;
2392 DDSBesChanged1=FALSE;
2393 DDSBesChanged2=FALSE;
2394 nDDSChange=0.0;
2395 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ;
2396 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1);
2397 SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit) ;
2398 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit);
2399 SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init) ;
2400 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyDDS3Init);
2401 nstabilization=0;
2402 }
2403
2404
2405 break;
2406 }
2407 return 0;
2408 }
2409
2410 int CVICALLBACK CB_OnN3Stop (int panel, int control, int event,
2411 void *callbackData, int eventData1, int eventData2)
2412 {
2413 int PanelIsVisible;
2414
2415 switch (event)
2416 {
2417 case EVENT_COMMIT:
2418 GetPanelAttribute (CalcN3Panel, ATTR_VISIBLE , &PanelIsVisible);
2419 if (PanelIsVisible) {
2420 HidePanel(CalcN3Panel) ;
2421 }
2422
2423 Measuring_3=FALSE;
2424 Step1_3=FALSE ;
2425 Step2_3=FALSE ;
2426 Step3_3=FALSE ;
2427 Frepminus_3=0.0;
2428 Frepplus_3=0.0;
2429 t1_3=0.0;
2430 t2_3=0.0;
2431 t3_3=0.0;
2432 N_slope_3=0;
2433 Frequ_slope_3=0.0;
2434 Moy_slope_3=0.0;
2435 Slope_slope_3 =0.0;
2436 break;
2437 }
2438 return 0; 2453 return 0;
2439 } 2454 }
2440 2455
2441 2456
2442 int CVICALLBACK CB_OnIntegrationTime (int panel, int control, int event, 2457 int CVICALLBACK CB_OnIntegrationTime (int panel, int control, int event,
2443 void *callbackData, int eventData1, int eventData2) 2458 void *callbackData, int eventData1, int eventData2)
2444 { 2459 {
2445 double Time ; 2460 double Time ;
2446 2461
2447 switch (event) 2462 switch (event) {
2448 { 2463 case EVENT_COMMIT:
2449 case EVENT_COMMIT: 2464 if (panel == CalcN1Panel) {
2450 if (control==CALCN1_INTEGRATIONTIME){
2451 GetCtrlVal(CalcN1Panel, CALCN1_INTEGRATIONTIME, &Time) ; 2465 GetCtrlVal(CalcN1Panel, CALCN1_INTEGRATIONTIME, &Time) ;
2452 DeltaT_1=Time; 2466 DeltaT_1=Time;
2453 } 2467 }
2454 if (control==CALCN2_INTEGRATIONTIME){ 2468 if (panel == CalcN2Panel) {
2455 GetCtrlVal(CalcN2Panel, CALCN2_INTEGRATIONTIME, &Time) ; 2469 GetCtrlVal(CalcN2Panel, CALCN2_INTEGRATIONTIME, &Time) ;
2456 DeltaT_2=Time; 2470 DeltaT_2=Time;
2457 } 2471 }
2458 if (control==CALCN3_INTEGRATIONTIME){ 2472 if (panel == CalcN3Panel) {
2459 GetCtrlVal(CalcN3Panel, CALCN3_INTEGRATIONTIME, &Time) ; 2473 GetCtrlVal(CalcN3Panel, CALCN3_INTEGRATIONTIME, &Time) ;
2460 DeltaT_3=Time; 2474 DeltaT_3=Time;
2461 } 2475 }
2462 2476 break;
2463 break; 2477 }
2464
2465 }
2466 return 0; 2478 return 0;
2467 } 2479 }
2468 2480
2469 2481
2470 int CVICALLBACK CB_OnDeltaFreq (int panel, int control, int event, 2482 int CVICALLBACK CB_OnDeltaFreq (int panel, int control, int event,
2471 void *callbackData, int eventData1, int eventData2) 2483 void *callbackData, int eventData1, int eventData2)
2472 { 2484 {
2473 double Frequ ; 2485 double Frequ ;
2474 2486
2475 switch (event) 2487 switch (event)
2476 { 2488 {
2477 case EVENT_COMMIT: 2489 case EVENT_COMMIT:
2478 if (control==CALCN1_DELTAFREQ){ 2490 if (panel == CalcN1Panel) {
2479 GetCtrlVal(CalcN1Panel, CALCN1_DELTAFREQ, &Frequ) ; 2491 GetCtrlVal(CalcN1Panel, CALCN1_DELTAFREQ, &Frequ);
2480 DeltakHz_1=Frequ; 2492 DeltakHz_1 = Frequ;
2481 } 2493 }
2482 if (control==CALCN2_DELTAFREQ){ 2494 if (panel == CalcN2Panel) {
2483 GetCtrlVal(CalcN2Panel, CALCN2_DELTAFREQ, &Frequ) ; 2495 GetCtrlVal(CalcN2Panel, CALCN2_DELTAFREQ, &Frequ) ;
2484 DeltakHz_2=Frequ; 2496 DeltakHz_2=Frequ;
2485 } 2497 }
2486 if (control==CALCN3_DELTAFREQ){ 2498 if (panel == CalcN3Panel) {
2487 GetCtrlVal(CalcN3Panel, CALCN3_DELTAFREQ, &Frequ) ; 2499 GetCtrlVal(CalcN3Panel, CALCN3_DELTAFREQ, &Frequ) ;
2488 DeltakHz_3=Frequ; 2500 DeltakHz_3=Frequ;
2489 } 2501 }
2490 2502 break;
2491 break; 2503 }
2492
2493 }
2494 return 0; 2504 return 0;
2495 } 2505 }
2496 2506
2497 2507
2498 int CVICALLBACK CB_OnFindSign (int panel, int control, int event, 2508 int CVICALLBACK CB_OnFindSign (int panel, int control, int event,
2499 void *callbackData, int eventData1, int eventData2) 2509 void *callbackData, int eventData1, int eventData2)
2500 { 2510 {
2501 2511
2502 switch (event) 2512 switch (event) {
2503 { 2513 case EVENT_COMMIT:
2504 case EVENT_COMMIT: 2514 switch (control)
2505 if (control==PANEL_FINDSIGN1){ 2515 {
2506 tbegin1=utc; 2516 case PANEL_FINDSIGN1:
2507 Frepbefore1=Math1; 2517 tbegin1 = utc;
2508 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency1) ; 2518 Frepbefore1 = Math1;
2509 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency1+Frequencystep1) ; 2519 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency1) ;
2510 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency1+Frequencystep1); 2520 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency1+Frequencystep1) ;
2511 Getsign1=TRUE; 2521 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency1+Frequencystep1);
2522 Getsign1 = TRUE;
2523 break;
2524 case PANEL_FINDSIGN2:
2525 tbegin2 = utc;
2526 Frepbefore2 = Math1;
2527 Ch2before = Ch2;
2528 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency2) ;
2529 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency2+Frequencystep2) ;
2530 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency2+Frequencystep2);
2531 Getsign2 = TRUE;
2532 break;
2533 case PANEL_FINDSIGN3:
2534 tbegin3 = utc;
2535 Frepbefore3 = Math1;
2536 GetCtrlVal(MainPanel, PANEL_DDS4, &Frequency3) ;
2537 SetCtrlVal(MainPanel, PANEL_DDS4, Frequency3+Frequencystep3) ;
2538 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, Frequency3+Frequencystep3);
2539 Getsign3 = TRUE;
2540 break;
2512 } 2541 }
2513 if (control==PANEL_FINDSIGN2){ 2542 break;
2514 tbegin2=utc; 2543 }
2515 Frepbefore2=Math1; 2544 return 0;
2516 Ch2before=Ch2; 2545 }
2517 GetCtrlVal(MainPanel, PANEL_DDS1, &Frequency2) ;
2518 SetCtrlVal(MainPanel, PANEL_DDS1, Frequency2+Frequencystep2) ;
2519 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, Frequency2+Frequencystep2);
2520 Getsign2=TRUE;
2521 }
2522 if (control==PANEL_FINDSIGN3){
2523 tbegin3=utc;
2524 Frepbefore3=Ch1;
2525 GetCtrlVal(MainPanel, PANEL_DDS3, &Frequency3) ;
2526 SetCtrlVal(MainPanel, PANEL_DDS3, Frequency3+Frequencystep3) ;
2527 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, Frequency3+Frequencystep3);
2528 Getsign3=TRUE;
2529 }
2530
2531
2532 break;
2533
2534 }
2535 return 0;
2536 }
2537
2538 2546
2539 2547
2540 int CVICALLBACK CB_OnFind275K (int panel, int control, int event, 2548 int CVICALLBACK CB_OnFind275K (int panel, int control, int event,
2541 void *callbackData, int eventData1, int eventData2) 2549 void *callbackData, int eventData1, int eventData2)
2542 { 2550 {
2575 void *callbackData, int eventData1, int eventData2) 2583 void *callbackData, int eventData1, int eventData2)
2576 { 2584 {
2577 double Time ; 2585 double Time ;
2578 2586
2579 switch (event) 2587 switch (event)
2580 { 2588 {
2581 case EVENT_COMMIT: 2589 case EVENT_COMMIT:
2582 if (control==CALCN1_SLOPETIME){ 2590 if (panel == CalcN1Panel) {
2583 GetCtrlVal(CalcN1Panel, CALCN1_SLOPETIME, &Time) ; 2591 GetCtrlVal(CalcN1Panel, CALCN1_SLOPETIME, &Time);
2584 SlopeTime1=Time; 2592 SlopeTime1=Time;
2585 } 2593 }
2586 2594 if (panel == CalcN2Panel) {
2587 if (control==CALCN2_SLOPETIME){ 2595 GetCtrlVal(CalcN2Panel, CALCN2_SLOPETIME, &Time);
2588 GetCtrlVal(CalcN2Panel, CALCN2_SLOPETIME, &Time) ;
2589 SlopeTime2=Time; 2596 SlopeTime2=Time;
2590 } 2597 }
2591 2598 if (panel == CalcN3Panel) {
2592 break; 2599 GetCtrlVal(CalcN3Panel, CALCN3_SLOPETIME, &Time);
2593 2600 SlopeTime3=Time;
2594 } 2601 }
2602 break;
2603 }
2595 return 0; 2604 return 0;
2596 } 2605 }
2597 2606
2598 2607
2599 int CVICALLBACK CB_OnChangeNdiv (int panel, int control, int event, 2608 int CVICALLBACK CB_OnChangeNdiv (int panel, int control, int event,
2874 2883
2875 } 2884 }
2876 return 0; 2885 return 0;
2877 } 2886 }
2878 2887
2879 int CVICALLBACK SlopeReference_cb (int panel, int control, int event, 2888 int CVICALLBACK CB_OnSlopeReference (int panel, int control, int event,
2880 void *callbackData, int eventData1, int eventData2) 2889 void *callbackData, int eventData1, int eventData2)
2881 { 2890 {
2882 switch (event) 2891 switch (event)
2883 { 2892 {
2884 case EVENT_COMMIT: 2893 case EVENT_COMMIT:
2885 GetCtrlVal(MainPanel, PANEL_SLOPE_REFERENCE, &slopeReference); 2894 GetCtrlVal(MainPanel, PANEL_SLOPE_REFERENCE, &slopeReference);
2886 break; 2895 break;
2887 } 2896 }
2888 return 0; 2897 return 0;
2889 } 2898 }
2899
2900
2901 int CVICALLBACK CB_OnEstimateN (int panel, int control, int event,
2902 void *callbackData, int eventData1, int eventData2)
2903 {
2904 int visible;
2905 double wl;
2906
2907 switch (event)
2908 {
2909 case EVENT_COMMIT:
2910 /* be prepaid to support more N estimates for different beat notes */
2911 switch (control)
2912 {
2913 case PANEL_ESTIMATE_N3:
2914 GetPanelAttribute(EstimateN3Panel, ATTR_VISIBLE , &visible);
2915 if (! visible) {
2916 DisplayPanel(EstimateN3Panel);
2917 }
2918 /* set current frep */
2919 SetCtrlVal(EstimateN3Panel, ESTIMATEN3_FREP, 250e6 + Math1);
2920 /* default wavelenght for Sr cavity */
2921 GetCtrlVal(EstimateN3Panel, ESTIMATEN3_WAVELENGTH, &wl);
2922 if (wl == 0.0)
2923 SetCtrlVal(EstimateN3Panel, ESTIMATEN3_WAVELENGTH, 698.50);
2924 /* reset N3 estimate */
2925 SetCtrlVal(EstimateN3Panel, ESTIMATEN3_N, 0.0);
2926 break;
2927 }
2928 break;
2929 }
2930
2931 return 0;
2932 }
2933
2934 int CVICALLBACK CB_OnNEstimateCancel (int panel, int control, int event,
2935 void *callbackData, int eventData1, int eventData2)
2936 {
2937 int visible;
2938
2939 switch (event)
2940 {
2941 case EVENT_COMMIT:
2942 GetPanelAttribute(panel, ATTR_VISIBLE, &visible);
2943 if (visible)
2944 HidePanel(panel);
2945 break;
2946 }
2947 return 0;
2948 }
2949
2950 int CVICALLBACK CB_OnNEstimateSet (int panel, int control, int event,
2951 void *callbackData, int eventData1, int eventData2)
2952 {
2953 switch (event)
2954 {
2955 case EVENT_COMMIT:
2956 GetCtrlVal(panel, ESTIMATEN3_N, &N3);
2957 SetCtrlVal(MainPanel, PANEL_N3CHOICE, N3);
2958 HidePanel(panel);
2959 break;
2960 }
2961 return 0;
2962 }
2963
2964 int CVICALLBACK CB_OnNEstimate (int panel, int control, int event,
2965 void *callbackData, int eventData1, int eventData2)
2966 {
2967 double frep, wl, N;
2968
2969 switch (event)
2970 {
2971 case EVENT_COMMIT:
2972 GetCtrlVal(panel, ESTIMATEN3_FREP, &frep);
2973 GetCtrlVal(panel, ESTIMATEN3_WAVELENGTH, &wl);
2974 N = round(299792458.0 / wl / 1e-9 / frep);
2975 SetCtrlVal(panel, ESTIMATEN3_N, N);
2976 break;
2977 }
2978 return 0;
2979 }