comparison kk-data-provider.c @ 91:4102fe614df2

Fix timestamping. Cleanup data providers
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Fri, 22 Mar 2013 16:32:15 +0100
parents c9e4f63c2033
children b7ae2d947617
comparison
equal deleted inserted replaced
90:c9aec93005a4 91:4102fe614df2
2 2
3 #include <ansi_c.h> 3 #include <ansi_c.h>
4 #include <userint.h> 4 #include <userint.h>
5 #include <formatio.h> 5 #include <formatio.h>
6 #include <utility.h> 6 #include <utility.h>
7
8 #include "data-provider.h"
7 #include "KKFX80E.h" 9 #include "KKFX80E.h"
8 10
9 #define SERIAL "COM1:115200" 11 #define SERIAL "COM1:115200"
10
11 /* data acquisition flag */
12 extern int acquiring;
13 /* data queue */
14 extern CmtTSQHandle dataQueue;
15 /* callback receiving messages in the main thread */
16 void CVICALLBACK MessageCB (void *callbackData);
17 /* message */
18 char message[1024];
19 12
20 int CVICALLBACK KKDataProvider (void *functionData) 13 int CVICALLBACK KKDataProvider (void *functionData)
21 { 14 {
22 int mainThreadId; 15 int mainThreadId;
23 char *resp; 16 char *resp;
24 double data[5]; 17 struct event event;
25 18
26 /* get main thread id to post messages to it */ 19 /* get main thread id to post messages to it */
27 mainThreadId = CmtGetMainThreadID(); 20 mainThreadId = CmtGetMainThreadID();
28 21
29 /* initialize library */ 22 /* initialize library */
52 FX_Recv(&resp); 45 FX_Recv(&resp);
53 46
54 if (strncmp(resp, "2900;", 5) == 0) { 47 if (strncmp(resp, "2900;", 5) == 0) {
55 48
56 /* timestamp */ 49 /* timestamp */
57 GetCurrentDateTime(&data[0]); 50 gettimeofday(&event.time, NULL);
58 51
59 /* parse received data */ 52 /* parse received data */
60 Scan(resp, "2900; %f; %f; %f; %f", &data[1], &data[2], &data[3], &data[4]); 53 Scan(resp, "2900; %f; %f; %f; %f",
54 &event.data[0], &event.data[1], &event.data[2], &event.data[3]);
61 55
62 /* convert from kHz to Hz */ 56 /* convert from kHz to Hz */
63 data[1] = data[1] * 1000.0; 57 event.data[0] *= 1000.0;
64 data[2] = data[2] * 1000.0; 58 event.data[1] *= 1000.0;
65 data[3] = data[3] * 1000.0; 59 event.data[2] *= 1000.0;
66 data[4] = data[4] * 1000.0; 60 event.data[3] *= 1000.0;
67 61
68 /* push data into the data queue */ 62 /* push data into the data queue */
69 CmtWriteTSQData(dataQueue, data, 5, TSQ_INFINITE_TIMEOUT, 0); 63 CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0);
70 64
71 } else if (strncmp(resp, "7000;", 5) == 0) { 65 } else if (strncmp(resp, "7000;", 5) == 0) {
72 /* ignore heart beat response */ 66 /* ignore heart beat response */
73 } else { 67 } else {
74 /* send message to the main thread */ 68 /* send message to the main thread */
75 strncpy(message, resp, sizeof(message)); 69 SendMessage(mainThreadId, resp);
76 PostDeferredCallToThread(MessageCB, message, mainThreadId);
77 } 70 }
78 } 71 }
79 72
80 /* close serial port */ 73 /* close serial port */
81 FX_Close(); 74 FX_Close();