Mercurial > hg > fxanalyse
diff FXAnalyse.c @ 227:a2f99632a80c
Implement N estimate tacking into account measured beatnote frequency
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Fri, 19 Sep 2014 19:04:47 +0200 |
parents | c244a1ecb6c3 |
children | 5e69d9abbbf2 |
line wrap: on
line diff
--- a/FXAnalyse.c Thu Sep 18 18:50:16 2014 +0200 +++ b/FXAnalyse.c Fri Sep 19 19:04:47 2014 +0200 @@ -24,9 +24,14 @@ #define FREP_STEP_SIZE 50000.0 + #define SPEED_OF_LIGHT 299792458.0 // m/s -#define SR_WAVELENGTH 698.4460 // nm -#define HG_WAVELENGTH 1062.4000 // nm + +#define SR_FREQUENCY 429.228293 // THz +#define SR_WAVELENGTH (SPEED_OF_LIGHT / SR_FREQUENCY / 1.0e3) // nm + +#define HG_FREQUENCY 282.143 // THz +#define HG_WAVELENGTH (SPEED_OF_LIGHT / HG_FREQUENCY / 1.0e3) // nm // select which data provider to use @@ -1616,7 +1621,7 @@ case PANEL_N1CALCULUS: GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); if (! visible) { - SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, LO); + SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(LO)); SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo"); SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time_1); SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time_1); @@ -1628,7 +1633,7 @@ case PANEL_N2CALCULUS: GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); if (! visible) { - SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, HG); + SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(HG)); SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg"); SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time_2); SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time_2); @@ -1640,7 +1645,7 @@ case PANEL_N3CALCULUS: GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); if (! visible) { - SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, SR); + SetPanelAttribute(CalcNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(SR)); SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr"); SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, integration_time_3); SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, slope_time_3); @@ -1658,11 +1663,13 @@ int CVICALLBACK CB_OnStartNCalculus (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { + void *v; int measuring; switch (event) { case EVENT_COMMIT: - GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measuring); + GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v); + measuring = PTR_TO_INT(v); switch (measuring) { case LO: GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &integration_time_1); @@ -1697,12 +1704,14 @@ int CVICALLBACK CB_OnNStop (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { + void *v; int measuring; switch (event) { case EVENT_COMMIT: HidePanel(CalcNPanel); - GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measuring); + GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v); + measuring = PTR_TO_INT(v); switch (measuring) { case LO: n_measurement_1 = FALSE; @@ -1936,96 +1945,6 @@ return 0; } -int CVICALLBACK CB_OnEstimateN (int panel, int control, int event, - void *callbackData, int eventData1, int eventData2) -{ - int visible; - - switch (event) - { - case EVENT_COMMIT: - // reset N estimate - SetCtrlVal(EstimateNPanel, ESTIMATEN_N, 0.0); - // set current frep - SetCtrlVal(EstimateNPanel, ESTIMATEN_FREP, 250e6 + Math1); - switch (control) { - case PANEL_ESTIMATE_N2: - SetCtrlVal(EstimateNPanel, ESTIMATEN_WAVELENGTH, HG_WAVELENGTH); - SetPanelAttribute(EstimateNPanel, ATTR_TITLE, "Estimate N_Hg"); - SetPanelAttribute(EstimateNPanel, ATTR_CALLBACK_DATA, HG); - break; - case PANEL_ESTIMATE_N3: - SetCtrlVal(EstimateNPanel, ESTIMATEN_WAVELENGTH, SR_WAVELENGTH); - SetPanelAttribute(EstimateNPanel, ATTR_TITLE, "Estimate N_Sr"); - SetPanelAttribute(EstimateNPanel, ATTR_CALLBACK_DATA, SR); - break; - } - GetPanelAttribute(EstimateNPanel, ATTR_VISIBLE , &visible); - if (! visible) - DisplayPanel(EstimateNPanel); - break; - } - return 0; -} - -int CVICALLBACK CB_OnNEstimateCancel (int panel, int control, int event, - void *callbackData, int eventData1, int eventData2) -{ - int visible; - - switch (event) - { - case EVENT_COMMIT: - GetPanelAttribute(panel, ATTR_VISIBLE, &visible); - if (visible) - HidePanel(panel); - break; - } - return 0; -} - -int CVICALLBACK CB_OnNEstimateSet (int panel, int control, int event, - void *callbackData, int eventData1, int eventData2) -{ - int estimate; - - switch (event) - { - case EVENT_COMMIT: - GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &estimate); - switch (estimate) { - case HG: - GetCtrlVal(panel, ESTIMATEN_N, &N2); - SetCtrlVal(MainPanel, PANEL_N2, N2); - break; - case SR: - GetCtrlVal(panel, ESTIMATEN_N, &N3); - SetCtrlVal(MainPanel, PANEL_N3, N3); - break; - } - HidePanel(panel); - break; - } - return 0; -} - -int CVICALLBACK CB_OnNEstimate (int panel, int control, int event, - void *callbackData, int eventData1, int eventData2) -{ - double frep, wl, N; - - switch (event) - { - case EVENT_COMMIT: - GetCtrlVal(panel, ESTIMATEN_FREP, &frep); - GetCtrlVal(panel, ESTIMATEN_WAVELENGTH, &wl); - N = round(SPEED_OF_LIGHT / wl / 1e-9 / frep); - SetCtrlVal(panel, ESTIMATEN_N, N); - break; - } - return 0; -} - int CVICALLBACK CB_SetSlope (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { @@ -2219,3 +2138,171 @@ } return 0; } + + +// +// N estimate +// + +static void estimateN (void) +{ + double nu, fbeat, frep, N; + int sign; + + GetCtrlVal(EstimateNPanel, ESTIMATEN_FREQUENCY, &nu); + GetCtrlVal(EstimateNPanel, ESTIMATEN_FREP, &frep); + GetCtrlVal(EstimateNPanel, ESTIMATEN_FBEAT, &fbeat); + GetCtrlVal(EstimateNPanel, ESTIMATEN_SIGN, &sign); + + N = (nu * 1.0e12 - sign * fbeat) / frep; + + SetCtrlVal(EstimateNPanel, ESTIMATEN_N, N); +} + +int CVICALLBACK cb_onEstimateN (int panel, int control, int event, + void *callbackData, int eventData1, int eventData2) +{ + int visible; + + switch (event) + { + case EVENT_COMMIT: + // reset N estimate + SetCtrlVal(EstimateNPanel, ESTIMATEN_N, 0.0); + // set current frep + SetCtrlVal(EstimateNPanel, ESTIMATEN_FREP, 250e6 + Math1); + switch (control) { + case PANEL_ESTIMATE_N2: + // expected frequency + SetCtrlVal(EstimateNPanel, ESTIMATEN_FREQUENCY, HG_FREQUENCY); + SetCtrlVal(EstimateNPanel, ESTIMATEN_WAVELENGTH, HG_WAVELENGTH); + // sign + SetCtrlVal(EstimateNPanel, ESTIMATEN_SIGN, (int)Sign2); + // f_DDS + SetCtrlVal(EstimateNPanel, ESTIMATEN_FDDS, ad9912.frequency[2]); + // f_counter + SetCtrlVal(EstimateNPanel, ESTIMATEN_FDDS, Ch2); + // f_beat + SetCtrlVal(EstimateNPanel, ESTIMATEN_FBEAT, ad9912.frequency[2] - Ch2); + + SetPanelAttribute(EstimateNPanel, ATTR_TITLE, "Estimate N_Hg"); + SetPanelAttribute(EstimateNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(HG)); + break; + case PANEL_ESTIMATE_N3: + // expected frequency + SetCtrlVal(EstimateNPanel, ESTIMATEN_FREQUENCY, SR_FREQUENCY); + SetCtrlVal(EstimateNPanel, ESTIMATEN_WAVELENGTH, SR_WAVELENGTH); + // sign + SetCtrlVal(EstimateNPanel, ESTIMATEN_SIGN, (int)Sign3); + // f_DDS + SetCtrlVal(EstimateNPanel, ESTIMATEN_FDDS, ad9912.frequency[3]); + // f_counter + SetCtrlVal(EstimateNPanel, ESTIMATEN_FDDS, Ch3); + // f_beat + SetCtrlVal(EstimateNPanel, ESTIMATEN_FBEAT, ad9912.frequency[3] - Ch3); + + SetPanelAttribute(EstimateNPanel, ATTR_TITLE, "Estimate N_Sr"); + SetPanelAttribute(EstimateNPanel, ATTR_CALLBACK_DATA, INT_TO_PTR(SR)); + break; + } + + // display dialog + GetPanelAttribute(EstimateNPanel, ATTR_VISIBLE , &visible); + if (! visible) + DisplayPanel(EstimateNPanel); + + // compute + estimateN(); + break; + } + return 0; +} + +int CVICALLBACK cb_onEstimateNWaveleght (int panel, int control, int event, + void *callbackData, int eventData1, int eventData2) +{ + double wavelenght, frequency; + + switch (event) + { + case EVENT_COMMIT: + GetCtrlVal(panel, control, &wavelenght); + frequency = SPEED_OF_LIGHT / (wavelenght * 1.0e-9) / 1.0e12; + SetCtrlVal(panel, ESTIMATEN_FREQUENCY, frequency); + estimateN(); + break; + } + return 0; +} + +int CVICALLBACK cb_onEstimateNFrequency (int panel, int control, int event, + void *callbackData, int eventData1, int eventData2) +{ + double wavelenght, frequency; + + switch (event) + { + case EVENT_COMMIT: + GetCtrlVal(panel, control, &frequency); + wavelenght = SPEED_OF_LIGHT / (frequency * 1.0e12) / 1.0e-9; + SetCtrlVal(panel, ESTIMATEN_WAVELENGTH, wavelenght); + estimateN(); + break; + } + return 0; +} + +int CVICALLBACK cb_onEstimateNChange (int panel, int control, int event, + void *callbackData, int eventData1, int eventData2) +{ + switch (event) + { + case EVENT_COMMIT: + estimateN(); + break; + } + return 0; +} + +int CVICALLBACK cb_onEstimateNClose (int panel, int control, int event, + void *callbackData, int eventData1, int eventData2) +{ + int visible; + + switch (event) + { + case EVENT_COMMIT: + GetPanelAttribute(panel, ATTR_VISIBLE, &visible); + if (visible) + HidePanel(panel); + break; + } + return 0; +} + +int CVICALLBACK cb_onEstimateNSet (int panel, int control, int event, + void *callbackData, int eventData1, int eventData2) +{ + void *v; + int estimate = 0; + + switch (event) + { + case EVENT_COMMIT: + GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &v); + estimate = PTR_TO_INT(v); + switch (estimate) { + case HG: + GetCtrlVal(panel, ESTIMATEN_N, &N2); + SetCtrlVal(MainPanel, PANEL_N2, N2); + break; + case SR: + GetCtrlVal(panel, ESTIMATEN_N, &N3); + SetCtrlVal(MainPanel, PANEL_N3, N3); + break; + } + HidePanel(panel); + break; + } + return 0; +}