comparison fake-data-provider.c @ 146:931ebae87964

Tweaks to FakeDataProvider Make generated counter data more realistic. Add the possibility to add noise to the generated data. Make the sampling period easier to change.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Wed, 22 Jan 2014 14:45:24 +0100
parents 5bba1d1c3b46
children 8a94f1913b4e
comparison
equal deleted inserted replaced
145:ceac0c01661f 146:931ebae87964
1 /* FXAnalise fake data provider */ 1 /* FXAnalise fake data provider */
2 2
3 #include <analysis.h>
3 #include <userint.h> 4 #include <userint.h>
4 #include <utility.h> 5 #include <utility.h>
5 #include <future.h> 6 #include <future.h>
6 7
7 #include "data-provider.h" 8 #include "data-provider.h"
8 9
10 #define PERIOD 1.0
11 #define INCREMENT 0.1
12 #define NOISE 0.25
13
14
9 int CVICALLBACK FakeDataProvider (void *functionData) 15 int CVICALLBACK FakeDataProvider (void *functionData)
10 { 16 {
11 int mainThreadId; 17 int i, mainThreadId;
12 double mark; 18 double mark;
13 struct event event = { 19 struct event event = { 0, };
14 .time = { 0, }, 20 double f[NCHAN] = { 55000000.0, 10000.0, 10000.0, 275000.0 };
15 .data = { 55000000.0, 2.0, 3.0, 4.0 } 21 double noise[NCHAN];
16 };
17 22
18 /* get main thread id to post messages to it */ 23 /* get main thread id to post messages to it */
19 mainThreadId = CmtGetMainThreadID(); 24 mainThreadId = CmtGetMainThreadID();
20 25
21 while (acquiring) { 26 while (acquiring) {
22 mark = Timer(); 27 mark = Timer();
23 28
24 /* update data */ 29 /* update data */
25 gettimeofday(&event.time, NULL); 30 gettimeofday(&event.time, NULL);
26 event.data[0] += 0.1; 31 f[0] += INCREMENT;
32 for (i = 0; i < NCHAN; i++)
33 event.data[i] = f[i];
34
35 #ifdef NOISE
36 /* add noise */
37 GaussNoise(NCHAN, NOISE, -1, noise);
38 for (i = 0; i < NCHAN; i++)
39 event.data[i] += noise[i];
40 #endif
27 41
28 /* push data into the data queue */ 42 /* push data into the data queue */
29 CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0); 43 CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0);
30 44
31 /* wait till next second */ 45 /* wait till next second */
32 SyncWait(mark, 1.00); 46 SyncWait(mark, PERIOD);
33 } 47 }
34 48
35 return 0; 49 return 0;
36 } 50 }