comparison 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
comparison
equal deleted inserted replaced
263:8d9a4c5eb7a4 264:a40c8af8b028
6 6
7 #include "future.h" 7 #include "future.h"
8 #include "data-provider.h" 8 #include "data-provider.h"
9 9
10 #define PERIOD 1.0 10 #define PERIOD 1.0
11 #define INCREMENT 0.1 11 #define NOISE 0.01
12 #define NOISE 0.25 12 #define SLOPE 0.1
13 #define BADPOINTS 0.01
14 #define UNLOCK 100
13 15
14 16
15 int CVICALLBACK FakeDataProvider (void *functionData) 17 int CVICALLBACK FakeDataProvider (void *functionData)
16 { 18 {
17 int i, mainThreadId; 19 int i, mainThreadId, random, count = 0;
18 double mark; 20 double mark;
19 struct event event = { 0, }; 21 struct event event = { 0, };
20 double f[NCHAN] = { 55000000.0, 10000.0, 10000.0, 275000.0 }; 22 double f[NCHAN] = { 55000000.0, 10000.0, 10000.0, 275000.0 };
21 double noise[NCHAN]; 23 double noise[NCHAN];
22 24
26 while (acquiring) { 28 while (acquiring) {
27 mark = Timer(); 29 mark = Timer();
28 30
29 /* update data */ 31 /* update data */
30 gettimeofday(&event.time, NULL); 32 gettimeofday(&event.time, NULL);
31 f[0] += INCREMENT;
32 for (i = 0; i < NCHAN; i++) 33 for (i = 0; i < NCHAN; i++)
33 event.data[i] = f[i]; 34 event.data[i] = f[i];
35
36 #ifdef SLOPE
37 /* add frequency drift */
38 f[0] += SLOPE;
39 f[2] += SLOPE * 10;
40 #endif
34 41
35 #ifdef NOISE 42 #ifdef NOISE
36 /* add noise */ 43 /* add noise */
37 GaussNoise(NCHAN, NOISE, -1, noise); 44 GaussNoise(NCHAN, NOISE, -1, noise);
38 for (i = 0; i < NCHAN; i++) 45 for (i = 0; i < NCHAN; i++)
39 event.data[i] += noise[i]; 46 event.data[i] += noise[i];
47 #endif
48
49 #ifdef BADPOINTS
50 /* simulate bad points */
51 random = rand();
52 if (random > BADPOINTS * RAND_MAX)
53 event.data[i] += 1000 * random;
54 #endif
55
56 #ifdef UNLOCK
57 /* simulate unlock */
58 if (count > UNLOCK)
59 f[0] += 10;
40 #endif 60 #endif
41 61
42 /* push data into the data queue */ 62 /* push data into the data queue */
43 CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0); 63 CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0);
44 64
45 /* wait till next second */ 65 /* wait till next second */
46 SyncWait(mark, PERIOD); 66 SyncWait(mark, PERIOD);
47 } 67 }
48 68
69 count++;
49 return 0; 70 return 0;
50 } 71 }