Mercurial > hg > fxanalyse
comparison FXAnalyse.c @ 133:7540703b8473
Major code cleanup. Implement beatnote recentering.
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Wed, 22 Jan 2014 12:10:17 +0100 |
parents | fbd72d87b4dc |
children | bd28161e5ac2 |
comparison
equal
deleted
inserted
replaced
132:fbd72d87b4dc | 133:7540703b8473 |
---|---|
12 #include "Plot.h" | 12 #include "Plot.h" |
13 #include "Allan.h" | 13 #include "Allan.h" |
14 #include "DDS4xAD9912.h" | 14 #include "DDS4xAD9912.h" |
15 #include "DDS_Fox.h" | 15 #include "DDS_Fox.h" |
16 #include "muParserDLL.h" | 16 #include "muParserDLL.h" |
17 #include "stat.h" | |
17 | 18 |
18 #define SR_LOGGER_IP "145.238.204.91" | 19 #define SR_LOGGER_IP "145.238.204.91" |
19 #define DATAFOLDER "Z:\\Measures-2013" | 20 #define DATAFOLDER "Z:\\Measures-2013" |
20 | 21 |
21 #define FREP_STEP_SIZE 50000.0 | 22 #define FREP_STEP_SIZE 50000.0 |
116 double Frequencystep3=100000.0, tbegin3=0.0, Frepbefore3=0.0, Frequency3=0.0; | 117 double Frequencystep3=100000.0, tbegin3=0.0, Frepbefore3=0.0, Frequency3=0.0; |
117 | 118 |
118 volatile bool Getsign1=FALSE,Getsign2=FALSE,Getsign3=FALSE; | 119 volatile bool Getsign1=FALSE,Getsign2=FALSE,Getsign3=FALSE; |
119 double Sign1=1.0, Sign2=1.0, Sign3=0.0; | 120 double Sign1=1.0, Sign2=1.0, Sign3=0.0; |
120 | 121 |
121 // slope cancelling | 122 |
122 | 123 struct stat stat_math1, stat_ch2, stat_ch3, stat_ch4, freq; |
123 double dedrift_DDS_freq = 70e6; | 124 struct rollmean rollmean_ch1, rollmean_ch2, rollmean_ch3, rollmean_ch4; |
124 int SlopeMeasuring = FALSE; | 125 |
125 int StopSlopeCancellingOnUnlocked = TRUE; | 126 |
126 double TimetoSlope = 60.0; | 127 // dedrift |
127 double SlopeMeasuringTimeBegin = 0.0; | 128 struct dedrift { |
128 double appliedSlope = 0.0; // currently applied frequency dedrifiting slope | 129 int enabled; // dedrift enabled |
129 int slopeX2 = FALSE; | 130 int reference; // reference frequency |
130 | 131 int invert; // invert applied slope sign |
131 double limitotakoff=70.0; | 132 int doubleslope; // double applied slope |
132 | 133 int keep_freq; // keep current frequency value when dedrift is disabled |
133 int ratio=10; //Recentre la frequence tous les ratios | 134 int keep_slope; // keep current slope value when dedrift is disabled |
134 | 135 double freq0; // DDS center frequency |
135 int FrequCorrec = FALSE, KeepFrequ = TRUE, KeepSlope = TRUE; | 136 double threshold; // maximum allowed frequency change |
136 int Nratio = -1; | 137 double applied; // currently applied slope |
137 double MoyMath2 = 0.0, CenterFrequencyCh2 = 0.0; | 138 double interval; // measurement duration |
138 int CenterFrequencyCh2ToDetermine = FALSE; | 139 double t0; // beginning of currrent measurement interval |
140 }; | |
139 | 141 |
140 enum { | 142 enum { |
141 SLOPE_REFERENCE_MICROWAVE = 0, | 143 DEDRIFT_REFERENCE_MICROWAVE = 0, |
142 SLOPE_REFERENCE_HG_CAVITY = 1, | 144 DEDRIFT_REFERENCE_HG = 1, |
143 }; | 145 }; |
144 | 146 |
145 int invertSlopeSign = 0; | 147 struct dedrift dedrift = { |
146 int slopeReference = SLOPE_REFERENCE_MICROWAVE; | 148 .enabled = FALSE, |
147 | 149 .reference = DEDRIFT_REFERENCE_MICROWAVE, |
148 int KeepCentering = FALSE; | 150 .invert = FALSE, |
149 double Timetorecenter275K = 3600.0 * 10; | 151 .doubleslope = FALSE, |
150 double Timetorecenter10K = 3600.0 * 3; | 152 .keep_freq = TRUE, |
151 double CenteringTimeBegin275K = 0.0; | 153 .keep_slope = TRUE, |
152 double CenteringTimeBegin10K = 0.0; | 154 .freq0 = 70e6, |
155 .threshold = 100.0, | |
156 .applied = 0.0, | |
157 .interval = 40.0, | |
158 .t0 = 0.0 | |
159 }; | |
160 | |
161 | |
162 // recenter | |
163 struct recenter { | |
164 int enabled; // recenter enabled | |
165 int Lo; // recenter microwave beatnote | |
166 int Sr; // recenter Sr beatnote | |
167 int Hg; // recenter Hg beatnote | |
168 double interval; // interval | |
169 double t0; // beginning of current interval | |
170 }; | |
171 | |
172 struct recenter recenter = { | |
173 .enabled = FALSE, | |
174 .Lo = FALSE, | |
175 .Sr = FALSE, | |
176 .Hg = FALSE, | |
177 .interval = 1800.0, | |
178 .t0 = 0.0 | |
179 }; | |
153 | 180 |
154 | 181 |
155 // panels | 182 // panels |
156 static int MainPanel; | 183 static int MainPanel; |
157 static int CalcNPanel; | 184 static int CalcNPanel; |
181 *dst-- = ' '; | 208 *dst-- = ' '; |
182 } | 209 } |
183 return buffer; | 210 return buffer; |
184 } | 211 } |
185 | 212 |
186 | |
187 struct stat { | |
188 int samples; | |
189 double mean; | |
190 double slope; | |
191 double previous; | |
192 }; | |
193 | |
194 void stat_zero(struct stat *s) | |
195 { | |
196 s->samples = 0; | |
197 s->mean = 0.0; | |
198 s->slope = 0.0; | |
199 s->previous = 0.0; | |
200 } | |
201 | |
202 void stat_accumulate(struct stat *s, double value) | |
203 { | |
204 s->samples += 1; | |
205 | |
206 if (s->samples > 1) | |
207 s->slope = (s->slope * (s->samples - 2) + 6 * (value - s->mean) / s->samples) / (s->samples + 1); | |
208 | |
209 s->mean = ((s->samples - 1) * s->mean + value) / s->samples; | |
210 | |
211 s->previous = value; | |
212 } | |
213 | |
214 struct stat stat_math1, stat_ch2, stat_ch4, stat_ch3, freq; | |
215 | 213 |
216 #define MIN(x, y) (x) < (y) ? (x) : (y) | 214 #define MIN(x, y) (x) < (y) ? (x) : (y) |
217 | 215 |
218 // MJD functiom used by the Sr programs | 216 // MJD functiom used by the Sr programs |
219 static inline double utc2mjd(double utc) | 217 static inline double utc2mjd(double utc) |
375 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, frequency); | 373 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, frequency); |
376 GetCtrlVal(MainPanel, PANEL_DDS4, &frequency); | 374 GetCtrlVal(MainPanel, PANEL_DDS4, &frequency); |
377 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, frequency); | 375 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 4, frequency); |
378 | 376 |
379 // initialyze 1x AD9956 DDS box | 377 // initialyze 1x AD9956 DDS box |
380 DDSFox_Initialize(&DDS1xAD9956, "145.238.205.58", 6665, dedrift_DDS_freq); | 378 DDSFox_Initialize(&DDS1xAD9956, "145.238.205.58", 6665, dedrift.freq0); |
381 | 379 |
382 Ch1 = Ch2 = Ch3 = Ch4 = 0.0; | 380 Ch1 = Ch2 = Ch3 = Ch4 = 0.0; |
383 | 381 |
384 GetCtrlVal(MainPanel, PANEL_N1CHOICE, &N1); | 382 GetCtrlVal(MainPanel, PANEL_N1CHOICE, &N1); |
385 GetCtrlVal(MainPanel, PANEL_N2CHOICE, &N2); | 383 GetCtrlVal(MainPanel, PANEL_N2CHOICE, &N2); |
659 SetCtrlVal(MainPanel, PANEL_UTC, utc); | 657 SetCtrlVal(MainPanel, PANEL_UTC, utc); |
660 SetCtrlVal(MainPanel, PANEL_CH1, Ch1); | 658 SetCtrlVal(MainPanel, PANEL_CH1, Ch1); |
661 SetCtrlVal(MainPanel, PANEL_CH2, Ch2); | 659 SetCtrlVal(MainPanel, PANEL_CH2, Ch2); |
662 SetCtrlVal(MainPanel, PANEL_CH3, Ch3); | 660 SetCtrlVal(MainPanel, PANEL_CH3, Ch3); |
663 SetCtrlVal(MainPanel, PANEL_CH4, Ch4); | 661 SetCtrlVal(MainPanel, PANEL_CH4, Ch4); |
664 | |
665 SetCtrlVal(MainPanel, PANEL_CENTERFREQUENCY, CenterFrequencyCh2); | |
666 | 662 |
667 // compute | 663 // compute |
668 Math1 = mupEval(MathParser1); | 664 Math1 = mupEval(MathParser1); |
669 Math2 = mupEval(MathParser2); | 665 Math2 = mupEval(MathParser2); |
670 Math3 = mupEval(MathParser3); | 666 Math3 = mupEval(MathParser3); |
1295 SetCtrlVal(MainPanel, PANEL_SIGN3, Sign3); | 1291 SetCtrlVal(MainPanel, PANEL_SIGN3, Sign3); |
1296 } | 1292 } |
1297 } | 1293 } |
1298 | 1294 |
1299 // select reference | 1295 // select reference |
1300 double current = 0.0; | 1296 double f = 0.0; |
1301 switch (slopeReference) { | 1297 switch (dedrift.reference) { |
1302 case SLOPE_REFERENCE_MICROWAVE: | 1298 case DEDRIFT_REFERENCE_MICROWAVE: |
1303 current = Math2; | 1299 f = Math2; |
1304 break; | 1300 break; |
1305 case SLOPE_REFERENCE_HG_CAVITY: | 1301 case DEDRIFT_REFERENCE_HG: |
1306 current = Ch2 * 1062.5 / 1542.2; | 1302 f = Ch2 * 1062.5 / 1542.2; |
1307 break; | 1303 break; |
1308 } | 1304 } |
1309 | 1305 |
1310 // stop slope cancelling if the comb is not locked | 1306 // stop dedrift if the comb is not locked |
1311 if (SlopeMeasuring & StopSlopeCancellingOnUnlocked | 1307 if ((dedrift.enabled) |
1308 & (dedrift.threshold != 0.0) | |
1312 & (freq.previous != 0.0) | 1309 & (freq.previous != 0.0) |
1313 & (fabs(current - freq.previous) > limitotakoff)) { | 1310 & (fabs(f - freq.previous) > dedrift.threshold)) { |
1314 | 1311 |
1315 if (! KeepSlope) { | 1312 if (! dedrift.keep_slope) { |
1316 appliedSlope = 0.0; | 1313 dedrift.applied = 0.0; |
1317 DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope); | 1314 DDSFox_SetSweepRate(&DDS1xAD9956, dedrift.applied); |
1318 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope); | 1315 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied); |
1319 } | 1316 } |
1320 if (! KeepFrequ) { | 1317 if (! dedrift.keep_freq) { |
1321 DDSFox_Set(&DDS1xAD9956, dedrift_DDS_freq, appliedSlope); | 1318 DDSFox_Set(&DDS1xAD9956, dedrift.freq0, dedrift.applied); |
1322 } | 1319 } |
1323 | 1320 |
1324 stat_zero(&freq); | 1321 stat_zero(&freq); |
1325 SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, freq.slope); | 1322 SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, freq.slope); |
1326 SlopeMeasuring = FALSE; | 1323 dedrift.enabled = FALSE; |
1327 SetCtrlVal(MainPanel, PANEL_MEASURE_SLOPE, 0); | 1324 SetCtrlVal(MainPanel, PANEL_MEASURE_SLOPE, 0); |
1328 } | 1325 } |
1329 | 1326 |
1330 // slope measurement | 1327 // dedrifting |
1331 if (SlopeMeasuring) | 1328 if (dedrift.enabled) |
1332 { | 1329 { |
1333 // update slope measurement | 1330 // update slope measurement |
1334 stat_accumulate(&freq, current); | 1331 stat_accumulate(&freq, f); |
1335 | 1332 |
1336 // update indicator | 1333 // update indicator |
1337 SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, freq.slope); | 1334 SetCtrlVal(MainPanel, PANEL_SLOPE_MEASURED, freq.slope); |
1338 | 1335 |
1339 // update applied slope | 1336 // update applied slope |
1340 if ((utc - SlopeMeasuringTimeBegin) > TimetoSlope) { | 1337 if ((utc - dedrift.t0) > dedrift.interval) { |
1341 | 1338 |
1342 if (invertSlopeSign) | 1339 if (dedrift.invert) |
1343 appliedSlope = appliedSlope - freq.slope; | 1340 dedrift.applied -= freq.slope; |
1344 else | 1341 else |
1345 appliedSlope = appliedSlope + freq.slope; | 1342 dedrift.applied += freq.slope; |
1346 | 1343 |
1347 if (FrequCorrec) { | 1344 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied); |
1348 // proportional correction | 1345 |
1349 | 1346 if (dedrift.doubleslope) |
1350 Nratio += 1; | 1347 DDSFox_SetSweepRate(&DDS1xAD9956, dedrift.applied * 2.0); |
1351 if (Nratio >= 1) { | |
1352 MoyMath2 = MoyMath2 + freq.mean; | |
1353 } | |
1354 if (Nratio == 1 && CenterFrequencyCh2ToDetermine == TRUE) { | |
1355 CenterFrequencyCh2 = MoyMath2; | |
1356 CenterFrequencyCh2ToDetermine = FALSE; | |
1357 } | |
1358 if (Nratio == ratio) { | |
1359 double correction = (MoyMath2/ratio-CenterFrequencyCh2)/TimetoSlope; | |
1360 appliedSlope = appliedSlope + correction; | |
1361 Nratio = 0; | |
1362 MoyMath2 = 0.0; | |
1363 } | |
1364 } | |
1365 | |
1366 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope); | |
1367 if (slopeX2) | |
1368 DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope * 2.0); | |
1369 else | 1348 else |
1370 DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope); | 1349 DDSFox_SetSweepRate(&DDS1xAD9956, dedrift.applied); |
1371 | 1350 |
1372 logmsg("Slope correction update (%+6g) %6g", freq.slope, appliedSlope); | 1351 logmsg("dedrift update (%+6g) %6g", freq.slope, dedrift.applied); |
1373 | 1352 |
1374 stat_zero(&freq); | 1353 stat_zero(&freq); |
1375 SlopeMeasuringTimeBegin = utc; | 1354 dedrift.t0 = utc; |
1376 } | 1355 } |
1377 } | 1356 } |
1378 | 1357 |
1379 // re-centering | 1358 // recenter |
1380 if (KeepCentering) { | 1359 if (recenter.enabled) |
1381 if ((utc - CenteringTimeBegin275K) > Timetorecenter275K && CenteringTimeBegin275K > 10) { | 1360 { |
1382 double frequency; | 1361 if (recenter.t0 == 0.0) { |
1383 GetCtrlVal(MainPanel, PANEL_DDS2, &frequency); | 1362 recenter.t0 = utc; |
1384 // adjust DDS2 frequency to keep Ch4 reading around 275000 | 1363 rollmean_zero(&rollmean_ch2, ROLLMEAN_N_OBS); |
1385 frequency = frequency + 275000 - Ch4; | 1364 rollmean_zero(&rollmean_ch3, ROLLMEAN_N_OBS); |
1386 SetCtrlVal(MainPanel, PANEL_DDS2, frequency); | 1365 rollmean_zero(&rollmean_ch4, ROLLMEAN_N_OBS); |
1387 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, frequency); | |
1388 CenteringTimeBegin275K = utc; | |
1389 } | 1366 } |
1390 | 1367 |
1391 if ((utc - CenteringTimeBegin10K) > Timetorecenter10K && CenteringTimeBegin10K > 10) { | 1368 rollmean_accumulate(&rollmean_ch2, Ch2); |
1392 double frequency; | 1369 rollmean_accumulate(&rollmean_ch3, Ch3); |
1393 GetCtrlVal(MainPanel, PANEL_DDS3, &frequency); | 1370 rollmean_accumulate(&rollmean_ch4, Ch4); |
1394 // adjust DDS3 frequency to keep Ch2 reading around 10000 | 1371 |
1395 frequency = frequency + 10000 - Ch2; | 1372 if ((utc - recenter.t0) > recenter.interval) { |
1396 SetCtrlVal(MainPanel, PANEL_DDS3, frequency); | 1373 |
1397 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, frequency); | 1374 if (recenter.Lo) { |
1398 CenteringTimeBegin10K = utc; | 1375 // adjust DDS2 frequency to keep Ch4 reading at 275 kHz |
1376 double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 2); | |
1377 freq = freq + 275000.0 - rollmean_ch4.mean; | |
1378 SetCtrlVal(MainPanel, PANEL_DDS2, freq); | |
1379 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, freq); | |
1380 } | |
1381 | |
1382 if (recenter.Hg) { | |
1383 // adjust DDS3 frequency to keep Ch2 reading at 10 kHz | |
1384 double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); | |
1385 freq = freq + 10000 - rollmean_ch2.mean; | |
1386 SetCtrlVal(MainPanel, PANEL_DDS3, freq); | |
1387 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, freq); | |
1388 } | |
1389 | |
1390 if (recenter.Sr) { | |
1391 // adjust DDS3 frequency to keep Ch3 reading at 10 kHz | |
1392 double freq = DDS4xAD9912_GetFrequency(&DDS4xAD9912, 3); | |
1393 freq = freq + 10000 - rollmean_ch3.mean; | |
1394 SetCtrlVal(MainPanel, PANEL_DDS3, freq); | |
1395 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, freq); | |
1396 } | |
1397 | |
1398 recenter.t0 = utc; | |
1399 rollmean_zero(&rollmean_ch2, ROLLMEAN_N_OBS); | |
1400 rollmean_zero(&rollmean_ch3, ROLLMEAN_N_OBS); | |
1401 rollmean_zero(&rollmean_ch4, ROLLMEAN_N_OBS); | |
1399 } | 1402 } |
1400 } | 1403 } |
1401 | 1404 |
1402 // local time | 1405 // local time |
1403 struct tm *ltime = localtime(&event.time.tv_sec); | 1406 struct tm *ltime = localtime(&event.time.tv_sec); |
1953 | 1956 |
1954 int CVICALLBACK CB_OnFindSign (int panel, int control, int event, | 1957 int CVICALLBACK CB_OnFindSign (int panel, int control, int event, |
1955 void *callbackData, int eventData1, int eventData2) | 1958 void *callbackData, int eventData1, int eventData2) |
1956 { | 1959 { |
1957 | 1960 |
1958 switch (event) { | 1961 switch (event) |
1962 { | |
1959 case EVENT_COMMIT: | 1963 case EVENT_COMMIT: |
1960 switch (control) | 1964 switch (control) |
1961 { | 1965 { |
1962 case PANEL_FINDSIGN1: | 1966 case PANEL_FINDSIGN1: |
1963 tbegin1 = utc; | 1967 tbegin1 = utc; |
2022 | 2026 |
2023 | 2027 |
2024 int CVICALLBACK CB_OnChangeNdiv (int panel, int control, int event, | 2028 int CVICALLBACK CB_OnChangeNdiv (int panel, int control, int event, |
2025 void *callbackData, int eventData1, int eventData2) | 2029 void *callbackData, int eventData1, int eventData2) |
2026 { | 2030 { |
2027 switch (event) { | 2031 switch (event) |
2032 { | |
2028 case EVENT_COMMIT: | 2033 case EVENT_COMMIT: |
2029 GetCtrlVal(MainPanel, PANEL_CHANGENDIV, &Ndiv); | 2034 GetCtrlVal(MainPanel, PANEL_CHANGENDIV, &Ndiv); |
2030 FrequDDS1 = 880000000.0 / Ndiv; | 2035 FrequDDS1 = 880000000.0 / Ndiv; |
2031 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); | 2036 SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); |
2032 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); | 2037 DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); |
2037 | 2042 |
2038 | 2043 |
2039 int CVICALLBACK CB_MeasureSlope (int panel, int control, int event, | 2044 int CVICALLBACK CB_MeasureSlope (int panel, int control, int event, |
2040 void *callbackData, int eventData1, int eventData2) | 2045 void *callbackData, int eventData1, int eventData2) |
2041 { | 2046 { |
2042 switch (event) { | 2047 switch (event) |
2043 case EVENT_COMMIT: | 2048 { |
2044 | 2049 case EVENT_COMMIT: |
2045 GetCtrlVal(panel, control, &SlopeMeasuring); | 2050 GetCtrlVal(panel, control, &dedrift.enabled); |
2046 if (SlopeMeasuring) { | 2051 if (dedrift.enabled) { |
2047 | 2052 dedrift.t0 = utc; |
2048 SlopeMeasuringTimeBegin = utc; | |
2049 | |
2050 stat_zero(&freq); | 2053 stat_zero(&freq); |
2051 | 2054 logmsg("dedrift start"); |
2052 Nratio = -1; | |
2053 MoyMath2 = 0.0; | |
2054 CenterFrequencyCh2ToDetermine = TRUE ; | |
2055 CenterFrequencyCh2 = 0.0; | |
2056 | |
2057 logmsg("Start slope measurement"); | |
2058 | |
2059 } else { | 2055 } else { |
2060 if (! KeepSlope) { | 2056 if (! dedrift.keep_slope) { |
2061 appliedSlope = 0.0; | 2057 dedrift.applied = 0.0; |
2062 DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope); | 2058 DDSFox_SetSweepRate(&DDS1xAD9956, dedrift.applied); |
2063 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope); | 2059 SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, dedrift.applied); |
2064 } | 2060 } |
2065 if (! KeepFrequ) { | 2061 if (! dedrift.keep_freq) { |
2066 DDSFox_Set(&DDS1xAD9956, dedrift_DDS_freq, appliedSlope); | 2062 DDSFox_Set(&DDS1xAD9956, dedrift.freq0, dedrift.applied); |
2067 } | 2063 } |
2068 stat_zero(&freq); | 2064 stat_zero(&freq); |
2069 SetCtrlVal(panel, PANEL_SLOPE_MEASURED, freq.slope); | 2065 SetCtrlVal(panel, PANEL_SLOPE_MEASURED, freq.slope); |
2070 | 2066 logmsg("dedrift stop"); |
2071 logmsg("Stop slope measurement"); | |
2072 } | 2067 } |
2073 break; | 2068 break; |
2074 } | 2069 } |
2075 return 0; | 2070 return 0; |
2076 } | 2071 } |
2078 | 2073 |
2079 int CVICALLBACK CB_OnResetSlope (int panel, int control, int event, | 2074 int CVICALLBACK CB_OnResetSlope (int panel, int control, int event, |
2080 void *callbackData, int eventData1, int eventData2) | 2075 void *callbackData, int eventData1, int eventData2) |
2081 { | 2076 { |
2082 | 2077 |
2083 switch (event) { | 2078 switch (event) |
2084 case EVENT_COMMIT: | 2079 { |
2085 CenterFrequencyCh2 = 0.0; | 2080 case EVENT_COMMIT: |
2086 MoyMath2 = 0.0; | 2081 dedrift.applied = 0.0; |
2087 Nratio = -1; | 2082 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied); |
2088 CenterFrequencyCh2ToDetermine = TRUE ; | 2083 DDSFox_Set(&DDS1xAD9956, dedrift.freq0, dedrift.applied); |
2089 appliedSlope = 0.0; | 2084 logmsg("dedrift reset"); |
2090 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, appliedSlope); | |
2091 DDSFox_Set(&DDS1xAD9956, dedrift_DDS_freq, appliedSlope); | |
2092 logmsg("Reset slope measurement"); | |
2093 break; | 2085 break; |
2094 } | 2086 } |
2095 return 0; | 2087 return 0; |
2096 } | 2088 } |
2097 | 2089 |
2098 | 2090 |
2099 int CVICALLBACK CB_ChangeSlopeTime (int panel, int control, int event, | 2091 int CVICALLBACK CB_ChangeSlopeTime (int panel, int control, int event, |
2100 void *callbackData, int eventData1, int eventData2) | 2092 void *callbackData, int eventData1, int eventData2) |
2101 { | 2093 { |
2102 | 2094 |
2103 switch (event) { | 2095 switch (event) |
2104 case EVENT_COMMIT: | 2096 { |
2105 GetCtrlVal(MainPanel, PANEL_SLOPETIME, &TimetoSlope); | 2097 case EVENT_COMMIT: |
2098 GetCtrlVal(MainPanel, PANEL_SLOPETIME, &dedrift.interval); | |
2106 break; | 2099 break; |
2107 } | 2100 } |
2108 return 0; | 2101 return 0; |
2109 } | 2102 } |
2110 | 2103 |
2111 | 2104 |
2112 int CVICALLBACK CB_OnCROX (int panel, int control, int event, | 2105 int CVICALLBACK CB_OnCROX (int panel, int control, int event, |
2113 void *callbackData, int eventData1, int eventData2) | 2106 void *callbackData, int eventData1, int eventData2) |
2114 { | 2107 { |
2115 switch (event) { | 2108 switch (event) |
2109 { | |
2116 case EVENT_COMMIT: | 2110 case EVENT_COMMIT: |
2117 switch (control) { | 2111 switch (control) { |
2118 | 2112 |
2119 case PANEL_CHECKBOX_CORRFREQU: | 2113 case PANEL_CHECKBOX_CORRFREQU: |
2120 // enable frequency correction | 2114 // enable frequency correction |
2121 GetCtrlVal(MainPanel, PANEL_CHECKBOX_CORRFREQU, &FrequCorrec); | 2115 // GetCtrlVal(MainPanel, PANEL_CHECKBOX_CORRFREQU, &FrequCorrec); |
2122 break; | 2116 break; |
2123 | 2117 |
2124 case PANEL_CHECKBOX_KEEP: | 2118 case PANEL_CHECKBOX_KEEP: |
2125 // keep current dedrifting frequency when dedrifting is disabled | 2119 // keep current dedrifting frequency when dedrifting is disabled |
2126 GetCtrlVal(MainPanel, PANEL_CHECKBOX_KEEP, &KeepFrequ); | 2120 GetCtrlVal(MainPanel, PANEL_CHECKBOX_KEEP, &dedrift.keep_freq); |
2127 break; | 2121 break; |
2128 | 2122 |
2129 case PANEL_CHECKBOX_KEEPSLOPE: | 2123 case PANEL_CHECKBOX_KEEPSLOPE: |
2130 // keep current dedrifting slope when dedrifting is disabled | 2124 // keep current dedrifting slope when dedrifting is disabled |
2131 GetCtrlVal(MainPanel, PANEL_CHECKBOX_KEEPSLOPE, &KeepSlope); | 2125 GetCtrlVal(MainPanel, PANEL_CHECKBOX_KEEPSLOPE, &dedrift.keep_slope); |
2132 break; | 2126 break; |
2133 } | 2127 } |
2134 break; | 2128 break; |
2135 } | 2129 } |
2136 return 0; | 2130 return 0; |
2139 | 2133 |
2140 | 2134 |
2141 int CVICALLBACK CB_OnReCentering (int panel, int control, int event, | 2135 int CVICALLBACK CB_OnReCentering (int panel, int control, int event, |
2142 void *callbackData, int eventData1, int eventData2) | 2136 void *callbackData, int eventData1, int eventData2) |
2143 { | 2137 { |
2144 bool BoxChecked = FALSE; | 2138 switch (event) |
2145 | 2139 { |
2146 switch (event) | 2140 case EVENT_COMMIT: |
2147 { | 2141 GetCtrlVal(panel, control, &recenter.enabled); |
2148 case EVENT_COMMIT: | 2142 recenter.t0 = 0.0; |
2149 | |
2150 if (control== PANEL_CHECKBOX_RECENTER) | |
2151 { | |
2152 GetCtrlVal(MainPanel, PANEL_CHECKBOX_RECENTER, &BoxChecked) ; | |
2153 if (BoxChecked) { | |
2154 KeepCentering=TRUE ; | |
2155 CenteringTimeBegin275K=utc; | |
2156 CenteringTimeBegin10K=utc; | |
2157 } | |
2158 else {KeepCentering=FALSE ;} | |
2159 | |
2160 } | |
2161 | |
2162 | |
2163 break; | 2143 break; |
2164 | 2144 } |
2165 } | |
2166 return 0; | 2145 return 0; |
2167 } | 2146 } |
2168 | 2147 |
2169 | 2148 |
2170 int CVICALLBACK CB_OnStopSlopeCancellingOnUnlocked (int panel, int control, int event, | 2149 int CVICALLBACK CB_OnStopSlopeCancellingOnUnlocked (int panel, int control, int event, |
2171 void *callbackData, int eventData1, int eventData2) | 2150 void *callbackData, int eventData1, int eventData2) |
2172 { | 2151 { |
2173 switch (event) | 2152 int value; |
2174 { | 2153 switch (event) |
2175 case EVENT_COMMIT: | 2154 { |
2176 GetCtrlVal(MainPanel, PANEL_CHECKBOX_STOPIFAUTODE, &StopSlopeCancellingOnUnlocked); | 2155 case EVENT_COMMIT: |
2156 GetCtrlVal(MainPanel, PANEL_CHECKBOX_STOPIFAUTODE, &value); | |
2157 dedrift.threshold = value ? 100.0 : 0.0; | |
2177 break; | 2158 break; |
2178 } | 2159 } |
2179 return 0; | 2160 return 0; |
2180 } | 2161 } |
2181 | 2162 |
2183 void *callbackData, int eventData1, int eventData2) | 2164 void *callbackData, int eventData1, int eventData2) |
2184 { | 2165 { |
2185 switch (event) | 2166 switch (event) |
2186 { | 2167 { |
2187 case EVENT_COMMIT: | 2168 case EVENT_COMMIT: |
2188 GetCtrlVal(MainPanel, PANEL_SLOPE_REFERENCE, &slopeReference); | 2169 GetCtrlVal(MainPanel, PANEL_SLOPE_REFERENCE, &dedrift.reference); |
2189 break; | 2170 break; |
2190 } | 2171 } |
2191 return 0; | 2172 return 0; |
2192 } | 2173 } |
2193 | 2174 |
2276 void *callbackData, int eventData1, int eventData2) | 2257 void *callbackData, int eventData1, int eventData2) |
2277 { | 2258 { |
2278 switch (event) | 2259 switch (event) |
2279 { | 2260 { |
2280 case EVENT_COMMIT: | 2261 case EVENT_COMMIT: |
2281 GetCtrlVal(panel, control, &appliedSlope); | 2262 GetCtrlVal(panel, control, &dedrift.applied); |
2282 DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope); | 2263 DDSFox_SetSweepRate(&DDS1xAD9956, dedrift.applied); |
2283 break; | 2264 break; |
2284 } | 2265 } |
2285 return 0; | 2266 return 0; |
2286 } | 2267 } |
2287 | 2268 |
2289 void *callbackData, int eventData1, int eventData2) | 2270 void *callbackData, int eventData1, int eventData2) |
2290 { | 2271 { |
2291 switch (event) | 2272 switch (event) |
2292 { | 2273 { |
2293 case EVENT_COMMIT: | 2274 case EVENT_COMMIT: |
2294 GetCtrlVal(panel, control, &invertSlopeSign); | 2275 GetCtrlVal(panel, control, &dedrift.invert); |
2295 break; | 2276 break; |
2296 } | 2277 } |
2297 return 0; | 2278 return 0; |
2298 } | 2279 } |
2299 | 2280 |
2302 { | 2283 { |
2303 switch (event) | 2284 switch (event) |
2304 { | 2285 { |
2305 case EVENT_COMMIT: | 2286 case EVENT_COMMIT: |
2306 // stop slope measurement and reset slope | 2287 // stop slope measurement and reset slope |
2307 SlopeMeasuring = 0; | 2288 dedrift.enabled = FALSE; |
2308 SetCtrlVal(panel, PANEL_MEASURE_SLOPE, SlopeMeasuring); | 2289 SetCtrlVal(panel, PANEL_MEASURE_SLOPE, 0); |
2309 CenterFrequencyCh2 = 0.0; | 2290 dedrift.applied = 0.0; |
2310 MoyMath2 = 0.0; | 2291 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, dedrift.applied); |
2311 Nratio = -1; | |
2312 CenterFrequencyCh2ToDetermine = TRUE ; | |
2313 appliedSlope = 0.0; | |
2314 SetCtrlVal(panel, PANEL_SLOPE_APPLIED, appliedSlope); | |
2315 // reset DDS | 2292 // reset DDS |
2316 DDSFox_Reset(&DDS1xAD9956); | 2293 DDSFox_Reset(&DDS1xAD9956); |
2317 DDSFox_SetProfile(&DDS1xAD9956); | 2294 DDSFox_SetProfile(&DDS1xAD9956); |
2318 DDSFox_SetDiv(&DDS1xAD9956, 1); | 2295 DDSFox_SetDiv(&DDS1xAD9956, 1); |
2319 DDSFox_Set(&DDS1xAD9956, dedrift_DDS_freq, appliedSlope); | 2296 DDSFox_Set(&DDS1xAD9956, dedrift.freq0, 0.0); |
2320 break; | 2297 break; |
2321 } | 2298 } |
2322 return 0; | 2299 return 0; |
2323 } | 2300 } |
2324 | 2301 |
2365 void *callbackData, int eventData1, int eventData2) | 2342 void *callbackData, int eventData1, int eventData2) |
2366 { | 2343 { |
2367 switch (event) | 2344 switch (event) |
2368 { | 2345 { |
2369 case EVENT_COMMIT: | 2346 case EVENT_COMMIT: |
2370 GetCtrlVal(panel, control, &slopeX2); | 2347 GetCtrlVal(panel, control, &dedrift.doubleslope); |
2371 break; | 2348 break; |
2372 } | 2349 } |
2373 return 0; | 2350 return 0; |
2374 } | 2351 } |
2375 | 2352 |
2377 void *callbackData, int eventData1, int eventData2) | 2354 void *callbackData, int eventData1, int eventData2) |
2378 { | 2355 { |
2379 switch (event) | 2356 switch (event) |
2380 { | 2357 { |
2381 case EVENT_COMMIT: | 2358 case EVENT_COMMIT: |
2382 GetCtrlVal(panel, control, &dedrift_DDS_freq); | 2359 GetCtrlVal(panel, control, &dedrift.freq0); |
2383 DDSFox_Set(&DDS1xAD9956, dedrift_DDS_freq, appliedSlope); | 2360 DDSFox_Set(&DDS1xAD9956, dedrift.freq0, dedrift.applied); |
2384 break; | 2361 break; |
2385 } | 2362 } |
2386 return 0; | 2363 return 0; |
2387 } | 2364 } |