diff FXAnalyse.c @ 166:fdd2f8fd7714

Minor cleanup
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Thu, 13 Feb 2014 19:17:32 +0100
parents 211ea3950310
children 4de7f2c9f328
line wrap: on
line diff
--- a/FXAnalyse.c	Mon Feb 10 15:19:34 2014 +0100
+++ b/FXAnalyse.c	Thu Feb 13 19:17:32 2014 +0100
@@ -4,8 +4,8 @@
 #include <cvirte.h>		
 #include <userint.h>
 #include <formatio.h>
+#include <inifile.h>
 #include <string.h>
-#include <future.h>
 
 #include "FXAnalyse.h" 
 #include "Plot.h"
@@ -15,8 +15,10 @@
 #include "muParserDLL.h"
 #include "utils.h"
 #include "stat.h"
+#include "future.h"
 #include "data-provider.h"
 
+
 #define CONFIGFILE "FXAnalyse.ini"
 #define SR_LOGGER_IP "145.238.204.91"
 #define DATAFOLDER "Z:\\Measures-2014"
@@ -27,6 +29,7 @@
 #define SR_WAVELENGTH  698.4460    // nm
 #define HG_WAVELENGTH 1062.4000    // nm
 
+
 // data acquisition status
 int acquiring;
 // data queue
@@ -46,12 +49,16 @@
 double Ch1, Ch2, Ch3, Ch4;
 double Math1, Math2, Math3, Math4, Math5;
 double N1, N2, N3;
+double Ndiv = 8.0;
+double Sign1 = 1.0, Sign2 = 1.0, Sign3 = 0.0;
+typedef void* mathparser_t;
+mathparser_t *MathParser1, *MathParser2, *MathParser3, *MathParser4, *MathParser5;
 
 // panels
 static int MainPanel;
+static int LoggingPanel;
 static int CalcNPanel;
 static int EstimateNPanel;
-static int LoggingPanel;
 
 
 struct adev {
@@ -155,12 +162,11 @@
 };
 
 
-// 1xAD9956 DDS box
+// dedrift DDS
 DDSParameter DDS1xAD9956;
 // 4xAD9912 DDS box
 DDS4xAD9912_Data DDS4xAD9912;
 
-muParserHandle_t MathParser1, MathParser2, MathParser3, MathParser4, MathParser5;
 
 enum {
 	LO = 1,
@@ -182,8 +188,6 @@
 int Measuring_2 = N_MEASUREMENT_NONE;											  
 int Measuring_3 = N_MEASUREMENT_NONE;
 
-double Ndiv = 8.0;
-
 int nobs = 0;
 int settling = 0;
 
@@ -204,8 +208,6 @@
 double Frequencystep3=100000.0, tbegin3=0.0, Frepbefore3=0.0, Frequency3=0.0;
 
 int Getsign1=FALSE,Getsign2=FALSE,Getsign3=FALSE;
-double Sign1=1.0, Sign2=1.0, Sign3=0.0;
-
 
 struct stat stat_math1, stat_ch2, stat_ch3, freq;
 struct rollmean rollmean_ch1, rollmean_ch2, rollmean_ch3, rollmean_ch4;
@@ -386,20 +388,22 @@
 }
 
 
