changeset 177:5b4b7f37bd3b

Make number of KK counter channels read configurable
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 21 Feb 2014 18:38:44 +0100
parents 6ccc428c412a
children 03dcca7e5ba4
files kk-data-provider.c
diffstat 1 files changed, 22 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/kk-data-provider.c	Fri Feb 21 18:38:44 2014 +0100
+++ b/kk-data-provider.c	Fri Feb 21 18:38:44 2014 +0100
@@ -10,7 +10,8 @@
 #include "KKFX80E.h"
 
 #define CONFIGFILE "FXAnalyse.ini"
-#define DEFAULTPORT "COM4:115200"
+#define DEFAULT_PORT "COM4:115200"
+#define DEFAULT_NCHAN 4
 #define TIMEOUT 1 /* seconds */
 
 #define strneq(a, b, len) (strncmp((a), (b), (len)) == 0)
@@ -21,6 +22,7 @@
 	int rv;
 	char *resp;
 	struct event event;
+	int nchan;
 	char port[256];
 	
 	/* get main thread id to post messages to it */
@@ -39,7 +41,12 @@
 	/* get serial port name configuration */
 	rv = Ini_GetStringIntoBuffer(configuration, "KK", "port", port, sizeof(port));
 	if (! rv)
-		strncpy(port, DEFAULTPORT, sizeof(port));
+		strncpy(port, DEFAULT_PORT, sizeof(port));
+	
+	/* channels number */
+	rv = Ini_GetInt(configuration, "KK", "nchan", &nchan);
+	if (! rv)
+		nchan = DEFAULT_NCHAN;
 	
 	/* free */ 
 	Ini_Dispose(configuration);
@@ -78,8 +85,10 @@
 		goto error;
 	}
 	
-	/* read 4 channels */
-	rv = FX_Send("\x34");
+	/* read nchan channels */
+	char *cmd = "\x30";
+	cmd[0] += nchan;
+	rv = FX_Send(cmd);
 	if (! rv) {
 		SendMessage(mainThreadId, FX_Error());
 		goto error;
@@ -140,14 +149,17 @@
 			gettimeofday(&event.time, NULL);
 			
 			/* parse received data */
-			Scan(resp, "2900; %f; %f; %f; %f",
-				&event.data[0], &event.data[1], &event.data[2], &event.data[3]);
+			rv = Scan(resp + 6, "%f; %f; %f; %f; %f; %f; %f; %f",
+				&event.data[0], &event.data[1], &event.data[2], &event.data[3],
+				&event.data[4], &event.data[5], &event.data[6], &event.data[7]);
+			if (rv != nchan) {
+				SendMessage(mainThreadId, "KK Counter: data conversion error");
+				goto error;
+			}
 			
 			/* convert from kHz to Hz */
-			event.data[0] *= 1000.0;
-			event.data[1] *= 1000.0;
-			event.data[2] *= 1000.0;
-			event.data[3] *= 1000.0;
+			for (int i = 0; i < nchan; i++)
+				event.data[i] *= 1000.0;
 			
 			/* push data into the data queue */
 			CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0);