Mercurial > hg > fxanalyse
comparison kk-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 | d7f91b9fb515 |
children | 9b35a2b2c759 |
comparison
equal
deleted
inserted
replaced
238:78fdba868884 | 239:ec81395bf08d |
---|---|
44 } | 44 } |
45 | 45 |
46 | 46 |
47 int CVICALLBACK KKDataProvider (void *functionData) | 47 int CVICALLBACK KKDataProvider (void *functionData) |
48 { | 48 { |
49 int mainThreadId; | 49 int main_thread_id; |
50 int rv; | 50 int rv; |
51 char *resp; | 51 char *resp; |
52 struct event event; | 52 struct event event; |
53 int nchan; | 53 int nchan; |
54 char port[256]; | 54 char port[256]; |
55 | 55 |
56 /* get main thread id to post messages to it */ | 56 /* get main thread id to post messages to it */ |
57 mainThreadId = CmtGetMainThreadID(); | 57 main_thread_id = CmtGetMainThreadID(); |
58 | 58 |
59 /* configuration file path */ | 59 /* configuration file path */ |
60 char path[MAX_PATHNAME_LEN]; | 60 char path[MAX_PATHNAME_LEN]; |
61 GetIniFilePath(path); | 61 GetIniFilePath(path); |
62 | 62 |
81 FX_Init(); | 81 FX_Init(); |
82 | 82 |
83 /* connect to KK FX80E counter */ | 83 /* connect to KK FX80E counter */ |
84 rv = FX_Open(port); | 84 rv = FX_Open(port); |
85 if (! rv) { | 85 if (! rv) { |
86 SendMessage(mainThreadId, FX_Error()); | 86 send_message(main_thread_id, FX_Error()); |
87 goto error; | 87 goto error; |
88 } | 88 } |
89 | 89 |
90 /* get counter hardware version string */ | 90 /* get counter hardware version string */ |
91 resp = FX_Command(0x81, 0xFFFF, 0x7001); | 91 resp = FX_Command(0x81, 0xFFFF, 0x7001); |
92 if (! resp) { | 92 if (! resp) { |
93 SendMessage(mainThreadId, FX_Error()); | 93 send_message(main_thread_id, FX_Error()); |
94 goto error; | 94 goto error; |
95 } | 95 } |
96 SendMessage(mainThreadId, "KK Counter version: %s", resp + 4); | 96 send_message(main_thread_id, "KK Counter version: %s", resp + 4); |
97 | 97 |
98 /* set report interval 1sec */ | 98 /* set report interval 1sec */ |
99 resp = FX_Command(0x29, 0x0F00, 0x0900); | 99 resp = FX_Command(0x29, 0x0F00, 0x0900); |
100 if (! resp) { | 100 if (! resp) { |
101 SendMessage(mainThreadId, FX_Error()); | 101 send_message(main_thread_id, FX_Error()); |
102 goto error; | 102 goto error; |
103 } | 103 } |
104 | 104 |
105 /* set mode to instantaneous frequency measurement */ | 105 /* set mode to instantaneous frequency measurement */ |
106 resp = FX_Command(0x42, 0x6F00, 0x2900); | 106 resp = FX_Command(0x42, 0x6F00, 0x2900); |
107 if (! resp) { | 107 if (! resp) { |
108 SendMessage(mainThreadId, FX_Error()); | 108 send_message(main_thread_id, FX_Error()); |
109 goto error; | 109 goto error; |
110 } | 110 } |
111 | 111 |
112 /* disable scrambler */ | 112 /* disable scrambler */ |
113 resp = FX_Command(0x50, 0x6FFF, 0x2900); | 113 resp = FX_Command(0x50, 0x6FFF, 0x2900); |
114 if (! resp) { | 114 if (! resp) { |
115 SendMessage(mainThreadId, FX_Error()); | 115 send_message(main_thread_id, FX_Error()); |
116 goto error; | 116 goto error; |
117 } | 117 } |
118 | 118 |
119 /* read nchan channels */ | 119 /* read nchan channels */ |
120 resp = FX_Command(0x30 + nchan, 0x6FFF, 0x2900); | 120 resp = FX_Command(0x30 + nchan, 0x6FFF, 0x2900); |
121 if (! resp) { | 121 if (! resp) { |
122 SendMessage(mainThreadId, FX_Error()); | 122 send_message(main_thread_id, FX_Error()); |
123 goto error; | 123 goto error; |
124 } | 124 } |
125 | 125 |
126 /* enable synchronization */ | 126 /* enable synchronization */ |
127 resp = FX_Command(0x0F, 0x00, 0x00); | 127 resp = FX_Command(0x0F, 0x00, 0x00); |
128 if (! resp) { | 128 if (! resp) { |
129 SendMessage(mainThreadId, FX_Error()); | 129 send_message(main_thread_id, FX_Error()); |
130 goto error; | 130 goto error; |
131 } | 131 } |
132 | 132 |
133 while (acquiring) { | 133 while (acquiring) { |
134 /* receive data from counter */ | 134 /* receive data from counter */ |
135 FX_Recv(&resp, TIMEOUT); | 135 FX_Recv(&resp, TIMEOUT); |
136 if (! resp) { | 136 if (! resp) { |
137 SendMessage(mainThreadId, FX_Error()); | 137 send_message(main_thread_id, FX_Error()); |
138 break; | 138 break; |
139 } | 139 } |
140 | 140 |
141 /* data packets */ | 141 /* data packets */ |
142 if (strneq(resp, "2900", 2)) { | 142 if (strneq(resp, "2900", 2)) { |
147 /* parse received data */ | 147 /* parse received data */ |
148 rv = Scan(resp + 6, "%f; %f; %f; %f; %f; %f; %f; %f", | 148 rv = Scan(resp + 6, "%f; %f; %f; %f; %f; %f; %f; %f", |
149 &event.data[0], &event.data[1], &event.data[2], &event.data[3], | 149 &event.data[0], &event.data[1], &event.data[2], &event.data[3], |
150 &event.data[4], &event.data[5], &event.data[6], &event.data[7]); | 150 &event.data[4], &event.data[5], &event.data[6], &event.data[7]); |
151 if (rv != nchan) { | 151 if (rv != nchan) { |
152 SendMessage(mainThreadId, "KK Counter: data conversion error: %d != %d", rv, nchan); | 152 send_message(main_thread_id, "KK Counter: data conversion error: %d != %d", rv, nchan); |
153 goto error; | 153 goto error; |
154 } | 154 } |
155 | 155 |
156 /* convert from kHz to Hz */ | 156 /* convert from kHz to Hz */ |
157 for (int i = 0; i < nchan; i++) | 157 for (int i = 0; i < nchan; i++) |
167 for each data packet. it probably contains a sample count along | 167 for each data packet. it probably contains a sample count along |
168 with some other information */ | 168 with some other information */ |
169 } else if (strneq(resp, "7020", 4)) { | 169 } else if (strneq(resp, "7020", 4)) { |
170 /* undocumented packet. it probably reports the header for | 170 /* undocumented packet. it probably reports the header for |
171 subsequent data packets */ | 171 subsequent data packets */ |
172 SendMessage(mainThreadId, "KK Counter packet header: %s", resp + 7); | 172 send_message(main_thread_id, "KK Counter packet header: %s", resp + 7); |
173 } else if (strneq(resp, "7F51", 4)) { | 173 } else if (strneq(resp, "7F51", 4)) { |
174 /* measurement interval synchronized */ | 174 /* measurement interval synchronized */ |
175 SendMessage(mainThreadId, "KK Counter measurement interval synchronized"); | 175 send_message(main_thread_id, "KK Counter measurement interval synchronized"); |
176 } else { | 176 } else { |
177 /* send message to the main thread */ | 177 /* send message to the main thread */ |
178 SendMessage(mainThreadId, "KK Counter: %s", resp); | 178 send_message(main_thread_id, "KK Counter: %s", resp); |
179 } | 179 } |
180 } | 180 } |
181 | 181 |
182 error: | 182 error: |
183 /* close serial port */ | 183 /* close serial port */ |