-muParserHandle_t initMathParser() 
+mathparser_t * mathparser_new()
 {
-	muParserHandle_t parser = mupCreate();
+	mathparser_t parser = mupCreate();
+	
 	mupDefineOprtChars(parser, "abcdefghijklmnopqrstuvwxyzµ"
                         	   "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                         	   "+-*^/?<>=#!$%&|~'_");
+	
 	mupDefineVar(parser, "Ch1", &Ch1);
 	mupDefineVar(parser, "Ch2", &Ch2);
 	mupDefineVar(parser, "Ch3", &Ch3);
 	mupDefineVar(parser, "Ch4", &Ch4);
 	mupDefineVar(parser, "DDS1", &(DDS4xAD9912.frequency[0]));
 	mupDefineVar(parser, "DDS2", &(DDS4xAD9912.frequency[1]));
-	mupDefineVar(parser, "DDS3", &(DDS4xAD9912.frequency[2]));  
-	mupDefineVar(parser, "DDS4", &(DDS4xAD9912.frequency[3]));  
+	mupDefineVar(parser, "DDS3", &(DDS4xAD9912.frequency[2]));
+	mupDefineVar(parser, "DDS4", &(DDS4xAD9912.frequency[3]));
 	mupDefineVar(parser, "N1", &N1);
 	mupDefineVar(parser, "N2", &N2);
 	mupDefineVar(parser, "N3", &N3);
@@ -423,8 +427,6 @@
 }
 
 
-
-
 void CVICALLBACK DataAvailableCB (CmtTSQHandle queueHandle, unsigned int event,
 		int value, void *callbackData);
 
@@ -434,18 +436,15 @@
 	int rv;
 	double frequency;
 	char expr[1024];
-	
-	if (InitCVIRTE (0, argv, 0) == 0)
+
+	if ((MainPanel = LoadPanel (0, "FXAnalyse.uir", PANEL)) < 0)
 		return -1;
-	
-	if ((MainPanel = LoadPanel (0, "FXAnalyse.uir", PANEL)) < 0)
+	if ((LoggingPanel = LoadPanel (0, "FXAnalyse.uir", LOGGING)) < 0)
 		return -1;
 	if ((CalcNPanel = LoadPanel (MainPanel, "FXAnalyse.uir", CALCN)) < 0)
 		return -1;
 	if ((EstimateNPanel = LoadPanel (MainPanel, "FXAnalyse.uir", ESTIMATEN)) < 0)
 		return -1;
-	if ((LoggingPanel = LoadPanel (0, "FXAnalyse.uir", LOGGING)) < 0)
-		return -1;
 
 	// construct configuration file path
 	char pathname[MAX_PATHNAME_LEN];
@@ -453,7 +452,7 @@
 	GetProjectDir(project);
 	MakePathname(project, CONFIGFILE, pathname);
 
-	// load configuration file */ 
+	// load configuration file
 	IniText configuration = Ini_New(TRUE);
 	Ini_ReadFromFile(configuration, pathname);
 
@@ -461,7 +460,7 @@
 	char host[256];
 	int port;
 	double clock;
-	rv = Ini_StringIntoBuffer(configuration, "AD9956", "host", host, sizeof(host));
+	rv = Ini_GetStringIntoBuffer(configuration, "AD9956", "host", host, sizeof(host));
 	if (! rv)
 		return -1;
 	rv = Ini_GetInt(configuration, "AD9956", "port", &port);
@@ -471,12 +470,12 @@
 	if (! rv)
 		return -1;
 	
-	// initialyze 1x AD9956 DDS box
+	// dispose configuration
+	Ini_Dispose(configuration);
+
+	// dedrift DDS
 	DDSFox_Initialize(&DDS1xAD9956, host, port, dedrift.freq0);
 	
-	// free
-	Ini_Dispose(configuration);
-	
 	// initialize 4x AD9959 DDS box
 	DDS4xAD9912_Reset(&DDS4xAD9912);
 	GetCtrlVal(MainPanel, PANEL_DDS1, &frequency);
@@ -491,37 +490,37 @@
 	GetCtrlVal(MainPanel, PANEL_N1CHOICE, &N1);
 	GetCtrlVal(MainPanel, PANEL_N2CHOICE, &N2);
 	GetCtrlVal(MainPanel, PANEL_N3CHOICE, &N3);
-	
-	MathParser1 = initMathParser();
+
+	MathParser1 = mathparser_new();
 	GetCtrlVal(MainPanel, PANEL_MATHSTRING1, expr);
 	mupSetExpr(MathParser1, expr);
 	
-	MathParser2 = initMathParser();
+	MathParser2 = mathparser_new();
 	mupDefineVar(MathParser2, "Math1", &Math1);
 	GetCtrlVal(MainPanel, PANEL_MATHSTRING2, expr);
 	mupSetExpr(MathParser2, expr);
 	
-	MathParser3 = initMathParser();
+	MathParser3 = mathparser_new();
 	mupDefineVar(MathParser3, "Math1", &Math1);
 	mupDefineVar(MathParser3, "Math2", &Math2);
 	GetCtrlVal(MainPanel, PANEL_MATHSTRING3, expr);
 	mupSetExpr(MathParser3, expr);
 	
-	MathParser4 = initMathParser();
+	MathParser4 = mathparser_new();
 	mupDefineVar(MathParser4, "Math1", &Math1);
 	mupDefineVar(MathParser4, "Math2", &Math2);
 	mupDefineVar(MathParser4, "Math3", &Math3);
 	GetCtrlVal(MainPanel, PANEL_MATHSTRING4, expr);
 	mupSetExpr(MathParser4, expr);
 	
-	MathParser5 = initMathParser();
+	MathParser5 = mathparser_new();
 	mupDefineVar(MathParser5, "Math1", &Math1);
 	mupDefineVar(MathParser5, "Math2", &Math2);
 	mupDefineVar(MathParser5, "Math3", &Math3);
 	mupDefineVar(MathParser5, "Math4", &Math4);
 	GetCtrlVal(MainPanel, PANEL_MATHSTRING5, expr);
 	mupSetExpr(MathParser5, expr);
-
+	
 	// data queue
 	CmtNewTSQ(128, sizeof(struct event), 0, &dataQueue);
 
@@ -537,7 +536,6 @@
 	return 0;
 }
 
