diff kk-data-provider.c @ 185:bc980095a24d

Add scrambler option to KK data provider. Report KK counter version.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Mon, 24 Feb 2014 13:16:52 +0100
parents c96f5f64c946
children f105ac22da05
line wrap: on
line diff
--- a/kk-data-provider.c	Fri Feb 21 18:42:30 2014 +0100
+++ b/kk-data-provider.c	Mon Feb 24 13:16:52 2014 +0100
@@ -20,9 +20,10 @@
 {
 	int mainThreadId;
 	int rv;
-	char *resp;
+	char *cmd, *resp;
 	struct event event;
 	int nchan;
+	int scrambler;
 	char port[256];
 	
 	/* get main thread id to post messages to it */
@@ -46,6 +47,11 @@
 	if (! rv)
 		nchan = DEFAULT_NCHAN;
 	
+	/* enable scrambler */
+	rv = Ini_GetInt(configuration, "KK", "scrambler", &scrambler);
+	if (! rv)
+		scrambler = FALSE;
+	
 	/* free */ 
 	Ini_Dispose(configuration);
 
@@ -71,6 +77,28 @@
 		goto error;
 	}
 	
+	/* get counter hardware version string */
+	rv = FX_Send("\x81");
+	if (! rv) {
+		SendMessage(mainThreadId, FX_Error());
+		goto error;
+	}
+	rv = FX_Recv(&resp, TIMEOUT);
+	if (! rv) {
+		SendMessage(mainThreadId, FX_Error());
+		goto error;
+	}
+	/* wait for response */
+	while (strneq(resp, "7000", 4)) {
+		rv = FX_Recv(&resp, TIMEOUT);
+		if (! rv) {
+			SendMessage(mainThreadId, FX_Error());
+			goto error;
+		}
+	}
+	if (strneq(resp, "7001", 4))
+		SendMessage(mainThreadId, "KK Counter version: %s", resp + 4);
+	
 	/* set report interval 1sec */
 	rv = FX_Send("\x29");
 	if (! rv) {
@@ -84,7 +112,7 @@
 	}
 	
 	/* read nchan channels */
-	char *cmd = "\x30";
+	cmd = "\x30";
 	cmd[0] += nchan;
 	rv = FX_Send(cmd);
 	if (! rv) {
@@ -109,7 +137,9 @@
 		goto error;
 	}
 	
-	/* switch scrambler off */
+	/* scrambler */
+	cmd = "\x50";
+	cmd[0] += scrambler;
 	rv = FX_Send("\x50");
 	if (! rv) {
 		SendMessage(mainThreadId, FX_Error());