]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * This file is part of the libsigrok project. | |
3 | * | |
4 | * Copyright (C) 2012 Bert Vermeulen <bert@biot.com> | |
5 | * Copyright (C) 2012 Alexandru Gagniuc <mr.nuke.me@gmail.com> | |
6 | * Copyright (C) 2012 Uwe Hermann <uwe@hermann-uwe.de> | |
7 | * | |
8 | * This program is free software: you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation, either version 3 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 | */ | |
21 | ||
22 | #include <sys/types.h> | |
23 | #include <sys/stat.h> | |
24 | #include <fcntl.h> | |
25 | #include <string.h> | |
26 | #include <errno.h> | |
27 | #include <glib.h> | |
28 | #include "libsigrok.h" | |
29 | #include "libsigrok-internal.h" | |
30 | #include "protocol.h" | |
31 | ||
32 | static const int32_t hwopts[] = { | |
33 | SR_CONF_CONN, | |
34 | SR_CONF_SERIALCOMM, | |
35 | }; | |
36 | ||
37 | static const int32_t hwcaps[] = { | |
38 | SR_CONF_MULTIMETER, | |
39 | SR_CONF_LIMIT_SAMPLES, | |
40 | SR_CONF_LIMIT_MSEC, | |
41 | SR_CONF_CONTINUOUS, | |
42 | }; | |
43 | ||
44 | SR_PRIV struct sr_dev_driver bbcgm_m2110_driver_info; | |
45 | SR_PRIV struct sr_dev_driver digitek_dt4000zc_driver_info; | |
46 | SR_PRIV struct sr_dev_driver tekpower_tp4000zc_driver_info; | |
47 | SR_PRIV struct sr_dev_driver metex_me31_driver_info; | |
48 | SR_PRIV struct sr_dev_driver peaktech_3410_driver_info; | |
49 | SR_PRIV struct sr_dev_driver mastech_mas345_driver_info; | |
50 | SR_PRIV struct sr_dev_driver va_va18b_driver_info; | |
51 | SR_PRIV struct sr_dev_driver va_va40b_driver_info; | |
52 | SR_PRIV struct sr_dev_driver metex_m3640d_driver_info; | |
53 | SR_PRIV struct sr_dev_driver metex_m4650cr_driver_info; | |
54 | SR_PRIV struct sr_dev_driver peaktech_4370_driver_info; | |
55 | SR_PRIV struct sr_dev_driver pce_pce_dm32_driver_info; | |
56 | SR_PRIV struct sr_dev_driver radioshack_22_168_driver_info; | |
57 | SR_PRIV struct sr_dev_driver radioshack_22_805_driver_info; | |
58 | SR_PRIV struct sr_dev_driver radioshack_22_812_driver_info; | |
59 | SR_PRIV struct sr_dev_driver tecpel_dmm_8061_ser_driver_info; | |
60 | SR_PRIV struct sr_dev_driver voltcraft_m3650cr_driver_info; | |
61 | SR_PRIV struct sr_dev_driver voltcraft_m3650d_driver_info; | |
62 | SR_PRIV struct sr_dev_driver voltcraft_m4650cr_driver_info; | |
63 | SR_PRIV struct sr_dev_driver voltcraft_me42_driver_info; | |
64 | SR_PRIV struct sr_dev_driver voltcraft_vc820_ser_driver_info; | |
65 | SR_PRIV struct sr_dev_driver voltcraft_vc830_ser_driver_info; | |
66 | SR_PRIV struct sr_dev_driver voltcraft_vc840_ser_driver_info; | |
67 | SR_PRIV struct sr_dev_driver uni_t_ut60a_ser_driver_info; | |
68 | SR_PRIV struct sr_dev_driver uni_t_ut60e_ser_driver_info; | |
69 | SR_PRIV struct sr_dev_driver uni_t_ut60g_ser_driver_info; | |
70 | SR_PRIV struct sr_dev_driver uni_t_ut61b_ser_driver_info; | |
71 | SR_PRIV struct sr_dev_driver uni_t_ut61c_ser_driver_info; | |
72 | SR_PRIV struct sr_dev_driver uni_t_ut61d_ser_driver_info; | |
73 | SR_PRIV struct sr_dev_driver uni_t_ut61e_ser_driver_info; | |
74 | SR_PRIV struct sr_dev_driver iso_tech_idm103n_driver_info; | |
75 | SR_PRIV struct sr_dev_driver tenma_72_7745_ser_driver_info; | |
76 | SR_PRIV struct sr_dev_driver tenma_72_7750_ser_driver_info; | |
77 | SR_PRIV struct sr_dev_driver brymen_bm25x_ser_driver_info; | |
78 | ||
79 | SR_PRIV struct dmm_info dmms[] = { | |
80 | { | |
81 | "BBC Goertz Metrawatt", "M2110", "1200/7n2", 1200, | |
82 | BBCGM_M2110_PACKET_SIZE, 0, 0, NULL, | |
83 | sr_m2110_packet_valid, sr_m2110_parse, | |
84 | NULL, | |
85 | &bbcgm_m2110_driver_info, receive_data_BBCGM_M2110, | |
86 | }, | |
87 | { | |
88 | "Digitek", "DT4000ZC", "2400/8n1/dtr=1", 2400, | |
89 | FS9721_PACKET_SIZE, 0, 0, NULL, | |
90 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
91 | sr_fs9721_10_temp_c, | |
92 | &digitek_dt4000zc_driver_info, receive_data_DIGITEK_DT4000ZC, | |
93 | }, | |
94 | { | |
95 | "TekPower", "TP4000ZC", "2400/8n1/dtr=1", 2400, | |
96 | FS9721_PACKET_SIZE, 0, 0, NULL, | |
97 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
98 | sr_fs9721_10_temp_c, | |
99 | &tekpower_tp4000zc_driver_info, receive_data_TEKPOWER_TP4000ZC, | |
100 | }, | |
101 | { | |
102 | "Metex", "ME-31", "600/7n2/rts=0/dtr=1", 600, | |
103 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
104 | sr_metex14_packet_valid, sr_metex14_parse, | |
105 | NULL, | |
106 | &metex_me31_driver_info, receive_data_METEX_ME31, | |
107 | }, | |
108 | { | |
109 | "Peaktech", "3410", "600/7n2/rts=0/dtr=1", 600, | |
110 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
111 | sr_metex14_packet_valid, sr_metex14_parse, | |
112 | NULL, | |
113 | &peaktech_3410_driver_info, receive_data_PEAKTECH_3410, | |
114 | }, | |
115 | { | |
116 | "MASTECH", "MAS345", "600/7n2/rts=0/dtr=1", 600, | |
117 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
118 | sr_metex14_packet_valid, sr_metex14_parse, | |
119 | NULL, | |
120 | &mastech_mas345_driver_info, receive_data_MASTECH_MAS345, | |
121 | }, | |
122 | { | |
123 | "V&A", "VA18B", "2400/8n1", 2400, | |
124 | FS9721_PACKET_SIZE, 0, 0, NULL, | |
125 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
126 | sr_fs9721_01_temp_c, | |
127 | &va_va18b_driver_info, receive_data_VA_VA18B, | |
128 | }, | |
129 | { | |
130 | "V&A", "VA40B", "2400/8n1", 2400, | |
131 | FS9721_PACKET_SIZE, 0, 0, NULL, | |
132 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
133 | sr_fs9721_max_c_min, | |
134 | &va_va40b_driver_info, receive_data_VA_VA40B, | |
135 | }, | |
136 | { | |
137 | "Metex", "M-3640D", "1200/7n2/rts=0/dtr=1", 1200, | |
138 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
139 | sr_metex14_packet_valid, sr_metex14_parse, | |
140 | NULL, | |
141 | &metex_m3640d_driver_info, receive_data_METEX_M3640D, | |
142 | }, | |
143 | { | |
144 | "Metex", "M-4650CR", "1200/7n2/rts=0/dtr=1", 1200, | |
145 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
146 | sr_metex14_packet_valid, sr_metex14_parse, | |
147 | NULL, | |
148 | &metex_m4650cr_driver_info, receive_data_METEX_M4650CR, | |
149 | }, | |
150 | { | |
151 | "PeakTech", "4370", "1200/7n2/rts=0/dtr=1", 1200, | |
152 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
153 | sr_metex14_packet_valid, sr_metex14_parse, | |
154 | NULL, | |
155 | &peaktech_4370_driver_info, receive_data_PEAKTECH_4370, | |
156 | }, | |
157 | { | |
158 | "PCE", "PCE-DM32", "2400/8n1", 2400, | |
159 | FS9721_PACKET_SIZE, 0, 0, NULL, | |
160 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
161 | sr_fs9721_01_10_temp_f_c, | |
162 | &pce_pce_dm32_driver_info, receive_data_PCE_PCE_DM32, | |
163 | }, | |
164 | { | |
165 | "RadioShack", "22-168", "1200/7n2/rts=0/dtr=1", 1200, | |
166 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
167 | sr_metex14_packet_valid, sr_metex14_parse, | |
168 | NULL, | |
169 | &radioshack_22_168_driver_info, receive_data_RADIOSHACK_22_168, | |
170 | }, | |
171 | { | |
172 | "RadioShack", "22-805", "600/7n2/rts=0/dtr=1", 600, | |
173 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
174 | sr_metex14_packet_valid, sr_metex14_parse, | |
175 | NULL, | |
176 | &radioshack_22_805_driver_info, receive_data_RADIOSHACK_22_805, | |
177 | }, | |
178 | { | |
179 | "RadioShack", "22-812", "4800/8n1/rts=0/dtr=1", 4800, | |
180 | RS9LCD_PACKET_SIZE, 0, 0, NULL, | |
181 | sr_rs9lcd_packet_valid, sr_rs9lcd_parse, | |
182 | NULL, | |
183 | &radioshack_22_812_driver_info, receive_data_RADIOSHACK_22_812, | |
184 | }, | |
185 | { | |
186 | "Tecpel", "DMM-8061 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
187 | 2400, FS9721_PACKET_SIZE, 0, 0, NULL, | |
188 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
189 | sr_fs9721_00_temp_c, | |
190 | &tecpel_dmm_8061_ser_driver_info, | |
191 | receive_data_TECPEL_DMM_8061_SER, | |
192 | }, | |
193 | { | |
194 | "Voltcraft", "M-3650CR", "1200/7n2/rts=0/dtr=1", 1200, | |
195 | METEX14_PACKET_SIZE, 150, 20, sr_metex14_packet_request, | |
196 | sr_metex14_packet_valid, sr_metex14_parse, | |
197 | NULL, | |
198 | &voltcraft_m3650cr_driver_info, receive_data_VOLTCRAFT_M3650CR, | |
199 | }, | |
200 | { | |
201 | "Voltcraft", "M-3650D", "1200/7n2/rts=0/dtr=1", 1200, | |
202 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
203 | sr_metex14_packet_valid, sr_metex14_parse, | |
204 | NULL, | |
205 | &voltcraft_m3650d_driver_info, receive_data_VOLTCRAFT_M3650D, | |
206 | }, | |
207 | { | |
208 | "Voltcraft", "M-4650CR", "1200/7n2/rts=0/dtr=1", 1200, | |
209 | METEX14_PACKET_SIZE, 0, 0, sr_metex14_packet_request, | |
210 | sr_metex14_packet_valid, sr_metex14_parse, | |
211 | NULL, | |
212 | &voltcraft_m4650cr_driver_info, receive_data_VOLTCRAFT_M4650CR, | |
213 | }, | |
214 | { | |
215 | "Voltcraft", "ME-42", "600/7n2/rts=0/dtr=1", 600, | |
216 | METEX14_PACKET_SIZE, 250, 60, sr_metex14_packet_request, | |
217 | sr_metex14_packet_valid, sr_metex14_parse, | |
218 | NULL, | |
219 | &voltcraft_me42_driver_info, receive_data_VOLTCRAFT_ME42, | |
220 | }, | |
221 | { | |
222 | "Voltcraft", "VC-820 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
223 | 2400, FS9721_PACKET_SIZE, 0, 0, NULL, | |
224 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
225 | NULL, | |
226 | &voltcraft_vc820_ser_driver_info, | |
227 | receive_data_VOLTCRAFT_VC820_SER, | |
228 | }, | |
229 | { | |
230 | /* | |
231 | * Note: The VC830 doesn't set the 'volt' and 'diode' bits of | |
232 | * the FS9922 protocol. Instead, it only sets the user-defined | |
233 | * bit "z1" to indicate "diode mode" and "voltage". | |
234 | */ | |
235 | "Voltcraft", "VC-830 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
236 | 2400, FS9922_PACKET_SIZE, 0, 0, NULL, | |
237 | sr_fs9922_packet_valid, sr_fs9922_parse, | |
238 | &sr_fs9922_z1_diode, | |
239 | &voltcraft_vc830_ser_driver_info, | |
240 | receive_data_VOLTCRAFT_VC830_SER, | |
241 | }, | |
242 | { | |
243 | "Voltcraft", "VC-840 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
244 | 2400, FS9721_PACKET_SIZE, 0, 0, NULL, | |
245 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
246 | sr_fs9721_00_temp_c, | |
247 | &voltcraft_vc840_ser_driver_info, | |
248 | receive_data_VOLTCRAFT_VC840_SER, | |
249 | }, | |
250 | { | |
251 | "UNI-T", "UT60A (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
252 | 2400, FS9721_PACKET_SIZE, 0, 0, NULL, | |
253 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
254 | NULL, | |
255 | &uni_t_ut60a_ser_driver_info, | |
256 | receive_data_UNI_T_UT60A_SER, | |
257 | }, | |
258 | { | |
259 | "UNI-T", "UT60E (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
260 | 2400, FS9721_PACKET_SIZE, 0, 0, NULL, | |
261 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
262 | sr_fs9721_00_temp_c, | |
263 | &uni_t_ut60e_ser_driver_info, | |
264 | receive_data_UNI_T_UT60E_SER, | |
265 | }, | |
266 | { | |
267 | /* Note: ES51986 baudrate is actually 19230! */ | |
268 | "UNI-T", "UT60G (UT-D02 cable)", "19200/7o1/rts=0/dtr=1", | |
269 | 19200, ES519XX_11B_PACKET_SIZE, 0, 0, NULL, | |
270 | sr_es519xx_19200_11b_packet_valid, sr_es519xx_19200_11b_parse, | |
271 | NULL, | |
272 | &uni_t_ut60g_ser_driver_info, receive_data_UNI_T_UT60G_SER, | |
273 | }, | |
274 | { | |
275 | "UNI-T", "UT61B (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
276 | 2400, FS9922_PACKET_SIZE, 0, 0, NULL, | |
277 | sr_fs9922_packet_valid, sr_fs9922_parse, NULL, | |
278 | &uni_t_ut61b_ser_driver_info, receive_data_UNI_T_UT61B_SER, | |
279 | }, | |
280 | { | |
281 | "UNI-T", "UT61C (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
282 | 2400, FS9922_PACKET_SIZE, 0, 0, NULL, | |
283 | sr_fs9922_packet_valid, sr_fs9922_parse, NULL, | |
284 | &uni_t_ut61c_ser_driver_info, receive_data_UNI_T_UT61C_SER, | |
285 | }, | |
286 | { | |
287 | "UNI-T", "UT61D (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
288 | 2400, FS9922_PACKET_SIZE, 0, 0, NULL, | |
289 | sr_fs9922_packet_valid, sr_fs9922_parse, NULL, | |
290 | &uni_t_ut61d_ser_driver_info, receive_data_UNI_T_UT61D_SER, | |
291 | }, | |
292 | { | |
293 | /* Note: ES51922 baudrate is actually 19230! */ | |
294 | "UNI-T", "UT61E (UT-D02 cable)", "19200/7o1/rts=0/dtr=1", | |
295 | 19200, ES519XX_14B_PACKET_SIZE, 0, 0, NULL, | |
296 | sr_es519xx_19200_14b_packet_valid, sr_es519xx_19200_14b_parse, | |
297 | NULL, | |
298 | &uni_t_ut61e_ser_driver_info, receive_data_UNI_T_UT61E_SER, | |
299 | }, | |
300 | { | |
301 | "ISO-TECH", "IDM103N", "2400/7o1/rts=0/dtr=1", | |
302 | 2400, ES519XX_11B_PACKET_SIZE, 0, 0, NULL, | |
303 | sr_es519xx_2400_11b_packet_valid, sr_es519xx_2400_11b_parse, | |
304 | NULL, | |
305 | &iso_tech_idm103n_driver_info, receive_data_ISO_TECH_IDM103N, | |
306 | }, | |
307 | { | |
308 | "Tenma", "72-7745 (UT-D02 cable)", "2400/8n1/rts=0/dtr=1", | |
309 | 2400, FS9721_PACKET_SIZE, 0, 0, NULL, | |
310 | sr_fs9721_packet_valid, sr_fs9721_parse, | |
311 | sr_fs9721_00_temp_c, | |
312 | &tenma_72_7745_ser_driver_info, receive_data_TENMA_72_7745_SER, | |
313 | }, | |
314 | { | |
315 | /* Note: ES51986 baudrate is actually 19230! */ | |
316 | "Tenma", "72-7750 (UT-D02 cable)", "19200/7o1/rts=0/dtr=1", | |
317 | 19200, ES519XX_11B_PACKET_SIZE, 0, 0, NULL, | |
318 | sr_es519xx_19200_11b_packet_valid, sr_es519xx_19200_11b_parse, | |
319 | NULL, | |
320 | &tenma_72_7750_ser_driver_info, receive_data_TENMA_72_7750_SER, | |
321 | }, | |
322 | { | |
323 | "Brymen", "BM25x (BC20X cable)", "9600/8n1/rts=1/dtr=1", | |
324 | 9600, BRYMEN_BM25X_PACKET_SIZE, 0, 0, NULL, | |
325 | sr_brymen_bm25x_packet_valid, sr_brymen_bm25x_parse, | |
326 | NULL, | |
327 | &brymen_bm25x_ser_driver_info, receive_data_BRYMEN_BM25X_SER, | |
328 | }, | |
329 | }; | |
330 | ||
331 | static int dev_clear(int dmm) | |
332 | { | |
333 | return std_dev_clear(dmms[dmm].di, NULL); | |
334 | } | |
335 | ||
336 | static int init(struct sr_context *sr_ctx, int dmm) | |
337 | { | |
338 | return std_init(sr_ctx, dmms[dmm].di, LOG_PREFIX); | |
339 | } | |
340 | ||
341 | static GSList *sdmm_scan(const char *conn, const char *serialcomm, int dmm) | |
342 | { | |
343 | struct sr_dev_inst *sdi; | |
344 | struct drv_context *drvc; | |
345 | struct dev_context *devc; | |
346 | struct sr_channel *ch; | |
347 | struct sr_serial_dev_inst *serial; | |
348 | GSList *devices; | |
349 | int dropped, ret; | |
350 | size_t len; | |
351 | uint8_t buf[128]; | |
352 | ||
353 | if (!(serial = sr_serial_dev_inst_new(conn, serialcomm))) | |
354 | return NULL; | |
355 | ||
356 | if (serial_open(serial, SERIAL_RDWR | SERIAL_NONBLOCK) != SR_OK) | |
357 | return NULL; | |
358 | ||
359 | sr_info("Probing serial port %s.", conn); | |
360 | ||
361 | drvc = dmms[dmm].di->priv; | |
362 | devices = NULL; | |
363 | serial_flush(serial); | |
364 | ||
365 | /* Request a packet if the DMM requires this. */ | |
366 | if (dmms[dmm].packet_request) { | |
367 | if ((ret = dmms[dmm].packet_request(serial)) < 0) { | |
368 | sr_err("Failed to request packet: %d.", ret); | |
369 | return FALSE; | |
370 | } | |
371 | } | |
372 | ||
373 | /* | |
374 | * There's no way to get an ID from the multimeter. It just sends data | |
375 | * periodically (or upon request), so the best we can do is check if | |
376 | * the packets match the expected format. | |
377 | */ | |
378 | ||
379 | /* Let's get a bit of data and see if we can find a packet. */ | |
380 | len = sizeof(buf); | |
381 | ret = serial_stream_detect(serial, buf, &len, dmms[dmm].packet_size, | |
382 | dmms[dmm].packet_valid, 3000, | |
383 | dmms[dmm].baudrate); | |
384 | if (ret != SR_OK) | |
385 | goto scan_cleanup; | |
386 | ||
387 | /* | |
388 | * If we dropped more than two packets worth of data, something is | |
389 | * wrong. We shouldn't quit however, since the dropped bytes might be | |
390 | * just zeroes at the beginning of the stream. Those can occur as a | |
391 | * combination of the nonstandard cable that ships with some devices | |
392 | * and the serial port or USB to serial adapter. | |
393 | */ | |
394 | dropped = len - dmms[dmm].packet_size; | |
395 | if (dropped > 2 * dmms[dmm].packet_size) | |
396 | sr_warn("Had to drop too much data."); | |
397 | ||
398 | sr_info("Found device on port %s.", conn); | |
399 | ||
400 | if (!(sdi = sr_dev_inst_new(0, SR_ST_INACTIVE, dmms[dmm].vendor, | |
401 | dmms[dmm].device, NULL))) | |
402 | goto scan_cleanup; | |
403 | ||
404 | if (!(devc = g_try_malloc0(sizeof(struct dev_context)))) { | |
405 | sr_err("Device context malloc failed."); | |
406 | goto scan_cleanup; | |
407 | } | |
408 | ||
409 | sdi->inst_type = SR_INST_SERIAL; | |
410 | sdi->conn = serial; | |
411 | ||
412 | sdi->priv = devc; | |
413 | sdi->driver = dmms[dmm].di; | |
414 | if (!(ch = sr_channel_new(0, SR_CHANNEL_ANALOG, TRUE, "P1"))) | |
415 | goto scan_cleanup; | |
416 | sdi->channels = g_slist_append(sdi->channels, ch); | |
417 | drvc->instances = g_slist_append(drvc->instances, sdi); | |
418 | devices = g_slist_append(devices, sdi); | |
419 | ||
420 | scan_cleanup: | |
421 | serial_close(serial); | |
422 | ||
423 | return devices; | |
424 | } | |
425 | ||
426 | static GSList *scan(GSList *options, int dmm) | |
427 | { | |
428 | struct sr_config *src; | |
429 | GSList *l, *devices; | |
430 | const char *conn, *serialcomm; | |
431 | ||
432 | conn = serialcomm = NULL; | |
433 | for (l = options; l; l = l->next) { | |
434 | src = l->data; | |
435 | switch (src->key) { | |
436 | case SR_CONF_CONN: | |
437 | conn = g_variant_get_string(src->data, NULL); | |
438 | break; | |
439 | case SR_CONF_SERIALCOMM: | |
440 | serialcomm = g_variant_get_string(src->data, NULL); | |
441 | break; | |
442 | } | |
443 | } | |
444 | if (!conn) | |
445 | return NULL; | |
446 | ||
447 | if (serialcomm) { | |
448 | /* Use the provided comm specs. */ | |
449 | devices = sdmm_scan(conn, serialcomm, dmm); | |
450 | } else { | |
451 | /* Try the default. */ | |
452 | devices = sdmm_scan(conn, dmms[dmm].conn, dmm); | |
453 | } | |
454 | ||
455 | return devices; | |
456 | } | |
457 | ||
458 | static GSList *dev_list(int dmm) | |
459 | { | |
460 | return ((struct drv_context *)(dmms[dmm].di->priv))->instances; | |
461 | } | |
462 | ||
463 | static int cleanup(int dmm) | |
464 | { | |
465 | return dev_clear(dmm); | |
466 | } | |
467 | ||
468 | static int config_set(int id, GVariant *data, const struct sr_dev_inst *sdi, | |
469 | const struct sr_channel_group *cg) | |
470 | { | |
471 | struct dev_context *devc; | |
472 | ||
473 | (void)cg; | |
474 | ||
475 | if (sdi->status != SR_ST_ACTIVE) | |
476 | return SR_ERR_DEV_CLOSED; | |
477 | ||
478 | if (!(devc = sdi->priv)) { | |
479 | sr_err("sdi->priv was NULL."); | |
480 | return SR_ERR_BUG; | |
481 | } | |
482 | ||
483 | switch (id) { | |
484 | case SR_CONF_LIMIT_SAMPLES: | |
485 | devc->limit_samples = g_variant_get_uint64(data); | |
486 | sr_dbg("Setting sample limit to %" PRIu64 ".", | |
487 | devc->limit_samples); | |
488 | break; | |
489 | case SR_CONF_LIMIT_MSEC: | |
490 | devc->limit_msec = g_variant_get_uint64(data); | |
491 | sr_dbg("Setting time limit to %" PRIu64 "ms.", | |
492 | devc->limit_msec); | |
493 | break; | |
494 | default: | |
495 | return SR_ERR_NA; | |
496 | } | |
497 | ||
498 | return SR_OK; | |
499 | } | |
500 | ||
501 | static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi, | |
502 | const struct sr_channel_group *cg) | |
503 | { | |
504 | (void)sdi; | |
505 | (void)cg; | |
506 | ||
507 | switch (key) { | |
508 | case SR_CONF_SCAN_OPTIONS: | |
509 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, | |
510 | hwopts, ARRAY_SIZE(hwopts), sizeof(int32_t)); | |
511 | break; | |
512 | case SR_CONF_DEVICE_OPTIONS: | |
513 | *data = g_variant_new_fixed_array(G_VARIANT_TYPE_INT32, | |
514 | hwcaps, ARRAY_SIZE(hwcaps), sizeof(int32_t)); | |
515 | break; | |
516 | default: | |
517 | return SR_ERR_NA; | |
518 | } | |
519 | ||
520 | return SR_OK; | |
521 | } | |
522 | ||
523 | static int dev_acquisition_start(const struct sr_dev_inst *sdi, | |
524 | void *cb_data, int dmm) | |
525 | { | |
526 | struct dev_context *devc; | |
527 | struct sr_serial_dev_inst *serial; | |
528 | ||
529 | if (sdi->status != SR_ST_ACTIVE) | |
530 | return SR_ERR_DEV_CLOSED; | |
531 | ||
532 | if (!(devc = sdi->priv)) { | |
533 | sr_err("sdi->priv was NULL."); | |
534 | return SR_ERR_BUG; | |
535 | } | |
536 | ||
537 | devc->cb_data = cb_data; | |
538 | ||
539 | /* | |
540 | * Reset the number of samples to take. If we've already collected our | |
541 | * quota, but we start a new session, and don't reset this, we'll just | |
542 | * quit without acquiring any new samples. | |
543 | */ | |
544 | devc->num_samples = 0; | |
545 | devc->starttime = g_get_monotonic_time(); | |
546 | ||
547 | /* Send header packet to the session bus. */ | |
548 | std_session_send_df_header(cb_data, LOG_PREFIX); | |
549 | ||
550 | /* Poll every 50ms, or whenever some data comes in. */ | |
551 | serial = sdi->conn; | |
552 | serial_source_add(sdi->session, serial, G_IO_IN, 50, | |
553 | dmms[dmm].receive_data, (void *)sdi); | |
554 | ||
555 | return SR_OK; | |
556 | } | |
557 | ||
558 | static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data) | |
559 | { | |
560 | return std_serial_dev_acquisition_stop(sdi, cb_data, std_serial_dev_close, | |
561 | sdi->conn, LOG_PREFIX); | |
562 | } | |
563 | ||
564 | /* Driver-specific API function wrappers */ | |
565 | #define HW_INIT(X) \ | |
566 | static int init_##X(struct sr_context *sr_ctx) { return init(sr_ctx, X); } | |
567 | #define HW_CLEANUP(X) \ | |
568 | static int cleanup_##X(void) { return cleanup(X); } | |
569 | #define HW_SCAN(X) \ | |
570 | static GSList *scan_##X(GSList *options) { return scan(options, X); } | |
571 | #define HW_DEV_LIST(X) \ | |
572 | static GSList *dev_list_##X(void) { return dev_list(X); } | |
573 | #define HW_DEV_CLEAR(X) \ | |
574 | static int dev_clear_##X(void) { return dev_clear(X); } | |
575 | #define HW_DEV_ACQUISITION_START(X) \ | |
576 | static int dev_acquisition_start_##X(const struct sr_dev_inst *sdi, \ | |
577 | void *cb_data) { return dev_acquisition_start(sdi, cb_data, X); } | |
578 | ||
579 | /* Driver structs and API function wrappers */ | |
580 | #define DRV(ID, ID_UPPER, NAME, LONGNAME) \ | |
581 | HW_INIT(ID_UPPER) \ | |
582 | HW_CLEANUP(ID_UPPER) \ | |
583 | HW_SCAN(ID_UPPER) \ | |
584 | HW_DEV_LIST(ID_UPPER) \ | |
585 | HW_DEV_CLEAR(ID_UPPER) \ | |
586 | HW_DEV_ACQUISITION_START(ID_UPPER) \ | |
587 | SR_PRIV struct sr_dev_driver ID##_driver_info = { \ | |
588 | .name = NAME, \ | |
589 | .longname = LONGNAME, \ | |
590 | .api_version = 1, \ | |
591 | .init = init_##ID_UPPER, \ | |
592 | .cleanup = cleanup_##ID_UPPER, \ | |
593 | .scan = scan_##ID_UPPER, \ | |
594 | .dev_list = dev_list_##ID_UPPER, \ | |
595 | .dev_clear = dev_clear_##ID_UPPER, \ | |
596 | .config_get = NULL, \ | |
597 | .config_set = config_set, \ | |
598 | .config_list = config_list, \ | |
599 | .dev_open = std_serial_dev_open, \ | |
600 | .dev_close = std_serial_dev_close, \ | |
601 | .dev_acquisition_start = dev_acquisition_start_##ID_UPPER, \ | |
602 | .dev_acquisition_stop = dev_acquisition_stop, \ | |
603 | .priv = NULL, \ | |
604 | }; | |
605 | ||
606 | DRV(bbcgm_m2110, BBCGM_M2110, "bbcgm-m2110", "BBC Goertz Metrawatt M2110") | |
607 | DRV(digitek_dt4000zc, DIGITEK_DT4000ZC, "digitek-dt4000zc", "Digitek DT4000ZC") | |
608 | DRV(tekpower_tp4000zc, TEKPOWER_TP4000ZC, "tekpower-tp4000zc", "TekPower TP4000ZC") | |
609 | DRV(metex_me31, METEX_ME31, "metex-me31", "Metex ME-31") | |
610 | DRV(peaktech_3410, PEAKTECH_3410, "peaktech-3410", "PeakTech 3410") | |
611 | DRV(mastech_mas345, MASTECH_MAS345, "mastech-mas345", "MASTECH MAS345") | |
612 | DRV(va_va18b, VA_VA18B, "va-va18b", "V&A VA18B") | |
613 | DRV(va_va40b, VA_VA40B, "va-va40b", "V&A VA40B") | |
614 | DRV(metex_m3640d, METEX_M3640D, "metex-m3640d", "Metex M-3640D") | |
615 | DRV(metex_m4650cr, METEX_M4650CR, "metex-m4650cr", "Metex M-4650CR") | |
616 | DRV(peaktech_4370, PEAKTECH_4370, "peaktech-4370", "PeakTech 4370") | |
617 | DRV(pce_pce_dm32, PCE_PCE_DM32, "pce-pce-dm32", "PCE PCE-DM32") | |
618 | DRV(radioshack_22_168, RADIOSHACK_22_168, "radioshack-22-168", "RadioShack 22-168") | |
619 | DRV(radioshack_22_805, RADIOSHACK_22_805, "radioshack-22-805", "RadioShack 22-805") | |
620 | DRV(radioshack_22_812, RADIOSHACK_22_812, "radioshack-22-812", "RadioShack 22-812") | |
621 | DRV(tecpel_dmm_8061_ser, TECPEL_DMM_8061_SER, "tecpel-dmm-8061-ser", "Tecpel DMM-8061 (UT-D02 cable)") | |
622 | DRV(voltcraft_m3650cr, VOLTCRAFT_M3650CR, "voltcraft-m3650cr", "Voltcraft M-3650CR") | |
623 | DRV(voltcraft_m3650d, VOLTCRAFT_M3650D, "voltcraft-m3650d", "Voltcraft M-3650D") | |
624 | DRV(voltcraft_m4650cr, VOLTCRAFT_M4650CR, "voltcraft-m4650cr", "Voltcraft M-4650CR") | |
625 | DRV(voltcraft_me42, VOLTCRAFT_ME42, "voltcraft-me42", "Voltcraft ME-42") | |
626 | DRV(voltcraft_vc820_ser, VOLTCRAFT_VC820_SER, "voltcraft-vc820-ser", "Voltcraft VC-820 (UT-D02 cable)") | |
627 | DRV(voltcraft_vc830_ser, VOLTCRAFT_VC830_SER, "voltcraft-vc830-ser", "Voltcraft VC-830 (UT-D02 cable)") | |
628 | DRV(voltcraft_vc840_ser, VOLTCRAFT_VC840_SER, "voltcraft-vc840-ser", "Voltcraft VC-840 (UT-D02 cable)") | |
629 | DRV(uni_t_ut60a_ser, UNI_T_UT60A_SER, "uni-t-ut60a-ser", "UNI-T UT60A (UT-D02 cable)") | |
630 | DRV(uni_t_ut60e_ser, UNI_T_UT60E_SER, "uni-t-ut60e-ser", "UNI-T UT60E (UT-D02 cable)") | |
631 | DRV(uni_t_ut60g_ser, UNI_T_UT60G_SER, "uni-t-ut60g-ser", "UNI-T UT60G (UT-D02 cable)") | |
632 | DRV(uni_t_ut61b_ser, UNI_T_UT61B_SER, "uni-t-ut61b-ser", "UNI-T UT61B (UT-D02 cable)") | |
633 | DRV(uni_t_ut61c_ser, UNI_T_UT61C_SER, "uni-t-ut61c-ser", "UNI-T UT61C (UT-D02 cable)") | |
634 | DRV(uni_t_ut61d_ser, UNI_T_UT61D_SER, "uni-t-ut61d-ser", "UNI-T UT61D (UT-D02 cable)") | |
635 | DRV(uni_t_ut61e_ser, UNI_T_UT61E_SER, "uni-t-ut61e-ser", "UNI-T UT61E (UT-D02 cable)") | |
636 | DRV(iso_tech_idm103n, ISO_TECH_IDM103N, "iso-tech-idm103n", "ISO-TECH IDM103N") | |
637 | DRV(tenma_72_7745_ser, TENMA_72_7745_SER, "tenma-72-7745-ser", "Tenma 72-7745 (UT-D02 cable)") | |
638 | DRV(tenma_72_7750_ser, TENMA_72_7750_SER, "tenma-72-7750-ser", "Tenma 72-7750 (UT-D02 cable)") | |
639 | DRV(brymen_bm25x_ser, BRYMEN_BM25X_SER, "brymen-bm25x-ser", "Brymen BM25x (BC20X cable)") |