Mercurial > hg > fxanalyse
comparison kk-data-provider.c @ 177:5b4b7f37bd3b
Make number of KK counter channels read configurable
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Fri, 21 Feb 2014 18:38:44 +0100 |
parents | 4ff3e468ab5f |
children | c96f5f64c946 |
comparison
equal
deleted
inserted
replaced
176:6ccc428c412a | 177:5b4b7f37bd3b |
---|---|
8 | 8 |
9 #include "data-provider.h" | 9 #include "data-provider.h" |
10 #include "KKFX80E.h" | 10 #include "KKFX80E.h" |
11 | 11 |
12 #define CONFIGFILE "FXAnalyse.ini" | 12 #define CONFIGFILE "FXAnalyse.ini" |
13 #define DEFAULTPORT "COM4:115200" | 13 #define DEFAULT_PORT "COM4:115200" |
14 #define DEFAULT_NCHAN 4 | |
14 #define TIMEOUT 1 /* seconds */ | 15 #define TIMEOUT 1 /* seconds */ |
15 | 16 |
16 #define strneq(a, b, len) (strncmp((a), (b), (len)) == 0) | 17 #define strneq(a, b, len) (strncmp((a), (b), (len)) == 0) |
17 | 18 |
18 int CVICALLBACK KKDataProvider (void *functionData) | 19 int CVICALLBACK KKDataProvider (void *functionData) |
19 { | 20 { |
20 int mainThreadId; | 21 int mainThreadId; |
21 int rv; | 22 int rv; |
22 char *resp; | 23 char *resp; |
23 struct event event; | 24 struct event event; |
25 int nchan; | |
24 char port[256]; | 26 char port[256]; |
25 | 27 |
26 /* get main thread id to post messages to it */ | 28 /* get main thread id to post messages to it */ |
27 mainThreadId = CmtGetMainThreadID(); | 29 mainThreadId = CmtGetMainThreadID(); |
28 | 30 |
37 Ini_ReadFromFile(configuration, pathname); | 39 Ini_ReadFromFile(configuration, pathname); |
38 | 40 |
39 /* get serial port name configuration */ | 41 /* get serial port name configuration */ |
40 rv = Ini_GetStringIntoBuffer(configuration, "KK", "port", port, sizeof(port)); | 42 rv = Ini_GetStringIntoBuffer(configuration, "KK", "port", port, sizeof(port)); |
41 if (! rv) | 43 if (! rv) |
42 strncpy(port, DEFAULTPORT, sizeof(port)); | 44 strncpy(port, DEFAULT_PORT, sizeof(port)); |
45 | |
46 /* channels number */ | |
47 rv = Ini_GetInt(configuration, "KK", "nchan", &nchan); | |
48 if (! rv) | |
49 nchan = DEFAULT_NCHAN; | |
43 | 50 |
44 /* free */ | 51 /* free */ |
45 Ini_Dispose(configuration); | 52 Ini_Dispose(configuration); |
46 | 53 |
47 /* initialize library */ | 54 /* initialize library */ |
76 if (! rv) { | 83 if (! rv) { |
77 SendMessage(mainThreadId, FX_Error()); | 84 SendMessage(mainThreadId, FX_Error()); |
78 goto error; | 85 goto error; |
79 } | 86 } |
80 | 87 |
81 /* read 4 channels */ | 88 /* read nchan channels */ |
82 rv = FX_Send("\x34"); | 89 char *cmd = "\x30"; |
90 cmd[0] += nchan; | |
91 rv = FX_Send(cmd); | |
83 if (! rv) { | 92 if (! rv) { |
84 SendMessage(mainThreadId, FX_Error()); | 93 SendMessage(mainThreadId, FX_Error()); |
85 goto error; | 94 goto error; |
86 } | 95 } |
87 rv = FX_Recv(&resp, TIMEOUT); | 96 rv = FX_Recv(&resp, TIMEOUT); |
138 | 147 |
139 /* timestamp */ | 148 /* timestamp */ |
140 gettimeofday(&event.time, NULL); | 149 gettimeofday(&event.time, NULL); |
141 | 150 |
142 /* parse received data */ | 151 /* parse received data */ |
143 Scan(resp, "2900; %f; %f; %f; %f", | 152 rv = Scan(resp + 6, "%f; %f; %f; %f; %f; %f; %f; %f", |
144 &event.data[0], &event.data[1], &event.data[2], &event.data[3]); | 153 &event.data[0], &event.data[1], &event.data[2], &event.data[3], |
154 &event.data[4], &event.data[5], &event.data[6], &event.data[7]); | |
155 if (rv != nchan) { | |
156 SendMessage(mainThreadId, "KK Counter: data conversion error"); | |
157 goto error; | |
158 } | |
145 | 159 |
146 /* convert from kHz to Hz */ | 160 /* convert from kHz to Hz */ |
147 event.data[0] *= 1000.0; | 161 for (int i = 0; i < nchan; i++) |
148 event.data[1] *= 1000.0; | 162 event.data[i] *= 1000.0; |
149 event.data[2] *= 1000.0; | |
150 event.data[3] *= 1000.0; | |
151 | 163 |
152 /* push data into the data queue */ | 164 /* push data into the data queue */ |
153 CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0); | 165 CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0); |
154 | 166 |
155 } else if (strneq(resp, "7000", 4)) { | 167 } else if (strneq(resp, "7000", 4)) { |