-
 int CVICALLBACK QuitCallback (int panel, int control, int event,
 		void *callbackData, int eventData1, int eventData2)
 {
@@ -558,13 +556,13 @@
 	
 #define do_arrow(__DDS, __STEP)										\
 	do {															\
-		GetCtrlIndex(MainPanel, __STEP, &index);					\
+		GetCtrlIndex(panel, __STEP, &index);						\
 		if ((eventData1 == VAL_RIGHT_ARROW_VKEY) && (index < 14))	\
-			SetCtrlIndex(MainPanel, __STEP, index + 1);				\
+			SetCtrlIndex(panel, __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);  \
+			SetCtrlIndex(panel, __STEP, index - 1);					\
+		GetCtrlVal(panel, __STEP, &step);							\
+		SetCtrlAttribute(panel, __DDS, ATTR_INCR_VALUE, step);  	\
 	} while (0) 
 	
 	switch (event) {
@@ -594,16 +592,16 @@
 					}
 					break;
 				case VAL_F2_VKEY :
-					SetActiveCtrl(MainPanel, PANEL_DDS1);
+					SetActiveCtrl(panel, PANEL_DDS1);
 					break;
 				case VAL_F3_VKEY :
-					SetActiveCtrl(MainPanel, PANEL_DDS2);
+					SetActiveCtrl(panel, PANEL_DDS2);
 					break;
 				case VAL_F4_VKEY :
-					SetActiveCtrl(MainPanel, PANEL_DDS3);
+					SetActiveCtrl(panel, PANEL_DDS3);
 					break;
 				case VAL_F5_VKEY :
-					SetActiveCtrl(MainPanel, PANEL_DDS4);
+					SetActiveCtrl(panel, PANEL_DDS4);
 					break;
 			}
 			break;
@@ -620,7 +618,7 @@
 			if (acquiring)
 				break;
 			
-			logmsg("Start");
+			logmsg("start");
 			SetCtrlAttribute(panel, PANEL_STARTBUTTON, ATTR_DIMMED, TRUE);
 			acquiring = 1;
 			
@@ -642,16 +640,16 @@
 			if (! acquiring)
 				break;
 			
-			logmsg("Stop");
+			logmsg("stop");
 			acquiring = 0;
-			
+
 			// wait for data provider thread to terminate
 			CmtWaitForThreadPoolFunctionCompletion(
 				DEFAULT_THREAD_POOL_HANDLE, dataProviderThread,
 				OPT_TP_PROCESS_EVENTS_WHILE_WAITING);
 			CmtReleaseThreadPoolFunctionID(
 				DEFAULT_THREAD_POOL_HANDLE, dataProviderThread);
-			
+
 			SetCtrlAttribute(panel, PANEL_STARTBUTTON, ATTR_DIMMED, FALSE);
 			
 			break;
@@ -686,7 +684,7 @@
 				SetCtrlVal(MainPanel, PANEL_CH2, Ch2);
 				SetCtrlVal(MainPanel, PANEL_CH3, Ch3);  
 				SetCtrlVal(MainPanel, PANEL_CH4, Ch4);
-				
+
 				// compute
 				Math1 = mupEval(MathParser1);
 				Math2 = mupEval(MathParser2);
@@ -703,7 +701,7 @@
 				SetCtrlVal(MainPanel, PANEL_MATH3, thousands(buffer, sizeof(buffer), "%.3f", Math3));
 				SetCtrlVal(MainPanel, PANEL_MATH4, thousands(buffer, sizeof(buffer), "%.3f", Math4));
 				SetCtrlVal(MainPanel, PANEL_MATH5, thousands(buffer, sizeof(buffer), "%.3f", Math5));
-				
+
 				// update timeseries plots
 				for (struct plot *plot = plots; plot->data; plot++)
 					plot_update(plot);
@@ -1326,7 +1324,6 @@
 				// send Sr frequency (Math4) to Sr data logger
 				if (Sr_datalogger_enabled)
 					Sr_datalogger_send("FEMTO2", utc, Math4);
-				
 			}		
 			break;
 	}
@@ -1454,7 +1451,6 @@
 int CVICALLBACK CB_ChangeN (int panel, int control, int event,
 		void *callbackData, int eventData1, int eventData2)
 {
-
 	switch (event)
 	{
 		case EVENT_COMMIT:
@@ -1479,7 +1475,7 @@
 		void *callbackData, int eventData1, int eventData2)
 {
 	double Frequency ;
-	
+
 	switch (event)
 	{
 		case EVENT_COMMIT:
@@ -1585,7 +1581,6 @@
 int CVICALLBACK CB_OnNCalculus (int panel, int control, int event,
 		void *callbackData, int eventData1, int eventData2)
 {
-
 	int visible;
 	
 	switch (event) {
@@ -1715,7 +1710,6 @@
 int  CVICALLBACK CB_OnFindSign (int panel, int control, int event, 
 		void *callbackData, int eventData1, int eventData2)
 {
-	
 	switch (event)
 	{
 		case EVENT_COMMIT:
@@ -1828,7 +1822,6 @@
 int  CVICALLBACK CB_OnResetSlope (int panel, int control, int event, 
 		void *callbackData, int eventData1, int eventData2)
 {
-
 	switch (event)
 	{
 		case EVENT_COMMIT:
@@ -1844,7 +1837,6 @@
 int  CVICALLBACK CB_ChangeSlopeTime (int panel, int control, int event, 
 		void *callbackData, int eventData1, int eventData2)
 {
-
 	switch (event)
 	{
 		case EVENT_COMMIT: