Mercurial > hg > fxanalyse
changeset 161:6ee23cb3d6bb
Coding style fixes
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Tue, 04 Feb 2014 17:07:59 +0100 |
parents | f609fb29536b |
children | 1517a56163de |
files | FXAnalyse.c |
diffstat | 1 files changed, 111 insertions(+), 137 deletions(-) [+] |
line wrap: on
line diff
--- a/FXAnalyse.c Tue Feb 04 12:48:37 2014 +0100 +++ b/FXAnalyse.c Tue Feb 04 17:07:59 2014 +0100 @@ -62,7 +62,7 @@ }; -#define ADEV_INIT(__channel, __normalization) \ +#define ADEV(__channel, __normalization) \ { \ .data = & ## __channel, \ .title = #__channel, \ @@ -90,15 +90,15 @@ struct adev adevs[] = { - ADEV_INIT(Ch1, 1.84e12), - ADEV_INIT(Ch2, 10.0e3), - ADEV_INIT(Ch3, 429.228e12), - ADEV_INIT(Ch4, 275.0e3), - ADEV_INIT(Math1, 250.0e6), - ADEV_INIT(Math2, 194.395e12), - ADEV_INIT(Math3, 282.143e12), - ADEV_INIT(Math4, 429.228e12), - ADEV_INIT(Math5, 1.0), + ADEV(Ch1, 1.84e12), + ADEV(Ch2, 10.0e3), + ADEV(Ch3, 429.228e12), + ADEV(Ch4, 275.0e3), + ADEV(Math1, 250.0e6), + ADEV(Math2, 194.395e12), + ADEV(Math3, 282.143e12), + ADEV(Math4, 429.228e12), + ADEV(Math5, 1.0), { NULL } }; @@ -113,7 +113,7 @@ }; -#define PLOT_INIT(__channel, __min, __max) \ +#define PLOT(__channel, __min, __max) \ { \ .data = & ## __channel, \ .title = #__channel, \ @@ -141,15 +141,15 @@ } struct plot plots[] = { - PLOT_INIT(Ch1, 54.999e6, 55.001e6), - PLOT_INIT(Ch2, 0.0, 0.0), - PLOT_INIT(Ch3, 0.0, 0.0), - PLOT_INIT(Ch4, 0.0, 0.0), - PLOT_INIT(Math1, 0.0, 0.0), - PLOT_INIT(Math2, 0.0, 0.0), - PLOT_INIT(Math3, 0.0, 0.0), - PLOT_INIT(Math4, 0.0, 0.0), - PLOT_INIT(Math5, 0.0, 0.0), + PLOT(Ch1, 54.999e6, 55.001e6), + PLOT(Ch2, 0.0, 0.0), + PLOT(Ch3, 0.0, 0.0), + PLOT(Ch4, 0.0, 0.0), + PLOT(Math1, 0.0, 0.0), + PLOT(Math2, 0.0, 0.0), + PLOT(Math3, 0.0, 0.0), + PLOT(Math4, 0.0, 0.0), + PLOT(Math5, 0.0, 0.0), { NULL } }; @@ -162,10 +162,9 @@ muParserHandle_t MathParser1, MathParser2, MathParser3, MathParser4, MathParser5; enum { - N_NONE, - N_LO, - N_HG, - N_SR, + LO = 1, + HG = 2, + SR = 4, }; enum { @@ -195,7 +194,6 @@ double SlopeTime3=40.0, DeltaT_3=20.0, delta_f_lock_3=500.0; double DeltaDDS3=0.0; -double Nu1=0.0, Nu2= 200000-147000+282143746.557455e6; double t1, t2, t3; double f_rep_slope, f_beat_slope; @@ -215,6 +213,11 @@ // dedrift +enum { + DEDRIFT_REFERENCE_MICROWAVE = 0, + DEDRIFT_REFERENCE_HG = 1, +}; + struct dedrift { int enabled; // dedrift enabled int reference; // reference frequency @@ -229,11 +232,6 @@ double t0; // beginning of currrent measurement interval }; -enum { - DEDRIFT_REFERENCE_MICROWAVE = 0, - DEDRIFT_REFERENCE_HG = 1, -}; - struct dedrift dedrift = { .enabled = FALSE, .reference = DEDRIFT_REFERENCE_MICROWAVE, @@ -278,15 +276,23 @@ int write; }; +#define DATAFILE(__name, __data, __nchan, __control, __write) \ + { \ + .name = __name, \ + .data = __data, \ + .nchan = __nchan, \ + .control = __control, \ + .write = __write \ + } struct datafile datafiles[] = { - { "Raw", event.data, 4, PANEL_SAVE_RAW, TRUE }, - { "DDS", DDS4xAD9912.frequency, 4, PANEL_SAVE_DDS, FALSE }, - { "Lo", &Math2, 1, PANEL_SAVE_LO, FALSE }, - { "Hg", &Math3, 1, PANEL_SAVE_HG, FALSE }, - { "Sr", &Math4, 1, PANEL_SAVE_SR, FALSE }, - { "Ex", &Math5, 1, PANEL_SAVE_EXTRA, FALSE }, - { NULL, } + DATAFILE("Raw", event.data, 4, PANEL_SAVE_RAW, TRUE), + DATAFILE("DDS", DDS4xAD9912.frequency, 4, PANEL_SAVE_DDS, FALSE), + DATAFILE("Lo", &Math2, 1, PANEL_SAVE_LO, FALSE), + DATAFILE("Hg", &Math3, 1, PANEL_SAVE_HG, FALSE), + DATAFILE("Sr", &Math4, 1, PANEL_SAVE_SR, FALSE), + DATAFILE("Ex", &Math5, 1, PANEL_SAVE_EXTRA, FALSE), + { NULL, } }; @@ -453,8 +459,6 @@ // initialyze 1x AD9956 DDS box DDSFox_Initialize(&DDS1xAD9956, "145.238.205.58", 6665, dedrift.freq0); - Ch1 = Ch2 = Ch3 = Ch4 = 0.0; - GetCtrlVal(MainPanel, PANEL_N1CHOICE, &N1); GetCtrlVal(MainPanel, PANEL_N2CHOICE, &N2); GetCtrlVal(MainPanel, PANEL_N3CHOICE, &N3); @@ -520,83 +524,45 @@ int CVICALLBACK CB_OnEventMain(int panel, int event, void *callbackData, int eventData1, int eventData2) { - int ActiveControl ; - int StepIndex ; - double Step ; + int control, index; + double step; + +#define do_arrow(__DDS, __STEP) \ + do { \ + GetCtrlIndex(MainPanel, __STEP, &index); \ + if ((eventData1 == VAL_RIGHT_ARROW_VKEY) && (index < 14)) \ + SetCtrlIndex(MainPanel, __STEP, index + 1); \ + if ((eventData1 == VAL_LEFT_ARROW_VKEY) && (index > 0)) \ + SetCtrlIndex(MainPanel, __STEP, index - 1); \ + GetCtrlVal(MainPanel, __STEP, &step); \ + SetCtrlAttribute(MainPanel, __DDS, ATTR_INCR_VALUE, step); \ + } while (0) switch (event) { case EVENT_KEYPRESS: - switch (eventData1) // ie the code of the key which has been stroke - { - case VAL_RIGHT_ARROW_VKEY : - ActiveControl = GetActiveCtrl(panel); - if (ActiveControl==PANEL_DDS1 || ActiveControl==PANEL_DDS1STEP) { - GetCtrlIndex(MainPanel, PANEL_DDS1STEP, &StepIndex); - if (StepIndex<14){ - SetCtrlIndex(MainPanel, PANEL_DDS1STEP, ++StepIndex) ; - GetCtrlVal(MainPanel, PANEL_DDS1STEP, &Step); - SetCtrlAttribute(MainPanel, PANEL_DDS1, ATTR_INCR_VALUE, Step) ; - }; - }; - if (ActiveControl==PANEL_DDS2 || ActiveControl==PANEL_DDS2STEP) { - GetCtrlIndex(MainPanel, PANEL_DDS2STEP, &StepIndex); - if (StepIndex<14){ - SetCtrlIndex(MainPanel, PANEL_DDS2STEP, ++StepIndex) ; - GetCtrlVal(MainPanel, PANEL_DDS2STEP, &Step); - SetCtrlAttribute(MainPanel, PANEL_DDS2, ATTR_INCR_VALUE, Step) ; - }; - }; - if (ActiveControl==PANEL_DDS3|| ActiveControl==PANEL_DDS3STEP) { - GetCtrlIndex(MainPanel, PANEL_DDS3STEP, &StepIndex); - if (StepIndex<14){ - SetCtrlIndex(MainPanel, PANEL_DDS3STEP, ++StepIndex) ; - GetCtrlVal(MainPanel, PANEL_DDS3STEP, &Step); - SetCtrlAttribute(MainPanel, PANEL_DDS3, ATTR_INCR_VALUE, Step) ; - }; - }; - if (ActiveControl==PANEL_DDS4|| ActiveControl==PANEL_DDS4STEP) { - GetCtrlIndex(MainPanel, PANEL_DDS4STEP, &StepIndex); - if (StepIndex<14){ - SetCtrlIndex(MainPanel, PANEL_DDS4STEP, ++StepIndex) ; - GetCtrlVal(MainPanel, PANEL_DDS4STEP, &Step); - SetCtrlAttribute(MainPanel, PANEL_DDS4, ATTR_INCR_VALUE, Step) ; - }; - }; - break; - case VAL_LEFT_ARROW_VKEY : - ActiveControl = GetActiveCtrl(panel); - if (ActiveControl==PANEL_DDS1 || ActiveControl==PANEL_DDS1STEP) { - GetCtrlIndex(MainPanel, PANEL_DDS1STEP, &StepIndex); - if (StepIndex>0){ - SetCtrlIndex(MainPanel, PANEL_DDS1STEP, --StepIndex) ; - GetCtrlVal(MainPanel, PANEL_DDS1STEP, &Step); - SetCtrlAttribute(MainPanel, PANEL_DDS1, ATTR_INCR_VALUE, Step) ; - }; - }; - if (ActiveControl==PANEL_DDS2 || ActiveControl==PANEL_DDS2STEP) { - GetCtrlIndex(MainPanel, PANEL_DDS2STEP, &StepIndex); - if (StepIndex>0){ - SetCtrlIndex(MainPanel, PANEL_DDS2STEP, --StepIndex) ; - GetCtrlVal(MainPanel, PANEL_DDS2STEP, &Step); - SetCtrlAttribute(MainPanel, PANEL_DDS2, ATTR_INCR_VALUE, Step) ; - }; - }; - if (ActiveControl==PANEL_DDS3 || ActiveControl==PANEL_DDS3STEP) { - GetCtrlIndex(MainPanel, PANEL_DDS3STEP, &StepIndex); - if (StepIndex>0){ - SetCtrlIndex(MainPanel, PANEL_DDS3STEP, --StepIndex) ; - GetCtrlVal(MainPanel, PANEL_DDS3STEP, &Step); - SetCtrlAttribute(MainPanel, PANEL_DDS3, ATTR_INCR_VALUE, Step) ; - }; - }; - if (ActiveControl==PANEL_DDS4 || ActiveControl==PANEL_DDS4STEP) { - GetCtrlIndex(MainPanel, PANEL_DDS4STEP, &StepIndex); - if (StepIndex>0){ - SetCtrlIndex(MainPanel, PANEL_DDS4STEP, --StepIndex) ; - GetCtrlVal(MainPanel, PANEL_DDS4STEP, &Step); - SetCtrlAttribute(MainPanel, PANEL_DDS4, ATTR_INCR_VALUE, Step) ; - }; - }; + /* key code */ + switch (eventData1) { + case VAL_RIGHT_ARROW_VKEY: + case VAL_LEFT_ARROW_VKEY: + control = GetActiveCtrl(panel); + switch (control) { + case PANEL_DDS1: + case PANEL_DDS1STEP: + do_arrow(PANEL_DDS1, PANEL_DDS1STEP); + break; + case PANEL_DDS2: + case PANEL_DDS2STEP: + do_arrow(PANEL_DDS2, PANEL_DDS2STEP); + break; + case PANEL_DDS3: + case PANEL_DDS3STEP: + do_arrow(PANEL_DDS3, PANEL_DDS3STEP); + break; + case PANEL_DDS4: + case PANEL_DDS4STEP: + do_arrow(PANEL_DDS4, PANEL_DDS4STEP); + break; + } break; case VAL_F2_VKEY : SetActiveCtrl(MainPanel, PANEL_DDS1); @@ -610,9 +576,8 @@ case VAL_F5_VKEY : SetActiveCtrl(MainPanel, PANEL_DDS4); break; - }; + } break; - } return 0; } @@ -969,7 +934,12 @@ nobs = 0; // compute N2 - double delta_f_rep = f_rep_minus - f_rep_plus; + double delta_f_rep_m = f_rep_minus - f_rep_plus; + double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock_3 / N1; + + logmsg("delta frep: measured=%e expected=%e difference=%e", + delta_f_rep_m, delta_f_rep, delta_f_rep_m - delta_f_rep); + N_2 = -Sign2 * (DeltaDDS3 + f_beat_minus - f_beat_plus) / delta_f_rep; SetCtrlVal(CalcNPanel, CALCN_N, N_2); @@ -1116,20 +1086,24 @@ // check delta frep double delta_f_rep_m = f_rep_plus - f_rep_minus; double delta_f_rep = Sign1 * Ndiv * 2.0 * delta_f_lock_3 / N1; - logmsg("delta frep: measured=%.12e Hz expected=%.12e Hz difference=%.12e", + + logmsg("delta frep: measured=%e expected=%e difference=%e", delta_f_rep_m, delta_f_rep, delta_f_rep_m - delta_f_rep); - logmsg("f_beat_minus=%.12e", f_beat_minus); - logmsg("f_beat_plus =%.12e", f_beat_plus); + logmsg("f_beat_minus=%e", f_beat_minus); + logmsg("f_beat_plus =%e", f_beat_plus); // compute N3 double delta_f_beat = f_beat_plus - f_beat_minus + 2.0 * Sign1 * Sign3 * N3/N1 * Ndiv * delta_f_lock_3; double delta_f_beat_expected = delta_f_rep * N3; - logmsg("delta fbeat: measured=%.12e expected=%.12e difference=%.12e", + + logmsg("delta fbeat: measured=%e expected=%e difference=%e", delta_f_beat, delta_f_beat_expected, delta_f_beat - delta_f_beat_expected); + N_3 = delta_f_beat / delta_f_rep; + SetCtrlVal(CalcNPanel, CALCN_N, N_3); + logmsg("measured N3=%.3f", N_3); - SetCtrlVal(CalcNPanel, CALCN_N, N_3); // back to nominal frep DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); @@ -1561,15 +1535,15 @@ case EVENT_COMMIT: GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measure); switch (measure) { - case N_LO: + case LO: N1 = round(N_1); SetCtrlVal(MainPanel, PANEL_N1CHOICE, N1); break; - case N_HG: + case HG: N2 = round(N_2); SetCtrlVal(MainPanel, PANEL_N2CHOICE, N2); break; - case N_SR: + case SR: N3 = round(N_3); SetCtrlVal(MainPanel, PANEL_N3CHOICE, N3); break; @@ -1591,7 +1565,7 @@ case PANEL_N1CALCULUS: GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); if (! visible) { - SetPanelAttribute(panel, ATTR_CALLBACK_DATA, N_LO); + SetPanelAttribute(panel, ATTR_CALLBACK_DATA, LO); SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Lo"); SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_1); SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime1); @@ -1603,7 +1577,7 @@ case PANEL_N2CALCULUS: GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); if (! visible) { - SetPanelAttribute(panel, ATTR_CALLBACK_DATA, N_HG); + SetPanelAttribute(panel, ATTR_CALLBACK_DATA, HG); SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Hg"); SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_2); SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime2); @@ -1615,7 +1589,7 @@ case PANEL_N3CALCULUS: GetPanelAttribute(CalcNPanel, ATTR_VISIBLE, &visible); if (! visible) { - SetPanelAttribute(panel, ATTR_CALLBACK_DATA, N_SR); + SetPanelAttribute(panel, ATTR_CALLBACK_DATA, SR); SetPanelAttribute(CalcNPanel, ATTR_TITLE, "Measure N_Sr"); SetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, DeltaT_3); SetCtrlVal(CalcNPanel, CALCN_SLOPETIME, SlopeTime3); @@ -1639,7 +1613,7 @@ case EVENT_COMMIT: GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measuring); switch (measuring) { - case N_LO: + case LO: GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_1); GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime1); GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_1); @@ -1647,7 +1621,7 @@ delta_f_lock_1 = delta_f_lock_1 * 1000.0; Measuring_1 = TRUE; break; - case N_HG: + case HG: GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_2); GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime2); GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_2); @@ -1655,7 +1629,7 @@ delta_f_lock_2 = delta_f_lock_2 * 1000.0; Measuring_2 = TRUE; break; - case N_SR: + case SR: GetCtrlVal(CalcNPanel, CALCN_INTEGRATIONTIME, &DeltaT_3); GetCtrlVal(CalcNPanel, CALCN_SLOPETIME, &SlopeTime3); GetCtrlVal(CalcNPanel, CALCN_DELTAFREQ, &delta_f_lock_3); @@ -1679,18 +1653,18 @@ HidePanel(CalcNPanel); GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &measuring); switch (measuring) { - case N_LO: + case LO: Measuring_1 = FALSE; DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); break; - case N_HG: + case HG: Measuring_2 = FALSE; DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); DDS4xAD9912_SetFrequency(&DDS4xAD9912, 3, f0_DDS3); break; - case N_SR: + case SR: Measuring_3 = FALSE; DDS4xAD9912_RampFrequency(&DDS4xAD9912, 1, f0_DDS1, FREP_STEP_SIZE); DDS4xAD9912_SetFrequency(&DDS4xAD9912, 2, f0_DDS2); @@ -1933,12 +1907,12 @@ case PANEL_ESTIMATE_N2: SetCtrlVal(EstimateNPanel, ESTIMATEN_WAVELENGTH, HG_WAVELENGTH); SetPanelAttribute(panel, ATTR_TITLE, "Estimate N_Hg"); - SetPanelAttribute(panel, ATTR_CALLBACK_DATA, N_HG); + SetPanelAttribute(panel, ATTR_CALLBACK_DATA, HG); break; case PANEL_ESTIMATE_N3: SetCtrlVal(EstimateNPanel, ESTIMATEN_WAVELENGTH, SR_WAVELENGTH); SetPanelAttribute(panel, ATTR_TITLE, "Estimate N_Sr"); - SetPanelAttribute(panel, ATTR_CALLBACK_DATA, N_SR); + SetPanelAttribute(panel, ATTR_CALLBACK_DATA, SR); break; } break; @@ -1972,11 +1946,11 @@ case EVENT_COMMIT: GetPanelAttribute(panel, ATTR_CALLBACK_DATA, &estimate); switch (estimate) { - case N_HG: + case HG: GetCtrlVal(panel, ESTIMATEN_N, &N2); SetCtrlVal(MainPanel, PANEL_N3CHOICE, N2); break; - case N_SR: + case SR: GetCtrlVal(panel, ESTIMATEN_N, &N3); SetCtrlVal(MainPanel, PANEL_N3CHOICE, N3); break;