annotate fake-data-provider.c @ 271:4a2fa10b8421 default tip

Publish DDS and measured frequencies through ZMQ
author Daniele Nicolodi <daniele.nicolodi@nist.gov>
date Sat, 15 Aug 2020 18:22:42 -0600
parents a40c8af8b028
children
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
264
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
11 #define NOISE 0.01
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
12 #define SLOPE 0.1
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
13 #define BADPOINTS 0.01
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
14 #define UNLOCK 100
146
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
15
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
16
88
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
17 int CVICALLBACK FakeDataProvider (void *functionData)
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
18 {
264
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
19 int i, mainThreadId, random, count = 0;
88
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
20 double mark;
146
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
21 struct event event = { 0, };
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
22 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
23 double noise[NCHAN];
88
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
24
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
25 /* 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
26 mainThreadId = CmtGetMainThreadID();
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
27
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
28 while (acquiring) {
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
29 mark = Timer();
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
30
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
31 /* update data */
91
4102fe614df2 Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 88
diff changeset
32 gettimeofday(&event.time, NULL);
146
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
33 for (i = 0; i < NCHAN; i++)
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
34 event.data[i] = f[i];
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
35
264
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
36 #ifdef SLOPE
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
37 /* add frequency drift */
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
38 f[0] += SLOPE;
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
39 f[2] += SLOPE * 10;
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
40 #endif
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
41
146
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
42 #ifdef NOISE
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
43 /* add noise */
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
44 GaussNoise(NCHAN, NOISE, -1, noise);
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
45 for (i = 0; i < NCHAN; i++)
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
46 event.data[i] += noise[i];
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
47 #endif
264
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
48
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
49 #ifdef BADPOINTS
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
50 /* simulate bad points */
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
51 random = rand();
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
52 if (random > BADPOINTS * RAND_MAX)
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
53 event.data[i] += 1000 * random;
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
54 #endif
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
55
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
56 #ifdef UNLOCK
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
57 /* simulate unlock */
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
58 if (count > UNLOCK)
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
59 f[0] += 10;
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
60 #endif
88
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
61
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
62 /* push data into the data queue */
91
4102fe614df2 Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 88
diff changeset
63 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
64
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
65 /* wait till next second */
146
931ebae87964 Tweaks to FakeDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 126
diff changeset
66 SyncWait(mark, PERIOD);
88
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
67 }
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
68
264
a40c8af8b028 Improve fake data generator used in testing
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents: 167
diff changeset
69 count++;
88
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
70 return 0;
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
71 }