diff fake-data-provider.c @ 264:a40c8af8b028

Improve fake data generator used in testing
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Tue, 16 Jun 2015 17:38:30 +0200
parents 8a94f1913b4e
children
line wrap: on
line diff
--- a/fake-data-provider.c	Tue Jun 16 17:19:15 2015 +0200
+++ b/fake-data-provider.c	Tue Jun 16 17:38:30 2015 +0200
@@ -8,13 +8,15 @@
 #include "data-provider.h"
 
 #define PERIOD 1.0
-#define INCREMENT 0.1
-#define NOISE 0.25
+#define NOISE 0.01
+#define SLOPE 0.1
+#define BADPOINTS 0.01
+#define UNLOCK 100
 
 
 int CVICALLBACK FakeDataProvider (void *functionData)
 {
-	int i, mainThreadId;
+	int i, mainThreadId, random, count = 0;
 	double mark;
 	struct event event = { 0, };
 	double f[NCHAN] = { 55000000.0, 10000.0, 10000.0, 275000.0 };
@@ -28,16 +30,34 @@
 		
 		/* update data */
 		gettimeofday(&event.time, NULL);
-		f[0] += INCREMENT;
 		for (i = 0; i < NCHAN; i++) 
 			event.data[i] = f[i];
 		
+#ifdef SLOPE
+		/* add frequency drift */
+		f[0] += SLOPE;
+		f[2] += SLOPE * 10;
+#endif
+		
 #ifdef NOISE
 		/* add noise */
 		GaussNoise(NCHAN, NOISE, -1, noise);
 		for (i = 0; i < NCHAN; i++) 
 			event.data[i] += noise[i];
 #endif
+
+#ifdef BADPOINTS
+		/* simulate bad points */
+		random = rand();
+		if (random > BADPOINTS * RAND_MAX)
+			event.data[i] += 1000 * random;
+#endif
+		
+#ifdef UNLOCK
+		/* simulate unlock */
+		if (count > UNLOCK)
+			f[0] += 10;
+#endif
 		
 		/* push data into the data queue */
 		CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0);
@@ -46,5 +66,6 @@
    		SyncWait(mark, PERIOD);
 	}
 	
+	count++;
 	return 0;
 }