annotate fake-data-provider.c @ 88:9b7588cd4013

Move data acquisition into separate thread The data acquisition thread transfers data to the main thread trough a Thread Safe Queue. This separation allows for making the data acquisition system pluggable. The old file based communication to the KK counter is implemented along with a very simple fake data provider.
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Thu, 21 Mar 2013 18:24:45 +0100
parents
children 4102fe614df2
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
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
3 #include <userint.h>
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
4 #include <utility.h>
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
5
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
6 /* data acquisition flag */
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
7 extern int acquiring;
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
8 /* data queue */
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
9 extern CmtTSQHandle dataQueue;
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
10
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
11 int CVICALLBACK FakeDataProvider (void *functionData)
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
12 {
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
13 int mainThreadId;
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
14 double mark;
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
15 double data[5] = {0.0, 10000.0, 2.0, 3.0, 4.0};
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
16
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
17 /* 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
18 mainThreadId = CmtGetMainThreadID();
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
19
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
20 while (acquiring) {
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
21 mark = Timer();
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 /* update data */
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
24 GetCurrentDateTime(&data[0]);
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
25 data[1] = data[1] + 0.1;
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
26
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
27 /* push data into the data queue */
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
28 CmtWriteTSQData(dataQueue, data, 5, TSQ_INFINITE_TIMEOUT, 0);
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
29
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
30 /* wait till next second */
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
31 SyncWait(mark, 1.00);
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
32 }
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
33
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
34 return 0;
9b7588cd4013 Move data acquisition into separate thread
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff changeset
35 }