Mercurial > hg > fxanalyse
diff FXAnalyse.c @ 84:c03263186dd7
Rework and cleanup N measurement panels handling. Move logs to dedicated panel.
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Wed, 20 Mar 2013 16:36:36 +0100 |
parents | 47860259afe2 |
children | 6ac1d3de1ae2 |
line wrap: on
line diff
--- a/FXAnalyse.c Wed Mar 20 12:34:06 2013 +0100 +++ b/FXAnalyse.c Wed Mar 20 16:36:36 2013 +0100 @@ -22,11 +22,10 @@ #define DEDRIFT_DDS_FREQUENCY 70000000 // panel handling stuff -static PanelHandle MainPanel ; -static PanelHandle CalcN1Panel ; -static PanelHandle CalcN2Panel ; -static PanelHandle CalcN3Panel ; +static PanelHandle MainPanel; +static PanelHandle CalcNPanel; static PanelHandle EstimateN3Panel; +static PanelHandle LoggingPanel; char LogFileName[MAX_PATHNAME_LEN]; @@ -52,6 +51,17 @@ long OldLogFilePtr = 0; double Ndiv = 8.0; +int settling = 0; + +enum { + MEASURING_N_NONE, + MEASURING_N_Lo, + MEASURING_N_Hg, + MEASURING_N_Sr, +}; + +int measuring = MEASURING_N_NONE; + enum { N_MEASUREMENT_NONE, N_MEASUREMENT_INIT, @@ -62,15 +72,13 @@ N_MEASUREMENT_FREP_MINUS, }; -int settling = 0; - -int Measuring_1 = FALSE; -int Measuring_2 = FALSE; -int Measuring_3 = FALSE; +int Measuring_1 = N_MEASUREMENT_NONE; +int Measuring_2 = N_MEASUREMENT_NONE; +int Measuring_3 = N_MEASUREMENT_NONE; double FrequDDS1=110000000.0, FrequDDS4=110000000.0; -double Slope_1=0.0,Slope_2=0.0,Slope_3=0.0,Beatslope_2=0.0; -double SlopeTime1=40.0, SlopeTime2=40.0; SlopeTime3=40.0; +double Slope_1=0.0, Slope_2=0.0, Slope_3=0.0, Beatslope_2=0.0; +double SlopeTime1=40.0, SlopeTime2=40.0, SlopeTime3=40.0; double Ch4Slope = 0.0; double N_1=0.0, N_2=0.0, N_3=0.0; @@ -183,7 +191,7 @@ msg[len + 1] = '\0'; // display message - SetCtrlVal(MainPanel, PANEL_LOGGING, msg); + SetCtrlVal(LoggingPanel, LOGGING_LOGGING, msg); } @@ -253,14 +261,12 @@ if ((MainPanel = LoadPanel (0, "FXAnalyse.uir", PANEL)) < 0) return -1; - if ((CalcN1Panel = LoadPanel (0, "FXAnalyse.uir", CALCN1)) < 0) - return -1; - if ((CalcN2Panel = LoadPanel (0, "FXAnalyse.uir", CALCN2)) < 0) - return -1; - if ((CalcN3Panel = LoadPanel (0, "FXAnalyse.uir", CALCN3)) < 0) + if ((CalcNPanel = LoadPanel (MainPanel, "FXAnalyse.uir", CALCN)) < 0) return -1; if ((EstimateN3Panel = LoadPanel (MainPanel, "FXAnalyse.uir", ESTIMATEN3)) < 0) return -1; + if ((LoggingPanel = LoadPanel (0, "FXAnalyse.uir", LOGGING)) < 0) + return -1; DisplayPanel (MainPanel); @@ -365,7 +371,8 @@ return 0; } -int CVICALLBACK CB_OnEventMain(int panel, int event, void *callbackData, int eventData1, int eventData2) +int CVICALLBACK CB_OnEventMain(int panel, int event, + void *callbackData, int eventData1, int eventData2) { int ActiveControl ; int StepIndex ; @@ -757,7 +764,7 @@ if ((utc - t1_1) > SlopeTime1) { Slope_1 = stat_math1.slope; Ch4Slope = stat_ch4.slope; - SetCtrlVal(CalcN1Panel, CALCN1_SLOPE, Slope_1); + SetCtrlVal(CalcNPanel, CALCN_SLOPE, Slope_1); // frep positive step DDS4xAD9912_FrequencyRampe(&DDS4xAD9912,1, FrequDDS1,(FrequDDS1+DeltakHz_1*1000), Step1/Ndiv); @@ -849,7 +856,7 @@ // compute N1 N_1 = Signe1 * (2*Ndiv * DeltakHz_1 * 1000)/(Frepminus_1 - Frepplus_1 - Slope_1 * (t3_1 - t2_1)); - SetCtrlVal(CalcN1Panel, CALCN1_N, N_1); + SetCtrlVal(CalcNPanel, CALCN_N, N_1); t1_1 = 0.0; t2_1 = 0.0; @@ -905,7 +912,7 @@ if ((utc - t1_2) > SlopeTime2) { Slope_2 = stat_math1.slope; Beatslope_2 = stat_ch2.slope; - SetCtrlVal(CalcN2Panel, CALCN2_SLOPE, Beatslope_2); + SetCtrlVal(CalcNPanel, CALCN_SLOPE, Beatslope_2); // frep positive step double fDDS1 = FrequDDS1 + DeltakHz_2 * 1000; @@ -1016,7 +1023,7 @@ // compute N2 N_2 = (Signe2)*(-DeltaDDS3+Delta10K_Plus-Delta10K_Minus-Beatslope_2*(t3_2-t2_2) )/(Frepminus_2-Frepplus_2-Slope_2*(t3_2-t2_2)); - SetCtrlVal(CalcN2Panel, CALCN2_N, N_2); + SetCtrlVal(CalcNPanel, CALCN_N, N_2); // back to nominal frequency DDS4xAD9912_FrequencyRampe (&DDS4xAD9912, 1, FrequDDS1-DeltakHz_2*1000,FrequDDS1, Step2/Ndiv ); @@ -1157,7 +1164,7 @@ // compute N3 N_3 = 1000.0 * DeltakHz_3 / (Frepplus_3 - Frepminus_3 + (2 * N3/N1 * Ndiv * DeltakHz_3 * 1000)); - SetCtrlVal(CalcN3Panel, CALCN3_N, N_3); + SetCtrlVal(CalcNPanel, CALCN_N, N_3); t1_3=0.0; t2_3=0.0; @@ -1701,20 +1708,21 @@ int CVICALLBACK CB_OnAcceptN (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { - switch (event) - { + switch (event) { case EVENT_COMMIT: - if (panel == CalcN1Panel) { - N1 = round(N_1); - SetCtrlVal(MainPanel, PANEL_N1CHOICE, N1); - } - if (panel == CalcN2Panel) { - N2 = round(N_2); - SetCtrlVal(MainPanel, PANEL_N2CHOICE, N2); - } - if (panel == CalcN3Panel) { - N3 = round(N_3); - SetCtrlVal(MainPanel, PANEL_N3CHOICE, N3); + switch (measuring) { + case MEASURING_N_Lo: + N1 = round(N_1); + SetCtrlVal(MainPanel, PANEL_N1CHOICE, N1); + break; + case MEASURING_N_Hg: + N2 = round(N_2); + SetCtrlVal(MainPanel, PANEL_N2CHOICE, N2); + break; + case MEASURING_N_Sr: + N3 = round(N_3); + SetCtrlVal(MainPanel, PANEL_N3CHOICE, N3); + break; } break; } @@ -1726,54 +1734,47 @@ void *callbackData, int eventData1, int eventData2) { - int PanelIsVisible, PanelTop, PanelLeft, PanelWidth ; + int visible; - switch (event) - { + switch (event) { case EVENT_COMMIT: - - if (control==PANEL_N1CALCULUS){ - GetPanelAttribute (CalcN1Panel, ATTR_VISIBLE , &PanelIsVisible); - if (PanelIsVisible) { - } - else { - GetPanelAttribute (MainPanel, ATTR_TOP, &PanelTop) ; - GetPanelAttribute (MainPanel, ATTR_LEFT, &PanelLeft) ; - GetPanelAttribute (MainPanel, ATTR_WIDTH, &PanelWidth) ; - SetPanelAttribute (CalcN1Panel, ATTR_TOP, PanelTop+170 ) ; - SetPanelAttribute (CalcN1Panel, ATTR_LEFT, PanelLeft+PanelWidth+4 ) ; - DisplayPanel(CalcN1Panel) ; - } - } - if (control==PANEL_N2CALCULUS){ - GetPanelAttribute (CalcN2Panel, ATTR_VISIBLE , &PanelIsVisible); - if (PanelIsVisible) { - } - else { - GetPanelAttribute (MainPanel, ATTR_TOP, &PanelTop) ; - GetPanelAttribute (MainPanel, ATTR_LEFT, &PanelLeft) ; - GetPanelAttribute (MainPanel, ATTR_WIDTH, &PanelWidth) ; - SetPanelAttribute (CalcN2Panel, ATTR_TOP, PanelTop+310 ) ; - SetPanelAttribute (CalcN2Panel, ATTR_LEFT, PanelLeft+PanelWidth+4 ) ; - DisplayPanel(CalcN2Panel) ; - } - } - if (control==PANEL_N3CALCULUS){ - GetPanelAttribute (CalcN3Panel, ATTR_VISIBLE , &PanelIsVisible); - if (PanelIsVisible) { - } - else { - GetPanelAttribute (MainPanel, ATTR_TOP, &PanelTop) ; - GetPanelAttribute (MainPanel, ATTR_LEFT, &PanelLeft) ; - GetPanelAttribute (MainPanel, ATTR_WIDTH, &PanelWidth) ; - SetPanelAttribute (CalcN3Panel, ATTR_TOP, PanelTop+480 ) ; - SetPanelAttribute (CalcN3Panel, ATTR_LEFT, PanelLeft+PanelWidth+4 ) ; - DisplayPanel(CalcN3Panel) ; - } - } + switch (control) { + case PANEL_N1CALCULUS: + GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); + if (! visible) { + measuring = MEASURING_N_Lo; + SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_1); + SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime1); + SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, DeltakHz_1); + SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Calculate N_Lo"); + DisplayPanel(CalcNPanel); + } + break; + case PANEL_N2CALCULUS: + GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); + if (! visible) { + measuring = MEASURING_N_Hg; + SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_2); + SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime2); + SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, DeltakHz_2); + SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Calculate N_Hg"); + DisplayPanel(CalcNPanel); + } + break; + case PANEL_N3CALCULUS: + GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); + if (! visible) { + measuring = MEASURING_N_Sr; + SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_3); + SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime3); + SetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, DeltakHz_3); + SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Calculate N_Sr"); + DisplayPanel(CalcNPanel); + } + break; + } break; - } - + } return 0; } @@ -1781,19 +1782,30 @@ int CVICALLBACK CB_OnStartNCalculus (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { - - switch (event) - { + switch (event) { case EVENT_COMMIT: - if (panel == CalcN1Panel) - Measuring_1 = TRUE; - if (panel == CalcN2Panel) - Measuring_2 = TRUE; - if (panel == CalcN3Panel) - Measuring_3 = TRUE; - break; + switch (measuring) { + case MEASURING_N_Lo: + GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_1); + GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime1); + GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &DeltakHz_1); + Measuring_1 = TRUE; + break; + case MEASURING_N_Hg: + GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_2); + GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime2); + GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &DeltakHz_2); + Measuring_2 = TRUE; + break; + case MEASURING_N_Sr: + GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_3); + GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime3); + GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &DeltakHz_3); + Measuring_3 = TRUE; + break; + } + break; } - return 0; } @@ -1802,94 +1814,29 @@ int CVICALLBACK CB_OnNStop (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { - int PanelIsVisible; - - switch (event) - { - case EVENT_COMMIT: - if (panel == CalcN1Panel) { - GetPanelAttribute (CalcN1Panel, ATTR_VISIBLE, &PanelIsVisible); - if (PanelIsVisible) - HidePanel(CalcN1Panel); - - Measuring_1 = FALSE; - - SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ; - DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); - SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit) ; - DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit); - } - if (panel == CalcN2Panel) { - GetPanelAttribute (CalcN2Panel, ATTR_VISIBLE, &PanelIsVisible); - if (PanelIsVisible) - HidePanel(CalcN2Panel); - - Measuring_2 = FALSE; - - SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ; - DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); - SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit) ; - DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit); - SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init) ; - DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyDDS3Init); - } - if (panel == CalcN3Panel) { - GetPanelAttribute (CalcN3Panel, ATTR_VISIBLE, &PanelIsVisible); - if (PanelIsVisible) - HidePanel(CalcN3Panel); - - Measuring_3 = FALSE; - } - break; - } - return 0; -} - - -int CVICALLBACK CB_OnIntegrationTime (int panel, int control, int event, - void *callbackData, int eventData1, int eventData2) -{ - double Time ; - switch (event) { case EVENT_COMMIT: - if (panel == CalcN1Panel) { - GetCtrlVal(CalcN1Panel, CALCN1_INTEGRATIONTIME, &Time) ; - DeltaT_1=Time; - } - if (panel == CalcN2Panel) { - GetCtrlVal(CalcN2Panel, CALCN2_INTEGRATIONTIME, &Time) ; - DeltaT_2=Time; - } - if (panel == CalcN3Panel) { - GetCtrlVal(CalcN3Panel, CALCN3_INTEGRATIONTIME, &Time) ; - DeltaT_3=Time; - } - break; - } - return 0; -} - - -int CVICALLBACK CB_OnDeltaFreq (int panel, int control, int event, - void *callbackData, int eventData1, int eventData2) -{ - double Frequ ; - - switch (event) - { - case EVENT_COMMIT: - if (panel == CalcN1Panel) { - GetCtrlVal(CalcN1Panel, CALCN1_DELTAFREQ, &Frequ); - DeltakHz_1 = Frequ; - } - if (panel == CalcN2Panel) { - GetCtrlVal(CalcN2Panel, CALCN2_DELTAFREQ, &Frequ) ; - DeltakHz_2=Frequ; - } - if (panel == CalcN3Panel) { - GetCtrlVal(CalcN3Panel, CALCN3_DELTAFREQ, &Frequ) ; - DeltakHz_3=Frequ; + HidePanel(CalcNPanel); + switch (measuring) { + case MEASURING_N_Lo: + Measuring_1 = FALSE; + SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); + DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); + SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit); + DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit); + break; + case MEASURING_N_Hg: + Measuring_2 = FALSE; + SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); + DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); + SetCtrlVal(MainPanel, PANEL_DDS2, FrequencyDDSBesInit); + DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, FrequencyDDSBesInit); + SetCtrlVal(MainPanel, PANEL_DDS3, FrequencyDDS3Init); + DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, FrequencyDDS3Init); + break; + case MEASURING_N_Sr: + Measuring_3 = FALSE; + break; } break; } @@ -1967,55 +1914,17 @@ } -int CVICALLBACK CB_OnSlopeTime (int panel, int control, int event, - void *callbackData, int eventData1, int eventData2) -{ - double Time ; - - switch (event) - { - case EVENT_COMMIT: - if (panel == CalcN1Panel) { - GetCtrlVal(CalcN1Panel, CALCN1_SLOPETIME, &Time); - SlopeTime1=Time; - } - if (panel == CalcN2Panel) { - GetCtrlVal(CalcN2Panel, CALCN2_SLOPETIME, &Time); - SlopeTime2=Time; - } - if (panel == CalcN3Panel) { - GetCtrlVal(CalcN3Panel, CALCN3_SLOPETIME, &Time); - SlopeTime3=Time; - } - break; - } - return 0; -} - - int CVICALLBACK CB_OnChangeNdiv (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { - double NewN ; - - switch (event) - { + switch (event) { case EVENT_COMMIT: - if (control==PANEL_CHANGENDIV){ - GetCtrlVal(MainPanel, PANEL_CHANGENDIV, &NewN) ; - Ndiv=NewN; - FrequDDS1=880000000.0/Ndiv; - DeltakHz_1=1800.0*8/Ndiv; - DeltakHz_2=1500.0*8/Ndiv; - SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1) ; - DDS4xAD9912_SetFrequency(&DDS4xAD9912,1,FrequDDS1); - SetCtrlVal(CalcN1Panel, CALCN1_DELTAFREQ, DeltakHz_1) ; - SetCtrlVal(CalcN2Panel, CALCN2_DELTAFREQ, DeltakHz_2) ; - } - + GetCtrlVal(MainPanel, PANEL_CHANGENDIV, &Ndiv); + FrequDDS1 = 880000000.0 / Ndiv; + SetCtrlVal(MainPanel, PANEL_DDS1, FrequDDS1); + DDS4xAD9912_SetFrequency(&DDS4xAD9912, 1, FrequDDS1); break; - - } + } return 0; } @@ -2306,3 +2215,26 @@ return 0; } +int CVICALLBACK CB_ShowLog (int panel, int control, int event, + void *callbackData, int eventData1, int eventData2) +{ + switch (event) + { + case EVENT_COMMIT: + SetPanelAttribute(LoggingPanel, ATTR_VISIBLE, 1); + break; + } + return 0; +} + +int CVICALLBACK CB_OnLoggingPanelEvent(int panel, int event, + void *callbackData, int eventData1, int eventData2) +{ + switch (event) + { + case EVENT_CLOSE: + SetPanelAttribute(LoggingPanel, ATTR_VISIBLE, 0); + break; + } + return 0; +}