Mercurial > hg > fxanalyse
comparison file-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 | c9aec93005a4 |
children | ec81395bf08d |
comparison
equal
deleted
inserted
replaced
90:c9aec93005a4 | 91:4102fe614df2 |
---|---|
3 #include <userint.h> | 3 #include <userint.h> |
4 #include <ansi_c.h> | 4 #include <ansi_c.h> |
5 #include <utility.h> | 5 #include <utility.h> |
6 #include <formatio.h> | 6 #include <formatio.h> |
7 | 7 |
8 #include "data-provider.h" | |
9 | |
8 //#define LOGFILEPATH "C:\\Femto\\Software\\FXQE80" | 10 //#define LOGFILEPATH "C:\\Femto\\Software\\FXQE80" |
9 #define LOGFILEPATH "C:\\temp" | 11 #define LOGFILEPATH "C:\\temp" |
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 static char message[1024]; | |
19 | |
20 #define SendMessage(threadId, ...) \ | |
21 do { \ | |
22 snprintf(message, sizeof(message) - 1, ##__VA_ARGS__); \ | |
23 PostDeferredCallToThread(MessageCB, message, threadId); \ | |
24 } while (0) | |
25 | 12 |
26 | 13 |
27 int CVICALLBACK FileDataProvider (void *functionData) | 14 int CVICALLBACK FileDataProvider (void *functionData) |
28 { | 15 { |
29 int mainThreadId; | 16 int mainThreadId; |
31 int fd; | 18 int fd; |
32 int read; | 19 int read; |
33 int year, month, day, hour, min, sec, msec; | 20 int year, month, day, hour, min, sec, msec; |
34 struct tm t; | 21 struct tm t; |
35 char line[1024]; | 22 char line[1024]; |
36 double data[5]; | 23 struct event event; |
37 double now; | 24 double now; |
38 | 25 |
39 /* get main thread id to post messages to it */ | 26 /* get main thread id to post messages to it */ |
40 mainThreadId = CmtGetMainThreadID(); | 27 mainThreadId = CmtGetMainThreadID(); |
41 | 28 |
64 continue; | 51 continue; |
65 } | 52 } |
66 | 53 |
67 /* parse data */ | 54 /* parse data */ |
68 read = Scan(line, "%d[w2]%d[w2]%d[w2] %d[w2]%d[w2]%d[w2].%d %f %f %f %f", | 55 read = Scan(line, "%d[w2]%d[w2]%d[w2] %d[w2]%d[w2]%d[w2].%d %f %f %f %f", |
69 &year, &month, &day, &hour, &min, &sec, &msec, &data[1], &data[2], &data[3], &data[4]); | 56 &year, &month, &day, &hour, &min, &sec, &msec, |
57 &event.data[0], &event.data[1], &event.data[2], &event.data[3]); | |
70 if (read != 11) { | 58 if (read != 11) { |
71 /* notify error to the main thread */ | 59 /* notify error to the main thread */ |
72 SendMessage(mainThreadId, "error parsing data log line"); | 60 SendMessage(mainThreadId, "error parsing data log line"); |
73 /* skip line */ | 61 /* skip line */ |
74 continue; | 62 continue; |
80 t.tm_mday = day; | 68 t.tm_mday = day; |
81 /* correct month count */ | 69 /* correct month count */ |
82 t.tm_mon = month - 1; | 70 t.tm_mon = month - 1; |
83 /* years since 1900 */ | 71 /* years since 1900 */ |
84 t.tm_year = year + 2000 - 1900; | 72 t.tm_year = year + 2000 - 1900; |
85 /* daylight saving must be set to -1 */ | 73 /* deduce if daylight saving is in place from the date and time itself */ |
86 t.tm_isdst = -1; | 74 t.tm_isdst = -1; |
87 | 75 |
88 /* convert into seconds since 1 January 1900 00:00:00 and add milliseconds */ | 76 /* convert into seconds since 1 January 1900 00:00:00 and add milliseconds */ |
89 data[0] = mktime(&t) + 1e-3 * msec; | 77 event.time.tv_sec = mktime(&t); |
90 | 78 event.time.tv_usec = msec * 1000; |
79 | |
91 /* convert from kHz to Hz */ | 80 /* convert from kHz to Hz */ |
92 data[1] = data[1] * 1000.0; | 81 event.data[0] *= 1000.0; |
93 data[2] = data[2] * 1000.0; | 82 event.data[1] *= 1000.0; |
94 data[3] = data[3] * 1000.0; | 83 event.data[2] *= 1000.0; |
95 data[4] = data[4] * 1000.0; | 84 event.data[3] *= 1000.0; |
96 | 85 |
97 /* push data into the data queue */ | 86 /* push data into the data queue */ |
98 CmtWriteTSQData(dataQueue, data, 5, TSQ_INFINITE_TIMEOUT, 0); | 87 CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0); |
99 | 88 |
100 /* handle switch to next data file */ | 89 /* handle switch to next data file */ |
101 if ((hour == 23) && (min == 59) && (sec == 59)) { | 90 if ((hour == 23) && (min == 59) && (sec == 59)) { |
102 | 91 |
103 /* next data file name */ | 92 /* next data file name */ |
106 | 95 |
107 /* close data file */ | 96 /* close data file */ |
108 CloseFile(fd); | 97 CloseFile(fd); |
109 | 98 |
110 /* wait for new data file to appear */ | 99 /* wait for new data file to appear */ |
111 int retry = 0; | 100 int retry = 20; |
112 while (retry--) { | 101 while (retry--) { |
113 fd = OpenFile(dataFileName, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII); | 102 fd = OpenFile(dataFileName, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII); |
114 if (fd != -1) | 103 if (fd != -1) |
115 break; | 104 break; |
116 Delay(0.01); | 105 Delay(0.01); |