comparison file-data-provider.c @ 239:ec81395bf08d

Solve name collisions and other problems caused by including Windows headers
author Daniele Nicolodi <daniele.nicolodi@obspm.fr>
date Thu, 12 Feb 2015 19:13:55 +0100
parents 4102fe614df2
children
comparison
equal deleted inserted replaced
238:78fdba868884 239:ec81395bf08d
11 #define LOGFILEPATH "C:\\temp" 11 #define LOGFILEPATH "C:\\temp"
12 12
13 13
14 int CVICALLBACK FileDataProvider (void *functionData) 14 int CVICALLBACK FileDataProvider (void *functionData)
15 { 15 {
16 int mainThreadId; 16 int main_thread_id;
17 char dataFileName[MAX_PATHNAME_LEN]; 17 char datafile[MAX_PATHNAME_LEN];
18 int fd; 18 int fd;
19 int read; 19 int read;
20 int year, month, day, hour, min, sec, msec; 20 int year, month, day, hour, min, sec, msec;
21 struct tm t; 21 struct tm t;
22 char line[1024]; 22 char line[1024];
23 struct event event; 23 struct event event;
24 double now; 24 double now;
25 25
26 /* get main thread id to post messages to it */ 26 /* get main thread id to post messages to it */
27 mainThreadId = CmtGetMainThreadID(); 27 main_thread_id = CmtGetMainThreadID();
28 28
29 /* guess current data log file name */ 29 /* guess current data log file name */
30 GetCurrentDateTime(&now); 30 GetCurrentDateTime(&now);
31 GetDateTimeElements(now, NULL, NULL, NULL, &month, &day, &year); 31 GetDateTimeElements(now, NULL, NULL, NULL, &month, &day, &year);
32 snprintf(dataFileName, sizeof(dataFileName) - 1, 32 snprintf(datafile, sizeof(datafile) - 1,
33 "%s\\%02d%02d%02d_Frequ.txt", LOGFILEPATH, year % 100, month, day); 33 "%s\\%02d%02d%02d_Frequ.txt", LOGFILEPATH, year % 100, month, day);
34 34
35 /* open file */ 35 /* open file */
36 fd = OpenFile(dataFileName, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII); 36 fd = OpenFile(datafile, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII);
37 if (fd < 0) { 37 if (fd < 0) {
38 /* notify error to the main thread */ 38 /* notify error to the main thread */
39 SendMessage(mainThreadId, "error opening data file '%s'", dataFileName); 39 send_message(main_thread_id, "error opening data file '%s'", datafile);
40 } 40 }
41 41
42 /* seek to file end */ 42 /* seek to file end */
43 SetFilePtr(fd, 0, 2); 43 SetFilePtr(fd, 0, 2);
44 44
55 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",
56 &year, &month, &day, &hour, &min, &sec, &msec, 56 &year, &month, &day, &hour, &min, &sec, &msec,
57 &event.data[0], &event.data[1], &event.data[2], &event.data[3]); 57 &event.data[0], &event.data[1], &event.data[2], &event.data[3]);
58 if (read != 11) { 58 if (read != 11) {
59 /* notify error to the main thread */ 59 /* notify error to the main thread */
60 SendMessage(mainThreadId, "error parsing data log line"); 60 send_message(main_thread_id, "error parsing data log line");
61 /* skip line */ 61 /* skip line */
62 continue; 62 continue;
63 } 63 }
64 64
65 t.tm_hour = hour; 65 t.tm_hour = hour;
88 88
89 /* handle switch to next data file */ 89 /* handle switch to next data file */
90 if ((hour == 23) && (min == 59) && (sec == 59)) { 90 if ((hour == 23) && (min == 59) && (sec == 59)) {
91 91
92 /* next data file name */ 92 /* next data file name */
93 snprintf(dataFileName, sizeof(dataFileName) - 1, 93 snprintf(datafile, sizeof(datafile) - 1,
94 "%s\\%02d%02d%02d_Frequ.txt", LOGFILEPATH, year, month, day + 1); 94 "%s\\%02d%02d%02d_Frequ.txt", LOGFILEPATH, year, month, day + 1);
95 95
96 /* close data file */ 96 /* close data file */
97 CloseFile(fd); 97 CloseFile(fd);
98 98
99 /* wait for new data file to appear */ 99 /* wait for new data file to appear */
100 int retry = 20; 100 int retry = 20;
101 while (retry--) { 101 while (retry--) {
102 fd = OpenFile(dataFileName, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII); 102 fd = OpenFile(datafile, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII);
103 if (fd != -1) 103 if (fd != -1)
104 break; 104 break;
105 Delay(0.01); 105 Delay(0.01);
106 } 106 }
107 } 107 }