Mercurial > hg > fxanalyse
annotate kk-data-provider.c @ 120:84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
author | Daniele Nicolodi <daniele.nicolodi@obspm.fr> |
---|---|
date | Tue, 17 Sep 2013 14:18:20 +0200 |
parents | 4f1f353e84f5 |
children | 4ff3e468ab5f |
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 |
120
84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
102
diff
changeset
|
117 /* enable synchronization */ |
84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
102
diff
changeset
|
118 rv = FX_Send("\x0F"); |
84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
102
diff
changeset
|
119 if (! rv) { |
84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
102
diff
changeset
|
120 SendMessage(mainThreadId, FX_Error()); |
84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
102
diff
changeset
|
121 goto error; |
84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
102
diff
changeset
|
122 } |
84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
102
diff
changeset
|
123 rv = FX_Recv(&resp, TIMEOUT); |
84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
102
diff
changeset
|
124 if (! rv) { |
84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
102
diff
changeset
|
125 SendMessage(mainThreadId, FX_Error()); |
84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
102
diff
changeset
|
126 goto error; |
84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
102
diff
changeset
|
127 } |
84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
102
diff
changeset
|
128 |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
129 while (acquiring) { |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
130 /* 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
|
131 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
|
132 if (! resp) { |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
133 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
|
134 break; |
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
135 } |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
136 |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
137 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
|
138 |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
139 /* timestamp */ |
91
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
140 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
|
141 |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
142 /* parse received data */ |
91
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
143 Scan(resp, "2900; %f; %f; %f; %f", |
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
144 &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
|
145 |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
146 /* convert from kHz to Hz */ |
91
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
147 event.data[0] *= 1000.0; |
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
148 event.data[1] *= 1000.0; |
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
149 event.data[2] *= 1000.0; |
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
150 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
|
151 |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
152 /* push data into the data queue */ |
91
4102fe614df2
Fix timestamping. Cleanup data providers
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
89
diff
changeset
|
153 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
|
154 |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
155 } 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
|
156 /* 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
|
157 } 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
|
158 /* 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
|
159 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
|
160 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
|
161 } 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
|
162 /* 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
|
163 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
|
164 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
|
165 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
|
166 } |
120
84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
102
diff
changeset
|
167 } else if (strneq(resp, "7F51", 4)) { |
84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
102
diff
changeset
|
168 /* measurement interval synchronized */ |
84fb0796936b
Add KK counter measurement interval synchronization to PPS trigger
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
102
diff
changeset
|
169 SendMessage(mainThreadId, "KK Counter measurement interval synchronized"); |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
170 } else { |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
171 /* 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
|
172 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
|
173 } |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
174 } |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
175 |
102
4f1f353e84f5
Add timeout to FX_Recv() function. Improve error handling in KKDataProvider
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
96
diff
changeset
|
176 error: |
89
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
177 /* close serial port */ |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
178 FX_Close(); |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
179 /* free allocated resources */ |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
180 FX_Free(); |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
181 |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
182 return 0; |
c9e4f63c2033
Implement data acquisition through direct communication with the KK counter
Daniele Nicolodi <daniele.nicolodi@obspm.fr>
parents:
diff
changeset
|
183 } |