changeset 82:47860259afe2

Implement logging
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Wed, 20 Mar 2013 12:08:49 +0100
parents be814b934eca
children b7810db29c12
files FXAnalyse.c FXAnalyse.h FXAnalyse.uir
diffstat 3 files changed, 40 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/FXAnalyse.c	Mon Mar 18 12:36:34 2013 +0100
+++ b/FXAnalyse.c	Wed Mar 20 12:08:49 2013 +0100
@@ -158,6 +158,34 @@
 
 struct stat stat_math1, stat_ch2, stat_ch4, freq;
 
+#define MIN(x, y) (x) < (y) ? (x) : (y)
+
+void logmsg(const char *frmt, ...)
+{
+	char msg[1024];
+	int len = 0;
+	
+	// timestamp
+	len += sprintf(msg, "%014.3f ", utc);
+	time_t now = time(NULL);
+	struct tm *t = localtime(&now);
+	len += strftime(msg + len, sizeof(msg) - len, "%d-%m-%Y %H:%M:%S ", t);
+	
+	// message
+	va_list args;
+	va_start(args, frmt);
+	len += vsnprintf(msg + len, sizeof(msg) - len, frmt, args);
+	va_end(args);
+	
+	// add newline
+	len = MIN(len, sizeof(msg) - 2);
+	msg[len] = '\n';
+	msg[len + 1] = '\0';
+	
+	// display message
+	SetCtrlVal(MainPanel, PANEL_LOGGING, msg);
+}
+
 
 muParserHandle_t initMathParser() 
 {
@@ -478,8 +506,11 @@
 			CurrentFileName(LogFileName);
 			GetFileInfo(LogFileName, &OldLogFilePtr);
 			OldLogFilePtr -= OldLogFilePtr%FXLINELENGTH + FXLINELENGTH - 2;
+			
+			logmsg("Start");
+			
 			break;
-		}
+	}
 	return 0;
 }
 
@@ -1264,6 +1295,8 @@
 						SetCtrlVal(MainPanel, PANEL_SLOPE_APPLIED, appliedSlope);
 						DDSFox_SetSweepRate(&DDS1xAD9956, appliedSlope);
 						
+						logmsg("Slope correction update (%+6g) %6g", freq.slope, appliedSlope);
+						
 						stat_zero(&freq);
 						SlopeMeasuringTimeBegin = utc;
 					}
@@ -2005,6 +2038,8 @@
 				CenterFrequencyCh2ToDetermine = TRUE ;
 				CenterFrequencyCh2 = 0.0;
 				
+				logmsg("Start slope measurement");
+				
 			} else {
 				if (! KeepSlope) {
 					appliedSlope = 0.0;
@@ -2016,6 +2051,8 @@
 				}
 				stat_zero(&freq);
 				SetCtrlVal(panel, PANEL_SLOPE_MEASURED, freq.slope);
+				
+				logmsg("Stop slope measurement");
 			}
 			break;
 	}
@@ -2036,6 +2073,7 @@
 			appliedSlope = 0.0; 
 			SetCtrlVal(panel, PANEL_SLOPE_APPLIED, appliedSlope);
 			DDSFox_Set(&DDS1xAD9956, DEDRIFT_DDS_FREQUENCY, appliedSlope);
+			logmsg("Reset slope measurement");
 			break;
 	}
 	return 0;
--- a/FXAnalyse.h	Mon Mar 18 12:36:34 2013 +0100
+++ b/FXAnalyse.h	Wed Mar 20 12:08:49 2013 +0100
@@ -172,6 +172,7 @@
 #define  PANEL_MEASURE_SLOPE              118     /* control type: LED, callback function: CB_MeasureSlope */
 #define  PANEL_SLOPE_MEASURED             119     /* control type: numeric, callback function: (none) */
 #define  PANEL_RESET_DEDRIFT_DDS          120     /* control type: command, callback function: CB_ResetDedriftDDS */
+#define  PANEL_LOGGING                    121     /* control type: textBox, callback function: (none) */
 
 
      /* Menu Bars, Menus, and Menu Items: */
Binary file FXAnalyse.uir has changed