Mercurial > hg > fxanalyse
comparison kk-data-provider.c @ 96:4a11331eacbf
Ignore packet with id '7015' in KK driver
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Tue, 26 Mar 2013 18:17:18 +0100 |
parents | b7ae2d947617 |
children | 4f1f353e84f5 |
comparison
equal
deleted
inserted
replaced
95:e437666ab710 | 96:4a11331eacbf |
---|---|
10 #include "KKFX80E.h" | 10 #include "KKFX80E.h" |
11 | 11 |
12 #define CONFIGFILE "FXAnalise.ini" | 12 #define CONFIGFILE "FXAnalise.ini" |
13 #define DEFAULTPORT "COM4:115200" | 13 #define DEFAULTPORT "COM4:115200" |
14 | 14 |
15 #define strneq(a, b, len) (strncmp((a), (b), (len)) == 0) | |
16 | |
15 int CVICALLBACK KKDataProvider (void *functionData) | 17 int CVICALLBACK KKDataProvider (void *functionData) |
16 { | 18 { |
17 int mainThreadId; | 19 int mainThreadId; |
20 int rv; | |
18 char *resp; | 21 char *resp; |
19 struct event event; | 22 struct event event; |
20 char port[256]; | 23 char port[256]; |
21 | 24 |
22 /* get main thread id to post messages to it */ | 25 /* get main thread id to post messages to it */ |
23 mainThreadId = CmtGetMainThreadID(); | 26 mainThreadId = CmtGetMainThreadID(); |
24 | 27 |
25 /* path for the configuration file */ | 28 /* construct configuration file path */ |
26 char pathname[MAX_PATHNAME_LEN]; | 29 char pathname[MAX_PATHNAME_LEN]; |
27 char project[MAX_PATHNAME_LEN]; | 30 char project[MAX_PATHNAME_LEN]; |
28 GetProjectDir(project); | 31 GetProjectDir(project); |
29 MakePathname(project, CONFIGFILE, pathname); | 32 MakePathname(project, CONFIGFILE, pathname); |
30 | 33 |
31 /* load configuration file */ | 34 /* load configuration file */ |
32 IniText configuration = Ini_New(TRUE); | 35 IniText configuration = Ini_New(TRUE); |
33 Ini_ReadFromFile(configuration, pathname); | 36 Ini_ReadFromFile(configuration, pathname); |
34 | 37 |
35 /* get serial port name configuration */ | 38 /* get serial port name configuration */ |
36 int rv = Ini_GetStringIntoBuffer(configuration, "KK", "port", port, sizeof(port)); | 39 rv = Ini_GetStringIntoBuffer(configuration, "KK", "port", port, sizeof(port)); |
37 if (rv == 0) | 40 if (rv == 0) |
38 strncpy(port, DEFAULTPORT, sizeof(port)); | 41 strncpy(port, DEFAULTPORT, sizeof(port)); |
39 | 42 |
40 /* free */ | 43 /* free */ |
41 Ini_Dispose(configuration); | 44 Ini_Dispose(configuration); |
42 | 45 |
43 /* initialize library */ | 46 /* initialize library */ |
44 FX_Init(); | 47 FX_Init(); |
45 /* connect to KK FX80E counter */ | 48 /* connect to KK FX80E counter */ |
46 FX_Open(port); | 49 rv = FX_Open(port); |
47 | 50 |
48 /* clear transmit buffer */ | 51 /* clear transmit buffer */ |
49 FX_Send("\x80"); | 52 FX_Send("\x80"); |
50 FX_Recv(&resp); | 53 FX_Recv(&resp); |
51 /* set report interval 1sec */ | 54 /* set report interval 1sec */ |
63 | 66 |
64 while (acquiring) { | 67 while (acquiring) { |
65 /* receive data from counter */ | 68 /* receive data from counter */ |
66 FX_Recv(&resp); | 69 FX_Recv(&resp); |
67 | 70 |
68 if (strncmp(resp, "2900;", 5) == 0) { | 71 if (strneq(resp, "2900;", 5)) { |
69 | 72 |
70 /* timestamp */ | 73 /* timestamp */ |
71 gettimeofday(&event.time, NULL); | 74 gettimeofday(&event.time, NULL); |
72 | 75 |
73 /* parse received data */ | 76 /* parse received data */ |
80 event.data[2] *= 1000.0; | 83 event.data[2] *= 1000.0; |
81 event.data[3] *= 1000.0; | 84 event.data[3] *= 1000.0; |
82 | 85 |
83 /* push data into the data queue */ | 86 /* push data into the data queue */ |
84 CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0); | 87 CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0); |
85 | 88 |
86 } else if (strncmp(resp, "7000;", 5) == 0) { | 89 } else if (strneq(resp, "7000;", 5)) { |
87 /* ignore heart beat response */ | 90 /* ignore heart beat packet */ |
91 } else if (strneq(resp, "7015;", 5)) { | |
92 /* ignore undocumented packet. it is sent by newer kk counters | |
93 for each data packet. it contains a sample count along with | |
94 other information */ | |
88 } else { | 95 } else { |
89 /* send message to the main thread */ | 96 /* send message to the main thread */ |
90 SendMessage(mainThreadId, resp); | 97 SendMessage(mainThreadId, resp); |
91 } | 98 } |
92 } | 99 } |