annotate fake-data-provider.c @ 183:791ca26fee6a

Rewrite data writing to file Fmt() uses by default truncation to conver double arguments to their text representation. Rounding must be used. Rewrite using standard C functions to get rid of this problem (and probably make it more efficient). Extend to handle arbitrary number of channels and to report errors on opening the data files.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 21 Feb 2014 18:42:30 +0100
parents 8a94f1913b4e
children a40c8af8b028
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
1 /* FXAnalise fake data provider */
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
2
146
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
3 #include <analysis.h>
88
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
4 #include <userint.h>
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
5 #include <utility.h>
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
6
167
8a94f1913b4e Fix local header include
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 146
diff changeset
7 #include "future.h"
91
4102fe614df2 Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 88
diff changeset
8 #include "data-provider.h"
88
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
9
146
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
10 #define PERIOD 1.0
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
11 #define INCREMENT 0.1
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
12 #define NOISE 0.25
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
13
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
14
88
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
15 int CVICALLBACK FakeDataProvider (void *functionData)
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
16 {
146
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
17 int i, mainThreadId;
88
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
18 double mark;
146
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
19 struct event event = { 0, };
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
20 double f[NCHAN] = { 55000000.0, 10000.0, 10000.0, 275000.0 };
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
21 double noise[NCHAN];
88
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
22
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
23 /* get main thread id to post messages to it */
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
24 mainThreadId = CmtGetMainThreadID();
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
25
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
26 while (acquiring) {
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
27 mark = Timer();
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
28
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
29 /* update data */
91
4102fe614df2 Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 88
diff changeset
30 gettimeofday(&event.time, NULL);
146
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
31 f[0] += INCREMENT;
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
32 for (i = 0; i < NCHAN; i++)
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
33 event.data[i] = f[i];
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
34
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
35 #ifdef NOISE
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
36 /* add noise */
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
37 GaussNoise(NCHAN, NOISE, -1, noise);
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
38 for (i = 0; i < NCHAN; i++)
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
39 event.data[i] += noise[i];
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
40 #endif
88
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
41
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
42 /* push data into the data queue */
91
4102fe614df2 Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 88
diff changeset
43 CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0);
88
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
44
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
45 /* wait till next second */
146
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
46 SyncWait(mark, PERIOD);
88
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
47 }
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
48
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
49 return 0;
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
50 }