diff FXAnalyse.c @ 119:f9fb17fb64cc

Add Sr frequency logging to disk and to Sr data logger
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Thu, 12 Sep 2013 18:01:49 +0200
parents 43b35f4aae78
children f48e8ff21f0f
line wrap: on
line diff
--- a/FXAnalyse.c	Thu Sep 12 15:49:27 2013 +0200
+++ b/FXAnalyse.c	Thu Sep 12 18:01:49 2013 +0200
@@ -1,3 +1,4 @@
+#include <tcpsupp.h>
 #include <utility.h>
 #include <ansi_c.h>
 #include <cvirte.h>		
@@ -187,6 +188,12 @@
 
 #define MIN(x, y) (x) < (y) ? (x) : (y)
 
+// MJD functiom used by the Sr programs
+static inline double utc2mjd(double utc)
+{
+	return 15020.0 + utc / 86400.0;
+}
+
 void logmsg(const char *frmt, ...)
 {
 	char msg[1024];
@@ -213,6 +220,30 @@
 	SetCtrlVal(LoggingPanel, LOGGING_LOGGING, msg);
 }
 
+// Sr data logger
+int sendLogger(const char* id, double utc, double data)
+{
+	static unsigned int handle = 0;
+	char buffer[1024];
+
+	// try to connect and quit if unsuccessfull
+	if (handle == 0) {
+		if (ConnectToTCPServer(&handle, 3491, "145.238.204.146", NULL, NULL, 1) < 0) {
+			logmsg("Sr data logger connection error");
+			return -1;
+		}
+		logmsg("connected to Sr data logger");
+	}
+
+	snprintf(buffer, sizeof(buffer), "%s %.7f %.8f", id, utc2mjd(utc), data);
+	if (ClientTCPWrite(handle, buffer, strlen(buffer) + 1, 0) < 0) {
+		// try to reconnect and resend
+		handle = 0;
+		sendLogger(id, utc, data);
+	}
+	
+	return 0;
+}
 
 muParserHandle_t initMathParser() 
 {
@@ -1375,6 +1406,19 @@
 					writeData("C:\\Femto\\Results", "Hg", id, timestr, utc, Math3);
 				}
 				
+				// write Sr frequency (Math4) to disk
+				GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH4SAVE, &save);
+				if (save) {
+					writeData(DATAFOLDER, "Sr", id, timestr, utc, Math4);
+				}
+				
+				// send Sr frequency (Math4) to Sr data logger
+				GetCtrlVal(MainPanel, PANEL_SR_LOGGER, &save);
+				if (save) {
+					sendLogger("FEMTO2", utc, Math4);
+				}
+				
+				
 				// write ExtraMath (Math5) to disk
 				GetCtrlVal(MainPanel, PANEL_CHECKBOX_MATH5SAVE, &save);
 				if (save) {