changeset 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
files FXAnalyse.c FXAnalyse.h FXAnalyse.uir future.h
diffstat 4 files changed, 204 insertions(+), 108 deletions(-) [+]
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;
+}
--- a/FXAnalyse.h	Thu Sep 18 18:50:16 2014 +0200
+++ b/FXAnalyse.h	Fri Sep 19 19:04:47 2014 +0200
@@ -25,11 +25,15 @@
 
 #define  ESTIMATEN                        2
 #define  ESTIMATEN_N                      2       /* control type: numeric, callback function: (none) */
-#define  ESTIMATEN_ESTIMATE               3       /* control type: command, callback function: CB_OnNEstimate */
-#define  ESTIMATEN_FREP                   4       /* control type: numeric, callback function: (none) */
-#define  ESTIMATEN_SET                    5       /* control type: command, callback function: CB_OnNEstimateSet */
-#define  ESTIMATEN_CANCEL                 6       /* control type: command, callback function: CB_OnNEstimateCancel */
-#define  ESTIMATEN_WAVELENGTH             7       /* control type: numeric, callback function: (none) */
+#define  ESTIMATEN_FCOUNT                 3       /* control type: numeric, callback function: (none) */
+#define  ESTIMATEN_FDDS                   4       /* control type: numeric, callback function: (none) */
+#define  ESTIMATEN_FREP                   5       /* control type: numeric, callback function: cb_onEstimateNChange */
+#define  ESTIMATEN_CLOSE                  6       /* control type: command, callback function: cb_onEstimateNClose */
+#define  ESTIMATEN_SET                    7       /* control type: command, callback function: cb_onEstimateNSet */
+#define  ESTIMATEN_SIGN                   8       /* control type: numeric, callback function: cb_onEstimateNChange */
+#define  ESTIMATEN_FBEAT                  9       /* control type: numeric, callback function: cb_onEstimateNChange */
+#define  ESTIMATEN_FREQUENCY              10      /* control type: numeric, callback function: cb_onEstimateNFrequency */
+#define  ESTIMATEN_WAVELENGTH             11      /* control type: numeric, callback function: cb_onEstimateNWaveleght */
 
 #define  LOGGING                          3       /* callback function: CB_OnLoggingPanelEvent */
 #define  LOGGING_LOGGING                  2       /* control type: textBox, callback function: (none) */
@@ -109,8 +113,8 @@
 #define  PANEL_CHECKBOX_KEEPSLOPE         73      /* control type: radioButton, callback function: CB_OnCROX */
 #define  PANEL_CHECKBOX_KEEP              74      /* control type: radioButton, callback function: CB_OnCROX */
 #define  PANEL_SLOPE_REFERENCE            75      /* control type: ring, callback function: CB_OnSlopeReference */
-#define  PANEL_ESTIMATE_N2                76      /* control type: command, callback function: CB_OnEstimateN */
-#define  PANEL_ESTIMATE_N3                77      /* control type: command, callback function: CB_OnEstimateN */
+#define  PANEL_ESTIMATE_N2                76      /* control type: command, callback function: cb_onEstimateN */
+#define  PANEL_ESTIMATE_N3                77      /* control type: command, callback function: cb_onEstimateN */
 #define  PANEL_INVERT_SLOPE_SIGN          78      /* control type: radioButton, callback function: CB_InvertSlopeSign */
 #define  PANEL_RECENTER                   79      /* control type: LED, callback function: CB_RecenterEnable */
 #define  PANEL_MEASURE_SLOPE              80      /* control type: LED, callback function: CB_MeasureSlope */
@@ -171,15 +175,17 @@
 int  CVICALLBACK CB_OnAllanPlot(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
 int  CVICALLBACK CB_OnChangeNdiv(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
 int  CVICALLBACK CB_OnCROX(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
-int  CVICALLBACK CB_OnEstimateN(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
+int  CVICALLBACK cb_onEstimateN(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
+int  CVICALLBACK cb_onEstimateNChange(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
+int  CVICALLBACK cb_onEstimateNClose(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
+int  CVICALLBACK cb_onEstimateNFrequency(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
+int  CVICALLBACK cb_onEstimateNSet(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
+int  CVICALLBACK cb_onEstimateNWaveleght(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
 int  CVICALLBACK CB_OnEventMain(int panel, int event, void *callbackData, int eventData1, int eventData2);
 int  CVICALLBACK CB_OnFindSign(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
 int  CVICALLBACK CB_OnFreqPlot(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
 int  CVICALLBACK CB_OnLoggingPanelEvent(int panel, int event, void *callbackData, int eventData1, int eventData2);
 int  CVICALLBACK CB_OnNCalculus(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
-int  CVICALLBACK CB_OnNEstimate(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
-int  CVICALLBACK CB_OnNEstimateCancel(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
-int  CVICALLBACK CB_OnNEstimateSet(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
 int  CVICALLBACK CB_OnNStop(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
 int  CVICALLBACK CB_OnResetSlope(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
 int  CVICALLBACK CB_OnSlopeReference(int panel, int control, int event, void *callbackData, int eventData1, int eventData2);
Binary file FXAnalyse.uir has changed
--- a/future.h	Thu Sep 18 18:50:16 2014 +0200
+++ b/future.h	Fri Sep 19 19:04:47 2014 +0200
@@ -1,6 +1,9 @@
 #ifndef __FUTURE_H__
 #define __FUTURE_H__
 
+#define PTR_TO_INT(p) ((int) ((intptr_t)(p)))
+#define INT_TO_PTR(u) ((void *) ((intptr_t)(u)))
+
 double round(double x);
 
 typedef unsigned int time_t;