Mercurial > hg > fxanalyse
annotate kk-data-provider.c @ 117:96ab53ab9496
Fix computaion of expected frep change
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Fri, 05 Jul 2013 16:23:43 +0200 |
parents | 4f1f353e84f5 |
children | 84fb0796936b |
rev | line source |
---|---|
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
1 /* FXAnalise data provider which directly interfaces with the KK FX80E counter */ |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
2 |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
3 #include <ansi_c.h> |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
4 #include <userint.h> |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
5 #include <formatio.h> |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
6 #include <utility.h> |
94
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
7 #include <inifile.h> |
91
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
8 |
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
9 #include "data-provider.h" |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
10 #include "KKFX80E.h" |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
11 |
94
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
12 #define CONFIGFILE "FXAnalise.ini" |
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
13 #define DEFAULTPORT "COM4:115200" |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
14 #define TIMEOUT 1 /* seconds */ |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
15 |
96
4a11331eacbf
Ignore packet with id '7015' in KK driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
94
diff
changeset
|
16 #define strneq(a, b, len) (strncmp((a), (b), (len)) == 0) |
4a11331eacbf
Ignore packet with id '7015' in KK driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
94
diff
changeset
|
17 |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
18 int CVICALLBACK KKDataProvider (void *functionData) |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
19 { |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
20 int mainThreadId; |
96
4a11331eacbf
Ignore packet with id '7015' in KK driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
94
diff
changeset
|
21 int rv; |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
22 char *resp; |
91
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
23 struct event event; |
94
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
24 char port[256]; |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
25 |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
26 /* get main thread id to post messages to it */ |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
27 mainThreadId = CmtGetMainThreadID(); |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
28 |
96
4a11331eacbf
Ignore packet with id '7015' in KK driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
94
diff
changeset
|
29 /* construct configuration file path */ |
94
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
30 char pathname[MAX_PATHNAME_LEN]; |
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
31 char project[MAX_PATHNAME_LEN]; |
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
32 GetProjectDir(project); |
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
33 MakePathname(project, CONFIGFILE, pathname); |
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
34 |
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
35 /* load configuration file */ |
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
36 IniText configuration = Ini_New(TRUE); |
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
37 Ini_ReadFromFile(configuration, pathname); |
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
38 |
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
39 /* get serial port name configuration */ |
96
4a11331eacbf
Ignore packet with id '7015' in KK driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
94
diff
changeset
|
40 rv = Ini_GetStringIntoBuffer(configuration, "KK", "port", port, sizeof(port)); |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
41 if (! rv) |
94
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
42 strncpy(port, DEFAULTPORT, sizeof(port)); |
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
43 |
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
44 /* free */ |
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
45 Ini_Dispose(configuration); |
b7ae2d947617
Change default KK port to COM4. Make port configurable via .ini file
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
91
diff
changeset
|
46 |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
47 /* initialize library */ |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
48 FX_Init(); |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
49 |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
50 /* connect to KK FX80E counter */ |
96
4a11331eacbf
Ignore packet with id '7015' in KK driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
94
diff
changeset
|
51 rv = FX_Open(port); |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
52 if (! rv) { |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
53 SendMessage(mainThreadId, FX_Error()); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
54 goto error; |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
55 } |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
56 |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
57 /* clear transmit buffer */ |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
58 rv = FX_Send("\x80"); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
59 if (! rv) { |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
60 SendMessage(mainThreadId, FX_Error()); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
61 goto error; |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
62 } |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
63 rv = FX_Recv(&resp, TIMEOUT); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
64 if (! rv) { |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
65 SendMessage(mainThreadId, FX_Error()); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
66 goto error; |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
67 } |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
68 |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
69 /* set report interval 1sec */ |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
70 rv = FX_Send("\x29"); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
71 if (! rv) { |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
72 SendMessage(mainThreadId, FX_Error()); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
73 goto error; |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
74 } |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
75 rv = FX_Recv(&resp, TIMEOUT); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
76 if (! rv) { |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
77 SendMessage(mainThreadId, FX_Error()); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
78 goto error; |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
79 } |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
80 |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
81 /* read 4 channels */ |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
82 rv = FX_Send("\x34"); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
83 if (! rv) { |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
84 SendMessage(mainThreadId, FX_Error()); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
85 goto error; |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
86 } |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
87 rv = FX_Recv(&resp, TIMEOUT); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
88 if (! rv) { |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
89 SendMessage(mainThreadId, FX_Error()); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
90 goto error; |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
91 } |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
92 |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
93 /* set mode to instantaneous frequency measurement */ |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
94 rv = FX_Send("\x42"); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
95 if (! rv) { |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
96 SendMessage(mainThreadId, FX_Error()); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
97 goto error; |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
98 } |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
99 rv = FX_Recv(&resp, TIMEOUT); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
100 if (! rv) { |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
101 SendMessage(mainThreadId, FX_Error()); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
102 goto error; |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
103 } |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
104 |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
105 /* switch scrambler off */ |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
106 rv = FX_Send("\x50"); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
107 if (! rv) { |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
108 SendMessage(mainThreadId, FX_Error()); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
109 goto error; |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
110 } |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
111 rv = FX_Recv(&resp, TIMEOUT); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
112 if (! rv) { |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
113 SendMessage(mainThreadId, FX_Error()); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
114 goto error; |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
115 } |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
116 |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
117 while (acquiring) { |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
118 /* receive data from counter */ |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
119 FX_Recv(&resp, TIMEOUT); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
120 if (! resp) { |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
121 SendMessage(mainThreadId, FX_Error()); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
122 break; |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
123 } |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
124 |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
125 if (strneq(resp, "2900", 4)) { |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
126 |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
127 /* timestamp */ |
91
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
128 gettimeofday(&event.time, NULL); |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
129 |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
130 /* parse received data */ |
91
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
131 Scan(resp, "2900; %f; %f; %f; %f", |
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
132 &event.data[0], &event.data[1], &event.data[2], &event.data[3]); |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
133 |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
134 /* convert from kHz to Hz */ |
91
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
135 event.data[0] *= 1000.0; |
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
136 event.data[1] *= 1000.0; |
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
137 event.data[2] *= 1000.0; |
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
138 event.data[3] *= 1000.0; |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
139 |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
140 /* push data into the data queue */ |
91
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
141 CmtWriteTSQData(dataQueue, &event, 1, TSQ_INFINITE_TIMEOUT, 0); |
96
4a11331eacbf
Ignore packet with id '7015' in KK driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
94
diff
changeset
|
142 |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
143 } else if (strneq(resp, "7000", 4)) { |
96
4a11331eacbf
Ignore packet with id '7015' in KK driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
94
diff
changeset
|
144 /* ignore heart beat packet */ |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
145 } else if (strneq(resp, "7015", 4)) { |
96
4a11331eacbf
Ignore packet with id '7015' in KK driver
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
94
diff
changeset
|
146 /* ignore undocumented packet. it is sent by newer kk counters |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
147 for each data packet. it probably contains a sample count along |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
148 with some other information */ |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
149 } else if (strneq(resp, "7020", 4)) { |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
150 /* undocumented packet. it probably reports the header for |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
151 subsequent data packets. match it against expected value */ |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
152 if (strcmp(resp + 6, "$2900")) { |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
153 SendMessage(mainThreadId, "KK Counter: %s", resp); |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
154 } |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
155 } else { |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
156 /* send message to the main thread */ |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
157 SendMessage(mainThreadId, "KK Counter: %s", resp); |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
158 } |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
159 } |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
160 |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
161 error: |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
162 /* close serial port */ |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
163 FX_Close(); |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
164 /* free allocated resources */ |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
165 FX_Free(); |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
166 |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
167 return 0; |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
168 } |